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

Withdrawals #30

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
2 changes: 2 additions & 0 deletions .github/workflows/post-merge-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ jobs:
# Manual sanity checks
- name: Run EIP-1559 sanity checks
run: bash ./scripts/test_eip1559.sh
- name: Run EIP-4895 sanity checks
run: bash ./scripts/test_withdrawals_eip4895.sh


3 changes: 3 additions & 0 deletions scripts/chiado_genesis_alloc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"config": {
"chainId": 10200,
"depositContractAddress":
"0x566b8783a28a46dc8d88ebf712303938985e121e",

"consensus": "aura",
"homesteadBlock": 0,
"eip150Block": 0,
Expand Down
483 changes: 483 additions & 0 deletions scripts/test_withdrawals_eip4895.sh

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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 @@ -249,19 +249,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
68 changes: 30 additions & 38 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,37 @@ 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())))?;

println!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't merge this log

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, removing

"debjit debug (payload) requests (building): {:?}",
Requests::new(vec![deposit_requests.clone(),])
);

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 Expand Up @@ -580,7 +573,6 @@ where
};

let sealed_block = block.seal_slow();
debug!(target: "payload_builder", ?sealed_block, "sealed built block");

// create the executed block data
let executed = ExecutedBlock {
Expand Down
Loading