Skip to content

Commit 19f26e3

Browse files
authored
Merge pull request #1455 from Shourya742/2025-01-31-remove-serde-feature-from-protocol
remove serde feature from protocol crate
2 parents 1370768 + f7b068a commit 19f26e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+319
-1258
lines changed

examples/interop-cpp/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ const_sv2 = { path = "../../protocols/v2/const-sv2" }
1313
binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" }
1414
common_messages_sv2 = { path = "../../protocols/v2/subprotocols/common-messages" }
1515
template_distribution_sv2 = { path = "../../protocols/v2/subprotocols/template-distribution" }
16-
17-
[features]
18-
with_serde = []

examples/interop-cpp/src/main.rs

-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ fn main() -> Result<(), std::io::Error> {
33
main()
44
}
55

6-
#[cfg(feature = "with_serde")]
7-
mod main_ {
8-
pub fn main() -> Result<(), std::io::Error> {
9-
Ok(())
10-
}
11-
}
12-
13-
#[cfg(not(feature = "with_serde"))]
146
mod main_ {
157
use codec_sv2::{Encoder, StandardDecoder, StandardSv2Frame};
168
use common_messages_sv2::{Protocol, SetupConnection, SetupConnectionError};

protocols/v2/codec-sv2/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ key-utils = { path = "../../../utils/key-utils" }
2727
[features]
2828
default = ["std"]
2929
std = ["noise_sv2?/std", "rand/std", "rand/std_rng", "dep:tracing"]
30-
with_serde = ["binary_sv2/with_serde", "serde", "framing_sv2/with_serde", "buffer_sv2/with_serde"]
3130
with_buffer_pool = ["framing_sv2/with_buffer_pool"]
3231

3332
[package.metadata.docs.rs]

protocols/v2/codec-sv2/README.md

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ This crate can be built with the following feature flags:
3131
- `std`: Enable usage of rust `std` library, enabled by default.
3232
- `noise_sv2`: Enables support for Noise protocol encryption and decryption.
3333
- `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
34-
- `with_serde`: builds [`binary_sv2`](https://crates.io/crates/binary_sv2) and
35-
[`buffer_sv2`](https://crates.io/crates/buffer_sv2) crates with `serde`-based encoding and
36-
decoding. Note that this feature flag is only used for the Message Generator, and deprecated
37-
for any other kind of usage. It will likely be fully deprecated in the future.
3834

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

protocols/v2/codec-sv2/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
//! - `std`: Enable usage of rust `std` library, enabled by default.
2323
//! - `noise_sv2`: Enables support for Noise protocol encryption and decryption.
2424
//! - `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
25-
//! - `with_serde`: builds [`binary_sv2`] and [`buffer_sv2`] crates with `serde`-based encoding and
26-
//! decoding. Note that this feature flag is only used for the Message Generator, and deprecated
27-
//! for any other kind of usage. It will likely be fully deprecated in the future.
2825
//!
2926
//! In order to use this crate in a `#![no_std]` environment, use the `--no-default-features` to
3027
//! remove the `std` feature.

protocols/v2/framing-sv2/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "framing_sv2"
3-
version = "3.0.0"
3+
version = "4.0.0"
44
authors = ["The Stratum V2 Developers"]
55
edition = "2018"
66
readme = "README.md"
@@ -25,7 +25,6 @@ rand = "0.8.3"
2525
secp256k1 = { version = "0.28.2", default-features = false, features =["alloc","rand","rand-std"] }
2626

2727
[features]
28-
with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2?/with_serde"]
2928
with_buffer_pool = ["binary_sv2/with_buffer_pool", "buffer_sv2"]
3029

3130
[package.metadata.docs.rs]

protocols/v2/framing-sv2/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ cargo add framing_sv2
5757
This crate can be built with the following feature flags:
5858

5959
- `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
60-
- `with_serde`: builds [`binary_sv2`](https://crates.io/crates/binary_sv2) and
61-
[`buffer_sv2`](https://crates.io/crates/buffer_sv2) crates with `serde`-based encoding and
62-
decoding. Note that this feature flag is only used for the Message Generator, and deprecated
63-
for any other kind of usage. It will likely be fully deprecated in the future.
6460

6561
### Examples
6662

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

6965
1. **[Sv2 Frame](https://github.com/stratum-mining/stratum/blob/main/protocols/v2/framing-sv2/examples/sv2_frame.rs)**:
70-
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).
66+
Constructs, serializes, and deserialize a regular Sv2 message frame (`Sv2Frame`).

protocols/v2/framing-sv2/examples/sv2_frame.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,22 @@
1414
// ## Run
1515
//
1616
// ```
17-
// cargo run --example sv2_frame --features with_serde
17+
// cargo run --example sv2_frame
1818
// ```
1919

20-
#[cfg(feature = "with_serde")]
21-
use binary_sv2::{GetSize, Serialize};
22-
#[cfg(feature = "with_serde")]
20+
use binary_sv2::{binary_codec_sv2, Serialize};
2321
use framing_sv2::framing::Sv2Frame;
2422

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

32-
#[cfg(feature = "with_serde")]
3328
#[derive(Serialize, Debug)]
34-
struct CustomMessage {
29+
pub struct CustomMessage {
3530
pub data: u32,
3631
}
3732

38-
// Implemented to help determine the size of the message when framing.
39-
#[cfg(feature = "with_serde")]
40-
impl GetSize for CustomMessage {
41-
fn get_size(&self) -> usize {
42-
4 // `data` is `u32`, which is 4 bytes
43-
}
44-
}
45-
46-
#[cfg(feature = "with_serde")]
4733
fn main() {
4834
// Create the message payload
4935
let message = CustomMessage { data: 42 };
@@ -67,11 +53,7 @@ fn main() {
6753
// Deserialize the frame from bytes back into an Sv2Frame
6854
let mut deserialized_frame = Sv2Frame::<CustomMessage, Vec<u8>>::from_bytes(serialized_frame)
6955
.expect("Failed to deserialize frame");
56+
7057
assert_eq!(deserialized_frame.encoded_length(), 10); // 6 header bytes + 4 payload bytes
7158
assert_eq!(deserialized_frame.payload(), [42, 0, 0, 0]);
7259
}
73-
74-
#[cfg(not(feature = "with_serde"))]
75-
fn main() {
76-
eprintln!("Serde feature not enabled. Skipping example.");
77-
}

protocols/v2/framing-sv2/src/framing.rs

-7
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,8 @@ impl<T: Serialize + GetSize, B: AsMut<[u8]> + AsRef<[u8]>> Sv2Frame<T, B> {
8282
dst.swap_with_slice(serialized.as_mut());
8383
Ok(())
8484
} else if let Some(payload) = self.payload {
85-
#[cfg(not(feature = "with_serde"))]
8685
to_writer(self.header, dst).map_err(Error::BinarySv2Error)?;
87-
#[cfg(not(feature = "with_serde"))]
8886
to_writer(payload, &mut dst[Header::SIZE..]).map_err(Error::BinarySv2Error)?;
89-
#[cfg(feature = "with_serde")]
90-
to_writer(&self.header, dst.as_mut()).map_err(Error::BinarySv2Error)?;
91-
#[cfg(feature = "with_serde")]
92-
to_writer(&payload, &mut dst.as_mut()[Header::SIZE..])
93-
.map_err(Error::BinarySv2Error)?;
9487
Ok(())
9588
} else {
9689
// Sv2Frame always has a payload or a serialized payload

protocols/v2/framing-sv2/src/header.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
//! header itself.
2121
2222
use crate::Error;
23-
#[cfg(not(feature = "with_serde"))]
2423
use alloc::vec::Vec;
25-
#[cfg(not(feature = "with_serde"))]
26-
use binary_sv2::binary_codec_sv2;
27-
use binary_sv2::{Deserialize, Serialize, U24};
24+
use binary_sv2::{binary_codec_sv2, Deserialize, Serialize, U24};
2825
use const_sv2::{AEAD_MAC_LEN, SV2_FRAME_CHUNK_SIZE};
2926
use core::convert::TryInto;
3027

protocols/v2/framing-sv2/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
//! This crate can be built with the following features:
4141
//!
4242
//! - `with_buffer_pool`: Enables buffer pooling for more efficient memory management.
43-
//! - `with_serde`: builds [`binary_sv2`] and [`buffer_sv2`](https://crates.io/crates/buffer_sv2)
44-
//! crates with `serde`-based encoding and decoding. Note that this feature flag is only used for
45-
//! the Message Generator, and deprecated for any other kind of usage. It will likely be fully
46-
//! deprecated in the future.
4743
//!
4844
//! ## Examples
4945
//!

protocols/v2/roles-logic-sv2/Cargo.toml

-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"]
1414

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

3736
[features]
38-
with_serde = [ "serde",
39-
"framing_sv2/with_serde",
40-
"binary_sv2/with_serde",
41-
"common_messages_sv2/with_serde",
42-
"template_distribution_sv2/with_serde",
43-
"job_declaration_sv2/with_serde",
44-
"mining_sv2/with_serde"]
4537
prop_test = ["template_distribution_sv2/prop_test"]
4638
# Code coverage tools may conflict with the nopanic logic, so we can disable it when needed
4739
disable_nopanic = []

protocols/v2/roles-logic-sv2/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ cargo add roles_logic_sv2
2727

2828
This crate can be built with the following feature flags:
2929

30-
- `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`.
31-
Note that this feature flag is only used for the Message Generator, and deprecated
32-
for any other kind of usage. It will likely be fully deprecated in the future.
3330
- `prop_test`: Enables property-based testing features for template distribution logic, leveraging dependencies' testing capabilities such as `template_distribution_sv2` crate.
3431
- `disable_nopanic`: Disables the nopanic logic in scenarios where code coverage tools might conflict with it.

protocols/v2/roles-logic-sv2/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
//!
1717
//! This crate can be built with the following features:
1818
//!
19-
//! - `with_serde`: builds [`framing_sv2`], [`binary_sv2`], [`common_messages_sv2`],
20-
//! [`template_distribution_sv2`], [`job_declaration_sv2`], and [`mining_sv2`] crates with
21-
//! `serde`-based encoding and decoding. Note that this feature flag is only used for the Message
22-
//! Generator, and deprecated for any other kind of usage. It will likely be fully deprecated in
23-
//! the future.
2419
//! - `prop_test`: Enables support for property testing in [`template_distribution_sv2`] crate.
2520
pub mod channel_logic;
2621
pub mod common_properties;

0 commit comments

Comments
 (0)