Skip to content

Commit

Permalink
chore(node): updating verify_data_test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Nov 1, 2023
1 parent 9addc91 commit 4c803c0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sn_node/tests/verify_data_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ async fn verify_data_location() -> Result<()> {
fn print_node_close_groups(all_peers: &[PeerId]) {
let all_peers = all_peers.to_vec();
println!("\nNode close groups:");

let all_peers_hashset = all_peers.iter().cloned().collect::<HashSet<_>>();

for (node_index, peer) in all_peers.iter().enumerate() {
let node_index = node_index + 1;
let key = NetworkAddress::from_peer(*peer).as_kbucket_key();
let closest_peers =
sort_peers_by_key(&all_peers, &key, CLOSE_GROUP_SIZE).expect("failed to sort peer");
let closest_peers = sort_peers_by_key(&all_peers_hashset, &key, CLOSE_GROUP_SIZE)
.expect("failed to sort peer");
let closest_peers_idx = closest_peers
.iter()
.map(|&&peer| all_peers.iter().position(|&p| p == peer).unwrap() + 1)
Expand Down Expand Up @@ -181,16 +184,20 @@ async fn get_records_and_holders() -> Result<RecordHolders> {
// Verifies that the chunk is stored by the actual closest peers to the RecordKey
async fn verify_location(record_holders: &RecordHolders, all_peers: &[PeerId]) -> Result<()> {
let mut failed = HashMap::new();

let all_peers_hashset = all_peers.iter().cloned().collect::<HashSet<_>>();

let mut verification_attempts = 0;
while verification_attempts < VERIFICATION_ATTEMPTS {
failed.clear();
for (key, actual_holders_idx) in record_holders.iter() {
println!("Verifying {:?}", PrettyPrintRecordKey::from(key));
let record_key = KBucketKey::from(key.to_vec());
let expected_holders = sort_peers_by_key(all_peers, &record_key, CLOSE_GROUP_SIZE)?
.into_iter()
.cloned()
.collect::<BTreeSet<_>>();
let expected_holders =
sort_peers_by_key(&all_peers_hashset, &record_key, CLOSE_GROUP_SIZE)?
.into_iter()
.cloned()
.collect::<BTreeSet<_>>();

let actual_holders = actual_holders_idx
.iter()
Expand Down

0 comments on commit 4c803c0

Please sign in to comment.