diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 116e85c7849..e29de924ae6 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -32,6 +32,9 @@ - Refactor gossipsub with in-place negative-score peer removal. See [PR 6209](https://github.com/libp2p/rust-libp2p/pull/6209). +- Avoid direct casting from u128 to u64. + See [PR 6211](https://github.com/libp2p/rust-libp2p/pull/6211). + ## 0.49.2 - Relax `Behaviour::with_metrics` requirements, do not require DataTransform and TopicSubscriptionFilter to also impl Default diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 521b603efad..cdf160b4aaf 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -183,7 +183,7 @@ enum PublishConfig { /// A strictly linearly increasing sequence number. /// -/// We start from the current time as unix timestamp in milliseconds. +/// We start from the current time as unix timestamp in nanoseconds. #[derive(Debug)] struct SequenceNumber(u64); @@ -194,7 +194,10 @@ impl SequenceNumber { .expect("time to be linear") .as_nanos(); - Self(unix_timestamp as u64) + Self( + u64::try_from(unix_timestamp) + .expect("timestamp in nanos since UNIX_EPOCH should fit in u64"), + ) } fn next(&mut self) -> u64 {