mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: rename BundleStateWithReceipts to BlockExecutionOutcome (#8730)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
#![warn(unused_crate_dependencies)]
|
||||
|
||||
use reth::providers::BundleStateWithReceipts;
|
||||
use reth::providers::ExecutionOutcome;
|
||||
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_ethereum::EthereumNode;
|
||||
@ -15,14 +15,14 @@ use std::{
|
||||
struct InMemoryStateExEx<Node: FullNodeComponents> {
|
||||
/// The context of the ExEx
|
||||
ctx: ExExContext<Node>,
|
||||
/// Entire plain state of the chain
|
||||
state: BundleStateWithReceipts,
|
||||
/// Execution outcome of the chain
|
||||
execution_outcome: ExecutionOutcome,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents> InMemoryStateExEx<Node> {
|
||||
/// Create a new instance of the ExEx
|
||||
fn new(ctx: ExExContext<Node>) -> Self {
|
||||
Self { ctx, state: BundleStateWithReceipts::default() }
|
||||
Self { ctx, execution_outcome: ExecutionOutcome::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,18 +39,18 @@ impl<Node: FullNodeComponents + Unpin> Future for InMemoryStateExEx<Node> {
|
||||
}
|
||||
ExExNotification::ChainReorged { old, new } => {
|
||||
// revert to block before the reorg
|
||||
this.state.revert_to(new.first().number - 1);
|
||||
this.execution_outcome.revert_to(new.first().number - 1);
|
||||
info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg");
|
||||
}
|
||||
ExExNotification::ChainReverted { old } => {
|
||||
this.state.revert_to(old.first().number - 1);
|
||||
this.execution_outcome.revert_to(old.first().number - 1);
|
||||
info!(reverted_chain = ?old.range(), "Received revert");
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(committed_chain) = notification.committed_chain() {
|
||||
// extend the state with the new chain
|
||||
this.state.extend(committed_chain.state().clone());
|
||||
this.execution_outcome.extend(committed_chain.execution_outcome().clone());
|
||||
this.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ mod tests {
|
||||
use std::pin::pin;
|
||||
|
||||
use reth::{
|
||||
providers::{BundleStateWithReceipts, Chain},
|
||||
providers::{Chain, ExecutionOutcome},
|
||||
revm::db::BundleState,
|
||||
};
|
||||
use reth_exex_test_utils::{test_exex_context, PollOnce};
|
||||
@ -89,60 +89,62 @@ mod tests {
|
||||
let (ctx, handle) = test_exex_context().await?;
|
||||
let mut exex = pin!(super::InMemoryStateExEx::new(ctx));
|
||||
|
||||
let mut expected_state = BundleStateWithReceipts::default();
|
||||
let mut expected_state = ExecutionOutcome::default();
|
||||
|
||||
// Generate first block and its state
|
||||
let block_1 = random_block(&mut rng, 0, None, Some(1), None)
|
||||
.seal_with_senders()
|
||||
.ok_or(eyre::eyre!("failed to recover senders"))?;
|
||||
let block_number_1 = block_1.number;
|
||||
let state_1 = BundleStateWithReceipts::new(
|
||||
let execution_outcome1 = ExecutionOutcome::new(
|
||||
BundleState::default(),
|
||||
vec![random_receipt(&mut rng, &block_1.body[0], None)].into(),
|
||||
block_1.number,
|
||||
vec![],
|
||||
);
|
||||
// Extend the expected state with the first block
|
||||
expected_state.extend(state_1.clone());
|
||||
expected_state.extend(execution_outcome1.clone());
|
||||
|
||||
// Send a notification to the Execution Extension that the chain with the first block has
|
||||
// been committed
|
||||
handle.send_notification_chain_committed(Chain::new(vec![block_1], state_1, None)).await?;
|
||||
handle
|
||||
.send_notification_chain_committed(Chain::new(vec![block_1], execution_outcome1, None))
|
||||
.await?;
|
||||
exex.poll_once().await?;
|
||||
|
||||
// Assert that the state of the first block has been added to the total state
|
||||
assert_eq!(exex.as_mut().state, expected_state);
|
||||
assert_eq!(exex.as_mut().execution_outcome, expected_state);
|
||||
|
||||
// Generate second block and its state
|
||||
let block_2 = random_block(&mut rng, 1, None, Some(2), None)
|
||||
.seal_with_senders()
|
||||
.ok_or(eyre::eyre!("failed to recover senders"))?;
|
||||
let state_2 = BundleStateWithReceipts::new(
|
||||
let execution_outcome2 = ExecutionOutcome::new(
|
||||
BundleState::default(),
|
||||
vec![random_receipt(&mut rng, &block_2.body[0], None)].into(),
|
||||
block_2.number,
|
||||
vec![],
|
||||
);
|
||||
// Extend the expected state with the second block
|
||||
expected_state.extend(state_2.clone());
|
||||
// Extend the expected execution outcome with the second block
|
||||
expected_state.extend(execution_outcome2.clone());
|
||||
|
||||
// Send a notification to the Execution Extension that the chain with the second block has
|
||||
// been committed
|
||||
let chain_2 = Chain::new(vec![block_2], state_2, None);
|
||||
let chain_2 = Chain::new(vec![block_2], execution_outcome2, None);
|
||||
handle.send_notification_chain_committed(chain_2.clone()).await?;
|
||||
exex.poll_once().await?;
|
||||
|
||||
// Assert that the state of the second block has been added to the total state
|
||||
assert_eq!(exex.as_mut().state, expected_state);
|
||||
// Assert that the execution outcome of the second block has been added to the total state
|
||||
assert_eq!(exex.as_mut().execution_outcome, expected_state);
|
||||
|
||||
// Send a notification to the Execution Extension that the chain with the second block has
|
||||
// been reverted
|
||||
handle.send_notification_chain_reverted(chain_2).await?;
|
||||
exex.poll_once().await?;
|
||||
|
||||
// Assert that the state of the second block has been reverted
|
||||
// Assert that the execution outcome of the second block has been reverted
|
||||
expected_state.revert_to(block_number_1);
|
||||
assert_eq!(exex.as_mut().state, expected_state);
|
||||
assert_eq!(exex.as_mut().execution_outcome, expected_state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -54,10 +54,9 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::pin::pin;
|
||||
|
||||
use reth::providers::{BundleStateWithReceipts, Chain};
|
||||
use reth::providers::{Chain, ExecutionOutcome};
|
||||
use reth_exex_test_utils::{test_exex_context, PollOnce};
|
||||
use std::pin::pin;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_exex() -> eyre::Result<()> {
|
||||
@ -71,7 +70,7 @@ mod tests {
|
||||
handle
|
||||
.send_notification_chain_committed(Chain::from_block(
|
||||
handle.genesis.clone(),
|
||||
BundleStateWithReceipts::default(),
|
||||
ExecutionOutcome::default(),
|
||||
None,
|
||||
))
|
||||
.await?;
|
||||
|
||||
@ -264,7 +264,7 @@ mod tests {
|
||||
Address, Block, Header, Log, Receipt, Transaction, TransactionSigned, TxKind, TxLegacy,
|
||||
TxType, U256,
|
||||
};
|
||||
use reth_provider::{BundleStateWithReceipts, Chain};
|
||||
use reth_provider::{Chain, ExecutionOutcome};
|
||||
use reth_testing_utils::generators::sign_tx_with_random_key_pair;
|
||||
use rusqlite::Connection;
|
||||
|
||||
@ -341,7 +341,7 @@ mod tests {
|
||||
// Construct a chain
|
||||
let chain = Chain::new(
|
||||
vec![block.clone()],
|
||||
BundleStateWithReceipts::new(
|
||||
ExecutionOutcome::new(
|
||||
BundleState::default(),
|
||||
vec![deposit_tx_receipt, withdrawal_tx_receipt].into(),
|
||||
block.number,
|
||||
|
||||
Reference in New Issue
Block a user