Skip to content

Commit 733de28

Browse files
committed
packet: Use Bytes instead of an array in Packet
The reason behind the switch is that `Packet` gets cloned in multiple places. `Bytes` provides a zero-copy abstraction, where calling `clone()` doesn't make an actual copy of the underlying data and all instances point to the same memory. However, the old layout containing a sized array is convenient for CUDA. To not break CUDA support, this change introduces a new struct called `PacketArray`, which a `Packet` can be converted into just before calling GPU-based sigverify. That requires a copy, ideally just one. At the same time, CPU-based sigverify and all the other components are going to benefit from zero-copy properties of `Bytes`.
1 parent 4b1ade7 commit 733de28

File tree

6 files changed

+471
-117
lines changed

6 files changed

+471
-117
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ bs58 = { version = "0.5.1", default-features = false }
140140
bv = "0.11.1"
141141
bytemuck = "1.21.0"
142142
bytemuck_derive = "1.8.1"
143+
bytes = { version = "1.10", features = ["serde"] }
143144
cfg_eval = "0.1.2"
144145
chrono = { version = "0.4.39", default-features = false }
145146
console = "0.15.10"

frozen-abi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = { workspace = true }
1111

1212
[dependencies]
1313
bs58 = { workspace = true, features = ["alloc"] }
14+
bytes = { workspace = true, optional = true }
1415
bv = { workspace = true, features = ["serde"] }
1516
log = { workspace = true, features = ["std"] }
1617
serde = { workspace = true, features = ["rc"] }
@@ -34,7 +35,7 @@ serde_with = { workspace = true, features = ["macros"] }
3435
default = []
3536
# activate the frozen-abi feature when we actually want to do frozen-abi testing,
3637
# otherwise leave it off because it requires nightly Rust
37-
frozen-abi = []
38+
frozen-abi = ["bytes"]
3839

3940
[lints]
4041
workspace = true

frozen-abi/src/abi_example.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use {
22
crate::abi_digester::{AbiDigester, DigestError, DigestResult},
3+
bytes::Bytes,
34
log::*,
45
serde::Serialize,
56
std::any::type_name,
@@ -507,6 +508,12 @@ impl AbiExample for IpAddr {
507508
}
508509
}
509510

511+
impl AbiExample for Bytes {
512+
fn example() -> Self {
513+
Bytes::new()
514+
}
515+
}
516+
510517
// This is a control flow indirection needed for digesting all variants of an enum.
511518
//
512519
// All of types (including non-enums) will be processed by this trait, albeit the

packet/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edition = { workspace = true }
1212
[dependencies]
1313
bincode = { workspace = true, optional = true }
1414
bitflags = { workspace = true }
15+
bytes = { workspace = true }
1516
cfg_eval = { workspace = true, optional = true }
1617
serde = { workspace = true, optional = true }
1718
serde_derive = { workspace = true, optional = true }

0 commit comments

Comments
 (0)