Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Jun 11, 2024
1 parent b818946 commit 1bd67d3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
32 changes: 16 additions & 16 deletions crates/evm/execution-types/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,18 @@ mod tests {
// Define the first block number
let first_block = 123;

// Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and
// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let exec_res = BundleStateWithReceipts {
let exec_res = ExecutionOutcome {
bundle: bundle.clone(),
receipts: receipts.clone(),
requests: requests.clone(),
first_block,
};

// Assert that creating a new BundleStateWithReceipts using the constructor matches exec_res
// Assert that creating a new ExecutionOutcome using the constructor matches exec_res
assert_eq!(
BundleStateWithReceipts::new(bundle, receipts.clone(), first_block, requests.clone()),
ExecutionOutcome::new(bundle, receipts.clone(), first_block, requests.clone()),
exec_res
);

Expand All @@ -405,10 +405,10 @@ mod tests {
let mut revert_init: RevertsInit = HashMap::new();
revert_init.insert(123, revert_inner);

// Assert that creating a new BundleStateWithReceipts using the new_init method matches
// Assert that creating a new ExecutionOutcome using the new_init method matches
// exec_res
assert_eq!(
BundleStateWithReceipts::new_init(
ExecutionOutcome::new_init(
state_init,
revert_init,
vec![],
Expand Down Expand Up @@ -439,9 +439,9 @@ mod tests {
// Define the first block number
let first_block = 123;

// Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and
// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let exec_res = BundleStateWithReceipts {
let exec_res = ExecutionOutcome {
bundle: Default::default(),
receipts,
requests: vec![],
Expand Down Expand Up @@ -477,9 +477,9 @@ mod tests {
// Define the first block number
let first_block = 123;

// Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and
// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let exec_res = BundleStateWithReceipts {
let exec_res = ExecutionOutcome {
bundle: Default::default(),
receipts,
requests: vec![],
Expand Down Expand Up @@ -512,9 +512,9 @@ mod tests {
// Define the first block number
let first_block = 123;

// Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and
// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let exec_res = BundleStateWithReceipts {
let exec_res = ExecutionOutcome {
bundle: Default::default(), // Default value for bundle
receipts, // Include the created receipts
requests: vec![], // Empty vector for requests
Expand Down Expand Up @@ -562,9 +562,9 @@ mod tests {
// Define the first block number
let first_block = 123;

// Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and
// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let exec_res = BundleStateWithReceipts {
let exec_res = ExecutionOutcome {
bundle: Default::default(), // Default value for bundle
receipts, // Include the created receipts
requests: vec![], // Empty vector for requests
Expand All @@ -577,8 +577,8 @@ mod tests {
// Assert that exec_res is not empty
assert!(!exec_res.is_empty());

// Create a BundleStateWithReceipts object with an empty Receipts object
let exec_res_empty_receipts = BundleStateWithReceipts {
// Create a ExecutionOutcome object with an empty Receipts object
let exec_res_empty_receipts = ExecutionOutcome {
bundle: Default::default(), // Default value for bundle
receipts: receipts_empty, // Include the empty receipts
requests: vec![], // Empty vector for requests
Expand Down
42 changes: 22 additions & 20 deletions examples/exex/in-memory-state/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}

Expand All @@ -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))?;
}
}
Expand All @@ -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};
Expand All @@ -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(())
}
Expand Down

0 comments on commit 1bd67d3

Please sign in to comment.