Skip to content

Conversation

skaunov
Copy link
Contributor

@skaunov skaunov commented Oct 10, 2025

Description

superseeds #6176, see #6176 (comment) for some details.

@skaunov skaunov changed the title fix[kad]: enable putting Record with None publisher in a confus… fix: enable putting Record with None publisher in a confus… Oct 10, 2025
@jxs jxs changed the title fix: enable putting Record with None publisher in a confus… feat(kad): enable putting Record without publisher Oct 20, 2025
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, and thanks for the cleaned up version.
left some suggestions

Comment on lines +873 to +875
if record.publisher.is_some() {
record.publisher = Some(*self.kbuckets.local_key().preimage())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if record.publisher.is_some() {
record.publisher = Some(*self.kbuckets.local_key().preimage())
}
record.publisher = record.publisher.map(|| Some(*self.kbuckets.local_key().preimage()))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm absolutely with you on an improving, so could you explain to me some benefits of this nit? I mean to my eye the former is better because map which fully disregards the thing it "maps" is confusing and the former version better convey semantics of what goings on: it doesn't matter what was in the Option - it will be changed to the value from the structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if the aim is to have one less allocation would keeping if condition and .replace inside of it help? Instead of assigning the new value... Actually I have this question for some time already: how much better such approach or it's just optimized away. But savings are so insignificant in these cases I had no chance to ask yet.

Comment on lines +567 to +568
// this test relies on counting republished `Record` against `records.len()`
records.retain(|r| r.publisher.is_some());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we then add a new test for new_anonymous?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not get any new ideas since #6176 (comment).

Notes & open questions

I don't have a fine test for this in mind as it doesn't really do anything (because replication context doesn't yield an event). Simultaneously I'm not really satisfied with the approach I took to adapt/fix the test (retaining only Record with publisher: Some); but I need a hint if that's possible to do better due to the same fact of how silent replication is.

Co-authored-by: João Oliveira <hello@jxs.pt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants