refactor: simplify withdrawals outcome (#12780)

This commit is contained in:
Hai | RISE
2024-11-22 21:15:43 +07:00
committed by GitHub
parent 87ecb43413
commit 64728e0856
3 changed files with 23 additions and 56 deletions

View File

@ -4,7 +4,7 @@ use std::{fmt::Display, sync::Arc};
use alloy_consensus::{Header, Transaction, EMPTY_OMMER_ROOT_HASH};
use alloy_eips::merge::BEACON_NONCE;
use alloy_primitives::{Address, Bytes, U256};
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rpc_types_debug::ExecutionWitness;
use alloy_rpc_types_engine::PayloadId;
use reth_basic_payload_builder::*;
@ -318,13 +318,13 @@ where
}
}
let withdrawals_outcome = ctx.commit_withdrawals(state)?;
let withdrawals_root = ctx.commit_withdrawals(state)?;
// merge all transitions into bundle state, this would apply the withdrawal balance changes
// and 4788 contract call
state.merge_transitions(BundleRetention::Reverts);
Ok(BuildOutcomeKind::Better { payload: ExecutedPayload { info, withdrawals_outcome } })
Ok(BuildOutcomeKind::Better { payload: ExecutedPayload { info, withdrawals_root } })
}
/// Builds the payload on top of the state.
@ -338,10 +338,7 @@ where
DB: Database<Error = ProviderError> + AsRef<P>,
P: StateRootProvider,
{
let ExecutedPayload {
info,
withdrawals_outcome: WithdrawalsOutcome { withdrawals, withdrawals_root },
} = match self.execute(&mut state, &ctx)? {
let ExecutedPayload { info, withdrawals_root } = match self.execute(&mut state, &ctx)? {
BuildOutcomeKind::Better { payload } | BuildOutcomeKind::Freeze(payload) => payload,
BuildOutcomeKind::Cancelled => return Ok(BuildOutcomeKind::Cancelled),
BuildOutcomeKind::Aborted { fees } => return Ok(BuildOutcomeKind::Aborted { fees }),
@ -419,7 +416,7 @@ where
body: BlockBody {
transactions: info.executed_transactions,
ommers: vec![],
withdrawals,
withdrawals: Some(ctx.attributes().payload_attributes.withdrawals.clone()),
},
};
@ -501,8 +498,8 @@ impl OpPayloadTransactions for () {
pub struct ExecutedPayload {
/// Tracked execution info
pub info: ExecutionInfo,
/// Outcome after committing withdrawals.
pub withdrawals_outcome: WithdrawalsOutcome,
/// Withdrawal hash.
pub withdrawals_root: Option<B256>,
}
/// This acts as the container for executed transactions and its byproducts (receipts, gas used)
@ -652,10 +649,7 @@ impl<EvmConfig> OpPayloadBuilderCtx<EvmConfig> {
}
/// Commits the withdrawals from the payload attributes to the state.
pub fn commit_withdrawals<DB>(
&self,
db: &mut State<DB>,
) -> Result<WithdrawalsOutcome, ProviderError>
pub fn commit_withdrawals<DB>(&self, db: &mut State<DB>) -> Result<Option<B256>, ProviderError>
where
DB: Database<Error = ProviderError>,
{
@ -663,7 +657,7 @@ impl<EvmConfig> OpPayloadBuilderCtx<EvmConfig> {
db,
&self.chain_spec,
self.attributes().payload_attributes.timestamp,
self.attributes().payload_attributes.withdrawals.clone(),
&self.attributes().payload_attributes.withdrawals,
)
}