Skip to content

Commit

Permalink
feat: small refactor, fix check fails
Browse files Browse the repository at this point in the history
  • Loading branch information
allnil committed Oct 3, 2024
1 parent eddaf8d commit b4d54ee
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions crates/revm/src/handler/mainnet/post_execution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::primitives::{address, alloy_primitives};
use crate::{
interpreter::{Gas, SuccessOrHalt},
primitives::{
db::Database, EVMError, ExecutionResult, ResultAndState, Spec, SpecId, SpecId::LONDON, U256,
},
Context, FrameResult,
};
use crate::primitives::{address};

const WVM_TREASURY_ADDRESS: alloy_primitives::Address =
address!("a2A0D977847805fE224B789D8C4d3D711ab251e7");

/// Mainnet end handle does not change the output.
#[inline]
Expand Down Expand Up @@ -41,8 +44,11 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
effective_gas_price
};

// WVM: send base fee back to treasury
wvm_add_base_fee_to_treasury(context, gas)?;
// WVM: if EIP-1559 enabled we send base fee back to treasury
// instead of burning it
if SPEC::enabled(LONDON) {
wvm_add_base_fee_to_treasury(context)?;
}

let coinbase_account = context
.evm
Expand All @@ -61,23 +67,20 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
}

/// WVM: send base fee back to treasury
fn wvm_add_base_fee_to_treasury<SPEC: Spec, EXT, DB: Database>(
#[inline]
fn wvm_add_base_fee_to_treasury<EXT, DB: Database>(
context: &mut Context<EXT, DB>,
gas: &Gas,
) -> Result<(), EVMError<DB::Error>> {
let treasury_address = address!("a2A0D977847805fE224B789D8C4d3D711ab251e7")?; // e.g treasury account
let base_fee = context.evm.env.block.basefee.clone();
let treasury_account = context
.evm
.inner
.journaled_state
.load_account(treasury_address, &mut context.evm.inner.db)?;
.load_account(WVM_TREASURY_ADDRESS, &mut context.evm.inner.db)?;

treasury_account.data.mark_touch();
treasury_account.data.info.balance = treasury_account
.data
.info
.balance
.saturating_add(context.evm.env.block.basefee);
treasury_account.data.info.balance =
treasury_account.data.info.balance.saturating_add(base_fee);

Ok(())
}
Expand Down

0 comments on commit b4d54ee

Please sign in to comment.