Skip to content

Commit

Permalink
fix: truncate request vectors when reverting exec outcome (paradigmxy…
Browse files Browse the repository at this point in the history
…z#8815)

Co-authored-by: Dan Cline <[email protected]>
  • Loading branch information
tcoratger and Rjected authored Jun 13, 2024
1 parent 560080e commit bc15e6c
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions crates/evm/execution-types/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ impl ExecutionOutcome {

// remove receipts
self.receipts.truncate(new_len);
// remove requests
self.requests.truncate(new_len);
// Revert last n reverts.
self.bundle.revert(rm_trx);

Expand Down Expand Up @@ -595,37 +597,51 @@ mod tests {

#[test]
fn test_revert_to() {
// Create a random receipt object
let receipt = Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
};

// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
#[cfg(feature = "optimism")]
deposit_nonce: Some(18),
#[cfg(feature = "optimism")]
deposit_receipt_version: Some(34),
})]],
receipt_vec: vec![vec![Some(receipt.clone())], vec![Some(receipt.clone())]],
};

// Define the first block number
let first_block = 123;

// Create a DepositRequest object with specific attributes.
let request = Request::DepositRequest(DepositRequest {
pubkey: FixedBytes::<48>::from([1; 48]),
withdrawal_credentials: B256::from([0; 32]),
amount: 1111,
signature: FixedBytes::<96>::from([2; 96]),
index: 222,
});

// Create a vector of Requests containing the request.
let requests = vec![Requests(vec![request]), Requests(vec![request])];

// Create a ExecutionOutcome object with the created bundle, receipts, requests, and
// first_block
let mut exec_res = ExecutionOutcome {
bundle: Default::default(),
receipts: receipts.clone(),
requests: vec![],
first_block,
};
let mut exec_res =
ExecutionOutcome { bundle: Default::default(), receipts, requests, first_block };

// Assert that the revert_to method returns true when reverting to the initial block number.
assert!(exec_res.revert_to(123));

// Assert that the receipts remain unchanged after reverting to the initial block number.
assert_eq!(exec_res.receipts, receipts);
// 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 that the requests are properly cut after reverting to the initial block number.
assert_eq!(exec_res.requests, vec![Requests(vec![request])]);

// Assert that the revert_to method returns false when attempting to revert to a block
// number greater than the initial block number.
Expand Down

0 comments on commit bc15e6c

Please sign in to comment.