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

fix: insert genesis hash into db #7325

Merged
Merged
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
7 changes: 6 additions & 1 deletion crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,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 @@ -297,6 +297,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
Loading