-
Notifications
You must be signed in to change notification settings - Fork 957
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
Changes from all commits
aef5b12
0369ff9
b56aed2
e20265d
cb72b3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ mod tests; | |
#[derive(Clone)] | ||
pub enum MessageAuthenticity { | ||
/// Message signing is enabled. The author will be the owner of the key and the sequence number | ||
/// will be a random number. | ||
/// will be linearly increasing. | ||
Signed(Keypair), | ||
/// Message signing is disabled. | ||
/// | ||
|
@@ -155,6 +155,8 @@ enum PublishConfig { | |
keypair: Keypair, | ||
author: PeerId, | ||
inline_key: Option<Vec<u8>>, | ||
last_seq_no: u64, // This starts from a random number and increases then overflows (if | ||
// required) | ||
}, | ||
Author(PeerId), | ||
RandomAuthor, | ||
|
@@ -190,6 +192,7 @@ impl From<MessageAuthenticity> for PublishConfig { | |
keypair, | ||
author: public_key.to_peer_id(), | ||
inline_key: key, | ||
last_seq_no: rand::random(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. :) |
||
} | ||
} | ||
MessageAuthenticity::Author(peer_id) => PublishConfig::Author(peer_id), | ||
|
@@ -2749,18 +2752,21 @@ where | |
|
||
/// Constructs a [`RawMessage`] performing message signing if required. | ||
pub(crate) fn build_raw_message( | ||
&self, | ||
&mut self, | ||
topic: TopicHash, | ||
data: Vec<u8>, | ||
) -> Result<RawMessage, PublishError> { | ||
match &self.publish_config { | ||
match &mut self.publish_config { | ||
PublishConfig::Signing { | ||
ref keypair, | ||
author, | ||
inline_key, | ||
mut last_seq_no, | ||
} => { | ||
// Build and sign the message | ||
let sequence_number: u64 = rand::random(); | ||
// Increment the last sequence number | ||
last_seq_no = last_seq_no.wrapping_add(1); | ||
|
||
let sequence_number = last_seq_no; | ||
|
||
let signature = { | ||
let message = proto::Message { | ||
|
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.
Missing
Cargo.toml
version bump. Thus a "ghost version". Will be fixed with #3668.