Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signed repair request test fixes/cleanup (backport #28691) #28824

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions core/src/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down
55 changes: 41 additions & 14 deletions core/src/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -1467,58 +1465,84 @@ 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(),
));

// 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);

// outside time window
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();
Expand All @@ -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);
}
Expand Down