From be0c4ee98e3906c1731ce0e75ff040698917b473 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 13 Aug 2026 14:47:18 +0530 Subject: [PATCH 1/5] framing-sv2: use owned SV2 datatypes instead of Vec in test/bench messages --- sv2/framing-sv2/benches/framing.rs | 15 +++++++++------ sv2/framing-sv2/src/framing.rs | 8 +++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sv2/framing-sv2/benches/framing.rs b/sv2/framing-sv2/benches/framing.rs index 02497ad104..5236ad46b6 100644 --- a/sv2/framing-sv2/benches/framing.rs +++ b/sv2/framing-sv2/benches/framing.rs @@ -1,7 +1,7 @@ //! Performance benchmarks for SV2 framing layer operations //! Tests both Vec and buffer_pool backends across different message sizes -use binary_sv2::Serialize; +use binary_sv2::{B016MOwned, Serialize}; use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; use framing_sv2::{framing::Sv2Frame, header::Header}; @@ -42,12 +42,15 @@ fn frame_from_payload_size(size: usize) -> Vec { #[derive(Serialize, Clone)] struct Test { - _a: Vec, + _a: B016MOwned, } impl Test { + // `size` is the total encoded message size: 3-byte B016M length prefix + data fn new(size: usize) -> Self { - Test { _a: vec![2; size] } + Test { + _a: vec![2; size - 3].try_into().unwrap(), + } } } @@ -71,7 +74,7 @@ fn bench_serialize(c: &mut Criterion) { for &size in PAYLOAD_SIZES { let frame = - Sv2Frame::, Slice>::from_bytes(frame_from_payload_size(size).into()).unwrap(); + Sv2Frame::::from_bytes(frame_from_payload_size(size).into()).unwrap(); let mut buf = vec![0u8; frame.encoded_length()]; @@ -92,7 +95,7 @@ fn bench_from_bytes(c: &mut Criterion) { for &size in PAYLOAD_SIZES { let frame = frame_from_payload_size(size); group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, _| { - b.iter(|| Sv2Frame::, _>::from_bytes(black_box(frame.clone())).unwrap()) + b.iter(|| Sv2Frame::::from_bytes(black_box(frame.clone())).unwrap()) }); } @@ -106,7 +109,7 @@ fn bench_size_hint(c: &mut Criterion) { for &size in PAYLOAD_SIZES { let frame = frame_from_payload_size(size); group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, _| { - b.iter(|| Sv2Frame::, Slice>::size_hint(black_box(&frame))) + b.iter(|| Sv2Frame::::size_hint(black_box(&frame))) }); } diff --git a/sv2/framing-sv2/src/framing.rs b/sv2/framing-sv2/src/framing.rs index 72507fb1d0..8e9e4948fa 100644 --- a/sv2/framing-sv2/src/framing.rs +++ b/sv2/framing-sv2/src/framing.rs @@ -301,7 +301,7 @@ fn update_extension_type(extension_type: u16, channel_msg: bool) -> u16 { mod tests { use super::*; use alloc::vec; - use binary_sv2::Serialize; + use binary_sv2::{B064KOwned, Serialize}; use quickcheck::{Arbitrary, Gen}; use quickcheck_macros::quickcheck; @@ -325,7 +325,7 @@ mod tests { #[derive(Debug, Clone, PartialEq, Serialize)] struct TestMessage { - data: Vec, + data: B064KOwned, } impl Arbitrary for TestMessage { @@ -394,7 +394,9 @@ mod tests { #[quickcheck] fn prop_sv2frame_serialization_roundtrip_small(data: Vec) { let data: Vec = data.iter().take(1000).copied().collect(); - let msg = TestMessage { data }; + let msg = TestMessage { + data: data.try_into().unwrap(), + }; let msg_type = 0x01u8; let extension_type = 0x0000u16; From ed91cb5d77c49f1e62315d07553e55e533b8a351 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 13 Aug 2026 14:47:18 +0530 Subject: [PATCH 2/5] fuzz: use len() instead of get_size() on raw byte buffers --- fuzz/fuzz_targets/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzz/fuzz_targets/common.rs b/fuzz/fuzz_targets/common.rs index c8c8b989ae..fbef6a3dcc 100644 --- a/fuzz/fuzz_targets/common.rs +++ b/fuzz/fuzz_targets/common.rs @@ -124,7 +124,7 @@ macro_rules! test_datatype_roundtrip { // Ensure serialization is canonical: re-encoding must match the consumed input. assert_eq!( encoded, - input[..encoded.get_size()], + input[..encoded.len()], "Serialization is not stable" ); } @@ -162,7 +162,7 @@ macro_rules! test_datatype_roundtrip { // reserialization must match the consumed input bytes. assert_eq!( encoded, - input[..encoded.get_size()], + input[..encoded.len()], "{}: Serialization is not stable", stringify!($datatype) ); From edc63168f24d884562f5df5c99d4ca90fa6c45d6 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 13 Aug 2026 14:47:18 +0530 Subject: [PATCH 3/5] binary-sv2: remove From> and From for EncodableField --- sv2/binary-sv2/src/lib.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/sv2/binary-sv2/src/lib.rs b/sv2/binary-sv2/src/lib.rs index 32dfb55a42..68b98002f3 100644 --- a/sv2/binary-sv2/src/lib.rs +++ b/sv2/binary-sv2/src/lib.rs @@ -231,16 +231,3 @@ impl GetSize for Vec { self.len() } } - -impl From> for EncodableField<'_> { - fn from(v: Vec) -> Self { - EncodableField::Struct(v.into_iter().map(Into::into).collect()) - } -} - -#[cfg(feature = "with_buffer_pool")] -impl From for EncodableField<'_> { - fn from(_v: buffer_sv2::Slice) -> Self { - unreachable!() - } -} From 479fcfbfd53b6cff3770a2927ef18555a3a42045 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 13 Aug 2026 14:47:19 +0530 Subject: [PATCH 4/5] binary-sv2: remove GetSize impl for Vec --- sv2/binary-sv2/src/lib.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sv2/binary-sv2/src/lib.rs b/sv2/binary-sv2/src/lib.rs index 68b98002f3..8a71705633 100644 --- a/sv2/binary-sv2/src/lib.rs +++ b/sv2/binary-sv2/src/lib.rs @@ -224,10 +224,3 @@ pub enum Error { /// elements. Sv2OptionHaveMoreThenOneElement(u8), } - -/// Vec is used as the Sv2 type Bytes -impl GetSize for Vec { - fn get_size(&self) -> usize { - self.len() - } -} From faced72908484e41080f26b182aad42d4cdedb19 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Fri, 14 Aug 2026 08:59:27 +0530 Subject: [PATCH 5/5] Remove BYTES from binary_sv2 doc and also add comment explaining the removal --- sv2/binary-sv2/README.md | 5 ++++- sv2/binary-sv2/src/lib.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sv2/binary-sv2/README.md b/sv2/binary-sv2/README.md index d8e6bcf69a..23c6f60c45 100644 --- a/sv2/binary-sv2/README.md +++ b/sv2/binary-sv2/README.md @@ -27,10 +27,13 @@ The crate supports the following mappings between Rust and SV2 types | `f32` | `F32` | | `Str0255` | `STRO_255` | | `Signature` | `SIGNATURE` | -| `[u8]` | `BYTES` | | `Seq0255` | `SEQ0_255[T]` | | `Seq064K` | `SEQ0_64K[T]` | +`BYTES` is not listed above: it only appears as the length-prefixed frame payload, whose length +comes from the frame header, so it is handled by the framing layer (`framing-sv2`) rather than by +this crate. + ## Features diff --git a/sv2/binary-sv2/src/lib.rs b/sv2/binary-sv2/src/lib.rs index 8a71705633..bc8fa12b03 100644 --- a/sv2/binary-sv2/src/lib.rs +++ b/sv2/binary-sv2/src/lib.rs @@ -26,12 +26,15 @@ //! B0255 <-> B0_255 //! B064K <-> B0_64K //! B016M <-> B0_16M -//! [u8] <-> BYTES //! Pubkey <-> PUBKEY //! Seq0255 <-> SEQ0_255[T] //! Seq064K <-> SEQ0_64K[T] //! ``` //! +//! `BYTES` is not in this table: it only appears as the length-prefixed frame payload, whose +//! length comes from the frame header, so it is handled by the framing layer (`framing-sv2`) +//! rather than by this crate. +//! //! # Encoding & Decoding //! //! Enables conversion between various Rust types and SV2-specific data formats for efficient