Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove binary sv2 serde #1459

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/coverage-protocols.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ jobs:
file: ./protocols/target/tarpaulin-reports/binary-sv2-coverage/cobertura.xml
flags: binary_sv2-coverage
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload binary_serde_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
with:
directory: ./protocols/target/tarpaulin-reports/serde-sv2-coverage
file: ./protocols/target/tarpaulin-reports/serde-sv2-coverage/cobertura.xml
flags: binary_serde_sv2-coverage
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload codec_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,20 @@ jobs:
cd utils/buffer
cargo doc

- name: Rust Docs crate no_serde_sv2_derive_codec
- name: Rust Docs crate binary_sv2 derive_codec
run: |
cd protocols/v2/binary-sv2/no-serde-sv2/derive_codec
cd protocols/v2/binary-sv2/derive_codec
cargo doc

- name: Rust Docs crate no_serde_sv2_codec
- name: Rust Docs crate binary_sv2 codec
run: |
cd protocols/v2/binary-sv2/no-serde-sv2/codec
cd protocols/v2/binary-sv2/codec
cargo doc --features with_buffer_pool

- name: Rust Docs crate serde_sv2
run: |
cd protocols/v2/binary-sv2/serde-sv2
cargo doc

- name: Rust Docs crate binary_sv2
run: |
cd protocols/v2/binary-sv2/binary-sv2
cargo doc --features core,with_buffer_pool
cd protocols/v2/binary-sv2
cargo doc --features with_buffer_pool

- name: Rust Docs crate const_sv2
run: |
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/release-libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ jobs:
run: |
./scripts/release-libs.sh utils/buffer

- name: Publish crate no_serde_sv2_derive_codec
- name: Publish crate binary_sv2 derive_codec
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2/no-serde-sv2/derive_codec
./scripts/release-libs.sh protocols/v2/binary-sv2/derive_codec

- name: Publish crate no_serde_sv2_codec
- name: Publish crate binary_sv2 codec
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2/no-serde-sv2/codec

- name: Publish crate serde_sv2
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2/serde-sv2
./scripts/release-libs.sh protocols/v2/binary-sv2/codec

- name: Publish crate binary_sv2
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2/binary-sv2
./scripts/release-libs.sh protocols/v2/binary-sv2

- name: Publish crate const_sv2
run: |
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/semver-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ jobs:
working-directory: utils/buffer
run: cargo semver-checks

- name: Run semver checks for protocols/v2/binary-sv2/no-serde-sv2/codec
working-directory: protocols/v2/binary-sv2/no-serde-sv2/codec
- name: Run semver checks for protocols/v2/binary-sv2/codec
working-directory: protocols/v2/binary-sv2/codec
run: cargo semver-checks

- name: Run semver checks for protocols/v2/binary-sv2/serde-sv2
working-directory: protocols/v2/binary-sv2/serde-sv2
run: cargo semver-checks

- name: Run semver checks for protocols/v2/binary-sv2/binary-sv2
working-directory: protocols/v2/binary-sv2/binary-sv2
- name: Run semver checks for protocols/v2/binary-sv2
working-directory: protocols/v2/binary-sv2
run: cargo semver-checks

- name: Run semver checks for protocols/v2/const-sv2
Expand Down
2 changes: 1 addition & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ num-bigint = "0.4.3"
num-traits = "0.2.15"
bitcoin="0.28.1"
codec_sv2 = { path = "../protocols/v2/codec-sv2", features=["noise_sv2"] }
binary_sv2 = { path = "../protocols/v2/binary-sv2/binary-sv2" }
binary_sv2 = { path = "../protocols/v2/binary-sv2" }
network_helpers_sv2 = { path = "../roles/roles-utils/network-helpers" }
rand = "0.8.4"

Expand Down
11 changes: 4 additions & 7 deletions examples/interop-cpp-no-cargo/rust-build-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rustc \
rustc \
--crate-name binary_codec_sv2 \
--edition=2018 \
$ROOT/binary-sv2/no-serde-sv2/codec/src/lib.rs \
$ROOT/binary-sv2/codec/src/lib.rs \
--error-format=json \
--json=diagnostic-rendered-ansi \
--crate-type lib \
Expand All @@ -40,7 +40,7 @@ rustc \
rustc \
--crate-name binary_codec_sv2 \
--edition=2018 \
$ROOT/binary-sv2/no-serde-sv2/codec/src/lib.rs \
$ROOT/binary-sv2/codec/src/lib.rs \
--error-format=json \
--json=diagnostic-rendered-ansi,artifacts \
--crate-type lib \
Expand All @@ -66,7 +66,7 @@ rustc \
rustc \
--crate-name derive_codec_sv2 \
--edition=2018 \
$ROOT/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs \
$ROOT/binary-sv2/derive_codec/src/lib.rs \
--error-format=json \
--json=diagnostic-rendered-ansi \
--crate-type proc-macro \
Expand All @@ -82,17 +82,14 @@ rustc \
rustc \
--crate-name binary_sv2 \
--edition=2018 \
$ROOT/binary-sv2/binary-sv2/src/lib.rs \
$ROOT/binary-sv2/src/lib.rs \
--error-format=json \
--json=diagnostic-rendered-ansi,artifacts \
--crate-type lib \
--emit=dep-info,metadata,link \
-C opt-level=3 \
-C embed-bitcode=no \
--cfg 'feature="binary_codec_sv2"' \
--cfg 'feature="core"' \
--cfg 'feature="default"' \
--cfg 'feature="derive_codec_sv2"' \
--out-dir $DEPS \
-L dependency=$DEPS \
--extern binary_codec_sv2=$DEPS/libbinary_codec_sv2.rmeta \
Expand Down
2 changes: 1 addition & 1 deletion examples/interop-cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ publish = false
[dependencies]
codec_sv2 = { path = "../../protocols/v2/codec-sv2" }
const_sv2 = { path = "../../protocols/v2/const-sv2" }
binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" }
binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
common_messages_sv2 = { path = "../../protocols/v2/subprotocols/common-messages" }
template_distribution_sv2 = { path = "../../protocols/v2/subprotocols/template-distribution" }
2 changes: 1 addition & 1 deletion examples/ping-pong-encrypted/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [ "SRI Community" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" }
binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
codec_sv2 = { path = "../../protocols/v2/codec-sv2", features = [ "noise_sv2" ] }
noise_sv2 = { path = "../../protocols/v2/noise-sv2" }
key-utils = { version = "^1.0.0", path = "../../utils/key-utils" }
Expand Down
2 changes: 1 addition & 1 deletion examples/ping-pong/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [ "SRI Community" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" }
binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
codec_sv2 = { path = "../../protocols/v2/codec-sv2" }

rand = "0.8"
7 changes: 3 additions & 4 deletions protocols/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ resolver="2"

members = [
"v1",
"v2/binary-sv2/serde-sv2",
"v2/binary-sv2/no-serde-sv2/codec",
"v2/binary-sv2/no-serde-sv2/derive_codec",
"v2/binary-sv2/binary-sv2",
"v2/binary-sv2/codec",
"v2/binary-sv2/derive_codec",
"v2/binary-sv2",
"v2/noise-sv2",
"v2/framing-sv2",
"v2/codec-sv2",
Expand Down
2 changes: 1 addition & 1 deletion protocols/fuzz-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cargo-fuzz = true
libfuzzer-sys = { version = "0.4.0", features = ["arbitrary-derive"] }
arbitrary = { version = "1", features = ["derive"] }
rand = "0.8.3"
binary_codec_sv2 = { path = "../v2/binary-sv2/no-serde-sv2/codec"}
binary_codec_sv2 = { path = "../v2/binary-sv2/codec"}
codec_sv2 = { path = "../v2/codec-sv2", features = ["noise_sv2"]}
roles_logic_sv2 = { path = "../v2/roles-logic-sv2"}
affinity = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion protocols/v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hex = "0.4.3"
serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] }
tracing = {version = "0.1"}
binary_sv2 = { path = "../v2/binary-sv2/binary-sv2" }
binary_sv2 = { path = "../v2/binary-sv2" }

[dev-dependencies]
quickcheck = "1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
[package]
name = "serde_sv2"
name = "binary_sv2"
version = "2.0.0"
authors = ["The Stratum V2 Developers"]
edition = "2018"
readme = "README.md"
description = "Serlializer and Deserializer for Stratum V2 data format"
documentation = "https://docs.rs/serde_sv2"
description = "Sv2 data format"
documentation = "https://docs.rs/binary_sv2"
license = "MIT OR Apache-2.0"
repository = "https://github.com/stratum-mining/stratum"
homepage = "https://stratumprotocol.org"
keywords = ["stratum", "mining", "bitcoin", "protocol"]


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false }
buffer_sv2 = { path = "../../../../utils/buffer"}
binary_codec_sv2 = { path = "codec" }
derive_codec_sv2 = { path = "derive_codec" }

[features]
prop_test = ["binary_codec_sv2/prop_test"]
with_buffer_pool = ["binary_codec_sv2/with_buffer_pool"]

[package.metadata.docs.rs]
features = ["with_buffer_pool"]
Original file line number Diff line number Diff line change
Expand Up @@ -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)

`binary-sv2` is a Rust `no-std` crate that helps encode and decode binary data into Stratum V2 messages — either through `serde` or custom trait-based setup. Allowing it to be used in environment(s) where std or/and serde are not available.
`binary-sv2` is a Rust `no-std` crate that helps encode and decode binary data into Stratum V2 messages

## Key Capabilities

Expand All @@ -14,8 +14,6 @@

## Features

- **with_serde**: Enables `serde`-based encoding and decoding.
- **core**: Activates non-`serde` implementations via `binary_codec_sv2` and `derive_codec_sv2`.(default)
- **prop_test**: Adds property testing support.
- **with_buffer_pool**: Optimizes memory usage during encoding.

Expand Down
30 changes: 0 additions & 30 deletions protocols/v2/binary-sv2/binary-sv2/Cargo.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"]

[dependencies]
quickcheck = { version = "1.0.0", optional = true }
buffer_sv2 = { path = "../../../../../utils/buffer", optional=true }
buffer_sv2 = { path = "../../../../utils/buffer", optional=true }

[features]
no_std = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub enum Inner<
Owned(Vec<u8>),
}

// TODO add test for that and implement it also with serde!!!!
impl<'a, const SIZE: usize> Inner<'a, true, SIZE, 0, 0> {
// Converts the inner data to a vector, either by cloning the referenced slice or
// returning a clone of the owned vector.
Expand All @@ -101,7 +100,7 @@ impl<'a, const SIZE: usize> Inner<'a, true, SIZE, 0, 0> {
}
}
}
// TODO add test for that and implement it also with serde!!!!

impl<'a, const SIZE: usize, const HEADERSIZE: usize, const MAXSIZE: usize>
Inner<'a, false, SIZE, HEADERSIZE, MAXSIZE>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
// - `impl_into_encodable_field_for_seq!`: Implements conversions to `EncodableField` for a
// sequence, adapting the sequence for inclusion in serialized structures.
//
// ## Notes on Serialization
//
// Types are designed to interoperate with the `serde-sv2` framework, using lifetimes
// (`'a`) for compatibility with external lifetimes and ensuring the types can be converted into
// various serialized forms with or without `serde` support.
//
// ## Build Options
//
// - `prop_test`: Enables property-based testing compatibility by implementing `TryFrom` for `Vec`
Expand All @@ -60,7 +54,7 @@ use crate::{
};
use core::marker::PhantomData;

// TODO add test for that and implement it also with serde!!!!
// TODO add test for that
impl<'a, const SIZE: usize, const HEADERSIZE: usize, const MAXSIZE: usize>
Seq0255<'a, super::inner::Inner<'a, false, SIZE, HEADERSIZE, MAXSIZE>>
{
Expand All @@ -74,7 +68,7 @@ impl<'a, const SIZE: usize, const HEADERSIZE: usize, const MAXSIZE: usize>
}
}

// TODO add test for that and implement it also with serde!!!!
// TODO add test for that
impl<'a, const SIZE: usize> Seq0255<'a, super::inner::Inner<'a, true, SIZE, 0, 0>> {
/// Converts the inner types to owned vector, and collects.
pub fn to_vec(&self) -> Vec<Vec<u8>> {
Expand All @@ -86,7 +80,7 @@ impl<'a, const SIZE: usize> Seq0255<'a, super::inner::Inner<'a, true, SIZE, 0, 0
self.0.iter().map(|x| x.inner_as_ref()).collect()
}
}
// TODO add test for that and implement it also with serde!!!!
// TODO add test for that
impl<'a, const SIZE: usize, const HEADERSIZE: usize, const MAXSIZE: usize>
Seq064K<'a, super::inner::Inner<'a, false, SIZE, HEADERSIZE, MAXSIZE>>
{
Expand All @@ -101,7 +95,7 @@ impl<'a, const SIZE: usize, const HEADERSIZE: usize, const MAXSIZE: usize>
}
}

// TODO add test for that and implement it also with serde!!!!
// TODO add test for that
impl<'a, const SIZE: usize> Seq064K<'a, super::inner::Inner<'a, true, SIZE, 0, 0>> {
/// Converts the inner types to owned vector, and collects.
pub fn to_vec(&self) -> Vec<Vec<u8>> {
Expand All @@ -118,8 +112,7 @@ impl<'a, const SIZE: usize> Seq064K<'a, super::inner::Inner<'a, true, SIZE, 0, 0
use std::io::Read;

/// [`Seq0255`] represents a sequence with a maximum length of 255 elements.
/// This structure uses a generic type `T` and a lifetime parameter `'a`
/// to ensure compatibility with `serde-sv2`.
/// This structure uses a generic type `T` and a lifetime parameter `'a`.
plebhash marked this conversation as resolved.
Show resolved Hide resolved
#[repr(C)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Seq0255<'a, T>(pub Vec<T>, PhantomData<&'a T>);
Expand Down Expand Up @@ -163,8 +156,7 @@ impl<'a, T: GetSize> GetSize for Seq0255<'a, T> {
}

/// [`Seq064K`] represents a sequence with a maximum length of 65535 elements.
/// This structure uses a generic type `T` and a lifetime parameter `'a`
/// to ensure compatibility with `serde-sv2`.
/// This structure uses a generic type `T` and a lifetime parameter `'a`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the original motivation for the lifetime parameter was serde-sv2 compatibility, shouldn't we also do something about that?

it seems now there's no real motivation for this anymore, and simply removing the comment will make it hard for us to understand in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will remove the lifetime parameters in the refactor binary_sv2 PR. I just didn't touch them in this PR since we agreed it would bloat the scope. Thanks for pointing it out for other reviewers to keep in mind while reviewing this and the binary_sv2 PR!

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Seq064K<'a, T>(pub(crate) Vec<T>, PhantomData<&'a T>);

Expand Down Expand Up @@ -455,12 +447,12 @@ impl<'a, const ISFIXED: bool, const SIZE: usize, const HEADERSIZE: usize, const
}
}

/// The liftime is here only for type compatibility with serde-sv2
/// The lifetime 'a is defined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the original motivation for the lifetime parameter was serde-sv2 compatibility, shouldn't we also do something about that?

it seems now there's no real motivation for this anymore, and simply removing the comment will make it hard for us to understand in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will remove the lifetime parameters in the refactor binary_sv2 PR. I just didn't touch them in this PR since we agreed it would bloat the scope. Thanks for pointing it out for other reviewers to keep in mind while reviewing this and the binary_sv2 PR!

#[repr(C)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Sv2Option<'a, T>(pub Vec<T>, PhantomData<&'a T>);

// TODO add test for that and implement it also with serde!!!!
// TODO add test for that
impl<'a, const SIZE: usize> Sv2Option<'a, super::inner::Inner<'a, true, SIZE, 0, 0>> {
/// Gets the owned first element of the sequence, if present
pub fn to_option(&self) -> Option<Vec<u8>> {
Expand Down
Loading
Loading