feat: implement EIP-7685 (#8424)

Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com>
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Alexey Shekhirin
2024-05-28 15:06:28 +01:00
committed by GitHub
parent f6e1c7f76e
commit b4a1b733c9
83 changed files with 1053 additions and 214 deletions

View File

@ -27,4 +27,4 @@ parking_lot = { workspace = true, optional = true }
parking_lot.workspace = true
[features]
test-utils = ["dep:parking_lot"]
test-utils = ["dep:parking_lot"]

View File

@ -32,7 +32,7 @@ pub struct BundleStateWithReceipts {
// TODO(mattsse): unify the types, currently there's a cyclic dependency between
impl From<BatchBlockExecutionOutput> for BundleStateWithReceipts {
fn from(value: BatchBlockExecutionOutput) -> Self {
let BatchBlockExecutionOutput { bundle, receipts, first_block } = value;
let BatchBlockExecutionOutput { bundle, receipts, requests: _, first_block } = value;
Self { bundle, receipts, first_block }
}
}
@ -41,7 +41,8 @@ impl From<BatchBlockExecutionOutput> for BundleStateWithReceipts {
impl From<BundleStateWithReceipts> for BatchBlockExecutionOutput {
fn from(value: BundleStateWithReceipts) -> Self {
let BundleStateWithReceipts { bundle, receipts, first_block } = value;
Self { bundle, receipts, first_block }
// TODO(alexey): add requests
Self { bundle, receipts, requests: Vec::default(), first_block }
}
}

View File

@ -1,6 +1,8 @@
//! Traits for execution.
use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt, Receipts, U256};
use reth_primitives::{
BlockNumber, BlockWithSenders, PruneModes, Receipt, Receipts, Request, Requests, U256,
};
use revm::db::BundleState;
use revm_primitives::db::Database;
@ -96,6 +98,8 @@ pub struct BlockExecutionOutput<T> {
pub state: BundleState,
/// All the receipts of the transactions in the block.
pub receipts: Vec<T>,
/// All the EIP-7685 requests of the transactions in the block.
pub requests: Vec<Request>,
/// The total gas used by the block.
pub gas_used: u64,
}
@ -111,14 +115,26 @@ pub struct BatchBlockExecutionOutput {
///
/// If receipt is None it means it is pruned.
pub receipts: Receipts,
/// The collection of EIP-7685 requests.
/// Outer vector stores requests for each block sequentially.
/// The inner vector stores requests ordered by transaction number.
///
/// A transaction may have zero or more requests, so the length of the inner vector is not
/// guaranteed to be the same as the number of transactions.
pub requests: Vec<Requests>,
/// First block of bundle state.
pub first_block: BlockNumber,
}
impl BatchBlockExecutionOutput {
/// Create Bundle State.
pub fn new(bundle: BundleState, receipts: Receipts, first_block: BlockNumber) -> Self {
Self { bundle, receipts, first_block }
pub fn new(
bundle: BundleState,
receipts: Receipts,
requests: Vec<Requests>,
first_block: BlockNumber,
) -> Self {
Self { bundle, receipts, requests, first_block }
}
}
@ -260,8 +276,13 @@ mod tests {
let provider = TestExecutorProvider;
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
let executor = provider.executor(db);
let block =
Block { header: Default::default(), body: vec![], ommers: vec![], withdrawals: None };
let block = Block {
header: Default::default(),
body: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
};
let block = BlockWithSenders::new(block, Default::default()).unwrap();
let _ = executor.execute(BlockExecutionInput::new(&block, U256::ZERO));
}

View File

@ -50,11 +50,12 @@ impl<DB> Executor<DB> for MockExecutorProvider {
type Error = BlockExecutionError;
fn execute(self, _: Self::Input<'_>) -> Result<Self::Output, Self::Error> {
let BatchBlockExecutionOutput { bundle, receipts, .. } =
let BatchBlockExecutionOutput { bundle, receipts, requests, first_block: _ } =
self.exec_results.lock().pop().unwrap();
Ok(BlockExecutionOutput {
state: bundle,
receipts: receipts.into_iter().flatten().flatten().collect(),
requests: requests.into_iter().flatten().collect(),
gas_used: 0,
})
}