Expand description
Execution layer specific types for .era1
files
Contains implementations for compressed execution layer data structures:
CompressedHeader
- Block headerCompressedBody
- Block bodyCompressedReceipts
- Block receiptsTotalDifficulty
- Block total difficulty
These types use Snappy compression to match the specification.
See also https://github.com/eth-clients/e2store-format-specs/blob/main/formats/era1.md
§Examples
§CompressedHeader
use alloy_consensus::Header;
use reth_era::{execution_types::CompressedHeader, DecodeCompressed};
let header = Header { number: 100, ..Default::default() };
// Compress the header: rlp encoding and Snappy compression
let compressed = CompressedHeader::from_header(&header)?;
// Decompressed and decode typed compressed header
let decoded_header: Header = compressed.decode_header()?;
assert_eq!(decoded_header.number, 100);
§CompressedBody
use alloy_consensus::{BlockBody, Header};
use alloy_primitives::Bytes;
use reth_era::{execution_types::CompressedBody, DecodeCompressed};
use reth_ethereum_primitives::TransactionSigned;
let body: BlockBody<Bytes> = BlockBody {
transactions: vec![Bytes::from(vec![1, 2, 3])],
ommers: vec![],
withdrawals: None,
};
// Compress the body: rlp encoding and snappy compression
let compressed_body = CompressedBody::from_body(&body)?;
// Decode back to typed body by decompressing and decoding
let decoded_body: alloy_consensus::BlockBody<alloy_primitives::Bytes> =
compressed_body.decode()?;
assert_eq!(decoded_body.transactions.len(), 1);
§CompressedReceipts
use alloy_consensus::ReceiptWithBloom;
use reth_era::{execution_types::CompressedReceipts, DecodeCompressed};
use reth_ethereum_primitives::{Receipt, TxType};
let receipt = Receipt {
tx_type: TxType::Legacy,
success: true,
cumulative_gas_used: 21000,
logs: vec![],
};
let receipt_with_bloom = ReceiptWithBloom { receipt, logs_bloom: Default::default() };
// Compress the receipt: rlp encoding and snappy compression
let compressed_receipt_data = CompressedReceipts::from_encodable(&receipt_with_bloom)?;
// Get raw receipt by decoding and decompressing compressed and encoded receipt
let decompressed_receipt = compressed_receipt_data.decode::<ReceiptWithBloom>()?;
assert_eq!(decompressed_receipt.receipt.cumulative_gas_used, 21000);
Structs§
- Accumulator
- Accumulator is computed by constructing an SSZ list of header-records
and calculating the
hash_tree_root
- Block
Tuple - A block tuple in an Era1 file, containing all components for a single block
- Compressed
Body - Compressed block body using
snappyFramed(rlp(body))
- Compressed
Header - Compressed block header using
snappyFramed(rlp(header))
- Compressed
Receipts - Compressed receipts using snappyFramed(rlp(receipts))
- Snappy
RlpCodec - Generic codec for Snappy-compressed RLP data
- Total
Difficulty - Total difficulty for a block
Constants§
- ACCUMULATOR
Accumulator
record type- COMPRESSED_
BODY CompressedBody
record type- COMPRESSED_
HEADER CompressedHeader
record type- COMPRESSED_
RECEIPTS CompressedReceipts
record type- MAX_
BLOCKS_ PER_ ERA1 - Maximum number of blocks in an Era1 file, limited by accumulator size
- TOTAL_
DIFFICULTY TotalDifficulty
record type