Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

primitives: use alloy Receipts #12059

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,7 @@ impl BlockState {
receipts.receipt_vec.len()
);

receipts
.receipt_vec
.first()
.map(|block_receipts| {
block_receipts.iter().filter_map(|opt_receipt| opt_receipt.clone()).collect()
})
.unwrap_or_default()
receipts.receipt_vec.first().cloned().unwrap_or_default()
}

/// Returns a vector of __parent__ `BlockStates`.
Expand Down Expand Up @@ -1196,7 +1190,7 @@ mod tests {

#[test]
fn test_state_receipts() {
let receipts = Receipts { receipt_vec: vec![vec![Some(Receipt::default())]] };
let receipts = Receipts { receipt_vec: vec![vec![Receipt::default()]] };
let mut test_block_builder = TestBlockBuilder::default();
let block =
test_block_builder.get_executed_block_with_receipts(receipts.clone(), B256::random());
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl TestBlockBuilder {

let execution_outcome = ExecutionOutcome::new(
bundle_state_builder.build(),
vec![vec![None]].into(),
vec![vec![]].into(),
block.number,
Vec::new(),
);
Expand Down
3 changes: 1 addition & 2 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ impl StorageInner {
let receipts = execution_outcome.receipts_by_block(header.number);

// update logs bloom
let receipts_with_bloom =
receipts.iter().map(|r| r.as_ref().unwrap().bloom_slow()).collect::<Vec<Bloom>>();
let receipts_with_bloom = receipts.iter().map(|r| r.bloom_slow()).collect::<Vec<Bloom>>();
header.logs_bloom = receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | *r);

// update receipts root
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ where

cumulative_gas_used += exec_result.result.gas_used();
#[allow(clippy::needless_update)] // side-effect of optimism fields
receipts.push(Some(Receipt {
receipts.push(Receipt {
tx_type: tx.tx_type(),
success: exec_result.result.is_success(),
cumulative_gas_used,
logs: exec_result.result.into_logs().into_iter().map(Into::into).collect(),
..Default::default()
}));
});

// append transaction to the list of executed transactions
transactions.push(tx);
Expand Down
6 changes: 3 additions & 3 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ where

// Push transaction changeset and calculate header bloom filter for receipt.
#[allow(clippy::needless_update)] // side-effect of optimism fields
receipts.push(Some(Receipt {
receipts.push(Receipt {
tx_type: tx.tx_type(),
success: result.is_success(),
cumulative_gas_used,
logs: result.into_logs().into_iter().map(Into::into).collect(),
..Default::default()
}));
});

// update add to total fees
let miner_fee = tx
Expand All @@ -326,7 +326,7 @@ where

// calculate the requests and the requests root
let requests = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) {
let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten())
let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter())
.map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?;
let withdrawal_requests = system_caller
.post_block_withdrawal_requests_contract_call(
Expand Down
16 changes: 6 additions & 10 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Chain {
}

/// Returns an iterator over all the receipts of the blocks in the chain.
pub fn block_receipts_iter(&self) -> impl Iterator<Item = &Vec<Option<Receipt>>> + '_ {
pub fn block_receipts_iter(&self) -> impl Iterator<Item = &Vec<Receipt>> + '_ {
self.execution_outcome.receipts().iter()
}

Expand All @@ -173,7 +173,7 @@ impl Chain {
/// Returns an iterator over all blocks and their receipts in the chain.
pub fn blocks_and_receipts(
&self,
) -> impl Iterator<Item = (&SealedBlockWithSenders, &Vec<Option<Receipt>>)> + '_ {
) -> impl Iterator<Item = (&SealedBlockWithSenders, &Vec<Receipt>)> + '_ {
self.blocks_iter().zip(self.block_receipts_iter())
}

Expand Down Expand Up @@ -221,7 +221,7 @@ impl Chain {
/// Get all receipts for the given block.
pub fn receipts_by_block_hash(&self, block_hash: BlockHash) -> Option<Vec<&Receipt>> {
let num = self.block_number(block_hash)?;
self.execution_outcome.receipts_by_block(num).iter().map(Option::as_ref).collect()
Some(self.execution_outcome.receipts_by_block(num).iter().collect())
}

/// Get all receipts with attachment.
Expand All @@ -234,10 +234,7 @@ impl Chain {
{
let mut tx_receipts = Vec::with_capacity(receipts.len());
for (tx, receipt) in block.body.transactions().zip(receipts.iter()) {
tx_receipts.push((
tx.hash(),
receipt.as_ref().expect("receipts have not been pruned").clone(),
));
tx_receipts.push((tx.hash(), receipt.clone()));
}
let block_num_hash = BlockNumHash::new(*block_num, block.hash());
receipt_attach.push(BlockReceipts { block: block_num_hash, tx_receipts });
Expand Down Expand Up @@ -824,8 +821,7 @@ mod tests {
};

// Create a Receipts object with a vector of receipt vectors
let receipts =
Receipts { receipt_vec: vec![vec![Some(receipt1.clone())], vec![Some(receipt2)]] };
let receipts = Receipts { receipt_vec: vec![vec![receipt1.clone()], vec![receipt2]] };

// Create an ExecutionOutcome object with the created bundle, receipts, an empty requests
// vector, and first_block set to 10
Expand All @@ -850,7 +846,7 @@ mod tests {
// Create an ExecutionOutcome object with a single receipt vector containing receipt1
let execution_outcome1 = ExecutionOutcome {
bundle: Default::default(),
receipts: Receipts { receipt_vec: vec![vec![Some(receipt1)]] },
receipts: Receipts { receipt_vec: vec![vec![receipt1]] },
requests: vec![],
first_block: 10,
};
Expand Down
67 changes: 30 additions & 37 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl ExecutionOutcome {
/// Returns an iterator over all block logs.
pub fn logs(&self, block_number: BlockNumber) -> Option<impl Iterator<Item = &Log>> {
let index = self.block_number_to_index(block_number)?;
Some(self.receipts[index].iter().filter_map(|r| Some(r.as_ref()?.logs.iter())).flatten())
Some(self.receipts[index].iter().flat_map(|r| r.logs.iter()))
}

/// Return blocks logs bloom
Expand All @@ -197,10 +197,10 @@ impl ExecutionOutcome {
#[cfg(feature = "optimism")]
panic!("This should not be called in optimism mode. Use `optimism_receipts_root_slow` instead.");
#[cfg(not(feature = "optimism"))]
self.receipts.root_slow(
self.block_number_to_index(_block_number)?,
reth_primitives::proofs::calculate_receipt_root_no_memo,
)
self.receipts
.receipt_vec
.get(self.block_number_to_index(_block_number)?)
.map(|receipts| reth_primitives::proofs::calculate_receipt_root_no_memo(receipts))
}

/// Returns the receipt root for all recorded receipts.
Expand All @@ -209,9 +209,12 @@ impl ExecutionOutcome {
pub fn generic_receipts_root_slow(
&self,
block_number: BlockNumber,
f: impl FnOnce(&[&Receipt]) -> B256,
f: impl FnOnce(&[Receipt]) -> B256,
) -> Option<B256> {
self.receipts.root_slow(self.block_number_to_index(block_number)?, f)
self.receipts
.receipt_vec
.get(self.block_number_to_index(block_number)?)
.map(|receipts| f(receipts))
}

/// Returns reference to receipts.
Expand All @@ -225,7 +228,7 @@ impl ExecutionOutcome {
}

/// Return all block receipts
pub fn receipts_by_block(&self, block_number: BlockNumber) -> &[Option<Receipt>] {
pub fn receipts_by_block(&self, block_number: BlockNumber) -> &[Receipt] {
let Some(index) = self.block_number_to_index(block_number) else { return &[] };
&self.receipts[index]
}
Expand Down Expand Up @@ -385,12 +388,12 @@ mod tests {

// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
receipt_vec: vec![vec![Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
})]],
}]],
};

// Create a Requests object with a vector of requests
Expand Down Expand Up @@ -447,12 +450,12 @@ mod tests {
fn test_block_number_to_index() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
receipt_vec: vec![vec![Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
})]],
}]],
};

// Define the first block number
Expand Down Expand Up @@ -482,12 +485,12 @@ mod tests {
fn test_get_logs() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
receipt_vec: vec![vec![Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
})]],
}]],
};

// Define the first block number
Expand All @@ -514,12 +517,12 @@ mod tests {
fn test_receipts_by_block() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
receipt_vec: vec![vec![Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
})]],
}]],
};

// Define the first block number
Expand All @@ -540,12 +543,12 @@ mod tests {
// Assert that the receipts for block number 123 match the expected receipts
assert_eq!(
receipts_by_block,
vec![&Some(Receipt {
vec![&Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
})]
}]
);
}

Expand All @@ -554,12 +557,12 @@ mod tests {
fn test_receipts_len() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
receipt_vec: vec![vec![Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
success: true,
})]],
}]],
};

// Create an empty Receipts object
Expand Down Expand Up @@ -610,9 +613,7 @@ mod tests {
};

// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]],
};
let receipts = Receipts { receipt_vec: vec![vec![receipt.clone()], vec![receipt.clone()]] };

// Define the first block number
let first_block = 123;
Expand All @@ -633,7 +634,7 @@ mod tests {
assert!(exec_res.revert_to(123));

// Assert that the receipts are properly cut after reverting to the initial block number.
assert_eq!(exec_res.receipts, Receipts { receipt_vec: vec![vec![Some(receipt)]] });
assert_eq!(exec_res.receipts, Receipts { receipt_vec: vec![vec![receipt]] });

// Assert that the requests are properly cut after reverting to the initial block number.
assert_eq!(exec_res.requests, vec![Requests::new(vec![request])]);
Expand All @@ -659,7 +660,7 @@ mod tests {
};

// Create a Receipts object containing the receipt.
let receipts = Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] };
let receipts = Receipts { receipt_vec: vec![vec![receipt.clone()]] };

// Create a request.
let request = bytes!("deadbeef");
Expand All @@ -682,9 +683,7 @@ mod tests {
exec_res,
ExecutionOutcome {
bundle: Default::default(),
receipts: Receipts {
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]]
},
receipts: Receipts { receipt_vec: vec![vec![receipt.clone()], vec![receipt]] },
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 123,
}
Expand All @@ -704,11 +703,7 @@ mod tests {

// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![
vec![Some(receipt.clone())],
vec![Some(receipt.clone())],
vec![Some(receipt.clone())],
],
receipt_vec: vec![vec![receipt.clone()], vec![receipt.clone()], vec![receipt.clone()]],
};

// Define the first block number
Expand All @@ -735,17 +730,15 @@ mod tests {
// Define the expected lower ExecutionOutcome after splitting
let lower_execution_outcome = ExecutionOutcome {
bundle: Default::default(),
receipts: Receipts { receipt_vec: vec![vec![Some(receipt.clone())]] },
receipts: Receipts { receipt_vec: vec![vec![receipt.clone()]] },
requests: vec![Requests::new(vec![request.clone()])],
first_block,
};

// Define the expected higher ExecutionOutcome after splitting
let higher_execution_outcome = ExecutionOutcome {
bundle: Default::default(),
receipts: Receipts {
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt)]],
},
receipts: Receipts { receipt_vec: vec![vec![receipt.clone()], vec![receipt]] },
requests: vec![Requests::new(vec![request.clone()]), Requests::new(vec![request])],
first_block: 124,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<DB> Executor<DB> for MockExecutorProvider {
self.exec_results.lock().pop().unwrap();
Ok(BlockExecutionOutput {
state: bundle,
receipts: receipts.into_iter().flatten().flatten().collect(),
receipts: receipts.into_iter().flatten().collect(),
requests: requests.into_iter().fold(Requests::default(), |mut reqs, req| {
reqs.extend(req);
reqs
Expand Down
Loading
Loading