Skip to content

Commit

Permalink
fix(node): initialize records_by_bucket properly
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Nov 13, 2024
1 parent 72727ec commit 94127b9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sn_networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,23 @@ impl NodeRecordStore {

let records = Self::update_records_from_an_existing_store(&config, &encryption_details);

// Initialize records_by_bucket
let mut records_by_bucket = HashMap::new();
for (addr, _record_type) in records.values() {
let distance = self.local_address.distance(&addr);
let bucket = distance.ilog2().unwrap_or_default();
records_by_bucket
.entry(bucket)
.or_default()
.insert(key.clone());
}

let cache_size = config.records_cache_size;
let mut record_store = NodeRecordStore {
local_address: NetworkAddress::from_peer(local_id),
config,
records,
records_by_bucket: HashMap::new(),
records_by_bucket,
records_cache: RecordCache::new(cache_size),
network_event_sender,
local_swarm_cmd_sender: swarm_cmd_sender,
Expand Down

0 comments on commit 94127b9

Please sign in to comment.