Skip to content

Commit 82c7d6d

Browse files
committed
address review
1 parent 8783cf9 commit 82c7d6d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

protocols/kad/src/behaviour.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,10 @@ where
870870
mut record: Record,
871871
quorum: Quorum,
872872
) -> Result<QueryId, store::Error> {
873-
if record.publisher.is_some() {
874-
record.publisher = Some(*self.kbuckets.local_key().preimage())
875-
}
873+
record
874+
.publisher
875+
.and(Some(*self.kbuckets.local_key().preimage()));
876+
876877
self.store.put(record.clone())?;
877878
record.expires = record
878879
.expires

protocols/kad/src/behaviour/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,12 @@ fn get_record_not_found() {
557557
}))
558558
}
559559

560-
/// A node joining a fully connected network via three (ALPHA_VALUE) bootnodes
560+
/// A node joining a fully connected network via three (`ALPHA_VALUE`) bootnodes
561561
/// should be able to put a record to the X closest nodes of the network where X
562562
/// is equal to the configured replication factor.
563563
#[test]
564564
fn put_record() {
565-
fn prop(mut records: Vec<Record>, seed: Seed, filter_records: bool, drop_records: bool) {
566-
tracing::trace!("remove records without a publisher");
567-
// this test relies on counting republished `Record` against `records.len()`
568-
records.retain(|r| r.publisher.is_some());
569-
565+
fn prop(records: Vec<Record>, seed: Seed, filter_records: bool, drop_records: bool) {
570566
let mut rng = StdRng::from_seed(seed.0);
571567
let replication_factor =
572568
NonZeroUsize::new(rng.gen_range(1..(K_VALUE.get() / 2) + 1)).unwrap();
@@ -613,6 +609,8 @@ fn put_record() {
613609
#[allow(clippy::mutable_key_type)] // False positive, we never modify `Bytes`.
614610
let records = records
615611
.into_iter()
612+
// Exclude records without a publisher.
613+
.filter(|r| r.publisher.is_some())
616614
.take(num_total)
617615
.map(|mut r| {
618616
// We don't want records to expire prematurely, as they would

0 commit comments

Comments
 (0)