Skip to content
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): signed messages use monotonically increasing seq numbers #3551

Merged
merged 5 commits into from
Mar 14, 2023

Conversation

AgeManning
Copy link
Contributor

@AgeManning AgeManning commented Mar 6, 2023

Description

This modifies the gossipsub implementation to use monotonically increasing sequence numbers for signed messages (as dictated by the specification). There is a discussion about this in #3453. This change will make rust-libp2p gossipsub align with the go-implementation when messages are signed.

Messages will however still use randomized sequence numbers when messages are unsigned for security reasons (as discussed in the issue linked).

This shouldn't change any user-level API, only the seqno behavior. It is fully backwards compatible.

Resolves #3453.

@AgeManning AgeManning changed the title [Gossipsub] Monotonically increasing sequence numbers for signed messages fix: [Gossipsub] Monotonically increasing sequence numbers for signed messages Mar 6, 2023
@thomaseizinger thomaseizinger changed the title fix: [Gossipsub] Monotonically increasing sequence numbers for signed messages fix(gossipsub): use monotonically increasing sequence numbers for signed messages Mar 6, 2023
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks!

I think this deserves a changelog entry. Can you please add one?

@AgeManning
Copy link
Contributor Author

Yep sure, added (feel free to change format)

@thomaseizinger thomaseizinger changed the title fix(gossipsub): use monotonically increasing sequence numbers for signed messages fix(gossipsub): monotonically increasing seq numbers for signed messages Mar 6, 2023
@thomaseizinger thomaseizinger changed the title fix(gossipsub): monotonically increasing seq numbers for signed messages fix(gossipsub): signed messages use monotonically increasing seq numbers Mar 6, 2023
AgeManning and others added 2 commits March 6, 2023 13:58
@mergify
Copy link
Contributor

mergify bot commented Mar 10, 2023

This pull request has merge conflicts. Could you please resolve them @AgeManning? 🙏

@mergify mergify bot merged commit eb5e269 into libp2p:master Mar 14, 2023
mxinden added a commit that referenced this pull request Mar 23, 2023
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thanks for the work here.

@@ -190,6 +192,7 @@ impl From<MessageAuthenticity> for PublishConfig {
keypair,
author: public_key.to_peer_id(),
inline_key: key,
last_seq_no: rand::random(),
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, I don't think it actually matters: Why start with a random number and not the current timestamp as the go implementation does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure really. I think I have some innate aversion to giving out more information about ourselves than needed. Maybe also because I was lazy about finding out which timestamp to use in go, ms vs s etc.

Happy to change this, no real reason tbh, random just felt slightly safer, with no logical reason to back it up. :)

@@ -1,3 +1,10 @@
# 0.44.2 - unreleased
Copy link
Member

Choose a reason for hiding this comment

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

Missing Cargo.toml version bump. Thus a "ghost version". Will be fixed with #3668.

mergify bot pushed a commit that referenced this pull request Mar 23, 2023
mergify bot pushed a commit that referenced this pull request Apr 4, 2023
Previously, we only mutably borrowed the `last_seq_no` in the current scope but did not modify the underlying number. This is because `u64` is copy and calling `wrapping_add` consumes `self` so the compiler just copied it. We introduce a new-type instead that is not `Copy`.

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 <thomas@eizinger.io>

Pull-Request: #3716.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change sequence number in gossipsub to be linearly increasing
3 participants