Skip to content

Commit

Permalink
Fix withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Sep 28, 2024
1 parent 07fb859 commit f2a7459
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
22 changes: 7 additions & 15 deletions src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ethereum::{EthEvmExecutor, EthExecuteOutput};
use crate::gnosis::{apply_block_rewards_contract_call, apply_withdrawals_contract_call};
use eyre::eyre;
use reth::primitives::Withdrawal;
use reth::primitives::Withdrawals;
use reth::providers::ExecutionOutcome;
use reth::{
api::ConfigureEvm,
Expand Down Expand Up @@ -245,12 +245,7 @@ where
&block_env,
self.block_rewards_contract,
block.timestamp,
block
.withdrawals
.as_ref()
.ok_or(BlockExecutionError::Other(
"block has no withdrawals field".to_owned().into(),
))?,
block.withdrawals.as_ref(),
block.beneficiary,
)?;

Expand All @@ -266,7 +261,7 @@ pub(crate) fn gnosis_post_block_system_calls<EvmConfig, DB>(
initialized_block_env: &BlockEnv,
block_rewards_contract: Address,
block_timestamp: u64,
withdrawals: &[Withdrawal],
withdrawals: Option<&Withdrawals>,
coinbase: Address,
) -> Result<(), BlockExecutionError>
where
Expand All @@ -293,13 +288,10 @@ where
// - Call block rewards contract for bridged xDAI mint

if chain_spec.is_shanghai_active_at_timestamp(block_timestamp) {
apply_withdrawals_contract_call(
evm_config,
&chain_spec,
block_timestamp,
withdrawals,
&mut evm,
)?;
let withdrawals = withdrawals.ok_or(BlockExecutionError::Other(
"block has no withdrawals field".to_owned().into(),
))?;
apply_withdrawals_contract_call(evm_config, &chain_spec, withdrawals, &mut evm)?;
}

let balance_increments = apply_block_rewards_contract_call(
Expand Down
1 change: 0 additions & 1 deletion src/gnosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ sol!(
pub fn apply_withdrawals_contract_call<EvmConfig, EXT, DB>(
evm_config: &EvmConfig,
chain_spec: &ChainSpec,
_block_timestamp: u64,
withdrawals: &[Withdrawal],
evm: &mut Evm<'_, EXT, DB>,
) -> Result<(), BlockExecutionError>
Expand Down
14 changes: 4 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ impl GnosisNode {
where
Node: FullNodeTypes<Engine = EthEngineTypes>,
{
// TODO: fix address
let block_rewards_contract = SYSTEM_ADDRESS;

EthereumNode::components()
.payload(GnosisPayloadServiceBuilder::new(
GnosisEvmConfig {
// TODO: fix address
collector_address: SYSTEM_ADDRESS,
},
block_rewards_contract,
))
.payload(GnosisPayloadServiceBuilder::new(GnosisEvmConfig {
// TODO: fix address
collector_address: SYSTEM_ADDRESS,
}))
.executor(GnosisExecutorBuilder::default())
.consensus(GnosisConsensusBuilder::default())
}
Expand Down
24 changes: 15 additions & 9 deletions src/payload_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use eyre::eyre;
use reth::{
api::FullNodeTypes,
builder::{components::PayloadServiceBuilder, BuilderContext, PayloadBuilderConfig},
Expand Down Expand Up @@ -45,16 +46,12 @@ use crate::{evm_config::GnosisEvmConfig, execute::gnosis_post_block_system_calls
pub struct GnosisPayloadServiceBuilder<EVM = GnosisEvmConfig> {
/// The EVM configuration to use for the payload builder.
pub evm_config: EVM,
block_rewards_contract: Address,
}

impl<EVM> GnosisPayloadServiceBuilder<EVM> {
/// Create a new instance with the given evm config.
pub const fn new(evm_config: EVM, block_rewards_contract: Address) -> Self {
Self {
evm_config,
block_rewards_contract,
}
pub const fn new(evm_config: EVM) -> Self {
Self { evm_config }
}
}

Expand All @@ -69,8 +66,17 @@ where
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<PayloadBuilderHandle<Node::Engine>> {
let payload_builder =
GnosisPayloadBuilder::new(self.evm_config, self.block_rewards_contract);
let chain_spec = ctx.chain_spec();
let block_rewards_contract = chain_spec
.genesis()
.config
.extra_fields
.get("blockRewardsContract")
.ok_or(eyre!("blockRewardsContract not defined"))?;
let block_rewards_contract: Address =
serde_json::from_value(block_rewards_contract.clone())?;

let payload_builder = GnosisPayloadBuilder::new(self.evm_config, block_rewards_contract);
let conf = ctx.payload_builder_config();

let payload_job_config = BasicPayloadJobGeneratorConfig::default()
Expand Down Expand Up @@ -520,7 +526,7 @@ where
&initialized_block_env,
block_rewards_contract,
attributes.timestamp,
&attributes.withdrawals.iter().cloned().collect::<Vec<_>>(),
Some(&attributes.withdrawals),
attributes.suggested_fee_recipient,
)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
Expand Down

0 comments on commit f2a7459

Please sign in to comment.