Skip to content

Commit

Permalink
Merge pull request #1455 from Shourya742/2025-01-31-remove-serde-feat…
Browse files Browse the repository at this point in the history
…ure-from-protocol

remove serde feature from protocol crate
  • Loading branch information
plebhash authored Feb 7, 2025
2 parents 1370768 + f7b068a commit 19f26e3
Show file tree
Hide file tree
Showing 53 changed files with 319 additions and 1,258 deletions.
3 changes: 0 additions & 3 deletions examples/interop-cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ const_sv2 = { path = "../../protocols/v2/const-sv2" }
binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" }
common_messages_sv2 = { path = "../../protocols/v2/subprotocols/common-messages" }
template_distribution_sv2 = { path = "../../protocols/v2/subprotocols/template-distribution" }

[features]
with_serde = []
8 changes: 0 additions & 8 deletions examples/interop-cpp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ fn main() -> Result<(), std::io::Error> {
main()
}

#[cfg(feature = "with_serde")]
mod main_ {
pub fn main() -> Result<(), std::io::Error> {
Ok(())
}
}

#[cfg(not(feature = "with_serde"))]
mod main_ {
use codec_sv2::{Encoder, StandardDecoder, StandardSv2Frame};
use common_messages_sv2::{Protocol, SetupConnection, SetupConnectionError};
Expand Down
1 change: 0 additions & 1 deletion protocols/v2/codec-sv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ key-utils = { path = "../../../utils/key-utils" }
[features]
default = ["std"]
std = ["noise_sv2?/std", "rand/std", "rand/std_rng", "dep:tracing"]
with_serde = ["binary_sv2/with_serde", "serde", "framing_sv2/with_serde", "buffer_sv2/with_serde"]
with_buffer_pool = ["framing_sv2/with_buffer_pool"]

[package.metadata.docs.rs]
Expand Down
4 changes: 0 additions & 4 deletions protocols/v2/codec-sv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ This crate can be built with the following feature flags:
- `std`: Enable usage of rust `std` library, enabled by default.
- `noise_sv2`: Enables support for Noise protocol encryption and decryption.
- `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
- `with_serde`: builds [`binary_sv2`](https://crates.io/crates/binary_sv2) and
[`buffer_sv2`](https://crates.io/crates/buffer_sv2) crates with `serde`-based encoding and
decoding. Note that this 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.

In order to use this crate in a `#![no_std]` environment, use the `--no-default-features` to remove the `std` feature.

Expand Down
3 changes: 0 additions & 3 deletions protocols/v2/codec-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
//! - `std`: Enable usage of rust `std` library, enabled by default.
//! - `noise_sv2`: Enables support for Noise protocol encryption and decryption.
//! - `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
//! - `with_serde`: builds [`binary_sv2`] and [`buffer_sv2`] crates with `serde`-based encoding and
//! decoding. Note that this 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.
//!
//! In order to use this crate in a `#![no_std]` environment, use the `--no-default-features` to
//! remove the `std` feature.
Expand Down
3 changes: 1 addition & 2 deletions protocols/v2/framing-sv2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "framing_sv2"
version = "3.0.0"
version = "4.0.0"
authors = ["The Stratum V2 Developers"]
edition = "2018"
readme = "README.md"
Expand All @@ -25,7 +25,6 @@ rand = "0.8.3"
secp256k1 = { version = "0.28.2", default-features = false, features =["alloc","rand","rand-std"] }

[features]
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]
Expand Down
6 changes: 1 addition & 5 deletions protocols/v2/framing-sv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ cargo add framing_sv2
This crate can be built with the following feature flags:

- `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
- `with_serde`: builds [`binary_sv2`](https://crates.io/crates/binary_sv2) and
[`buffer_sv2`](https://crates.io/crates/buffer_sv2) crates with `serde`-based encoding and
decoding. Note that this 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.

### Examples

This crate provides an example demonstrating how to serialize and deserialize Sv2 message frames:

1. **[Sv2 Frame](https://github.com/stratum-mining/stratum/blob/main/protocols/v2/framing-sv2/examples/sv2_frame.rs)**:
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).
26 changes: 4 additions & 22 deletions protocols/v2/framing-sv2/examples/sv2_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,22 @@
// ## Run
//
// ```
// cargo run --example sv2_frame --features with_serde
// cargo run --example sv2_frame
// ```

#[cfg(feature = "with_serde")]
use binary_sv2::{GetSize, Serialize};
#[cfg(feature = "with_serde")]
use binary_sv2::{binary_codec_sv2, Serialize};
use framing_sv2::framing::Sv2Frame;

// Example message type (e.g., SetupConnection)
#[cfg(feature = "with_serde")]
const MSG_TYPE: u8 = 1;
// Example extension type (e.g., a standard Sv2 message)
#[cfg(feature = "with_serde")]
const EXT_TYPE: u16 = 0x0001;

#[cfg(feature = "with_serde")]
#[derive(Serialize, Debug)]
struct CustomMessage {
pub struct CustomMessage {
pub data: u32,
}

// Implemented to help determine the size of the message when framing.
#[cfg(feature = "with_serde")]
impl GetSize for CustomMessage {
fn get_size(&self) -> usize {
4 // `data` is `u32`, which is 4 bytes
}
}

#[cfg(feature = "with_serde")]
fn main() {
// Create the message payload
let message = CustomMessage { data: 42 };
Expand All @@ -67,11 +53,7 @@ fn main() {
// Deserialize the frame from bytes back into an Sv2Frame
let mut deserialized_frame = Sv2Frame::<CustomMessage, Vec<u8>>::from_bytes(serialized_frame)
.expect("Failed to deserialize frame");

assert_eq!(deserialized_frame.encoded_length(), 10); // 6 header bytes + 4 payload bytes
assert_eq!(deserialized_frame.payload(), [42, 0, 0, 0]);
}

#[cfg(not(feature = "with_serde"))]
fn main() {
eprintln!("Serde feature not enabled. Skipping example.");
}
7 changes: 0 additions & 7 deletions protocols/v2/framing-sv2/src/framing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,8 @@ impl<T: Serialize + GetSize, B: AsMut<[u8]> + AsRef<[u8]>> Sv2Frame<T, B> {
dst.swap_with_slice(serialized.as_mut());
Ok(())
} else if let Some(payload) = self.payload {
#[cfg(not(feature = "with_serde"))]
to_writer(self.header, dst).map_err(Error::BinarySv2Error)?;
#[cfg(not(feature = "with_serde"))]
to_writer(payload, &mut dst[Header::SIZE..]).map_err(Error::BinarySv2Error)?;
#[cfg(feature = "with_serde")]
to_writer(&self.header, dst.as_mut()).map_err(Error::BinarySv2Error)?;
#[cfg(feature = "with_serde")]
to_writer(&payload, &mut dst.as_mut()[Header::SIZE..])
.map_err(Error::BinarySv2Error)?;
Ok(())
} else {
// Sv2Frame always has a payload or a serialized payload
Expand Down
5 changes: 1 addition & 4 deletions protocols/v2/framing-sv2/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
//! header itself.
use crate::Error;
#[cfg(not(feature = "with_serde"))]
use alloc::vec::Vec;
#[cfg(not(feature = "with_serde"))]
use binary_sv2::binary_codec_sv2;
use binary_sv2::{Deserialize, Serialize, U24};
use binary_sv2::{binary_codec_sv2, Deserialize, Serialize, U24};
use const_sv2::{AEAD_MAC_LEN, SV2_FRAME_CHUNK_SIZE};
use core::convert::TryInto;

Expand Down
4 changes: 0 additions & 4 deletions protocols/v2/framing-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
//! This crate can be built with the following features:
//!
//! - `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
//! - `with_serde`: builds [`binary_sv2`] and [`buffer_sv2`](https://crates.io/crates/buffer_sv2)
//! crates with `serde`-based encoding and decoding. Note that this 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.
//!
//! ## Examples
//!
Expand Down
8 changes: 0 additions & 8 deletions protocols/v2/roles-logic-sv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"]

[dependencies]
stratum-common = { path = "../../../common", features=["bitcoin"]}
serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false, optional = true}
binary_sv2 = { path = "../../../protocols/v2/binary-sv2/binary-sv2", default-features = true }
common_messages_sv2 = { path = "../../../protocols/v2/subprotocols/common-messages" }
mining_sv2 = { path = "../../../protocols/v2/subprotocols/mining" }
Expand All @@ -35,13 +34,6 @@ rand = "0.8.5"
toml = {git = "https://github.com/diondokter/toml-rs", default-features = false, rev="c4161aa"}

[features]
with_serde = [ "serde",
"framing_sv2/with_serde",
"binary_sv2/with_serde",
"common_messages_sv2/with_serde",
"template_distribution_sv2/with_serde",
"job_declaration_sv2/with_serde",
"mining_sv2/with_serde"]
prop_test = ["template_distribution_sv2/prop_test"]
# Code coverage tools may conflict with the nopanic logic, so we can disable it when needed
disable_nopanic = []
3 changes: 0 additions & 3 deletions protocols/v2/roles-logic-sv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ cargo add roles_logic_sv2

This crate can be built with the following feature flags:

- `with_serde`: Enables serialization and deserialization support using the serde library. This feature flag also activates the with_serde feature for dependent crates such as `binary_sv2`, `common_messages_sv2`, `template_distribution_sv2`, `job_declaration_sv2`, and `mining_sv2`.
Note that this 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.
- `prop_test`: Enables property-based testing features for template distribution logic, leveraging dependencies' testing capabilities such as `template_distribution_sv2` crate.
- `disable_nopanic`: Disables the nopanic logic in scenarios where code coverage tools might conflict with it.
5 changes: 0 additions & 5 deletions protocols/v2/roles-logic-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
//!
//! This crate can be built with the following features:
//!
//! - `with_serde`: builds [`framing_sv2`], [`binary_sv2`], [`common_messages_sv2`],
//! [`template_distribution_sv2`], [`job_declaration_sv2`], and [`mining_sv2`] crates with
//! `serde`-based encoding and decoding. Note that this 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.
//! - `prop_test`: Enables support for property testing in [`template_distribution_sv2`] crate.
pub mod channel_logic;
pub mod common_properties;
Expand Down
Loading

0 comments on commit 19f26e3

Please sign in to comment.