feat(breaking): Use HlHeader for storing header

This commit is contained in:
sprites0
2025-10-06 00:27:33 +00:00
parent 567d6ce2e4
commit 2390ed864a
18 changed files with 147 additions and 74 deletions

View File

@ -1,8 +1,7 @@
pub mod hl; pub mod hl;
pub mod parser; pub mod parser;
use crate::hardforks::HlHardforks; use crate::{hardforks::HlHardforks, node::primitives::HlHeader};
use alloy_consensus::Header;
use alloy_eips::eip7840::BlobParams; use alloy_eips::eip7840::BlobParams;
use alloy_genesis::Genesis; use alloy_genesis::Genesis;
use alloy_primitives::{Address, B256, U256}; use alloy_primitives::{Address, B256, U256};
@ -20,10 +19,11 @@ pub const TESTNET_CHAIN_ID: u64 = 998;
#[derive(Debug, Default, Clone, PartialEq, Eq)] #[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct HlChainSpec { pub struct HlChainSpec {
pub inner: ChainSpec, pub inner: ChainSpec,
pub genesis_header: HlHeader,
} }
impl EthChainSpec for HlChainSpec { impl EthChainSpec for HlChainSpec {
type Header = Header; type Header = HlHeader;
fn blob_params_at_timestamp(&self, timestamp: u64) -> Option<BlobParams> { fn blob_params_at_timestamp(&self, timestamp: u64) -> Option<BlobParams> {
self.inner.blob_params_at_timestamp(timestamp) self.inner.blob_params_at_timestamp(timestamp)
@ -57,8 +57,8 @@ impl EthChainSpec for HlChainSpec {
Box::new(self.inner.display_hardforks()) Box::new(self.inner.display_hardforks())
} }
fn genesis_header(&self) -> &Header { fn genesis_header(&self) -> &HlHeader {
self.inner.genesis_header() &self.genesis_header
} }
fn genesis(&self) -> &Genesis { fn genesis(&self) -> &Genesis {
@ -127,4 +127,14 @@ impl HlChainSpec {
_ => unreachable!("Unreachable since ChainSpecParser won't return other chains"), _ => unreachable!("Unreachable since ChainSpecParser won't return other chains"),
} }
} }
fn new(inner: ChainSpec) -> Self {
let genesis_header = HlHeader {
inner: inner.genesis_header().clone(),
logs_bloom_with_system_txs: Default::default(),
system_tx_count: 0,
read_precompile_calls: Default::default(),
};
Self { inner, genesis_header }
}
} }

View File

@ -26,8 +26,8 @@ impl ChainSpecParser for HlChainSpecParser {
/// Currently only mainnet is supported. /// Currently only mainnet is supported.
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<HlChainSpec>> { pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<HlChainSpec>> {
match s { match s {
"mainnet" => Ok(Arc::new(HlChainSpec { inner: hl_mainnet() })), "mainnet" => Ok(Arc::new(HlChainSpec::new(hl_mainnet()))),
"testnet" => Ok(Arc::new(HlChainSpec { inner: hl_testnet() })), "testnet" => Ok(Arc::new(HlChainSpec::new(hl_testnet()))),
_ => Err(eyre::eyre!("Unsupported chain: {}", s)), _ => Err(eyre::eyre!("Unsupported chain: {}", s)),
} }
} }

View File

@ -7,4 +7,4 @@ pub mod node;
pub mod pseudo_peer; pub mod pseudo_peer;
pub mod version; pub mod version;
pub use node::primitives::{HlBlock, HlBlockBody, HlPrimitives}; pub use node::primitives::{HlBlock, HlBlockBody, HlHeader, HlPrimitives};

View File

@ -1,5 +1,4 @@
use crate::{HlBlock, HlBlockBody, HlPrimitives, hardforks::HlHardforks, node::HlNode}; use crate::{hardforks::HlHardforks, node::{primitives::HlHeader, HlNode}, HlBlock, HlBlockBody, HlPrimitives};
use alloy_consensus::Header;
use reth::{ use reth::{
api::{FullNodeTypes, NodeTypes}, api::{FullNodeTypes, NodeTypes},
beacon_consensus::EthBeaconConsensus, beacon_consensus::EthBeaconConsensus,
@ -101,14 +100,14 @@ where
impl<ChainSpec> Consensus<HlBlock> for HlConsensus<ChainSpec> impl<ChainSpec> Consensus<HlBlock> for HlConsensus<ChainSpec>
where where
ChainSpec: EthChainSpec<Header = Header> + HlHardforks, ChainSpec: EthChainSpec<Header = HlHeader> + HlHardforks,
{ {
type Error = ConsensusError; type Error = ConsensusError;
fn validate_body_against_header( fn validate_body_against_header(
&self, &self,
body: &HlBlockBody, body: &HlBlockBody,
header: &SealedHeader, header: &SealedHeader<HlHeader>,
) -> Result<(), ConsensusError> { ) -> Result<(), ConsensusError> {
Consensus::<HlBlock>::validate_body_against_header(&self.inner, body, header) Consensus::<HlBlock>::validate_body_against_header(&self.inner, body, header)
} }
@ -148,7 +147,7 @@ mod reth_copy;
impl<ChainSpec> FullConsensus<HlPrimitives> for HlConsensus<ChainSpec> impl<ChainSpec> FullConsensus<HlPrimitives> for HlConsensus<ChainSpec>
where where
ChainSpec: EthChainSpec<Header = Header> + HlHardforks, ChainSpec: EthChainSpec<Header = HlHeader> + HlHardforks,
{ {
fn validate_block_post_execution( fn validate_block_post_execution(
&self, &self,

View File

@ -1,8 +1,6 @@
use crate::{ use crate::{
HlBlock, node::evm::config::{HlBlockExecutorFactory, HlEvmConfig}, HlBlock, HlHeader
node::evm::config::{HlBlockExecutorFactory, HlEvmConfig},
}; };
use alloy_consensus::Header;
use reth_evm::{ use reth_evm::{
block::BlockExecutionError, block::BlockExecutionError,
execute::{BlockAssembler, BlockAssemblerInput}, execute::{BlockAssembler, BlockAssemblerInput},
@ -13,7 +11,7 @@ impl BlockAssembler<HlBlockExecutorFactory> for HlEvmConfig {
fn assemble_block( fn assemble_block(
&self, &self,
input: BlockAssemblerInput<'_, '_, HlBlockExecutorFactory, Header>, input: BlockAssemblerInput<'_, '_, HlBlockExecutorFactory, HlHeader>,
) -> Result<Self::Block, BlockExecutionError> { ) -> Result<Self::Block, BlockExecutionError> {
let HlBlock { header, body } = self.block_assembler.assemble_block(input)?; let HlBlock { header, body } = self.block_assembler.assemble_block(input)?;
Ok(HlBlock { header, body }) Ok(HlBlock { header, body })

View File

@ -1,15 +1,11 @@
use super::{executor::HlBlockExecutor, factory::HlEvmFactory}; use super::{executor::HlBlockExecutor, factory::HlEvmFactory};
use crate::{ use crate::{
HlBlock, HlBlockBody, HlPrimitives, chainspec::HlChainSpec, evm::{spec::HlSpecId, transaction::HlTxEnv}, hardforks::HlHardforks, node::{
chainspec::HlChainSpec,
evm::{spec::HlSpecId, transaction::HlTxEnv},
hardforks::HlHardforks,
node::{
evm::{executor::is_system_transaction, receipt_builder::RethReceiptBuilder}, evm::{executor::is_system_transaction, receipt_builder::RethReceiptBuilder},
primitives::{BlockBody, TransactionSigned}, primitives::{BlockBody, TransactionSigned},
rpc::engine_api::validator::HlExecutionData, rpc::engine_api::validator::HlExecutionData,
types::HlExtras, types::HlExtras,
}, }, HlBlock, HlBlockBody, HlHeader, HlPrimitives
}; };
use alloy_consensus::{BlockHeader, EMPTY_OMMER_ROOT_HASH, Header, Transaction as _, TxReceipt}; use alloy_consensus::{BlockHeader, EMPTY_OMMER_ROOT_HASH, Header, Transaction as _, TxReceipt};
use alloy_eips::{Encodable2718, merge::BEACON_NONCE}; use alloy_eips::{Encodable2718, merge::BEACON_NONCE};
@ -54,7 +50,7 @@ where
fn assemble_block( fn assemble_block(
&self, &self,
input: BlockAssemblerInput<'_, '_, F>, input: BlockAssemblerInput<'_, '_, F, HlHeader>,
) -> Result<Self::Block, BlockExecutionError> { ) -> Result<Self::Block, BlockExecutionError> {
// TODO: Copy of EthBlockAssembler::assemble_block // TODO: Copy of EthBlockAssembler::assemble_block
let inner = &self.inner; let inner = &self.inner;
@ -136,6 +132,7 @@ where
excess_blob_gas, excess_blob_gas,
requests_hash, requests_hash,
}; };
let header = HlHeader::from_ethereum_header(header, receipts);
Ok(Self::Block { Ok(Self::Block {
header, header,
@ -269,6 +266,8 @@ where
} }
} }
static EMPTY_OMMERS: [Header; 0] = [];
impl ConfigureEvm for HlEvmConfig impl ConfigureEvm for HlEvmConfig
where where
Self: Send + Sync + Unpin + Clone + 'static, Self: Send + Sync + Unpin + Clone + 'static,
@ -287,7 +286,7 @@ where
self self
} }
fn evm_env(&self, header: &Header) -> Result<EvmEnv<HlSpecId>, Self::Error> { fn evm_env(&self, header: &HlHeader) -> Result<EvmEnv<HlSpecId>, Self::Error> {
let blob_params = self.chain_spec().blob_params_at_timestamp(header.timestamp); let blob_params = self.chain_spec().blob_params_at_timestamp(header.timestamp);
let spec = revm_spec_by_timestamp_and_block_number( let spec = revm_spec_by_timestamp_and_block_number(
self.chain_spec().clone(), self.chain_spec().clone(),
@ -332,7 +331,7 @@ where
fn next_evm_env( fn next_evm_env(
&self, &self,
parent: &Header, parent: &HlHeader,
attributes: &Self::NextBlockEnvCtx, attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnv<HlSpecId>, Self::Error> { ) -> Result<EvmEnv<HlSpecId>, Self::Error> {
// ensure we're not missing any timestamp based hardforks // ensure we're not missing any timestamp based hardforks
@ -382,7 +381,7 @@ where
ctx: EthBlockExecutionCtx { ctx: EthBlockExecutionCtx {
parent_hash: block.header().parent_hash, parent_hash: block.header().parent_hash,
parent_beacon_block_root: block.header().parent_beacon_block_root, parent_beacon_block_root: block.header().parent_beacon_block_root,
ommers: &block.body().ommers, ommers: &EMPTY_OMMERS,
withdrawals: block.body().withdrawals.as_ref().map(Cow::Borrowed), withdrawals: block.body().withdrawals.as_ref().map(Cow::Borrowed),
}, },
extras: HlExtras { extras: HlExtras {
@ -420,7 +419,7 @@ impl ConfigureEngineEvm<HlExecutionData> for HlEvmConfig {
ctx: EthBlockExecutionCtx { ctx: EthBlockExecutionCtx {
parent_hash: block.header.parent_hash, parent_hash: block.header.parent_hash,
parent_beacon_block_root: block.header.parent_beacon_block_root, parent_beacon_block_root: block.header.parent_beacon_block_root,
ommers: &block.body.ommers, ommers: &EMPTY_OMMERS,
withdrawals: block.body.withdrawals.as_ref().map(Cow::Borrowed), withdrawals: block.body.withdrawals.as_ref().map(Cow::Borrowed),
}, },
extras: HlExtras { extras: HlExtras {

View File

@ -179,7 +179,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::chainspec::hl::hl_mainnet; use crate::{chainspec::hl::hl_mainnet, HlHeader};
use super::*; use super::*;
use alloy_primitives::{B256, U128}; use alloy_primitives::{B256, U128};
@ -355,7 +355,7 @@ mod tests {
/// Creates a test block message /// Creates a test block message
fn create_test_block() -> NewBlockMessage<HlNewBlock> { fn create_test_block() -> NewBlockMessage<HlNewBlock> {
let block = HlBlock { let block = HlBlock {
header: Header::default(), header: HlHeader::default(),
body: HlBlockBody { body: HlBlockBody {
inner: BlockBody { inner: BlockBody {
transactions: Vec::new(), transactions: Vec::new(),

View File

@ -38,10 +38,10 @@ pub struct HlNewBlock(pub NewBlock<HlBlock>);
mod rlp { mod rlp {
use super::*; use super::*;
use crate::{ use crate::{
HlBlockBody, HlBlockBody, HlHeader,
node::primitives::{BlockBody, TransactionSigned}, node::primitives::{BlockBody, TransactionSigned},
}; };
use alloy_consensus::{BlobTransactionSidecar, Header}; use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::{Address, U128}; use alloy_primitives::{Address, U128};
use alloy_rlp::{RlpDecodable, RlpEncodable}; use alloy_rlp::{RlpDecodable, RlpEncodable};
use alloy_rpc_types::Withdrawals; use alloy_rpc_types::Withdrawals;
@ -50,9 +50,9 @@ mod rlp {
#[derive(RlpEncodable, RlpDecodable)] #[derive(RlpEncodable, RlpDecodable)]
#[rlp(trailing)] #[rlp(trailing)]
struct BlockHelper<'a> { struct BlockHelper<'a> {
header: Cow<'a, Header>, header: Cow<'a, HlHeader>,
transactions: Cow<'a, Vec<TransactionSigned>>, transactions: Cow<'a, Vec<TransactionSigned>>,
ommers: Cow<'a, Vec<Header>>, ommers: Cow<'a, Vec<HlHeader>>,
withdrawals: Option<Cow<'a, Withdrawals>>, withdrawals: Option<Cow<'a, Withdrawals>>,
} }

View File

@ -1,16 +1,13 @@
use crate::node::primitives::HlBlockBody; use super::{HlBlockBody, HlHeader, rlp};
use alloy_consensus::Header;
use alloy_rlp::Encodable; use alloy_rlp::Encodable;
use reth_primitives_traits::{Block, InMemorySize}; use reth_primitives_traits::{Block, InMemorySize};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
use crate::node::primitives::rlp;
/// Block for HL /// Block for HL
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct HlBlock { pub struct HlBlock {
pub header: Header, pub header: HlHeader,
pub body: HlBlockBody, pub body: HlBlockBody,
} }
@ -21,7 +18,7 @@ impl InMemorySize for HlBlock {
} }
impl Block for HlBlock { impl Block for HlBlock {
type Header = Header; type Header = HlHeader;
type Body = HlBlockBody; type Body = HlBlockBody;
fn new(header: Self::Header, body: Self::Body) -> Self { fn new(header: Self::Header, body: Self::Body) -> Self {

View File

@ -1,4 +1,4 @@
use alloy_consensus::{BlobTransactionSidecar, Header}; use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::Address; use alloy_primitives::Address;
use reth_primitives_traits::{BlockBody as BlockBodyTrait, InMemorySize}; use reth_primitives_traits::{BlockBody as BlockBodyTrait, InMemorySize};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -43,7 +43,7 @@ impl InMemorySize for HlBlockBody {
impl BlockBodyTrait for HlBlockBody { impl BlockBodyTrait for HlBlockBody {
type Transaction = TransactionSigned; type Transaction = TransactionSigned;
type OmmerHeader = Header; type OmmerHeader = super::HlHeader;
fn transactions(&self) -> &[Self::Transaction] { fn transactions(&self) -> &[Self::Transaction] {
BlockBodyTrait::transactions(&self.inner) BlockBodyTrait::transactions(&self.inner)

View File

@ -1,8 +1,12 @@
use alloy_consensus::Header; use alloy_consensus::Header;
use alloy_primitives::{Address, B64, B256, BlockNumber, Bloom, Bytes, Sealable, U256}; use alloy_primitives::{Address, B64, B256, BlockNumber, Bloom, Bytes, Sealable, U256};
use alloy_rlp::{RlpDecodable, RlpEncodable}; use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_cli_commands::common::CliHeader;
use reth_codecs::Compact; use reth_codecs::Compact;
use reth_ethereum_primitives::EthereumReceipt;
use reth_primitives::{SealedHeader, logs_bloom};
use reth_primitives_traits::{BlockHeader, InMemorySize, serde_bincode_compat::RlpBincode}; use reth_primitives_traits::{BlockHeader, InMemorySize, serde_bincode_compat::RlpBincode};
use reth_rpc_convert::transaction::FromConsensusHeader;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::node::types::HlExtras; use crate::node::types::HlExtras;
@ -36,6 +40,18 @@ pub struct HlHeader {
pub system_tx_count: u64, pub system_tx_count: u64,
pub read_precompile_calls: HlExtras, pub read_precompile_calls: HlExtras,
} }
impl HlHeader {
pub(crate) fn from_ethereum_header(header: Header, receipts: &[EthereumReceipt]) -> HlHeader {
let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| &r.logs));
let system_tx_count = receipts.iter().filter(|r| r.cumulative_gas_used == 0).count() as u64;
HlHeader {
inner: header,
logs_bloom_with_system_txs: logs_bloom,
system_tx_count,
read_precompile_calls: Default::default(),
}
}
}
impl From<Header> for HlHeader { impl From<Header> for HlHeader {
fn from(_value: Header) -> Self { fn from(_value: Header) -> Self {
@ -185,3 +201,28 @@ impl reth_db_api::table::Decompress for HlHeader {
impl BlockHeader for HlHeader {} impl BlockHeader for HlHeader {}
impl RlpBincode for HlHeader {} impl RlpBincode for HlHeader {}
impl CliHeader for HlHeader {
fn set_number(&mut self, number: u64) {
self.inner.set_number(number);
}
}
impl From<HlHeader> for Header {
fn from(value: HlHeader) -> Self {
value.inner
}
}
pub fn to_ethereum_ommers(ommers: &[HlHeader]) -> Vec<Header> {
ommers.iter().map(|ommer| ommer.clone().into()).collect()
}
impl FromConsensusHeader<HlHeader> for alloy_rpc_types::Header {
fn from_consensus_header(header: SealedHeader<HlHeader>, block_size: usize) -> Self {
FromConsensusHeader::<Header>::from_consensus_header(
SealedHeader::<Header>::new(header.inner.clone(), header.hash()),
block_size,
)
}
}

View File

@ -1,4 +1,3 @@
use alloy_consensus::Header;
use reth_ethereum_primitives::Receipt; use reth_ethereum_primitives::Receipt;
use reth_primitives::NodePrimitives; use reth_primitives::NodePrimitives;
@ -10,6 +9,7 @@ pub use block::HlBlock;
pub mod body; pub mod body;
pub use body::HlBlockBody; pub use body::HlBlockBody;
pub mod header; pub mod header;
pub use header::HlHeader;
pub mod rlp; pub mod rlp;
pub mod serde_bincode_compat; pub mod serde_bincode_compat;
@ -21,7 +21,7 @@ pub struct HlPrimitives;
impl NodePrimitives for HlPrimitives { impl NodePrimitives for HlPrimitives {
type Block = HlBlock; type Block = HlBlock;
type BlockHeader = Header; type BlockHeader = HlHeader;
type BlockBody = HlBlockBody; type BlockBody = HlBlockBody;
type SignedTx = TransactionSigned; type SignedTx = TransactionSigned;
type Receipt = Receipt; type Receipt = Receipt;

View File

@ -1,7 +1,7 @@
#![allow(clippy::owned_cow)] #![allow(clippy::owned_cow)]
use super::{HlBlock, HlBlockBody, TransactionSigned}; use super::{HlBlock, HlBlockBody, TransactionSigned};
use crate::node::types::ReadPrecompileCalls; use crate::{node::types::ReadPrecompileCalls, HlHeader};
use alloy_consensus::{BlobTransactionSidecar, BlockBody, Header}; use alloy_consensus::{BlobTransactionSidecar, BlockBody};
use alloy_eips::eip4895::Withdrawals; use alloy_eips::eip4895::Withdrawals;
use alloy_primitives::Address; use alloy_primitives::Address;
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};
@ -11,7 +11,7 @@ use std::borrow::Cow;
#[rlp(trailing)] #[rlp(trailing)]
struct BlockBodyHelper<'a> { struct BlockBodyHelper<'a> {
transactions: Cow<'a, Vec<TransactionSigned>>, transactions: Cow<'a, Vec<TransactionSigned>>,
ommers: Cow<'a, Vec<Header>>, ommers: Cow<'a, Vec<HlHeader>>,
withdrawals: Option<Cow<'a, Withdrawals>>, withdrawals: Option<Cow<'a, Withdrawals>>,
sidecars: Option<Cow<'a, Vec<BlobTransactionSidecar>>>, sidecars: Option<Cow<'a, Vec<BlobTransactionSidecar>>>,
read_precompile_calls: Option<Cow<'a, ReadPrecompileCalls>>, read_precompile_calls: Option<Cow<'a, ReadPrecompileCalls>>,
@ -21,9 +21,9 @@ struct BlockBodyHelper<'a> {
#[derive(RlpEncodable, RlpDecodable)] #[derive(RlpEncodable, RlpDecodable)]
#[rlp(trailing)] #[rlp(trailing)]
pub(crate) struct BlockHelper<'a> { pub(crate) struct BlockHelper<'a> {
pub(crate) header: Cow<'a, Header>, pub(crate) header: Cow<'a, HlHeader>,
pub(crate) transactions: Cow<'a, Vec<TransactionSigned>>, pub(crate) transactions: Cow<'a, Vec<TransactionSigned>>,
pub(crate) ommers: Cow<'a, Vec<Header>>, pub(crate) ommers: Cow<'a, Vec<HlHeader>>,
pub(crate) withdrawals: Option<Cow<'a, Withdrawals>>, pub(crate) withdrawals: Option<Cow<'a, Withdrawals>>,
pub(crate) sidecars: Option<Cow<'a, Vec<BlobTransactionSidecar>>>, pub(crate) sidecars: Option<Cow<'a, Vec<BlobTransactionSidecar>>>,
pub(crate) read_precompile_calls: Option<Cow<'a, ReadPrecompileCalls>>, pub(crate) read_precompile_calls: Option<Cow<'a, ReadPrecompileCalls>>,
@ -95,7 +95,7 @@ impl Decodable for HlBlockBody {
Ok(Self { Ok(Self {
inner: BlockBody { inner: BlockBody {
transactions: transactions.into_owned(), transactions: transactions.into_owned(),
ommers: ommers.into_owned(), ommers: ommers.into_owned().into_iter().map(Into::into).collect(),
withdrawals: withdrawals.map(|w| w.into_owned()), withdrawals: withdrawals.map(|w| w.into_owned()),
}, },
sidecars: sidecars.map(|s| s.into_owned()), sidecars: sidecars.map(|s| s.into_owned()),

View File

@ -1,12 +1,12 @@
#![allow(clippy::owned_cow)] #![allow(clippy::owned_cow)]
use alloy_consensus::{BlobTransactionSidecar, Header}; use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::Address; use alloy_primitives::Address;
use reth_primitives_traits::serde_bincode_compat::{BincodeReprFor, SerdeBincodeCompat}; use reth_primitives_traits::serde_bincode_compat::{BincodeReprFor, SerdeBincodeCompat};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
use super::{HlBlock, HlBlockBody}; use super::{HlBlock, HlBlockBody};
use crate::node::{primitives::BlockBody, types::ReadPrecompileCalls}; use crate::{node::{primitives::BlockBody, types::ReadPrecompileCalls}, HlHeader};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct HlBlockBodyBincode<'a> { pub struct HlBlockBodyBincode<'a> {
@ -18,7 +18,7 @@ pub struct HlBlockBodyBincode<'a> {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct HlBlockBincode<'a> { pub struct HlBlockBincode<'a> {
header: BincodeReprFor<'a, Header>, header: BincodeReprFor<'a, HlHeader>,
body: BincodeReprFor<'a, HlBlockBody>, body: BincodeReprFor<'a, HlBlockBody>,
} }
@ -59,6 +59,6 @@ impl SerdeBincodeCompat for HlBlock {
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self { fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
let HlBlockBincode { header, body } = repr; let HlBlockBincode { header, body } = repr;
Self { header: Header::from_repr(header), body: HlBlockBody::from_repr(body) } Self { header: HlHeader::from_repr(header), body: HlBlockBody::from_repr(body) }
} }
} }

View File

@ -2,7 +2,7 @@
//! except that it supports pseudo signer for system transactions. //! except that it supports pseudo signer for system transactions.
use std::convert::Infallible; use std::convert::Infallible;
use crate::evm::transaction::HlTxEnv; use crate::{evm::transaction::HlTxEnv, HlHeader};
use alloy_consensus::{ use alloy_consensus::{
SignableTransaction, Signed, Transaction as TransactionTrait, TransactionEnvelope, TxEip1559, SignableTransaction, Signed, Transaction as TransactionTrait, TransactionEnvelope, TxEip1559,
TxEip2930, TxEip4844, TxEip7702, TxLegacy, TxType, TypedTransaction, crypto::RecoveryError, TxEip2930, TxEip4844, TxEip7702, TxLegacy, TxType, TypedTransaction, crypto::RecoveryError,
@ -181,7 +181,7 @@ impl SerdeBincodeCompat for TransactionSigned {
} }
} }
pub type BlockBody = alloy_consensus::BlockBody<TransactionSigned>; pub type BlockBody = alloy_consensus::BlockBody<TransactionSigned, HlHeader>;
impl TryFrom<TransactionSigned> for PooledTransactionVariant { impl TryFrom<TransactionSigned> for PooledTransactionVariant {
type Error = <InnerType as TryInto<PooledTransactionVariant>>::Error; type Error = <InnerType as TryInto<PooledTransactionVariant>>::Error;
@ -211,15 +211,15 @@ impl Decompress for TransactionSigned {
} }
} }
pub fn convert_to_eth_block_body(value: BlockBody) -> alloy_consensus::BlockBody<InnerType> { pub fn convert_to_eth_block_body(value: BlockBody) -> alloy_consensus::BlockBody<InnerType, HlHeader> {
alloy_consensus::BlockBody { alloy_consensus::BlockBody {
transactions: value.transactions.into_iter().map(|tx| tx.into_inner()).collect(), transactions: value.transactions.into_iter().map(|tx| tx.into_inner()).collect(),
ommers: value.ommers, ommers: value.ommers.into_iter().map(|ommer| ommer.into()).collect(),
withdrawals: value.withdrawals, withdrawals: value.withdrawals,
} }
} }
pub fn convert_to_hl_block_body(value: alloy_consensus::BlockBody<InnerType>) -> BlockBody { pub fn convert_to_hl_block_body(value: alloy_consensus::BlockBody<InnerType, HlHeader>) -> BlockBody {
BlockBody { BlockBody {
transactions: value.transactions.into_iter().map(TransactionSigned::Default).collect(), transactions: value.transactions.into_iter().map(TransactionSigned::Default).collect(),
ommers: value.ommers, ommers: value.ommers,

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
HlBlock, HlBlockBody, HlPrimitives, HlBlock, HlBlockBody, HlHeader, HlPrimitives,
node::{ node::{
primitives::transaction::{convert_to_eth_block_body, convert_to_hl_block_body}, primitives::transaction::{convert_to_eth_block_body, convert_to_hl_block_body},
types::HlExtras, types::HlExtras,
@ -13,6 +13,8 @@ use reth_db::{
cursor::{DbCursorRO, DbCursorRW}, cursor::{DbCursorRO, DbCursorRW},
transaction::{DbTx, DbTxMut}, transaction::{DbTx, DbTxMut},
}; };
use reth_primitives::TransactionSigned;
use reth_primitives_traits::Block;
use reth_provider::{ use reth_provider::{
BlockBodyReader, BlockBodyWriter, ChainSpecProvider, ChainStorageReader, ChainStorageWriter, BlockBodyReader, BlockBodyWriter, ChainSpecProvider, ChainStorageReader, ChainStorageWriter,
DBProvider, DatabaseProvider, EthStorage, ProviderResult, ReadBodyInput, StorageLocation, DBProvider, DatabaseProvider, EthStorage, ProviderResult, ReadBodyInput, StorageLocation,
@ -23,7 +25,7 @@ pub mod tables;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
#[non_exhaustive] #[non_exhaustive]
pub struct HlStorage(EthStorage); pub struct HlStorage(EthStorage<TransactionSigned, HlHeader>);
impl HlStorage { impl HlStorage {
fn write_precompile_calls<Provider>( fn write_precompile_calls<Provider>(
@ -146,15 +148,15 @@ where
inputs: Vec<ReadBodyInput<'_, Self::Block>>, inputs: Vec<ReadBodyInput<'_, Self::Block>>,
) -> ProviderResult<Vec<HlBlockBody>> { ) -> ProviderResult<Vec<HlBlockBody>> {
let read_precompile_calls = self.read_precompile_calls(provider, &inputs)?; let read_precompile_calls = self.read_precompile_calls(provider, &inputs)?;
let eth_bodies = self.0.read_block_bodies( let inputs: Vec<(&HlHeader, _)> = inputs
provider,
inputs
.into_iter() .into_iter()
.map(|(header, transactions)| { .map(|(header, transactions)| {
(header, transactions.into_iter().map(|tx| tx.into_inner()).collect()) (header, transactions.into_iter().map(|tx| tx.into_inner()).collect())
}) })
.collect(), .collect();
)?; let inputs: Vec<(&<Self::Block as Block>::Header, _)> = inputs;
let eth_bodies = self.0.read_block_bodies(provider, inputs)?;
let eth_bodies: Vec<alloy_consensus::BlockBody<_, HlHeader>> = eth_bodies;
// NOTE: sidecars are not used in HyperEVM yet. // NOTE: sidecars are not used in HyperEVM yet.
Ok(eth_bodies Ok(eth_bodies

View File

@ -2,9 +2,11 @@
//! //!
//! Changes: //! Changes:
//! - ReadPrecompileCalls supports RLP encoding / decoding //! - ReadPrecompileCalls supports RLP encoding / decoding
use alloy_consensus::TxType;
use alloy_primitives::{Address, B256, Bytes, Log}; use alloy_primitives::{Address, B256, Bytes, Log};
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};
use bytes::BufMut; use bytes::BufMut;
use reth_ethereum_primitives::EthereumReceipt;
use reth_primitives_traits::InMemorySize; use reth_primitives_traits::InMemorySize;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -67,6 +69,7 @@ impl BlockAndReceipts {
self.read_precompile_calls.clone(), self.read_precompile_calls.clone(),
self.highest_precompile_address, self.highest_precompile_address,
self.system_txs.clone(), self.system_txs.clone(),
self.receipts.clone(),
chain_id, chain_id,
) )
} }
@ -95,6 +98,23 @@ pub struct LegacyReceipt {
logs: Vec<Log>, logs: Vec<Log>,
} }
impl From<LegacyReceipt> for EthereumReceipt {
fn from(r: LegacyReceipt) -> Self {
EthereumReceipt {
tx_type: match r.tx_type {
LegacyTxType::Legacy => TxType::Legacy,
LegacyTxType::Eip2930 => TxType::Eip2930,
LegacyTxType::Eip1559 => TxType::Eip1559,
LegacyTxType::Eip4844 => TxType::Eip4844,
LegacyTxType::Eip7702 => TxType::Eip7702,
},
success: r.success,
cumulative_gas_used: r.cumulative_gas_used,
logs: r.logs,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
enum LegacyTxType { enum LegacyTxType {
Legacy = 0, Legacy = 0,

View File

@ -10,11 +10,11 @@ use std::{
use tracing::info; use tracing::info;
use crate::{ use crate::{
HlBlock, HlBlockBody, HlBlock, HlBlockBody, HlHeader,
node::{ node::{
primitives::TransactionSigned as TxSigned, primitives::TransactionSigned as TxSigned,
spot_meta::{SpotId, erc20_contract_to_spot_token}, spot_meta::{SpotId, erc20_contract_to_spot_token},
types::{ReadPrecompileCalls, SystemTx}, types::{LegacyReceipt, ReadPrecompileCalls, SystemTx},
}, },
}; };
@ -114,6 +114,7 @@ impl SealedBlock {
read_precompile_calls: ReadPrecompileCalls, read_precompile_calls: ReadPrecompileCalls,
highest_precompile_address: Option<Address>, highest_precompile_address: Option<Address>,
system_txs: Vec<super::SystemTx>, system_txs: Vec<super::SystemTx>,
receipts: Vec<LegacyReceipt>,
chain_id: u64, chain_id: u64,
) -> HlBlock { ) -> HlBlock {
let mut merged_txs = vec![]; let mut merged_txs = vec![];
@ -123,13 +124,19 @@ impl SealedBlock {
inner: reth_primitives::BlockBody { inner: reth_primitives::BlockBody {
transactions: merged_txs, transactions: merged_txs,
withdrawals: self.body.withdrawals.clone(), withdrawals: self.body.withdrawals.clone(),
ommers: self.body.ommers.clone(), ommers: vec![],
}, },
sidecars: None, sidecars: None,
read_precompile_calls: Some(read_precompile_calls), read_precompile_calls: Some(read_precompile_calls),
highest_precompile_address, highest_precompile_address,
}; };
HlBlock { header: self.header.header.clone(), body: block_body } HlBlock {
header: HlHeader::from_ethereum_header(
self.header.header.clone(),
&receipts.into_iter().map(From::from).collect::<Vec<_>>(),
),
body: block_body,
}
} }
} }