diff --git a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml index 3df8d5e3b..e510417fc 100644 --- a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml @@ -18,7 +18,7 @@ serde_sv2 = {version = "^1.0.0", path = "../serde-sv2", optional = true} serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false, optional = true } binary_codec_sv2 = {version = "^1.0.0", path = "../no-serde-sv2/codec", optional = true} derive_codec_sv2 = {version = "^1.0.0", path = "../no-serde-sv2/derive_codec", optional = true} -tracing = {version = "0.1"} +tracing = { version = "0.1", default-features = false } [features] default = ["core"] diff --git a/protocols/v2/binary-sv2/binary-sv2/README.md b/protocols/v2/binary-sv2/binary-sv2/README.md index e69de29bb..7fac0315f 100644 --- a/protocols/v2/binary-sv2/binary-sv2/README.md +++ b/protocols/v2/binary-sv2/binary-sv2/README.md @@ -0,0 +1,3 @@ +# binary_sv2 + +`binary_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs index ae13b38a6..85fc6b31b 100644 --- a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs +++ b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs @@ -1,5 +1,10 @@ // TODO unify errors from serde_sv2 and no-serde-sv2 -// + +#![no_std] + +#[macro_use] +extern crate alloc; + use core::convert::TryInto; #[cfg(feature = "with_serde")] @@ -34,6 +39,7 @@ pub fn u256_from_int>(value: V) -> U256<'static> { #[cfg(test)] mod test { use super::*; + use alloc::vec::Vec; mod test_struct { use super::*; @@ -748,7 +754,6 @@ mod test { } mod test_sv2_option_none { use super::*; - use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md b/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md new file mode 100644 index 000000000..f338a94db --- /dev/null +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md @@ -0,0 +1,3 @@ +# binary_codec_sv2 + +`binary_codec_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs index 45389b73a..1ec7037f7 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs @@ -6,7 +6,7 @@ use crate::{ Error, }; use alloc::vec::Vec; -use std::convert::TryFrom; +use core::convert::TryFrom; #[cfg(not(feature = "no_std"))] use std::io::{Cursor, Read}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs index fd626bc8f..a26ae8e72 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs @@ -11,6 +11,8 @@ mod impls; #[cfg(feature = "with_buffer_pool")] use buffer_sv2::Slice; +use alloc::vec::Vec; + /// Return the encoded byte size or a `Decodable` pub trait SizeHint { fn size_hint(data: &[u8], offset: usize) -> Result; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs index be6edeadc..690f719fd 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs @@ -1,5 +1,7 @@ //! Copy data types use crate::{codec::Fixed, datatypes::Sv2DataType, Error}; + +use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs index ad1bce76c..8ab1bc924 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs @@ -12,11 +12,11 @@ pub use non_copy_data_types::{ B0255, B032, B064K, U256, }; +use alloc::vec::Vec; +use core::convert::TryInto; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; -use std::convert::TryInto; - pub trait Sv2DataType<'a>: Sized + SizeHint + GetSize + TryInto { fn from_bytes_(data: &'a mut [u8]) -> Result { Self::size_hint(data, 0)?; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs index 1703c5d2e..e0f30bf38 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs @@ -4,9 +4,9 @@ use crate::{ datatypes::Sv2DataType, Error, }; -use core::convert::TryFrom; -use std::convert::TryInto; +use alloc::vec::Vec; +use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs index 9a117786e..40c47a7ba 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs @@ -1,6 +1,10 @@ #[cfg(feature = "prop_test")] use quickcheck::{Arbitrary, Gen}; +use alloc::string::String; +#[cfg(feature = "prop_test")] +use alloc::vec::Vec; + mod inner; mod seq_inner; @@ -28,7 +32,6 @@ impl<'decoder> From<[u8; 32]> for U256<'decoder> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> U256<'a> { pub fn from_gen(g: &mut Gen) -> Self { @@ -40,7 +43,6 @@ impl<'a> U256<'a> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> B016M<'a> { pub fn from_gen(g: &mut Gen) -> Self { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs index acc50f15f..9da799ba9 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs @@ -280,7 +280,7 @@ impl_into_encodable_field_for_seq!(B064K<'a>); impl_into_encodable_field_for_seq!(B016M<'a>); #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq0255<'a, T>) -> Result { if v.0.len() > 255 { @@ -292,7 +292,7 @@ impl<'a, T> std::convert::TryFrom> for Vec { } #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq064K<'a, T>) -> Result { if v.0.len() > 64 { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs index c1172f9da..cbca39977 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs @@ -19,6 +19,9 @@ //! Seq0255 <-> SEQ0_255[T] //! Seq064K <-> SEQ0_64K[T] //! ``` + +#![cfg_attr(feature = "no_std", no_std)] + #[cfg(not(feature = "no_std"))] use std::io::{Error as E, ErrorKind}; @@ -35,6 +38,8 @@ pub use crate::codec::{ Fixed, GetSize, SizeHint, }; +use alloc::vec::Vec; + #[allow(clippy::wrong_self_convention)] pub fn to_bytes(src: T) -> Result, Error> { let mut result = vec![0_u8; src.get_size()]; @@ -281,7 +286,7 @@ impl From<&[u8]> for CVec { // the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -296,7 +301,7 @@ impl From<&[u8]> for CVec { /// # Safety #[no_mangle] pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { - let input = std::slice::from_raw_parts(data, len); + let input = core::slice::from_raw_parts(data, len); let mut buffer: Vec = vec![0; len]; buffer.copy_from_slice(input); @@ -305,7 +310,7 @@ pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -360,7 +365,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -371,7 +376,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -393,7 +398,7 @@ pub unsafe extern "C" fn init_cvec2() -> CVec2 { // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec2 { data: ptr, @@ -412,7 +417,7 @@ pub unsafe extern "C" fn cvec2_push(cvec2: &mut CVec2, cvec: CVec) { let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); cvec2.data = ptr; cvec2.len = len; @@ -428,7 +433,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len, @@ -445,7 +450,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len, diff --git a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md new file mode 100644 index 000000000..01af2599e --- /dev/null +++ b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md @@ -0,0 +1,3 @@ +# derive_codec_sv2 + +`derive_codec_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs index aef883ba1..1cd3176f3 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs @@ -1,4 +1,13 @@ +#![no_std] + +extern crate alloc; extern crate proc_macro; + +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; use core::iter::FromIterator; use proc_macro::{Group, TokenStream, TokenTree}; diff --git a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml index 0b30e2199..b320d8ce1 100644 --- a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml @@ -18,8 +18,5 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false } buffer_sv2 = {version = "^1.0.0", path = "../../../../utils/buffer"} -[features] -no_std = [] - [package.metadata.docs.rs] all-features = true \ No newline at end of file diff --git a/protocols/v2/binary-sv2/serde-sv2/README.md b/protocols/v2/binary-sv2/serde-sv2/README.md new file mode 100644 index 000000000..43a6706d0 --- /dev/null +++ b/protocols/v2/binary-sv2/serde-sv2/README.md @@ -0,0 +1,3 @@ +# serde_sv2 + +`serde_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/serde-sv2/src/lib.rs b/protocols/v2/binary-sv2/serde-sv2/src/lib.rs index 6582619d4..8fd26b92f 100644 --- a/protocols/v2/binary-sv2/serde-sv2/src/lib.rs +++ b/protocols/v2/binary-sv2/serde-sv2/src/lib.rs @@ -75,7 +75,7 @@ //! [rkyv1]: https://docs.rs/rkyv/0.4.3/rkyv //! [rkyv2]: https://davidkoloski.me/blog/rkyv-is-faster-than/ -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] #[macro_use] extern crate alloc; diff --git a/protocols/v2/const-sv2/Cargo.toml b/protocols/v2/const-sv2/Cargo.toml index f9d49018a..ec759026c 100644 --- a/protocols/v2/const-sv2/Cargo.toml +++ b/protocols/v2/const-sv2/Cargo.toml @@ -13,8 +13,5 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -no_std = [] - [package.metadata.docs.rs] all-features = true diff --git a/protocols/v2/const-sv2/README.md b/protocols/v2/const-sv2/README.md index b49199745..3a414b3cc 100644 --- a/protocols/v2/const-sv2/README.md +++ b/protocols/v2/const-sv2/README.md @@ -5,7 +5,7 @@ [![rustc+](https://img.shields.io/badge/rustc-1.75.0%2B-lightgrey.svg)](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html) [![license](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/stratum-mining/stratum/blob/main/LICENSE.md) -`const_sv2` is a Rust crate that provides essential constants for the Sv2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various Sv2 components, including Mining, Job Declaration, and Template Distribution protocols. +`const_sv2` is a Rust `no_std` crate that provides essential constants for the Sv2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various Sv2 components, including Mining, Job Declaration, and Template Distribution protocols. ## Key Capabilities diff --git a/protocols/v2/const-sv2/src/lib.rs b/protocols/v2/const-sv2/src/lib.rs index 2e248a633..4d7829188 100644 --- a/protocols/v2/const-sv2/src/lib.rs +++ b/protocols/v2/const-sv2/src/lib.rs @@ -36,7 +36,7 @@ //! `channel_id`. In this case, the first 4 bytes of the payload represent the //! `channel_id` the message is destined for. -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] /// Identifier for the extension_type field in the SV2 frame, indicating no /// extensions. diff --git a/protocols/v2/framing-sv2/Cargo.toml b/protocols/v2/framing-sv2/Cargo.toml index 6797d7946..0429254ca 100644 --- a/protocols/v2/framing-sv2/Cargo.toml +++ b/protocols/v2/framing-sv2/Cargo.toml @@ -20,8 +20,7 @@ binary_sv2 = { version = "^1.0.0", path = "../../../protocols/v2/binary-sv2/bina buffer_sv2 = { version = "^1.0.0", path = "../../../utils/buffer", optional=true } [features] -no_std = [] -with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2/with_serde"] +with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2?/with_serde"] with_buffer_pool = ["binary_sv2/with_buffer_pool", "buffer_sv2"] [package.metadata.docs.rs] diff --git a/protocols/v2/framing-sv2/README.md b/protocols/v2/framing-sv2/README.md new file mode 100644 index 000000000..26e617ed2 --- /dev/null +++ b/protocols/v2/framing-sv2/README.md @@ -0,0 +1,3 @@ +# framing_sv2 + +`framing_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/framing-sv2/src/lib.rs b/protocols/v2/framing-sv2/src/lib.rs index a8d9335e7..4096384a9 100644 --- a/protocols/v2/framing-sv2/src/lib.rs +++ b/protocols/v2/framing-sv2/src/lib.rs @@ -23,7 +23,8 @@ //! The `with_serde` feature flag is only used for the Message Generator, and deprecated for any //! other kind of usage. It will likely be fully deprecated in the future. -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] + extern crate alloc; /// SV2 framing types diff --git a/utils/buffer/src/buffer_pool/mod.rs b/utils/buffer/src/buffer_pool/mod.rs index eae9c41ab..705facfd8 100644 --- a/utils/buffer/src/buffer_pool/mod.rs +++ b/utils/buffer/src/buffer_pool/mod.rs @@ -606,7 +606,7 @@ impl Buffer for BufferPool { "{} {} {}", self.inner_memory.raw_offset, self.inner_memory.raw_len, self.inner_memory.len ); - let mut res = self.inner_memory.get_data_owned(shared_state, mode); + let res = self.inner_memory.get_data_owned(shared_state, mode); self.pool_back .set_len_from_inner_memory(self.inner_memory.len); println!( @@ -684,7 +684,7 @@ impl Buffer for BufferPool { impl Drop for BufferPool { fn drop(&mut self) { while self.shared_state.load(Ordering::Relaxed) != 0 { - std::hint::spin_loop(); + core::hint::spin_loop(); } } } diff --git a/utils/buffer/src/lib.rs b/utils/buffer/src/lib.rs index be1d3f8c3..11d1eb0d1 100644 --- a/utils/buffer/src/lib.rs +++ b/utils/buffer/src/lib.rs @@ -1,4 +1,4 @@ -//#![cfg_attr(not(feature = "debug"), no_std)] +#![cfg_attr(not(feature = "debug"), no_std)] //#![feature(backtrace)] mod buffer;