Skip to content

Commit 3fc463c

Browse files
authored
feat: impl compress decompress for customheader (#16617)
1 parent b5c01d6 commit 3fc463c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Cargo.lock

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

examples/custom-node/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ reth-codecs.workspace = true
1212
reth-network-peers.workspace = true
1313
reth-node-builder.workspace = true
1414
reth-optimism-forks.workspace = true
15+
reth-db-api.workspace = true
1516
reth-op = { workspace = true, features = ["node", "pool"] }
1617
reth-payload-builder.workspace = true
1718
reth-rpc-api.workspace = true
@@ -62,5 +63,6 @@ arbitrary = [
6263
"revm/arbitrary",
6364
"reth-ethereum/arbitrary",
6465
"alloy-rpc-types-engine/arbitrary",
66+
"reth-db-api/arbitrary",
6567
]
6668
default = []

examples/custom-node/src/primitives/header.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ impl reth_codecs::Compact for CustomHeader {
166166
}
167167
}
168168

169+
impl reth_db_api::table::Compress for CustomHeader {
170+
type Compressed = Vec<u8>;
171+
172+
fn compress_to_buf<B: alloy_primitives::bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
173+
let _ = Compact::to_compact(self, buf);
174+
}
175+
}
176+
177+
impl reth_db_api::table::Decompress for CustomHeader {
178+
fn decompress(value: &[u8]) -> Result<Self, reth_db_api::DatabaseError> {
179+
let (obj, _) = Compact::from_compact(value, value.len());
180+
Ok(obj)
181+
}
182+
}
183+
169184
impl BlockHeader for CustomHeader {}
170185

171186
mod serde_bincode_compat {

0 commit comments

Comments
 (0)