Skip to content

Commit

Permalink
debugging withdrawals (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
debjit-bw authored Nov 13, 2024
1 parent 3c9b63b commit 7a1d49e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
9 changes: 2 additions & 7 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ where
fn apply_post_execution_changes(
&mut self,
block: &BlockWithSenders,
total_difficulty: U256,
_total_difficulty: U256,
receipts: &[Receipt],
) -> Result<Requests, Self::Error> {
let cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
Expand All @@ -250,19 +250,14 @@ where
block.beneficiary,
)?;

let env = self.evm_env_for_block(&block.header, total_difficulty);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);

let requests = if self
.chain_spec
.is_prague_active_at_timestamp(block.timestamp)
{
// Collect all EIP-6110 deposits
let deposit_requests = parse_deposits_from_receipts(&self.chain_spec, receipts)?;

let mut requests = Requests::new(vec![deposit_requests]);
requests.extend(self.system_caller.apply_post_execution_changes(&mut evm)?);
requests
Requests::new(vec![deposit_requests])
} else {
Requests::default()
};
Expand Down
61 changes: 24 additions & 37 deletions src/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use reth::{
transaction_pool::{noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool},
};
use reth_basic_payload_builder::{
commit_withdrawals, is_better_payload, BasicPayloadJobGenerator,
BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome, PayloadBuilder, PayloadConfig,
WithdrawalsOutcome,
is_better_payload, BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments,
BuildOutcome, PayloadBuilder, PayloadConfig, WithdrawalsOutcome,
};
use reth_chain_state::ExecutedBlock;
use reth_chainspec::{ChainSpec, EthereumHardforks};
Expand Down Expand Up @@ -423,34 +422,6 @@ 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())
.map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?;
let withdrawal_requests = system_caller
.post_block_withdrawal_requests_contract_call(
&mut db,
&initialized_cfg,
&initialized_block_env,
)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
let consolidation_requests = system_caller
.post_block_consolidation_requests_contract_call(
&mut db,
&initialized_cfg,
&initialized_block_env,
)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;

Some(Requests::new(vec![
deposit_requests,
withdrawal_requests,
consolidation_requests,
]))
} else {
None
};

// < GNOSIS SPECIFIC
apply_post_block_system_calls(
&chain_spec,
Expand All @@ -466,15 +437,31 @@ where
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
// GNOSIS SPECIFIC >

// 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())
.map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?;
Some(Requests::new(vec![deposit_requests]))
} else {
None
};

let WithdrawalsOutcome {
withdrawals_root,
withdrawals,
} = commit_withdrawals(
&mut db,
&chain_spec,
attributes.timestamp,
attributes.withdrawals,
)?;
} = if !chain_spec.is_shanghai_active_at_timestamp(attributes.timestamp) {
WithdrawalsOutcome::pre_shanghai()
} else if attributes.withdrawals.is_empty() {
WithdrawalsOutcome::empty()
} else {
let withdrawals_root = proofs::calculate_withdrawals_root(&attributes.withdrawals);

// calculate withdrawals root
WithdrawalsOutcome {
withdrawals: Some(attributes.withdrawals),
withdrawals_root: Some(withdrawals_root),
}
};

// merge all transitions into bundle state, this would apply the withdrawal balance changes
// and 4788 contract call
Expand Down

0 comments on commit 7a1d49e

Please sign in to comment.