diff --git a/core/src/ancestor_hashes_service.rs b/core/src/ancestor_hashes_service.rs index 38e7aac8b45bf1..ec802decc3083f 100644 --- a/core/src/ancestor_hashes_service.rs +++ b/core/src/ancestor_hashes_service.rs @@ -783,7 +783,10 @@ mod test { }, solana_ledger::{blockstore::make_many_slot_entries, get_tmp_ledger_path}, 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, std::collections::HashMap, trees::tr, @@ -967,10 +970,11 @@ mod test { fn new(slot_to_query: Slot) -> Self { assert!(slot_to_query >= MAX_ANCESTOR_RESPONSES as Slot); 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( responder_node.info.clone(), - Arc::new(Keypair::new()), + Arc::new(keypair), SocketAddrSpace::Unspecified, ); let responder_serve_repair = Arc::new(RwLock::new(ServeRepair::new( @@ -1055,9 +1059,10 @@ mod test { 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 epoch_schedule = *bank_forks.read().unwrap().root_bank().epoch_schedule(); + let keypair = Keypair::new(); let requester_cluster_info = Arc::new(ClusterInfo::new( - Node::new_localhost().info, - Arc::new(Keypair::new()), + Node::new_localhost_with_pubkey(&keypair.pubkey()).info, + Arc::new(keypair), SocketAddrSpace::Unspecified, )); let requester_serve_repair = diff --git a/core/src/serve_repair.rs b/core/src/serve_repair.rs index 4be6b4920067d7..7d34af093f5f34 100644 --- a/core/src/serve_repair.rs +++ b/core/src/serve_repair.rs @@ -1450,10 +1450,8 @@ mod tests { #[test] fn test_verify_signed_packet() { - let keypair = Keypair::new(); + let my_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) { let signable_data = [ @@ -1467,16 +1465,21 @@ mod tests { // well formed 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 request = RepairProtocol::Orphan { header, slot }; let mut packet = Packet::from_data(None, &request).unwrap(); - sign_packet(&mut packet, &keypair); + sign_packet(&mut packet, &my_keypair); packet }; let request: RepairProtocol = packet.deserialize_slice(..).unwrap(); assert!(ServeRepair::verify_signed_packet( - &my_id, + &other_keypair.pubkey(), &packet, &request, &mut ServeRepairStats::default(), @@ -1484,17 +1487,25 @@ mod tests { // recipient mismatch 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 request = RepairProtocol::Orphan { header, slot }; let mut packet = Packet::from_data(None, &request).unwrap(); - sign_packet(&mut packet, &keypair); + sign_packet(&mut packet, &my_keypair); packet }; let request: RepairProtocol = packet.deserialize_slice(..).unwrap(); let mut stats = ServeRepairStats::default(); 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); @@ -1502,23 +1513,36 @@ mod tests { let packet = { 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 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 request = RepairProtocol::Orphan { header, slot }; let mut packet = Packet::from_data(None, &request).unwrap(); - sign_packet(&mut packet, &keypair); + sign_packet(&mut packet, &my_keypair); packet }; let request: RepairProtocol = packet.deserialize_slice(..).unwrap(); let mut stats = ServeRepairStats::default(); 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); // bad signature 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 request = RepairProtocol::Orphan { header, slot }; let mut packet = Packet::from_data(None, &request).unwrap(); @@ -1528,7 +1552,10 @@ mod tests { let request: RepairProtocol = packet.deserialize_slice(..).unwrap(); let mut stats = ServeRepairStats::default(); 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); }