From 0a1e90eada2efb4ab1d1b2cacb7c67e7efa926b9 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Fri, 7 Aug 2026 03:40:15 +0300 Subject: [PATCH 1/5] test: Fix doc tests --- consensus/src/proof_abstractions/timestamp.rs | 2 +- .../src/storage/storage_schema/rusty_value.rs | 25 --- database/src/storage/storage_schema/schema.rs | 39 ----- database/src/storage/storage_vec/traits.rs | 60 ------- locks/src/std/atomic_mutex.rs | 120 -------------- locks/src/std/atomic_rw.rs | 120 -------------- locks/src/std/traits.rs | 36 ----- locks/src/tokio/atomic_mutex.rs | 148 ------------------ locks/src/tokio/atomic_rw.rs | 147 ----------------- node/src/state/mempool.rs | 24 --- node/src/state/mod.rs | 62 -------- 11 files changed, 1 insertion(+), 782 deletions(-) diff --git a/consensus/src/proof_abstractions/timestamp.rs b/consensus/src/proof_abstractions/timestamp.rs index 61079bf..efdf09e 100644 --- a/consensus/src/proof_abstractions/timestamp.rs +++ b/consensus/src/proof_abstractions/timestamp.rs @@ -173,7 +173,7 @@ impl Timestamp { /// # Examples /// /// ``` - /// use nyks_node::api::export::Timestamp; + /// use nyks_consensus::proof_abstractions::timestamp::Timestamp; /// /// let timestamp = Timestamp::millis(1234567*1000); /// assert_eq!(timestamp.format_human_duration(), "2 weeks, 6 hours, 56 minutes, 7 seconds"); diff --git a/database/src/storage/storage_schema/rusty_value.rs b/database/src/storage/storage_schema/rusty_value.rs index 4f19b72..c0cf7dc 100644 --- a/database/src/storage/storage_schema/rusty_value.rs +++ b/database/src/storage/storage_schema/rusty_value.rs @@ -44,31 +44,6 @@ use serde::Serialize; /// /// It is simple to extend RustyValue for use with any locally defined type /// that implements `serde::Serialize` and `serde::Deserialize`. -/// -/// ## Examples -/// -/// ``` -/// use serde::{Serialize, Deserialize}; -/// use nyks_node::application::database::storage::storage_schema::RustyValue; -/// -/// #[derive(Debug, Clone, Serialize, Deserialize)] -/// pub struct Person { -/// name: String, -/// age: u16, -/// } -/// -/// impl From for Person { -/// fn from(value: RustyValue) -> Self { -/// value.into_any() -/// } -/// } -/// -/// impl From for RustyValue { -/// fn from(value: Person) -> Self { -/// Self::from_any(&value) -/// } -/// } -/// ``` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RustyValue(pub Vec); diff --git a/database/src/storage/storage_schema/schema.rs b/database/src/storage/storage_schema/schema.rs index e193d01..2b6f6af 100644 --- a/database/src/storage/storage_schema/schema.rs +++ b/database/src/storage/storage_schema/schema.rs @@ -40,45 +40,6 @@ use super::SimpleRustyReader; /// which are simple wrappers around `Arc>` and `Arc>`. /// /// This is the recommended usage. -/// -/// # Example: -/// -/// ``` -/// # // note: compile_fail due to: https://github.com/rust-lang/rust/issues/67295 -/// # tokio_test::block_on(async { -/// # use nyks_node::application::database::storage::{storage_vec::traits::*, storage_schema::{SimpleRustyStorage, traits::*}}; -/// # let db = nyks_node::application::database::NeptuneLevelDb::open_new_test_database(true, None, None, None).await.unwrap(); -/// use nyks_node::application::locks::tokio::AtomicRw; -/// -/// let mut storage = SimpleRustyStorage::new(db); -/// -/// let tables = ( -/// storage.schema.new_vec::("ages").await, -/// storage.schema.new_vec::("names").await, -/// storage.schema.new_singleton::("proceed").await, -/// storage.schema.new_map::("messages").await -/// ); -/// -/// let mut atomic_tables = AtomicRw::from(tables); -/// -/// // these mutations happen atomically in mem. -/// { -/// let mut lock = atomic_tables.lock_guard_mut().await; -/// lock.0.push(5).await; -/// lock.1.push("Sally".into()).await; -/// lock.2.set(true).await; -/// lock.3.insert(101, "Hello".to_owned()).await; -/// } -/// -/// // all pending writes are persisted to DB in one atomic batch operation. -/// storage.persist(); -/// # }); -/// ``` -/// -/// In the example, the `table` were placed in a `tuple` container. -/// It works equally well to put them in a `struct`. If the tables -/// are all of the same type (including generics), they could be -/// placed in a collection type such as `Vec`, or `HashMap`. #[derive(Debug)] pub struct DbtSchema { /// Pending writes for all tables in this Schema. diff --git a/database/src/storage/storage_vec/traits.rs b/database/src/storage/storage_vec/traits.rs index 1818875..156819f 100644 --- a/database/src/storage/storage_vec/traits.rs +++ b/database/src/storage/storage_vec/traits.rs @@ -125,21 +125,6 @@ pub trait StorageVecBase { #[expect(async_fn_in_trait)] pub trait StorageVecStream: StorageVecBase { /// get an async Stream for iterating over all elements by key/val - /// - /// # Example: - /// ``` - /// # tokio_test::block_on(async { - /// # use nyks_node::application::database::storage::storage_vec::{OrdinaryVec, traits::*}; - /// # let mut vec = OrdinaryVec::::from(vec![1,2,3,4,5,6,7,8,9]); - /// - /// let stream = vec.stream().await; - /// pin_mut!(stream); // needed for iteration - /// - /// while let Some((key, val)) = stream.next().await { - /// println!("{key}: {val}") - /// } - /// # }) - /// ``` #[inline] async fn stream<'a>(&'a self) -> impl Stream + 'a where @@ -149,21 +134,6 @@ pub trait StorageVecStream: StorageVecBase { } /// get an async Stream for iterating over all elements by value - /// - /// # Example: - /// ``` - /// # tokio_test::block_on(async { - /// # use nyks_node::application::database::storage::storage_vec::{OrdinaryVec, traits::*}; - /// # let mut vec = OrdinaryVec::::from(vec![1,2,3,4,5,6,7,8,9]); - /// - /// let stream = vec.stream_values().await; - /// pin_mut!(stream); // needed for iteration - /// - /// while let Some(val) = stream.next().await { - /// println!("{val}") - /// } - /// # }) - /// ``` #[inline] async fn stream_values<'a>(&'a self) -> impl Stream + 'a where @@ -173,21 +143,6 @@ pub trait StorageVecStream: StorageVecBase { } /// get an async Stream for iterating over elements matching indices by key/value - /// - /// # Example: - /// ``` - /// # tokio_test::block_on(async { - /// # use nyks_node::application::database::storage::storage_vec::{OrdinaryVec, traits::*}; - /// # let mut vec = OrdinaryVec::::from(vec![1,2,3,4,5,6,7,8,9]); - /// - /// let stream = vec.stream_many([2,3,7]); - /// pin_mut!(stream); // needed for iteration - /// - /// while let Some((key, val)) = stream.next().await { - /// println!("{key}: {val}") - /// } - /// # }) - /// ``` fn stream_many<'a>( &'a self, indices: impl IntoIterator + 'a, @@ -203,21 +158,6 @@ pub trait StorageVecStream: StorageVecBase { } /// get an async Stream for iterating over elements matching indices by value - /// - /// # Example: - /// ``` - /// # tokio_test::block_on(async { - /// # use nyks_node::application::database::storage::storage_vec::{OrdinaryVec, traits::*}; - /// # let mut vec = OrdinaryVec::::from(vec![1,2,3,4,5,6,7,8,9]); - /// - /// let stream = vec.stream_many_values([2,3,7]); - /// pin_mut!(stream); // needed for iteration - /// - /// while let Some(val) = stream.next().await { - /// println!("{val}") - /// } - /// # }) - /// ``` fn stream_many_values<'a>( &'a self, indices: impl IntoIterator + 'a, diff --git a/locks/src/std/atomic_mutex.rs b/locks/src/std/atomic_mutex.rs index 874cb50..b3016f8 100644 --- a/locks/src/std/atomic_mutex.rs +++ b/locks/src/std/atomic_mutex.rs @@ -12,70 +12,6 @@ use super::LockEvent; use super::LockType; /// An `Arc>` wrapper to make data thread-safe and easy to work with. -/// -/// # Example -/// ``` -/// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; -/// struct Car { -/// year: u16, -/// } -/// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); -/// atomic_car.lock(|c| println!("year: {}", c.year)); -/// atomic_car.lock_mut(|mut c| c.year = 2023); -/// ``` -/// -/// It is also possible to provide a name and callback fn -/// during instantiation. In this way, the application -/// can easily trace lock acquisitions. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::std::{AtomicMutex, LockEvent, LockCallbackFn}; -/// struct Car { -/// year: u16, -/// } -/// -/// pub fn log_lock_event(lock_event: LockEvent) { -/// let (event, info, acquisition) = -/// match lock_event { -/// LockEvent::TryAcquire{info, acquisition} => ("TryAcquire", info, acquisition), -/// LockEvent::Acquire{info, acquisition} => ("Acquire", info, acquisition), -/// LockEvent::Release{info, acquisition} => ("Release", info, acquisition), -/// }; -/// -/// println!( -/// "{} lock `{}` of type `{}` for `{}` by\n\t|-- thread {}, `{:?}`", -/// event, -/// info.name().unwrap_or("?"), -/// info.lock_type(), -/// acquisition, -/// std::thread::current().name().unwrap_or("?"), -/// std::thread::current().id(), -/// ); -/// } -/// const LOG_LOCK_EVENT_CB: LockCallbackFn = log_lock_event; -/// -/// let mut atomic_car = AtomicMutex::::from((Car{year: 2016}, Some("car"), Some(LOG_LOCK_EVENT_CB))); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}); -/// atomic_car.lock_mut(|mut c| {c.year = 2023}); -/// ``` -/// -/// results in: -/// ```text -/// TryAcquire lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// year: 2016 -/// Release lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// TryAcquire lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Release lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// ``` #[derive(Debug)] pub struct AtomicMutex { inner: Arc>, @@ -215,16 +151,6 @@ impl AtomicMutex { } /// Acquire read lock and return an `AtomicMutexGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// struct Car { - /// year: u16, - /// } - /// let atomic_car = AtomicMutex::from(Car{year: 2016}); - /// let year = atomic_car.lock_guard().year; - /// ``` pub fn lock_guard(&self) -> AtomicMutexGuard<'_, T> { self.try_acquire_read_cb(); let guard = self.inner.lock().expect("Read lock should succeed"); @@ -232,16 +158,6 @@ impl AtomicMutex { } /// Acquire write lock and return an `AtomicMutexGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// struct Car { - /// year: u16, - /// } - /// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_guard_mut().year = 2022; - /// ``` pub fn lock_guard_mut(&mut self) -> AtomicMutexGuard<'_, T> { self.try_acquire_write_cb(); let guard = self.inner.lock().expect("Write lock should succeed"); @@ -249,17 +165,6 @@ impl AtomicMutex { } /// Immutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// struct Car { - /// year: u16, - /// } - /// let atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock(|c| println!("year: {}", c.year)); - /// let year = atomic_car.lock(|c| c.year); - /// ``` pub fn lock(&self, f: F) -> R where F: FnOnce(&T) -> R, @@ -272,17 +177,6 @@ impl AtomicMutex { } /// Mutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// struct Car { - /// year: u16, - /// } - /// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_mut(|mut c| {c.year = 2022}); - /// let year = atomic_car.lock_mut(|mut c| {c.year = 2023; c.year}); - /// ``` pub fn lock_mut(&mut self, f: F) -> R where F: FnOnce(&mut T) -> R, @@ -295,13 +189,6 @@ impl AtomicMutex { } /// get copy of the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// let atomic_u64 = AtomicMutex::from(25u64); - /// let age = atomic_u64.get(); - /// ``` #[inline] pub fn get(&self) -> T where @@ -311,13 +198,6 @@ impl AtomicMutex { } /// set the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicMutex, traits::*}; - /// let mut atomic_bool = AtomicMutex::from(false); - /// atomic_bool.set(true); - /// ``` #[inline] pub fn set(&mut self, value: T) where diff --git a/locks/src/std/atomic_rw.rs b/locks/src/std/atomic_rw.rs index 2cd012e..855af9d 100644 --- a/locks/src/std/atomic_rw.rs +++ b/locks/src/std/atomic_rw.rs @@ -13,70 +13,6 @@ use super::LockEvent; use super::LockType; /// An `Arc>` wrapper to make data thread-safe and easy to work with. -/// -/// # Example -/// ``` -/// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; -/// struct Car { -/// year: u16, -/// }; -/// let mut atomic_car = AtomicRw::from(Car{year: 2016}); -/// atomic_car.lock(|c| println!("year: {}", c.year)); -/// atomic_car.lock_mut(|mut c| c.year = 2023); -/// ``` -/// -/// It is also possible to provide a name and callback fn -/// during instantiation. In this way, the application -/// can easily trace lock acquisitions. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::std::{AtomicRw, LockEvent, LockCallbackFn}; -/// struct Car { -/// year: u16, -/// }; -/// -/// pub fn log_lock_event(lock_event: LockEvent) { -/// let (event, info, acquisition) = -/// match lock_event { -/// LockEvent::TryAcquire{info, acquisition} => ("TryAcquire", info, acquisition), -/// LockEvent::Acquire{info, acquisition} => ("Acquire", info, acquisition), -/// LockEvent::Release{info, acquisition} => ("Release", info, acquisition), -/// }; -/// -/// println!( -/// "{} lock `{}` of type `{}` for `{}` by\n\t|-- thread {}, `{:?}`", -/// event, -/// info.name().unwrap_or("?"), -/// info.lock_type(), -/// acquisition, -/// std::thread::current().name().unwrap_or("?"), -/// std::thread::current().id(), -/// ); -/// } -/// const LOG_LOCK_EVENT_CB: LockCallbackFn = log_lock_event; -/// -/// let mut atomic_car = AtomicRw::::from((Car{year: 2016}, Some("car"), Some(LOG_LOCK_EVENT_CB))); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}); -/// atomic_car.lock_mut(|mut c| {c.year = 2023}); -/// ``` -/// -/// results in: -/// ```text -/// TryAcquire lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// year: 2016 -/// Release lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// TryAcquire lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Release lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// ``` #[derive(Debug)] pub struct AtomicRw { inner: Arc>, @@ -199,16 +135,6 @@ impl From> for Arc> { // can be used without caller having to use the trait. impl AtomicRw { /// Acquire read lock and return an `RwLockReadGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// let year = atomic_car.lock_guard().year; - /// ``` pub fn lock_guard(&self) -> AtomicRwReadGuard<'_, T> { self.try_acquire_read_cb(); let guard = self.inner.read().expect("Read lock should succeed"); @@ -216,16 +142,6 @@ impl AtomicRw { } /// Acquire write lock and return an `RwLockWriteGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_guard_mut().year = 2022; - /// ``` pub fn lock_guard_mut(&mut self) -> AtomicRwWriteGuard<'_, T> { self.try_acquire_write_cb(); let guard = self.inner.write().expect("Write lock should succeed"); @@ -233,17 +149,6 @@ impl AtomicRw { } /// Immutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock(|c| println!("year: {}", c.year)); - /// let year = atomic_car.lock(|c| c.year); - /// ``` pub fn lock(&self, f: F) -> R where F: FnOnce(&T) -> R, @@ -255,17 +160,6 @@ impl AtomicRw { } /// Mutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_mut(|mut c| {c.year = 2022}); - /// let year = atomic_car.lock_mut(|mut c| {c.year = 2023; c.year}); - /// ``` pub fn lock_mut(&mut self, f: F) -> R where F: FnOnce(&mut T) -> R, @@ -277,13 +171,6 @@ impl AtomicRw { } /// get copy of the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// let atomic_u64 = AtomicRw::from(25u64); - /// let age = atomic_u64.get(); - /// ``` #[inline] pub fn get(&self) -> T where @@ -293,13 +180,6 @@ impl AtomicRw { } /// set the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// let mut atomic_bool = AtomicRw::from(false); - /// atomic_bool.set(true); - /// ``` #[inline] pub fn set(&mut self, value: T) where diff --git a/locks/src/std/traits.rs b/locks/src/std/traits.rs index 448f913..fdf9203 100644 --- a/locks/src/std/traits.rs +++ b/locks/src/std/traits.rs @@ -3,45 +3,16 @@ pub trait Atomic { /// Immutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock(|c| {println!("year: {}", c.year); }); - /// let year = atomic_car.lock(|c| c.year); - /// ``` fn lock(&self, f: F) -> R where F: FnOnce(&T) -> R; /// Mutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// struct Car { - /// year: u16, - /// }; - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_mut(|mut c| {c.year = 2022;}); - /// let year = atomic_car.lock_mut(|mut c| {c.year = 2023; c.year}); - /// ``` fn lock_mut(&mut self, f: F) -> R where F: FnOnce(&mut T) -> R; /// get copy of the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// let atomic_u64 = AtomicRw::from(25u64); - /// let age = atomic_u64.get(); - /// ``` #[inline] fn get(&self) -> T where @@ -51,13 +22,6 @@ pub trait Atomic { } /// set the locked value T (if T implements Copy). - /// - /// # Example - /// ``` - /// # use nyks_node::application::locks::std::{AtomicRw, traits::*}; - /// let mut atomic_bool = AtomicRw::from(false); - /// atomic_bool.set(true); - /// ``` #[inline] fn set(&mut self, value: T) where diff --git a/locks/src/tokio/atomic_mutex.rs b/locks/src/tokio/atomic_mutex.rs index dfe05f7..548ea3c 100644 --- a/locks/src/tokio/atomic_mutex.rs +++ b/locks/src/tokio/atomic_mutex.rs @@ -14,74 +14,6 @@ use super::LockEvent; use super::LockType; /// An `Arc>` wrapper to make data thread-safe and easy to work with. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::tokio::AtomicMutex; -/// struct Car { -/// year: u16, -/// }; -/// # tokio_test::block_on(async { -/// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}).await; -/// atomic_car.lock_mut(|mut c| {c.year = 2023}).await; -/// # }) -/// ``` -/// -/// It is also possible to provide a name and callback fn -/// during instantiation. In this way, the application -/// can easily trace lock acquisitions. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::tokio::{AtomicMutex, LockEvent, LockCallbackFn}; -/// struct Car { -/// year: u16, -/// }; -/// -/// pub fn log_lock_event(lock_event: LockEvent) { -/// let (event, info, acquisition) = -/// match lock_event { -/// LockEvent::TryAcquire{info, acquisition, ..} => ("TryAcquire", info, acquisition), -/// LockEvent::Acquire{info, acquisition, ..} => ("Acquire", info, acquisition), -/// LockEvent::Release{info, acquisition, ..} => ("Release", info, acquisition), -/// }; -/// -/// println!( -/// "{} lock `{}` of type `{}` for `{}` by\n\t|-- thread {}, `{:?}`", -/// event, -/// info.name().unwrap_or("?"), -/// info.lock_type(), -/// acquisition, -/// std::thread::current().name().unwrap_or("?"), -/// std::thread::current().id(), -/// ); -/// } -/// const LOG_TOKIO_LOCK_EVENT_CB: LockCallbackFn = log_lock_event; -/// -/// # tokio_test::block_on(async { -/// let mut atomic_car = AtomicMutex::::from((Car{year: 2016}, Some("car"), Some(LOG_TOKIO_LOCK_EVENT_CB))); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}).await; -/// atomic_car.lock_mut(|mut c| {c.year = 2023}).await; -/// # }) -/// ``` -/// -/// results in: -/// ```text -/// TryAcquire lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// year: 2016 -/// Release lock `car` of type `Mutex` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// TryAcquire lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Release lock `car` of type `Mutex` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// ``` #[derive(Debug)] pub struct AtomicMutex { inner: Arc>, @@ -204,18 +136,6 @@ impl From> for Arc> { // can be used without caller having to use the trait. impl AtomicMutex { /// Acquire read lock and return an `AtomicMutexGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicMutex::from(Car{year: 2016}); - /// let year = atomic_car.lock_guard().await.year; - /// # }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_guard(&self) -> AtomicMutexGuard<'_, T> { self.try_acquire_read_cb(); @@ -247,18 +167,6 @@ impl AtomicMutex { } /// Acquire write lock and return an `AtomicMutexGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_guard_mut().await.year = 2022; - /// # }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_guard_mut(&mut self) -> AtomicMutexGuard<'_, T> { self.try_acquire_write_cb(); @@ -274,19 +182,6 @@ impl AtomicMutex { } /// Immutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock(|c| println!("year: {}", c.year)).await; - /// let year = atomic_car.lock(|c| c.year).await; - /// }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock(&self, f: F) -> R where @@ -306,19 +201,6 @@ impl AtomicMutex { } /// Mutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_mut(|mut c| c.year = 2022).await; - /// let year = atomic_car.lock_mut(|mut c| {c.year = 2023; c.year}).await; - /// }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_mut(&mut self, f: F) -> R where @@ -341,21 +223,6 @@ impl AtomicMutex { /// /// The async callback uses dynamic dispatch and it is necessary to call /// `.boxed()` on the closure's async block and have [`FutureExt`](futures::future::FutureExt) in scope. - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// # use futures::future::FutureExt; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_async(|c| async {println!("year: {}", c.year)}.boxed()).await; - /// let year = atomic_car.lock_async(|c| async {c.year}.boxed()).await; - /// }) - /// ``` - // design background: https://stackoverflow.com/a/77657788/10087197 #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_async(&self, f: impl FnOnce(&T) -> BoxFuture<'_, R>) -> R { self.try_acquire_read_cb(); @@ -375,21 +242,6 @@ impl AtomicMutex { /// /// The async callback uses dynamic dispatch and it is necessary to call /// `.boxed()` on the closure's async block and have [`FutureExt`](futures::future::FutureExt) in scope. - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicMutex; - /// # use futures::future::FutureExt; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicMutex::from(Car{year: 2016}); - /// atomic_car.lock_mut_async(|mut c| async {c.year = 2022}.boxed()).await; - /// let year = atomic_car.lock_mut_async(|mut c| async {c.year = 2023; c.year}.boxed()).await; - /// }) - /// ``` - // design background: https://stackoverflow.com/a/77657788/10087197 #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_mut_async(&mut self, f: impl FnOnce(&mut T) -> BoxFuture<'_, R>) -> R { self.try_acquire_write_cb(); diff --git a/locks/src/tokio/atomic_rw.rs b/locks/src/tokio/atomic_rw.rs index 8969b35..bf4815b 100644 --- a/locks/src/tokio/atomic_rw.rs +++ b/locks/src/tokio/atomic_rw.rs @@ -24,73 +24,6 @@ use super::LockEvent; use super::LockType; /// An `Arc>` wrapper to make data thread-safe and easy to work with. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::tokio::AtomicRw; -/// struct Car { -/// year: u16, -/// }; -/// # tokio_test::block_on(async { -/// let mut atomic_car = AtomicRw::from(Car{year: 2016}); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}).await; -/// atomic_car.lock_mut(|mut c| {c.year = 2023}).await; -/// # }) -/// ``` -/// -/// It is also possible to provide a name and callback fn/// during instantiation. In this way, the application -/// can easily trace lock acquisitions. -/// -/// # Examples -/// ``` -/// # use nyks_node::application::locks::tokio::{AtomicRw, LockEvent, LockCallbackFn}; -/// struct Car { -/// year: u16, -/// }; -/// -/// pub fn log_lock_event(lock_event: LockEvent) { -/// let (event, info, acquisition) = -/// match lock_event { -/// LockEvent::TryAcquire{info, acquisition, ..} => ("TryAcquire", info, acquisition), -/// LockEvent::Acquire{info, acquisition, ..} => ("Acquire", info, acquisition), -/// LockEvent::Release{info, acquisition, ..} => ("Release", info, acquisition), -/// }; -/// -/// println!( -/// "{} lock `{}` of type `{}` for `{}` by\n\t|-- thread {}, `{:?}`", -/// event, -/// info.name().unwrap_or("?"), -/// info.lock_type(), -/// acquisition, -/// std::thread::current().name().unwrap_or("?"), -/// std::thread::current().id(), -/// ); -/// } -/// const LOG_TOKIO_LOCK_EVENT_CB: LockCallbackFn = log_lock_event; -/// -/// # tokio_test::block_on(async { -/// let mut atomic_car = AtomicRw::::from((Car{year: 2016}, Some("car"), Some(LOG_TOKIO_LOCK_EVENT_CB))); -/// atomic_car.lock(|c| {println!("year: {}", c.year)}).await; -/// atomic_car.lock_mut(|mut c| {c.year = 2023}).await; -/// # }) -/// ``` -/// -/// results in: -/// ```text -/// TryAcquire lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// year: 2016 -/// Release lock `car` of type `RwLock` for `Read` by -/// |-- thread main, `ThreadId(1)` -/// TryAcquire lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Acquire lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// Release lock `car` of type `RwLock` for `Write` by -/// |-- thread main, `ThreadId(1)` -/// ``` #[derive(Debug)] pub struct AtomicRw { inner: Arc>, @@ -213,18 +146,6 @@ impl From> for Arc> { // can be used without caller having to use the trait. impl AtomicRw { /// Acquire read lock and return an `AtomicRwReadGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// let year = atomic_car.lock_guard().await.year; - /// # }) - ///``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_guard(&self) -> AtomicRwReadGuard<'_, T> { self.try_acquire_read_cb(); @@ -235,18 +156,6 @@ impl AtomicRw { } /// Acquire write lock and return an `AtomicRwWriteGuard` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_guard_mut().await.year = 2022; - /// # }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_guard_mut(&mut self) -> AtomicRwWriteGuard<'_, T> { self.try_acquire_write_cb(); @@ -290,19 +199,6 @@ impl AtomicRw { } /// Immutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock(|c| println!("year: {}", c.year)).await; - /// let year = atomic_car.lock(|c| c.year).await; - /// }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock(&self, f: F) -> R where @@ -317,19 +213,6 @@ impl AtomicRw { } /// Mutably access the data of type `T` in a closure and possibly return a result of type `R` - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_mut(|mut c| c.year = 2022).await; - /// let year = atomic_car.lock_mut(|mut c| {c.year = 2023; c.year}).await; - /// }) - /// ``` #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_mut(&mut self, f: F) -> R where @@ -348,21 +231,6 @@ impl AtomicRw { /// /// The async callback uses dynamic dispatch and it is necessary to call /// `.boxed()` on the closure's async block and have [`FutureExt`](futures::future::FutureExt) in scope. - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// # use futures::future::FutureExt; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_async(|c| async {println!("year: {}", c.year)}.boxed()).await; - /// let year = atomic_car.lock_async(|c| async {c.year}.boxed()).await; - /// }) - /// ``` - // design background: https://stackoverflow.com/a/77657788/10087197 #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_async(&self, f: impl FnOnce(&T) -> BoxFuture<'_, R>) -> R { self.try_acquire_read_cb(); @@ -377,21 +245,6 @@ impl AtomicRw { /// /// The async callback uses dynamic dispatch and it is necessary to call /// `.boxed()` on the closure's async block and have [`FutureExt`](futures::future::FutureExt) in scope. - /// - /// # Examples - /// ``` - /// # use nyks_node::application::locks::tokio::AtomicRw; - /// # use futures::future::FutureExt; - /// struct Car { - /// year: u16, - /// }; - /// # tokio_test::block_on(async { - /// let mut atomic_car = AtomicRw::from(Car{year: 2016}); - /// atomic_car.lock_mut_async(|mut c| async {c.year = 2022}.boxed()).await; - /// let year = atomic_car.lock_mut_async(|mut c| async {c.year = 2023; c.year}.boxed()).await; - /// }) - /// ``` - // design background: https://stackoverflow.com/a/77657788/10087197 #[cfg_attr(feature = "track-lock-location", track_caller)] pub async fn lock_mut_async(&mut self, f: impl FnOnce(&mut T) -> BoxFuture<'_, R>) -> R { self.try_acquire_write_cb(); diff --git a/node/src/state/mempool.rs b/node/src/state/mempool.rs index 4bacb09..e30c523 100644 --- a/node/src/state/mempool.rs +++ b/node/src/state/mempool.rs @@ -831,30 +831,6 @@ impl Mempool { /// Produce a sorted iterator over a snapshot of the Double-Ended Priority Queue. /// - /// # Example - /// - /// ``` - /// use bytesize::ByteSize; - /// use nyks_node::application::config::network::Network; - /// use nyks_node::protocol::block::Block; - /// use nyks_node::state::mempool::Mempool; - /// use nyks_node::state::transaction::tx_proving_capability::TxProvingCapability; - /// - /// let network = Network::Main; - /// let genesis_block = Block::genesis(network); - /// let mempool = Mempool::new( - /// ByteSize::gb(1), - /// TxProvingCapability::ProofCollection, - /// &genesis_block - /// ); - /// // insert transactions here. - /// let mut most_valuable_transactions = vec![]; - /// for (transaction_id, fee_density) in mempool.fee_density_iter() { - /// let t = mempool.get(transaction_id); - /// most_valuable_transactions.push(t); - /// } - /// ``` - /// /// Yields the `transaction_digest` in order of descending `fee_density`, since /// users (miner or transaction merger) will likely only care about the most valuable transactions /// Computes in O(N lg N) diff --git a/node/src/state/mod.rs b/node/src/state/mod.rs index c592b48..7a253ac 100644 --- a/node/src/state/mod.rs +++ b/node/src/state/mod.rs @@ -250,68 +250,6 @@ impl DerefMut for GlobalStateLock { /// such generic methods can be called in series to share an already /// acquired lock-guard, or to each acquire its own lock-guard /// in the case of `Lock` variant. -/// -/// Example usage: -/// -/// ```rust -/// use nyks_node::state::GlobalState; -/// use nyks_node::state::GlobalStateLock; -/// use nyks_node::api::export::StateLock; -/// fn worker(gs: &GlobalState, truth: bool) { -/// // do something with gs and truth. -/// } -/// -/// // a callee that accepts &StateLock -/// async fn callee(state_lock: &StateLock<'_>, truth: bool) { -/// match state_lock { -/// StateLock::Lock(gsl) => worker(&*gsl.lock_guard().await, truth), -/// StateLock::ReadGuard(gs) => worker(&gs, truth), -/// StateLock::WriteGuard(gs) => worker(&gs, truth), -/// } -/// } -/// -/// // a caller that uses `Lock` variant -/// async fn caller_1(gsl: GlobalStateLock) { -/// // read-lock will be acquired each call. -/// callee(&gsl.clone().into(), true).await; -/// callee(&gsl.clone().into(), false).await; -/// } -/// -/// // a caller that uses `ReadLock` variant -/// async fn caller_2(gsl: GlobalStateLock) { -/// // read-lock is acquired only once. -/// let sl = StateLock::from(gsl.lock_guard().await); -/// callee(&sl, true).await; -/// callee(&sl, false).await; -/// } -/// -/// // a caller that uses `WriteLock` variant -/// async fn caller_3(mut gsl: GlobalStateLock) { -/// // write-lock is acquired only once. -/// let sl = StateLock::from(gsl.lock_guard_mut().await); -/// callee(&sl, true).await; -/// callee(&sl, false).await; -/// } -/// -/// // a caller that uses `ReadLock` variant and calls fn that accept `&GlobalState` -/// async fn caller_4(gsl: GlobalStateLock) { -/// // read-lock is acquired only once. -/// let sl = StateLock::from(gsl.lock_guard().await); -/// callee(&sl, true).await; -/// callee(&sl, false).await; -/// -/// // we can pass &GlobalState directly. -/// worker(sl.gs(), true); -/// -/// // convert back into a read-guard -/// let gs = sl.into_read_guard(); -/// worker(&gs, false); -/// } -/// ``` -/// -/// example usage as callee: see source of [TxOutputListBuilder::build()](crate::api::tx_initiation::builder::tx_output_list_builder::TxOutputListBuilder::build()) -/// -/// advanced usage as caller: see source of [TransactionSender::send()](crate::api::tx_initiation::send::TransactionSender::send()) #[derive(Debug)] pub enum StateLock<'a> { /// holds an instance GlobalStateLock. can be used to From 4e58fa7548dd3cfb6cd090e999dcbd2a0f30092a Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Fri, 7 Aug 2026 03:49:19 +0300 Subject: [PATCH 2/5] test: Github workflow for check, testing and lints --- .github/workflows/build-workaround | 13 -- .github/workflows/ci.yaml | 63 ++++++ .github/workflows/coverage.yml | 53 ----- .github/workflows/main.yml | 56 ----- .github/workflows/no_lock_build.yml | 29 --- .github/workflows/release.yml | 307 ---------------------------- 6 files changed, 63 insertions(+), 458 deletions(-) delete mode 100644 .github/workflows/build-workaround create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/coverage.yml delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/no_lock_build.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build-workaround b/.github/workflows/build-workaround deleted file mode 100644 index c70a795..0000000 --- a/.github/workflows/build-workaround +++ /dev/null @@ -1,13 +0,0 @@ -# A workaround for -# https://github.com/axodotdev/cargo-dist/issues/1571 -# using -# https://opensource.axo.dev/cargo-dist/book/ci/customizing.html#customizing-build-setup -- name: Update RUSTFLAGS with --cfg tokio_unstable (Linux/MacOS) - if: runner.os != 'Windows' - run: echo RUSTFLAGS="$RUSTFLAGS --cfg tokio_unstable" >> "$GITHUB_ENV" - -- name: Update RUSTFLAGS with --cfg tokio_unstable (Windows) - if: runner.os == 'Windows' - shell: pwsh - run: echo "RUSTFLAGS=$Env:RUSTFLAGS --cfg tokio_unstable" >> $Env:GITHUB_ENV - diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e0e5e45 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,63 @@ +name: Tests + +on: [ push, pull_request ] + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Set up cache + uses: Swatinem/rust-cache@v2 + + - name: Run cargo check + run: cargo check --tests --workspace + + test: + name: Test Suite + # runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + # matrix: + # os: [ ubuntu-latest, macos-latest, windows-latest ] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Set up cache + uses: Swatinem/rust-cache@v2 + + - name: Run cargo test + run: cargo test --workspace + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + toolchain: 1.97.1 + components: rustfmt, clippy + + - name: Set up cache + uses: Swatinem/rust-cache@v2 + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + - name: Run cargo clippy + run: cargo clippy --workspace --tests -- -D warnings diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index ce919b9..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Coverage - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - coverage: - name: Coverage - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install toolchain - uses: dtolnay/rust-toolchain@nightly - with: - components: llvm-tools-preview - - - name: Install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov - - - name: Install nextest - uses: taiki-e/install-action@nextest - - # For some reason, coverage data for the documentation tests is ~30GiB. - # Github's CI runners have ~15GiB of disk space. To have any coverage data - # at all, documentation tests are skipped. - - name: Collect coverage data (skip doctests & benchmarks) - run: > - cargo +nightly llvm-cov nextest - --lib --bins --tests --examples - --lcov --output-path lcov.info - -- - --skip mine_20_blocks_in_40_seconds - --skip hash_rate_independent_of_tx_size - --skip blocks_with_0_to_10_inputs_and_successors_are_valid - --skip can_cancel_preprocess_within_one_second - --skip can_cancel_merkle_tree_construction_within_two_seconds - --skip alice_updates_mutator_set_data_on_own_transaction - - - name: Upload coverage to coveralls.io - uses: coverallsapp/github-action@v2 - - - name: Archive coverage results - uses: actions/upload-artifact@v4 - with: - name: coverage-report - path: lcov.info diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 43bbd80..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,56 +0,0 @@ -on: - push: - branches: - - master - pull_request: - branches: - - master - -name: Rust - -jobs: - runner-matrix: - name: format, lint, test - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy - - - name: Run cargo fmt - run: cargo fmt --all -- --check - - - name: Build documentation - run: cargo doc --no-deps --workspace --document-private-items - env: - RUSTDOCFLAGS: -D warnings - - - name: Run clippy - run: cargo clippy --all-targets -- -D warnings - - - name: Build benches - run: cargo build --benches - - - name: Run tests without benches - run: > - cargo test - --lib --bins --tests --examples - -- - --skip mine_20_blocks_in_40_seconds - --skip hash_rate_independent_of_tx_size - --skip blocks_with_0_to_10_inputs_and_successors_are_valid - --skip can_cancel_preprocess_within_one_second - --skip can_cancel_merkle_tree_construction_within_two_seconds - --skip alice_updates_mutator_set_data_on_own_transaction - - # `--doc` cannot be mixed with other target option - - name: Run documentation tests - run: cargo test --doc diff --git a/.github/workflows/no_lock_build.yml b/.github/workflows/no_lock_build.yml deleted file mode 100644 index 36bfe61..0000000 --- a/.github/workflows/no_lock_build.yml +++ /dev/null @@ -1,29 +0,0 @@ -on: - push: - branches: - - master - pull_request: - branches: - - master - -name: Build without Cargo.lock - -jobs: - runner-matrix: - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Remove Cargo.lock - run: rm Cargo.lock - - - name: Build - run: cargo build --all --release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 287bdac..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,307 +0,0 @@ -# This file was autogenerated by dist: https://axodotdev.github.io/cargo-dist -# -# Copyright 2022-2024, axodotdev -# SPDX-License-Identifier: MIT or Apache-2.0 -# -# CI that: -# -# * checks for a Git Tag that looks like a release -# * builds artifacts with dist (archives, installers, hashes) -# * uploads those artifacts to temporary workflow zip -# * on success, uploads the artifacts to a GitHub Release -# -# Note that the GitHub Release will be created with a generated -# title/body based on your changelogs. - -name: Release -permissions: - "contents": "write" - -# This task will run whenever you push a git tag that looks like a version -# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. -# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where -# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION -# must be a Cargo-style SemVer Version (must have at least major.minor.patch). -# -# If PACKAGE_NAME is specified, then the announcement will be for that -# package (erroring out if it doesn't have the given version or isn't dist-able). -# -# If PACKAGE_NAME isn't specified, then the announcement will be for all -# (dist-able) packages in the workspace with that version (this mode is -# intended for workspaces with only one dist-able package, or with all dist-able -# packages versioned/released in lockstep). -# -# If you push multiple tags at once, separate instances of this workflow will -# spin up, creating an independent announcement for each one. However, GitHub -# will hard limit this to 3 tags per commit, as it will assume more tags is a -# mistake. -# -# If there's a prerelease-style suffix to the version, then the release(s) -# will be marked as a prerelease. -on: - pull_request: - push: - tags: - - '**[0-9]+.[0-9]+.[0-9]+*' - -jobs: - # Run 'dist plan' (or host) to determine what tasks we need to do - plan: - runs-on: "ubuntu-22.04" - outputs: - val: ${{ steps.plan.outputs.manifest }} - tag: ${{ !github.event.pull_request && github.ref_name || '' }} - tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} - publishing: ${{ !github.event.pull_request }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - submodules: recursive - - name: Install dist - # we specify bash to get pipefail; it guards against the `curl` command - # failing. otherwise `sh` won't catch that `curl` returned non-0 - shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.30.2/cargo-dist-installer.sh | sh" - - name: Cache dist - uses: actions/upload-artifact@v4 - with: - name: cargo-dist-cache - path: ~/.cargo/bin/dist - # sure would be cool if github gave us proper conditionals... - # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible - # functionality based on whether this is a pull_request, and whether it's from a fork. - # (PRs run on the *source* but secrets are usually on the *target* -- that's *good* - # but also really annoying to build CI around when it needs secrets to work right.) - - id: plan - run: | - dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json - echo "dist ran successfully" - cat plan-dist-manifest.json - echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - - name: "Upload dist-manifest.json" - uses: actions/upload-artifact@v4 - with: - name: artifacts-plan-dist-manifest - path: plan-dist-manifest.json - - # Build and packages all the platform-specific things - build-local-artifacts: - name: build-local-artifacts (${{ join(matrix.targets, ', ') }}) - # Let the initial task tell us to not run (currently very blunt) - needs: - - plan - if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} - strategy: - fail-fast: false - # Target platforms/runners are computed by dist in create-release. - # Each member of the matrix has the following arguments: - # - # - runner: the github runner - # - dist-args: cli flags to pass to dist - # - install-dist: expression to run to install dist on the runner - # - # Typically there will be: - # - 1 "global" task that builds universal installers - # - N "local" tasks that build each platform's binaries and platform-specific installers - matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} - runs-on: ${{ matrix.runner }} - container: ${{ matrix.container && matrix.container.image || null }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json - steps: - - name: enable windows longpaths - run: | - git config --global core.longpaths true - - uses: actions/checkout@v4 - with: - persist-credentials: false - submodules: recursive - - name: Install Rust non-interactively if not already installed - if: ${{ matrix.container }} - run: | - if ! command -v cargo > /dev/null 2>&1; then - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - echo "$HOME/.cargo/bin" >> $GITHUB_PATH - fi - - name: "Update RUSTFLAGS with --cfg tokio_unstable (Linux/MacOS)" - if: "runner.os != 'Windows'" - run: "echo RUSTFLAGS=\"$RUSTFLAGS --cfg tokio_unstable\" >> \"$GITHUB_ENV\"" - - name: "Update RUSTFLAGS with --cfg tokio_unstable (Windows)" - if: "runner.os == 'Windows'" - run: "echo \"RUSTFLAGS=$Env:RUSTFLAGS --cfg tokio_unstable\" >> $Env:GITHUB_ENV" - shell: "pwsh" - - uses: swatinem/rust-cache@v2 - with: - key: ${{ join(matrix.targets, '-') }} - cache-provider: ${{ matrix.cache_provider }} - - name: Install dist - run: ${{ matrix.install_dist.run }} - # Get the dist-manifest - - name: Fetch local artifacts - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: target/distrib/ - merge-multiple: true - - name: Install dependencies - run: | - ${{ matrix.packages_install }} - - name: Build artifacts - run: | - # Actually do builds and make zips and whatnot - dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json - echo "dist ran successfully" - - id: cargo-dist - name: Post-build - # We force bash here just because github makes it really hard to get values up - # to "real" actions without writing to env-vars, and writing to env-vars has - # inconsistent syntax between shell and powershell. - shell: bash - run: | - # Parse out what we just built and upload it to scratch storage - echo "paths<> "$GITHUB_OUTPUT" - dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT" - echo "EOF" >> "$GITHUB_OUTPUT" - - cp dist-manifest.json "$BUILD_MANIFEST_NAME" - - name: "Upload artifacts" - uses: actions/upload-artifact@v4 - with: - name: artifacts-build-local-${{ join(matrix.targets, '_') }} - path: | - ${{ steps.cargo-dist.outputs.paths }} - ${{ env.BUILD_MANIFEST_NAME }} - - # Build and package all the platform-agnostic(ish) things - build-global-artifacts: - needs: - - plan - - build-local-artifacts - runs-on: "ubuntu-22.04" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - submodules: recursive - - name: Install cached dist - uses: actions/download-artifact@v4 - with: - name: cargo-dist-cache - path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/dist - # Get all the local artifacts for the global tasks to use (for e.g. checksums) - - name: Fetch local artifacts - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: target/distrib/ - merge-multiple: true - - id: cargo-dist - shell: bash - run: | - dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "dist ran successfully" - - # Parse out what we just built and upload it to scratch storage - echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" - echo "EOF" >> "$GITHUB_OUTPUT" - - cp dist-manifest.json "$BUILD_MANIFEST_NAME" - - name: "Upload artifacts" - uses: actions/upload-artifact@v4 - with: - name: artifacts-build-global - path: | - ${{ steps.cargo-dist.outputs.paths }} - ${{ env.BUILD_MANIFEST_NAME }} - # Determines if we should publish/announce - host: - needs: - - plan - - build-local-artifacts - - build-global-artifacts - # Only run if we're "publishing", and only if plan, local and global didn't fail (skipped is fine) - if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - runs-on: "ubuntu-22.04" - outputs: - val: ${{ steps.host.outputs.manifest }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - submodules: recursive - - name: Install cached dist - uses: actions/download-artifact@v4 - with: - name: cargo-dist-cache - path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/dist - # Fetch artifacts from scratch-storage - - name: Fetch artifacts - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: target/distrib/ - merge-multiple: true - - id: host - shell: bash - run: | - dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json - echo "artifacts uploaded and released successfully" - cat dist-manifest.json - echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" - - name: "Upload dist-manifest.json" - uses: actions/upload-artifact@v4 - with: - # Overwrite the previous copy - name: artifacts-dist-manifest - path: dist-manifest.json - # Create a GitHub Release while uploading all files to it - - name: "Download GitHub Artifacts" - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: artifacts - merge-multiple: true - - name: Cleanup - run: | - # Remove the granular manifests - rm -f artifacts/*-dist-manifest.json - - name: Create GitHub Release - env: - PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" - ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}" - ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" - RELEASE_COMMIT: "${{ github.sha }}" - run: | - # Write and read notes from a file to avoid quoting breaking things - echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt - - gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* - - announce: - needs: - - plan - - host - # use "always() && ..." to allow us to wait for all publish jobs while - # still allowing individual publish jobs to skip themselves (for prereleases). - # "host" however must run to completion, no skipping allowed! - if: ${{ always() && needs.host.result == 'success' }} - runs-on: "ubuntu-22.04" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - submodules: recursive From d79b86e40c5b70c2fa4a6dfa21d2f57ee4597c37 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Fri, 7 Aug 2026 04:07:57 +0300 Subject: [PATCH 3/5] fix: Use clang by default --- .cargo/config.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 2c85d8e..a0e9bbd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -12,7 +12,5 @@ RUST_BACKTRACE = "1" # workaround for dependency `leveldb-sys v2.0.9` CMAKE_POLICY_VERSION_MINIMUM = "3.5" - -[target.'cfg(target_os = "linux")'.env] CC = "clang" CXX = "clang++" From 4f1fc0a5c04703cf230975f097738bb0ef27cf81 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Sat, 8 Aug 2026 02:32:55 +0300 Subject: [PATCH 4/5] fix: Fix some comments --- consensus/src/block/mod.rs | 22 ---------------------- node/src/application/network/actor.rs | 27 --------------------------- node/src/prelude.rs | 5 ----- 3 files changed, 54 deletions(-) diff --git a/consensus/src/block/mod.rs b/consensus/src/block/mod.rs index 6c86b89..24dd483 100644 --- a/consensus/src/block/mod.rs +++ b/consensus/src/block/mod.rs @@ -192,28 +192,6 @@ pub enum BlockProof { /// Public fields of `Block` are read-only, enforced by #[readonly::make]. /// Modifications are possible only through `Block` methods. -/// -/// Example: -/// -/// test: verify that compile fails on an attempt to mutate block -/// internals directly (bypassing encapsulation) -/// -/// ```compile_fail,E0594 -/// use nyks_node::protocol::block::Block; -/// use nyks_node::application::config::network::Network; -/// use nyks_node::prelude::twenty_first::math::b_field_element::BFieldElement; -/// use tasm_lib::prelude::Digest; -/// -/// let mut block = Block::genesis(Network::RegTest); -/// -/// let height = block.kernel.header.height; -/// -/// let nonce = Digest::default(); -/// -/// // this line fails to compile because we try to -/// // mutate an internal field. -/// block.kernel.header.pow.nonce = nonce; -/// ``` // ## About the private `digest` field: // // The `digest` field represents the `Block` hash. It is an optimization so diff --git a/node/src/application/network/actor.rs b/node/src/application/network/actor.rs index 79f6c63..d04a488 100644 --- a/node/src/application/network/actor.rs +++ b/node/src/application/network/actor.rs @@ -220,33 +220,6 @@ impl NetworkActorChannels { /// main loop to receive notifications from the [`NetworkActor`] /// (notifications of events). /// - /// # Example - /// - /// ```rust,ignore - /// use tokio::sync::broadcast; - /// use tokio::sync::mpsc; - /// - /// use crate::application::loops::peer_loop::channel::PeerTaskToMain; - /// use crate::application::loops::peer_loop::channel::MainToPeerTask; - /// use crate::application::network::actor::NetworkActorChannels; - /// - /// // Construct the broadcast channel to communicate from the main task to - /// // peer tasks - /// let (main_to_peer_broadcast_tx, _main_to_peer_broadcast_rx) = - /// broadcast::channel::(1000); - /// - /// // Add the MPSC (multi-producer, single consumer) channel for - /// // peer-task-to-main communication - /// let (peer_task_to_main_tx, peer_task_to_main_rx) = - /// mpsc::channel::(1000); - /// - /// // Construct the channels for the `NetworkActor` - /// let (channels, network_command_tx, network_event_rx) = NetworkActorChannels::setup( - /// peer_task_to_main_tx.clone(), - /// main_to_peer_broadcast_tx.clone(), - /// ); - /// ``` - /// /// (Note that the doctest cannor run because message types `PeerTaskToMain` /// and `MainToPeerTask`, not to mention this constructor, are private.) pub(crate) fn setup( diff --git a/node/src/prelude.rs b/node/src/prelude.rs index adeef78..91cdf9b 100644 --- a/node/src/prelude.rs +++ b/node/src/prelude.rs @@ -1,9 +1,4 @@ //! Re-exports the most commonly-needed APIs of nyks-node. -//! -//! This module is intended to be wildcard-imported, _i.e._, `use nyks_node::prelude::twenty_first;`. -//! You might also want to consider wildcard-importing these prelude, -//! `use nyks_node::prelude::tasm_lib::prelude::*;`. -//! `use nyks_node::prelude::triton_vm::prelude::*;`. pub use tasm_lib; pub use tasm_lib::prelude::triton_vm; From 62c921d2e37738d367a7d1eaee5f1024b0e615ab Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Sat, 8 Aug 2026 19:37:55 +0300 Subject: [PATCH 5/5] style: Fmt a special case --- consensus/src/mutator_set/mutator_set_accumulator.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/src/mutator_set/mutator_set_accumulator.rs b/consensus/src/mutator_set/mutator_set_accumulator.rs index e0f0859..b30ad10 100644 --- a/consensus/src/mutator_set/mutator_set_accumulator.rs +++ b/consensus/src/mutator_set/mutator_set_accumulator.rs @@ -102,6 +102,7 @@ impl MutatorSetAccumulator { /// Return the lowest and the highest chunk index that are represented in /// the active window, inclusive. + /// /// The returned limits are inclusive, i.e. they point to the chunk with /// the lowest chunk index and the chunk with the highest chunk index that /// are still contained in the active window.