Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
fix: rlp issue
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Nov 20, 2024
1 parent 9aaf5ad commit 955fee5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ mod tests {

use alloy_chains::Chain;
use alloy_genesis::{ChainConfig, GenesisAccount};
use alloy_primitives::{b256, hex};
use alloy_primitives::hex;
use alloy_trie::EMPTY_ROOT_HASH;
use reth_ethereum_forks::{ForkCondition, ForkHash, ForkId, Head};
use reth_trie_common::TrieAccount;
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ alloy-consensus = { workspace = true, features = ["serde"] }
alloy-eips.workspace = true
alloy-genesis.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-rlp = { workspace = true, features = ["derive"] }

revm-primitives = { workspace = true, features = ["serde"] }

Expand Down
44 changes: 36 additions & 8 deletions crates/primitives-traits/src/blob_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,57 @@ impl BlobSidecars {
/// check for errors because we assume that `BlobSidecars` will only ever contain valid
/// sidecars
pub fn encode_index(&self, out: &mut dyn BufMut, index: usize) {
let header = alloy_rlp::Header { list: true, payload_length: self.0[index].length() };
let header = alloy_rlp::Header { list: false, payload_length: self.0[index].length() };
header.encode(out);
self.0[index].encode(out);
}
}

impl Encodable for BlobSidecar {
fn encode(&self, out: &mut dyn BufMut) {
let list_header_self = alloy_rlp::Header { list: true, payload_length: self.length() };
let payload_length = self.blob_transaction_sidecar.length() +
self.block_number.length() +
self.block_hash.length() +
self.tx_index.length() +
self.tx_hash.length();

let list_header_self = alloy_rlp::Header { list: false, payload_length };
list_header_self.encode(out);

let list_header_tx_sidecar = alloy_rlp::Header {
list: true,
list: false,
payload_length: self.blob_transaction_sidecar.length(),
};
list_header_tx_sidecar.encode(out);

self.blob_transaction_sidecar.encode(out);
self.blob_transaction_sidecar.blobs.encode(out);
self.blob_transaction_sidecar.commitments.encode(out);
self.blob_transaction_sidecar.proofs.encode(out);
self.block_number.encode(out);
self.block_hash.encode(out);
self.tx_index.encode(out);
self.tx_hash.encode(out);
}

fn length(&self) -> usize {
self.blob_transaction_sidecar.length() +
self.blob_transaction_sidecar.length().length() +
let payload_length = self.blob_transaction_sidecar.length() +
self.block_number.length() +
self.block_hash.length() +
self.tx_index.length() +
self.tx_hash.length();

let list_header_self = alloy_rlp::Header { list: false, payload_length };
let list_header_self_length = list_header_self.length();

let list_header_tx_sidecar = alloy_rlp::Header {
list: false,
payload_length: self.blob_transaction_sidecar.length(),
};
let header_length = list_header_tx_sidecar.length();

list_header_self_length +
header_length +
self.blob_transaction_sidecar.length() +
self.block_number.length() +
self.block_hash.length() +
self.tx_index.length() +
Expand All @@ -114,7 +138,11 @@ impl Decodable for BlobSidecar {
let _rlp_head_tx_sidecar = alloy_rlp::Header::decode(buf)?;

let this = Self {
blob_transaction_sidecar: Decodable::decode(buf)?,
blob_transaction_sidecar: BlobTransactionSidecar {
blobs: Decodable::decode(buf)?,
commitments: Decodable::decode(buf)?,
proofs: Decodable::decode(buf)?,
},
block_number: Decodable::decode(buf)?,
block_hash: Decodable::decode(buf)?,
tx_index: Decodable::decode(buf)?,
Expand Down Expand Up @@ -222,7 +250,7 @@ mod tests {
fn test_blob_sidecar_rlp() {
let blob_sidecar = BlobSidecar {
blob_transaction_sidecar: BlobTransactionSidecar {
blobs: vec![],
blobs: vec![Default::default()],
commitments: vec![Default::default()],
proofs: vec![Default::default()],
},
Expand Down

0 comments on commit 955fee5

Please sign in to comment.