Skip to content

Commit

Permalink
fix: insert genesis hash into db (#7325)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Mar 8, 2024
1 parent 9fde758 commit 55c30dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 6 additions & 1 deletion crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,12 @@ latest block number: {latest_block}"
total_difficulty: block.header.total_difficulty.unwrap_or_default(),
};

(ForkedDatabase::new(backend, block_chain_db), config)
let mut db = ForkedDatabase::new(backend, block_chain_db);

// need to insert the forked block's hash
db.insert_block_hash(U256::from(config.block_number), config.block_hash);

(db, config)
}
}

Expand Down
12 changes: 5 additions & 7 deletions crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ impl ClientFork {
let base_fee = block.header.base_fee_per_gas;
let total_difficulty = block.header.total_difficulty.unwrap_or_default();

self.config.write().update_block(
block.header.number.ok_or(BlockchainError::BlockNotFound)?.to::<u64>(),
block_hash,
timestamp,
base_fee,
total_difficulty,
);
let number = block.header.number.ok_or(BlockchainError::BlockNotFound)?.to::<u64>();
self.config.write().update_block(number, block_hash, timestamp, base_fee, total_difficulty);

self.clear_cached_storage();

self.database.write().await.insert_block_hash(U256::from(number), block_hash);

Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ impl Backend {
for (account, info) in self.genesis.account_infos() {
db.insert_account(account, info);
}

// insert the new genesis hash to the database so it's available for the next block in
// the evm
db.insert_block_hash(U256::from(self.best_number()), self.best_hash());
}

let db = self.db.write().await;
Expand Down

0 comments on commit 55c30dd

Please sign in to comment.