Skip to content

Commit

Permalink
add coinbase only in execution, not in block header calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Oct 5, 2024
1 parent a5a347c commit 58bf00c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
36 changes: 34 additions & 2 deletions crates/executor/client/src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_evm_ethereum::EthEvmConfig;
use reth_evm_optimism::OptimismEvmConfig;
use reth_primitives::{
revm_primitives::{CfgEnvWithHandlerCfg, TxEnv},
Address, Bytes, Header, TransactionSigned, U256,
revm_primitives::{CfgEnvWithHandlerCfg, TxEnv, BlockEnv},
Address, Bytes, Header, TransactionSigned, U256
};
use reth_revm::{
handler::register::EvmHandler, precompile::PrecompileSpecId, primitives::Env,
Expand Down Expand Up @@ -210,6 +210,38 @@ impl ConfigureEvmEnv for CustomEvmConfig {
}
}

fn fill_block_env(
&self, block_env: &mut BlockEnv, header: &Header, after_merge: bool
) {
match self.0 {
ChainVariant::Ethereum => {
EthEvmConfig::default().fill_block_env(block_env, header, after_merge)
}
ChainVariant::Optimism => OptimismEvmConfig::default().fill_block_env(
block_env,
header,
after_merge,
),
ChainVariant::Linea => {
EthEvmConfig::default().fill_block_env(block_env, header, after_merge)
}
ChainVariant::Sepolia => {
EthEvmConfig::default().fill_block_env(block_env, header, after_merge)
}
ChainVariant::CliqueShanghaiChainID => {

// add beneficiary address from the extra data
let block_extra_data = header.extra_data.clone();
let addr = Address::from_slice(&block_extra_data[32..52]);

// We hijack the beneficiary address here to match the clique consensus.
let mut header = header.clone();
header.beneficiary = addr;
EthEvmConfig::default().fill_block_env(block_env, &header, after_merge)
}
}
}

fn fill_tx_env_system_contract_call(
&self,
env: &mut Env,
Expand Down
20 changes: 0 additions & 20 deletions crates/executor/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,24 +472,4 @@ impl Variant for SepoliaVariant {
) -> eyre::Result<()> {
Ok(validate_block_post_execution_ethereum(block, chain_spec, receipts, requests)?)
}

fn pre_process_block(block: &Block) -> Block {
// Linea network uses clique consensus, which is not implemented in reth.
// The main difference for the execution part is the block beneficiary:
// reth will credit the block reward to the beneficiary address (coinbase)
// whereas in clique, the block reward is credited to the signer.

// We extract the clique beneficiary address from the genesis extra data.
// - vanity: 32 bytes
// - address: 20 bytes
// - seal: 65 bytes
// we extract the address from the 32nd to 52nd byte.
let block_extra_data = block.header.extra_data.clone();
let addr = Address::from_slice(&block_extra_data[32..52]);

// We hijack the beneficiary address here to match the clique consensus.
let mut block = block.clone();
block.header.borrow_mut().beneficiary = addr;
block
}
}

0 comments on commit 58bf00c

Please sign in to comment.