signed repair request test fixes/cleanup (#28691)
This commit is contained in:
parent
ad24e37cc0
commit
e10d958352
|
@ -775,7 +775,10 @@ mod test {
|
||||||
},
|
},
|
||||||
solana_ledger::{blockstore::make_many_slot_entries, get_tmp_ledger_path},
|
solana_ledger::{blockstore::make_many_slot_entries, get_tmp_ledger_path},
|
||||||
solana_runtime::{accounts_background_service::AbsRequestSender, bank_forks::BankForks},
|
solana_runtime::{accounts_background_service::AbsRequestSender, bank_forks::BankForks},
|
||||||
solana_sdk::{hash::Hash, signature::Keypair},
|
solana_sdk::{
|
||||||
|
hash::Hash,
|
||||||
|
signature::{Keypair, Signer},
|
||||||
|
},
|
||||||
solana_streamer::socket::SocketAddrSpace,
|
solana_streamer::socket::SocketAddrSpace,
|
||||||
std::collections::HashMap,
|
std::collections::HashMap,
|
||||||
trees::tr,
|
trees::tr,
|
||||||
|
@ -959,10 +962,11 @@ mod test {
|
||||||
fn new(slot_to_query: Slot) -> Self {
|
fn new(slot_to_query: Slot) -> Self {
|
||||||
assert!(slot_to_query >= MAX_ANCESTOR_RESPONSES as Slot);
|
assert!(slot_to_query >= MAX_ANCESTOR_RESPONSES as Slot);
|
||||||
let vote_simulator = VoteSimulator::new(3);
|
let vote_simulator = VoteSimulator::new(3);
|
||||||
let responder_node = Node::new_localhost();
|
let keypair = Keypair::new();
|
||||||
|
let responder_node = Node::new_localhost_with_pubkey(&keypair.pubkey());
|
||||||
let cluster_info = ClusterInfo::new(
|
let cluster_info = ClusterInfo::new(
|
||||||
responder_node.info.clone(),
|
responder_node.info.clone(),
|
||||||
Arc::new(Keypair::new()),
|
Arc::new(keypair),
|
||||||
SocketAddrSpace::Unspecified,
|
SocketAddrSpace::Unspecified,
|
||||||
);
|
);
|
||||||
let responder_serve_repair =
|
let responder_serve_repair =
|
||||||
|
@ -1044,9 +1048,10 @@ mod test {
|
||||||
let ancestor_hashes_request_statuses = Arc::new(DashMap::new());
|
let ancestor_hashes_request_statuses = Arc::new(DashMap::new());
|
||||||
let ancestor_hashes_request_socket = Arc::new(UdpSocket::bind("0.0.0.0:0").unwrap());
|
let ancestor_hashes_request_socket = Arc::new(UdpSocket::bind("0.0.0.0:0").unwrap());
|
||||||
let epoch_schedule = *bank_forks.read().unwrap().root_bank().epoch_schedule();
|
let epoch_schedule = *bank_forks.read().unwrap().root_bank().epoch_schedule();
|
||||||
|
let keypair = Keypair::new();
|
||||||
let requester_cluster_info = Arc::new(ClusterInfo::new(
|
let requester_cluster_info = Arc::new(ClusterInfo::new(
|
||||||
Node::new_localhost().info,
|
Node::new_localhost_with_pubkey(&keypair.pubkey()).info,
|
||||||
Arc::new(Keypair::new()),
|
Arc::new(keypair),
|
||||||
SocketAddrSpace::Unspecified,
|
SocketAddrSpace::Unspecified,
|
||||||
));
|
));
|
||||||
let requester_serve_repair =
|
let requester_serve_repair =
|
||||||
|
|
|
@ -1375,10 +1375,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_signed_packet() {
|
fn test_verify_signed_packet() {
|
||||||
let keypair = Keypair::new();
|
let my_keypair = Keypair::new();
|
||||||
let other_keypair = Keypair::new();
|
let other_keypair = Keypair::new();
|
||||||
let my_id = Pubkey::new_unique();
|
|
||||||
let other_id = Pubkey::new_unique();
|
|
||||||
|
|
||||||
fn sign_packet(packet: &mut Packet, keypair: &Keypair) {
|
fn sign_packet(packet: &mut Packet, keypair: &Keypair) {
|
||||||
let signable_data = [
|
let signable_data = [
|
||||||
|
@ -1392,16 +1390,21 @@ mod tests {
|
||||||
|
|
||||||
// well formed packet
|
// well formed packet
|
||||||
let packet = {
|
let packet = {
|
||||||
let header = RepairRequestHeader::new(keypair.pubkey(), my_id, timestamp(), 678);
|
let header = RepairRequestHeader::new(
|
||||||
|
my_keypair.pubkey(),
|
||||||
|
other_keypair.pubkey(),
|
||||||
|
timestamp(),
|
||||||
|
678,
|
||||||
|
);
|
||||||
let slot = 239847;
|
let slot = 239847;
|
||||||
let request = RepairProtocol::Orphan { header, slot };
|
let request = RepairProtocol::Orphan { header, slot };
|
||||||
let mut packet = Packet::from_data(None, &request).unwrap();
|
let mut packet = Packet::from_data(None, &request).unwrap();
|
||||||
sign_packet(&mut packet, &keypair);
|
sign_packet(&mut packet, &my_keypair);
|
||||||
packet
|
packet
|
||||||
};
|
};
|
||||||
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
||||||
assert!(ServeRepair::verify_signed_packet(
|
assert!(ServeRepair::verify_signed_packet(
|
||||||
&my_id,
|
&other_keypair.pubkey(),
|
||||||
&packet,
|
&packet,
|
||||||
&request,
|
&request,
|
||||||
&mut ServeRepairStats::default(),
|
&mut ServeRepairStats::default(),
|
||||||
|
@ -1409,17 +1412,25 @@ mod tests {
|
||||||
|
|
||||||
// recipient mismatch
|
// recipient mismatch
|
||||||
let packet = {
|
let packet = {
|
||||||
let header = RepairRequestHeader::new(keypair.pubkey(), other_id, timestamp(), 678);
|
let header = RepairRequestHeader::new(
|
||||||
|
my_keypair.pubkey(),
|
||||||
|
other_keypair.pubkey(),
|
||||||
|
timestamp(),
|
||||||
|
678,
|
||||||
|
);
|
||||||
let slot = 239847;
|
let slot = 239847;
|
||||||
let request = RepairProtocol::Orphan { header, slot };
|
let request = RepairProtocol::Orphan { header, slot };
|
||||||
let mut packet = Packet::from_data(None, &request).unwrap();
|
let mut packet = Packet::from_data(None, &request).unwrap();
|
||||||
sign_packet(&mut packet, &keypair);
|
sign_packet(&mut packet, &my_keypair);
|
||||||
packet
|
packet
|
||||||
};
|
};
|
||||||
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
||||||
let mut stats = ServeRepairStats::default();
|
let mut stats = ServeRepairStats::default();
|
||||||
assert!(!ServeRepair::verify_signed_packet(
|
assert!(!ServeRepair::verify_signed_packet(
|
||||||
&my_id, &packet, &request, &mut stats,
|
&my_keypair.pubkey(),
|
||||||
|
&packet,
|
||||||
|
&request,
|
||||||
|
&mut stats,
|
||||||
));
|
));
|
||||||
assert_eq!(stats.err_id_mismatch, 1);
|
assert_eq!(stats.err_id_mismatch, 1);
|
||||||
|
|
||||||
|
@ -1427,23 +1438,36 @@ mod tests {
|
||||||
let packet = {
|
let packet = {
|
||||||
let time_diff_ms = u64::try_from(SIGNED_REPAIR_TIME_WINDOW.as_millis() * 2).unwrap();
|
let time_diff_ms = u64::try_from(SIGNED_REPAIR_TIME_WINDOW.as_millis() * 2).unwrap();
|
||||||
let old_timestamp = timestamp().saturating_sub(time_diff_ms);
|
let old_timestamp = timestamp().saturating_sub(time_diff_ms);
|
||||||
let header = RepairRequestHeader::new(keypair.pubkey(), my_id, old_timestamp, 678);
|
let header = RepairRequestHeader::new(
|
||||||
|
my_keypair.pubkey(),
|
||||||
|
other_keypair.pubkey(),
|
||||||
|
old_timestamp,
|
||||||
|
678,
|
||||||
|
);
|
||||||
let slot = 239847;
|
let slot = 239847;
|
||||||
let request = RepairProtocol::Orphan { header, slot };
|
let request = RepairProtocol::Orphan { header, slot };
|
||||||
let mut packet = Packet::from_data(None, &request).unwrap();
|
let mut packet = Packet::from_data(None, &request).unwrap();
|
||||||
sign_packet(&mut packet, &keypair);
|
sign_packet(&mut packet, &my_keypair);
|
||||||
packet
|
packet
|
||||||
};
|
};
|
||||||
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
||||||
let mut stats = ServeRepairStats::default();
|
let mut stats = ServeRepairStats::default();
|
||||||
assert!(!ServeRepair::verify_signed_packet(
|
assert!(!ServeRepair::verify_signed_packet(
|
||||||
&my_id, &packet, &request, &mut stats,
|
&other_keypair.pubkey(),
|
||||||
|
&packet,
|
||||||
|
&request,
|
||||||
|
&mut stats,
|
||||||
));
|
));
|
||||||
assert_eq!(stats.err_time_skew, 1);
|
assert_eq!(stats.err_time_skew, 1);
|
||||||
|
|
||||||
// bad signature
|
// bad signature
|
||||||
let packet = {
|
let packet = {
|
||||||
let header = RepairRequestHeader::new(keypair.pubkey(), my_id, timestamp(), 678);
|
let header = RepairRequestHeader::new(
|
||||||
|
my_keypair.pubkey(),
|
||||||
|
other_keypair.pubkey(),
|
||||||
|
timestamp(),
|
||||||
|
678,
|
||||||
|
);
|
||||||
let slot = 239847;
|
let slot = 239847;
|
||||||
let request = RepairProtocol::Orphan { header, slot };
|
let request = RepairProtocol::Orphan { header, slot };
|
||||||
let mut packet = Packet::from_data(None, &request).unwrap();
|
let mut packet = Packet::from_data(None, &request).unwrap();
|
||||||
|
@ -1453,7 +1477,10 @@ mod tests {
|
||||||
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
let request: RepairProtocol = packet.deserialize_slice(..).unwrap();
|
||||||
let mut stats = ServeRepairStats::default();
|
let mut stats = ServeRepairStats::default();
|
||||||
assert!(!ServeRepair::verify_signed_packet(
|
assert!(!ServeRepair::verify_signed_packet(
|
||||||
&my_id, &packet, &request, &mut stats,
|
&other_keypair.pubkey(),
|
||||||
|
&packet,
|
||||||
|
&request,
|
||||||
|
&mut stats,
|
||||||
));
|
));
|
||||||
assert_eq!(stats.err_sig_verify, 1);
|
assert_eq!(stats.err_sig_verify, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue