diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs index 7abc723c4047e293fa26dd45b271ac84fa5f65d6..5421db8194456fd66f1eb30a786bcf32949ea210 100644 --- a/substrate/client/network/src/discovery.rs +++ b/substrate/client/network/src/discovery.rs @@ -716,6 +716,8 @@ impl NetworkBehaviour for DiscoveryBehaviour { } } + // Will be removed below when we receive + // `FinishedWithNoAdditionalRecord`. self.records_to_publish.insert(id, r.record.clone()); DiscoveryOut::ValueFound( @@ -726,13 +728,14 @@ impl NetworkBehaviour for DiscoveryBehaviour { Ok(GetRecordOk::FinishedWithNoAdditionalRecord { cache_candidates, }) => { - if cache_candidates.is_empty() { - continue - } - - // Put the record to the `cache_candidates` that are nearest to the - // record key from our point of view of the network. + // We always need to remove the record to not leak any data! if let Some(record) = self.records_to_publish.remove(&id) { + if cache_candidates.is_empty() { + continue + } + + // Put the record to the `cache_candidates` that are nearest to + // the record key from our point of view of the network. if let Some(kad) = self.kademlia.as_mut() { kad.put_record_to( record,