Skip to content

Commit

Permalink
feat: add Receipt AT to provider write traits
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Nov 27, 2024
1 parent 2b1b316 commit a11b936
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 25 deletions.
5 changes: 4 additions & 1 deletion bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<
N: ProviderNodeTypes<
ChainSpec = C::ChainSpec,
Primitives: NodePrimitives<Block = reth_primitives::Block>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
&self,
Expand Down
5 changes: 4 additions & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<
N: ProviderNodeTypes<
ChainSpec = C::ChainSpec,
Primitives: NodePrimitives<Block = reth_primitives::Block>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
&self,
Expand Down
5 changes: 4 additions & 1 deletion bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<
N: ProviderNodeTypes<
ChainSpec = C::ChainSpec,
Primitives: NodePrimitives<Block = reth_primitives::Block>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
&self,
Expand Down
19 changes: 16 additions & 3 deletions crates/cli/commands/src/stage/dump/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ pub(crate) async fn dump_execution_stage<N, E>(
where
N: ProviderNodeTypes<
DB = Arc<DatabaseEnv>,
Primitives: NodePrimitives<Block = reth_primitives::Block>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
E: BlockExecutorProvider,
{
Expand Down Expand Up @@ -136,7 +139,12 @@ fn import_tables_with_range<N: NodeTypesWithDB>(
/// `PlainAccountState` safely. There might be some state dependency from an address
/// which hasn't been changed in the given range.
fn unwind_and_copy<
N: ProviderNodeTypes<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
N: ProviderNodeTypes<
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
db_tool: &DbTool<N>,
from: u64,
Expand Down Expand Up @@ -174,7 +182,12 @@ fn dry_run<N, E>(
executor: E,
) -> eyre::Result<()>
where
N: ProviderNodeTypes<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
N: ProviderNodeTypes<
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
E: BlockExecutorProvider,
{
info!(target: "reth::cli", "Executing stage. [dry-run]");
Expand Down
12 changes: 10 additions & 2 deletions crates/cli/commands/src/stage/dump/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use tracing::info;
pub(crate) async fn dump_merkle_stage<
N: ProviderNodeTypes<
DB = Arc<DatabaseEnv>,
Primitives: NodePrimitives<Block = reth_primitives::Block>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
db_tool: &DbTool<N>,
Expand Down Expand Up @@ -74,7 +77,12 @@ pub(crate) async fn dump_merkle_stage<

/// Dry-run an unwind to FROM block and copy the necessary table data to the new database.
fn unwind_and_copy<
N: ProviderNodeTypes<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
N: ProviderNodeTypes<
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>(
db_tool: &DbTool<N>,
range: (u64, u64),
Expand Down
5 changes: 4 additions & 1 deletion crates/exex/exex/src/backfill/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ where
Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
>,
{
Expand Down Expand Up @@ -171,6 +172,7 @@ where
Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
>,
{
Expand All @@ -194,7 +196,8 @@ pub(crate) fn blocks_and_execution_outcome<N>(
) -> eyre::Result<(Vec<SealedBlockWithSenders>, ExecutionOutcome)>
where
N: ProviderNodeTypes,
N::Primitives: FullNodePrimitives<Block = reth_primitives::Block>,
N::Primitives:
FullNodePrimitives<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>,
{
let (block1, block2) = blocks(chain_spec.clone(), key_pair)?;

Expand Down
2 changes: 2 additions & 0 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ where
N::Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
{
let factory = ProviderFactory::new(
Expand Down Expand Up @@ -455,6 +456,7 @@ where
N::Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
{
let factory = self.create_provider_factory().await?;
Expand Down
14 changes: 10 additions & 4 deletions crates/node/builder/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ where
N: ProviderNodeTypes,
Client: EthBlockClient + 'static,
Executor: BlockExecutorProvider,
N::Primitives:
FullNodePrimitives<Block = reth_primitives::Block, BlockBody = reth_primitives::BlockBody>,
N::Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
{
// building network downloaders using the fetch client
let header_downloader = ReverseHeadersDownloaderBuilder::new(config.headers)
Expand Down Expand Up @@ -90,8 +93,11 @@ where
H: HeaderDownloader<Header = alloy_consensus::Header> + 'static,
B: BodyDownloader<Body = BodyTy<N>> + 'static,
Executor: BlockExecutorProvider,
N::Primitives:
FullNodePrimitives<Block = reth_primitives::Block, BlockBody = reth_primitives::BlockBody>,
N::Primitives: FullNodePrimitives<
Block = reth_primitives::Block,
BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>,
{
let mut builder = Pipeline::<N>::builder();

Expand Down
9 changes: 6 additions & 3 deletions crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use reth_execution_types::ExecutionOutcome;
use reth_node_core::version::SHORT_VERSION;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::bedrock::is_dup_tx;
use reth_primitives::Receipts;
use reth_primitives::{NodePrimitives, Receipts};
use reth_provider::{
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory,
OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter,
Expand Down Expand Up @@ -85,7 +85,10 @@ pub async fn import_receipts_from_file<N, P, F>(
filter: F,
) -> eyre::Result<()>
where
N: ProviderNodeTypes<ChainSpec = OpChainSpec>,
N: ProviderNodeTypes<
ChainSpec = OpChainSpec,
Primitives: NodePrimitives<Receipt = reth_primitives::Receipt>,
>,
P: AsRef<Path>,
F: FnMut(u64, &mut Receipts) -> usize,
{
Expand Down Expand Up @@ -123,7 +126,7 @@ pub async fn import_receipts_from_reader<N, F>(
mut filter: F,
) -> eyre::Result<ImportReceiptsResult>
where
N: ProviderNodeTypes,
N: ProviderNodeTypes<Primitives: NodePrimitives<Receipt = reth_primitives::Receipt>>,
F: FnMut(u64, &mut Receipts) -> usize,
{
let static_file_provider = provider_factory.static_file_provider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<N: ProviderNodeTypes> BlockchainProvider2<N> {
pub fn get_state(
&self,
range: RangeInclusive<BlockNumber>,
) -> ProviderResult<Option<ExecutionOutcome>> {
) -> ProviderResult<Option<ExecutionOutcome<ReceiptTy<N>>>> {
self.consistent_provider()?.get_state(range)
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/storage/provider/src/providers/consistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,10 @@ impl<N: ProviderNodeTypes> StateReader for ConsistentProvider<N> {
/// inconsistent. Currently this can safely be called within the blockchain tree thread,
/// because the tree thread is responsible for modifying the [`CanonicalInMemoryState`] in the
/// first place.
fn get_state(&self, block: BlockNumber) -> ProviderResult<Option<ExecutionOutcome>> {
fn get_state(
&self,
block: BlockNumber,
) -> ProviderResult<Option<ExecutionOutcome<Self::Receipt>>> {
if let Some(state) = self.head_block.as_ref().and_then(|b| b.block_on_chain(block.into())) {
let state = state.block_ref().execution_outcome().clone();
Ok(Some(state))
Expand Down
5 changes: 3 additions & 2 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
for DatabaseProvider<TX, N>
{
type Block = BlockTy<N>;
type Receipt = ReceiptTy<N>;

/// Inserts the block into the database, always modifying the following tables:
/// * [`CanonicalHeaders`](tables::CanonicalHeaders)
Expand Down Expand Up @@ -3046,7 +3047,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
fn append_blocks_with_state(
&self,
blocks: Vec<SealedBlockWithSenders<Self::Block>>,
execution_outcome: ExecutionOutcome,
execution_outcome: ExecutionOutcome<Self::Receipt>,
hashed_state: HashedPostStateSorted,
trie_updates: TrieUpdates,
) -> ProviderResult<()> {
Expand Down Expand Up @@ -3116,7 +3117,7 @@ impl<TX: DbTxMut, N: NodeTypes> PruneCheckpointWriter for DatabaseProvider<TX, N
}
}

impl<TX: DbTx + 'static, N: NodeTypes> StatsReader for DatabaseProvider<TX, N> {
impl<TX: DbTx + 'static, N: NodeTypesForProvider> StatsReader for DatabaseProvider<TX, N> {
fn count_entries<T: Table>(&self) -> ProviderResult<usize> {
let db_entries = self.tx.entries::<T>()?;
let static_file_entries = match self.static_file_provider.count_entries::<T>() {
Expand Down
6 changes: 3 additions & 3 deletions crates/storage/provider/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ where
Storage: ChainStorage<Self::Primitives>,
Primitives: FullNodePrimitives<
SignedTx: Value,
Receipt: Value,
BlockHeader = alloy_consensus::Header,
Receipt = reth_primitives::Receipt,
>,
>,
{
Expand All @@ -92,8 +92,8 @@ impl<T> NodeTypesForProvider for T where
Storage: ChainStorage<T::Primitives>,
Primitives: FullNodePrimitives<
SignedTx: Value,
Receipt: Value,
BlockHeader = alloy_consensus::Header,
Receipt = reth_primitives::Receipt,
>,
>
{
Expand Down Expand Up @@ -541,7 +541,7 @@ impl<N: ProviderNodeTypes> ReceiptProvider for BlockchainProvider<N> {
}
}

impl<N: ProviderNodeTypes> ReceiptProviderIdExt for BlockchainProvider<N> {
impl<N: TreeNodeTypes> ReceiptProviderIdExt for BlockchainProvider<N> {
fn receipts_by_block_id(&self, block: BlockId) -> ProviderResult<Option<Vec<Receipt>>> {
match block {
BlockId::Hash(rpc_block_hash) => {
Expand Down
5 changes: 4 additions & 1 deletion crates/storage/provider/src/providers/static_file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,10 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
/// empty blocks and this function wouldn't be called.
///
/// Returns the current [`TxNumber`] as seen in the static file.
pub fn append_receipt(&mut self, tx_num: TxNumber, receipt: &Receipt) -> ProviderResult<()> {
pub fn append_receipt(&mut self, tx_num: TxNumber, receipt: &N::Receipt) -> ProviderResult<()>
where
N::Receipt: Compact,
{
let start = Instant::now();
self.ensure_no_queued_prune()?;

Expand Down
4 changes: 3 additions & 1 deletion crates/storage/provider/src/traits/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pub trait StateReader: Send + Sync {
pub trait BlockWriter: Send + Sync {
/// The body this writer can write.
type Block: reth_primitives_traits::Block;
/// The receipt type for [`ExecutionOutcome`].
type Receipt: Send + Sync;

/// Insert full block and make it canonical. Parent tx num and transition id is taken from
/// parent block in database.
Expand Down Expand Up @@ -154,7 +156,7 @@ pub trait BlockWriter: Send + Sync {
fn append_blocks_with_state(
&self,
blocks: Vec<SealedBlockWithSenders<Self::Block>>,
execution_outcome: ExecutionOutcome,
execution_outcome: ExecutionOutcome<Self::Receipt>,
hashed_state: HashedPostStateSorted,
trie_updates: TrieUpdates,
) -> ProviderResult<()>;
Expand Down

0 comments on commit a11b936

Please sign in to comment.