Skip to content

Commit

Permalink
fix(anvil): include gas limit in genesis block (foundry-rs#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jun 25, 2022
1 parent d06692d commit 034c379
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ pub struct Backend {
impl Backend {
/// Create a new instance of in-mem backend.
pub fn new(db: Arc<RwLock<dyn Db>>, env: Arc<RwLock<Env>>, fees: FeeManager) -> Self {
let blockchain = Blockchain::new(&*env.read(), fees.is_eip1559().then(|| fees.base_fee()));
Self {
db,
blockchain: Blockchain::new(fees.is_eip1559().then(|| fees.base_fee())),
blockchain,
states: Arc::new(RwLock::new(Default::default())),
env,
fork: None,
Expand Down Expand Up @@ -134,7 +135,7 @@ impl Backend {
trace!(target: "backend", "using forked blockchain at {}", fork.block_number());
Blockchain::forked(fork.block_number(), fork.block_hash())
} else {
Blockchain::new(fees.is_eip1559().then(|| fees.base_fee()))
Blockchain::new(&*env.read(), fees.is_eip1559().then(|| fees.base_fee()))
};

let backend = Self {
Expand Down
11 changes: 7 additions & 4 deletions anvil/src/eth/backend/mem/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ethers::{
prelude::{BlockId, BlockNumber, Trace, H256, H256 as TxHash, U64},
types::{ActionType, U256},
};
use forge::revm::Return;
use forge::revm::{Env, Return};
use parking_lot::RwLock;
use std::{
collections::{HashMap, VecDeque},
Expand Down Expand Up @@ -99,11 +99,14 @@ pub struct BlockchainStorage {

impl BlockchainStorage {
/// Creates a new storage with a genesis block
pub fn new(base_fee: Option<U256>) -> Self {
pub fn new(env: &Env, base_fee: Option<U256>) -> Self {
// create a dummy genesis block
let partial_header = PartialHeader {
timestamp: duration_since_unix_epoch().as_secs(),
base_fee,
gas_limit: env.block.gas_limit,
beneficiary: env.block.coinbase,
difficulty: env.block.difficulty,
..Default::default()
};
let block = Block::new(partial_header, vec![], vec![]);
Expand Down Expand Up @@ -170,8 +173,8 @@ pub struct Blockchain {

impl Blockchain {
/// Creates a new storage with a genesis block
pub fn new(base_fee: Option<U256>) -> Self {
Self { storage: Arc::new(RwLock::new(BlockchainStorage::new(base_fee))) }
pub fn new(env: &Env, base_fee: Option<U256>) -> Self {
Self { storage: Arc::new(RwLock::new(BlockchainStorage::new(env, base_fee))) }
}

pub fn forked(block_number: u64, block_hash: H256) -> Self {
Expand Down

0 comments on commit 034c379

Please sign in to comment.