diff --git a/CHANGELOG.md b/CHANGELOG.md index 04bd252..0ea4ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Move to stable MSRV 1.85 + ## [0.7.0] - 2024-10-21 ### Added @@ -18,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add network version to handshake messages - Add Ray-ID to MessageInfo for message tracking - Add warning when discarding incomplete messages -- Add tracing when broadcasting to an eclipsed network +- Add tracing when broadcasting to an eclipsed network ### Fixed @@ -26,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix ObjectTransmissionInformation deserialization - Fix duplicate processing for messages with different RaptorQ configurations - Fix idle nodes removal on maintainance -- Fix `find_new_nodes` to query the proper buckets +- Fix `find_new_nodes` to query the proper buckets ### Changed @@ -61,22 +65,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.5.0] - 2023-05-17 ### Added + - Add network blocklist implementation [#117] -### Changed +### Changed + - Change `Peer::new` to return a Result [#115] - Change `blake2` dependency from `0.9` to `0.10` [#115] ## [0.4.1] - 2022-07-27 ### Added + - Remove idle nodes during bucket mantainance [#108] ### Fixed + - Use provided nonce instead of regenerate it [#110] - Network bootstrap after being disconnected [#112] ## [0.4.0] - 2022-07-06 + ### Added - Add `kadcast::Config` [#96] @@ -92,6 +101,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Dupemap cache expiring [#101] ## [0.3.0] - 2022-01-07 + ### Added - Add network transport configuration [#72] [#76] @@ -107,7 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deadlock in `RWLock.write()` [#80] - Preserve propagation in some edge-corner cases -- Messages from buckets full are correctly handled +- Messages from buckets full are correctly handled - Empty payload NodesMessage decoding [#90] ## [0.2.0] - 2021-12-16 @@ -175,7 +185,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [0.7.0]: https://github.com/dusk-network/kadcast/compare/v0.6.1...v0.7.0 [0.6.1]: https://github.com/dusk-network/kadcast/compare/v0.6.0...v0.6.1 [0.6.0]: https://github.com/dusk-network/kadcast/compare/v0.5.0...v0.6.0 -[0.5.1]: https://github.com/dusk-network/kadcast/compare/v0.4.1...v0.5.0 +[0.5.0]: https://github.com/dusk-network/kadcast/compare/v0.4.1...v0.5.0 [0.4.1]: https://github.com/dusk-network/kadcast/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/dusk-network/kadcast/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/dusk-network/kadcast/compare/v0.2.0...v0.3.0 diff --git a/Cargo.toml b/Cargo.toml index 8fb5a70..94da17c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,13 +10,23 @@ license = "MPL-2.0" repository = "https://github.com/dusk-network/kadcast" publish = true +rust-version = "1.85" + exclude = [".git*", "ARCHITECTURE.md", "architecture.jpg"] [dependencies] arrayvec = "0.7" blake2 = "0.10" rand = "0.8" -tokio = { version = "1", features = ["rt", "net", "sync", "time", "io-std", "rt-multi-thread", "macros"] } +tokio = { version = "1", features = [ + "rt", + "net", + "sync", + "time", + "io-std", + "rt-multi-thread", + "macros", +] } raptorq = { version = "2.0", optional = true } tracing = "0.1" itertools = "0.10" @@ -35,7 +45,7 @@ tracing-subscriber = "0.2" toml = "0.5" [features] -default = [ "raptorq" ] +default = ["raptorq"] diagnostics = [] [[example]] diff --git a/examples/main.rs b/examples/main.rs index 918b2dd..aa88a0f 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -11,13 +11,6 @@ use clap::{App, Arg}; use kadcast::config::Config; use kadcast::{MessageInfo, NetworkListen, Peer}; use rustc_tools_util::{get_version_info, VersionInfo}; -use serde_derive::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -struct General { - kadcast: kadcast::config::Config, -} - #[tokio::main] pub async fn main() -> Result<(), Box> { let crate_info = get_version_info!(); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index aecbe3c..73cb934 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-05-22" +channel = "stable" components = ["rustfmt", "clippy"] diff --git a/rustfmt.toml b/rustfmt.toml index 2b1ff3b..9a2d1e7 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,2 @@ max_width = 80 newline_style = "Unix" -wrap_comments = true diff --git a/src/encoding/header.rs b/src/encoding/header.rs index 7bca372..5635555 100644 --- a/src/encoding/header.rs +++ b/src/encoding/header.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use std::io::{self, Error, ErrorKind, Read, Write}; +use std::io::{self, Error, Read, Write}; use super::Marshallable; use crate::{kbucket::BinaryID, K_ID_LEN_BYTES, K_NONCE_LEN}; @@ -26,7 +26,7 @@ impl Header { impl Marshallable for Header { fn marshal_binary(&self, writer: &mut W) -> io::Result<()> { if !self.binary_id.verify_nonce() { - return Err(Error::new(ErrorKind::Other, "Invalid Nonce")); + return Err(Error::other("Invalid Nonce")); } writer.write_all(self.binary_id.as_binary())?; writer.write_all(self.binary_id.nonce())?; diff --git a/src/encoding/message.rs b/src/encoding/message.rs index e5c3bb8..7d9a5e5 100644 --- a/src/encoding/message.rs +++ b/src/encoding/message.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use std::io::{self, Error, ErrorKind, Read, Write}; +use std::io::{self, Error, Read, Write}; use semver::Version; @@ -159,10 +159,10 @@ impl Marshallable for Message { let payload = BroadcastPayload::unmarshal_binary(reader)?; Ok(Message::broadcast(header, payload)) } - unknown => Err(Error::new( - ErrorKind::Other, - format!("Invalid message type: '{}'", unknown), - )), + unknown => Err(Error::other(format!( + "Invalid message type: '{}'", + unknown + ))), } } } diff --git a/src/kbucket.rs b/src/kbucket.rs index b50149d..4f9b20d 100644 --- a/src/kbucket.rs +++ b/src/kbucket.rs @@ -12,7 +12,7 @@ pub use bucket::InsertOk; pub use bucket::{NodeInsertError, NodeInsertOk}; use itertools::Itertools; pub use key::MAX_BUCKET_HEIGHT; -pub use key::{BinaryID, BinaryKey, BinaryNonce}; +pub use key::{BinaryID, BinaryKey}; pub use node::Node; use std::collections::hash_map::Entry; use tracing::info; @@ -35,7 +35,7 @@ impl Tree { pub fn insert( &mut self, node: Node, - ) -> Result, InsertError> { + ) -> Result, InsertError> { if self.root().network_id != node.network_id { return Err(NodeInsertError::MismatchNetwork(node)); } @@ -48,7 +48,7 @@ impl Tree { pub fn refresh( &mut self, node: Node, - ) -> Result, InsertError> { + ) -> Result, InsertError> { if self.root().network_id != node.network_id { return Err(NodeInsertError::MismatchNetwork(node)); } @@ -59,10 +59,10 @@ impl Tree { } fn get_or_create_bucket(&mut self, height: BucketHeight) -> &mut Bucket { - return match self.buckets.entry(height) { + match self.buckets.entry(height) { Entry::Occupied(o) => o.into_mut(), Entry::Vacant(v) => v.insert(Bucket::new(self.config)), - }; + } } // iter the buckets (up to max_height, inclusive) and pick at most Beta @@ -162,7 +162,7 @@ impl Tree { pub(crate) fn is_bucket_full(&self, height: BucketHeight) -> bool { self.buckets .get(&height) - .map_or(false, |bucket| bucket.is_full()) + .is_some_and(|bucket| bucket.is_full()) } pub(crate) fn bucket_size(&self, height: BucketHeight) -> usize { diff --git a/src/kbucket/bucket.rs b/src/kbucket/bucket.rs index 10890bf..a5d810b 100644 --- a/src/kbucket/bucket.rs +++ b/src/kbucket/bucket.rs @@ -153,7 +153,7 @@ impl Bucket { pub fn insert( &mut self, node: Node, - ) -> Result, InsertError> { + ) -> Result, InsertError> { if !node.id().verify_nonce() { return Err(NodeInsertError::Invalid(node)); } @@ -199,7 +199,7 @@ impl Bucket { pub fn refresh( &mut self, node: Node, - ) -> Result, InsertError> { + ) -> Result, InsertError> { if !node.id().verify_nonce() { return Err(NodeInsertError::Invalid(node)); } @@ -243,7 +243,7 @@ impl Bucket { /// Checks if the bucket has at least one idle node. pub(crate) fn has_idle(&self) -> bool { - self.nodes.first().map_or(false, |n| { + self.nodes.first().is_some_and(|n| { n.seen_at.elapsed() > self.bucket_config.bucket_ttl }) } @@ -286,13 +286,12 @@ impl Bucket { let node_idx = self.nodes.iter().position(|s| s.id().as_binary() == id)?; - self.nodes.pop_at(node_idx).map(|removed| { + self.nodes.pop_at(node_idx).inspect(|_| { if let Some(pending) = self.pending_node.take() { if pending.is_alive(self.bucket_config.node_ttl) { self.nodes.push(pending); } } - removed }) } } diff --git a/src/kbucket/key.rs b/src/kbucket/key.rs index c8bc744..82ff670 100644 --- a/src/kbucket/key.rs +++ b/src/kbucket/key.rs @@ -127,7 +127,7 @@ impl BinaryID { if ret.verify_nonce() { Ok(ret) } else { - Err(io::Error::new(io::ErrorKind::Other, "Invalid Nonce")) + Err(io::Error::other("Invalid Nonce")) } } @@ -177,7 +177,7 @@ impl BinaryID { where I: Iterator, { - bytes.next().map_or(false, |b| { + bytes.next().is_some_and(|b| { if difficulty <= 8 { b.trailing_zeros() as usize >= difficulty } else if b != &0 { diff --git a/src/transport/encoding/raptorq/decoder.rs b/src/transport/encoding/raptorq/decoder.rs index 68c7d6d..9449699 100644 --- a/src/transport/encoding/raptorq/decoder.rs +++ b/src/transport/encoding/raptorq/decoder.rs @@ -157,12 +157,9 @@ impl Decoder for RaptorQDecoder { }) } Err(e) => { - return Err(io::Error::new( - io::ErrorKind::Other, - format!( - "Invalid transmission info {e:?}", - ), - )); + return Err(io::Error::other(format!( + "Invalid transmission info {e:?}", + ))); } } } @@ -213,7 +210,7 @@ impl Decoder for RaptorQDecoder { // cache with new status. This // will drop useless Decoder and avoid // to propagate already processed messages - .map(|decoded| { + .inspect(|_decoded| { self.cache.insert( ray_id, CacheStatus::Processed( @@ -221,7 +218,6 @@ impl Decoder for RaptorQDecoder { ), ); trace!("> Broadcast message decoded!"); - decoded }) } }; diff --git a/src/transport/sockets.rs b/src/transport/sockets.rs index 20d0e43..81b32df 100644 --- a/src/transport/sockets.rs +++ b/src/transport/sockets.rs @@ -82,7 +82,7 @@ impl MultipleOutSocket { let send = timeout(self.udp_send_retry_interval, send_fn) .await - .map_err(|_| io::Error::new(io::ErrorKind::Other, "TIMEOUT")); + .map_err(|_| io::Error::other("TIMEOUT")); match send { Ok(Ok(_)) => {