-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gossipsub): prevent erroneously duplicate message IDs #3716
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the title and PR description, let me know if I understood the problem and fix correctly!
cc @divagant-martian In case you are also upgrading to 0.51.2 already. |
Co-authored-by: Thomas Eizinger <[email protected]>
Lockfile needs updating! |
We should never need to clone this, it might break the uniqueness guarantee of sequence numbers.
Basic data type are easily handled the wrong way because they implement Copy. This newtype doesn't implement Copy and increments every time to access the sequence number.
I've pushed an improved fix that should make handling this slightly safer. cc @AgeManning I've also changed this to start with the current time. The thinking was that if we want to be strictly increasing, I also chose to |
cc @MarcoPolo This PR changes our implementation to be the exact same as go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep this makes sense to me, the panic at u64::max() is for someone living 600k years in the future's problem (if they can keep a libp2p node running that long without updating :).)
This also doesn't effect us as we don't use sequence numbers, so all good from our end, thanks for the ping :).
Thank you @dariusc93 for the initial discovery of the bug and the pull request. |
Thanks @dariusc93 for debugging and proposing a patch! @thomaseizinger shall I cut a new patch release already, or do you want to wait for #3625? |
Description
Previously, we only mutably borrowed the
last_seq_no
in the current scope but did not modify the underlying number. This is becauseu64
is copy and callingwrapping_add
consumesself
so the compiler just copied it. We introduce a new-type instead that is notCopy
.Additionally,
wrapping_add
and initializing with a random u64 might actually warp the number and thus not give us sequential numbers as intended in #3551. To solve this, we initialize with the current unix timestamp in nanoseconds. This allows a node to publish 1000000 messages a second and still not reuse sequence numbers even after a restart / re-initialization of the configuration. This is also what the go implementation does.Resolves #3714.
Co-authored-by: Thomas Eizinger [email protected]
Notes & open questions
Change checklist