-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(anvil
): use header.number not best_number
#9151
Conversation
@@ -1917,7 +1917,7 @@ impl Backend { | |||
) = NamedChain::try_from(self.env.read().env.cfg.chain_id) | |||
{ | |||
// Block number is the best number. | |||
block.header.number = self.best_number(); | |||
block.header.number = number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proper fix would be
if self.is_fork() {
// Block number is the best number.
block.header.number = self.best_number();
}
and a test for could be
// <https://github.com/foundry-rs/foundry/issues/9143>
#[tokio::test(flavor = "multi_thread")]
async fn test_arbitrum_non_fork_block_number() {
let (api, _) =
spawn(NodeConfig::test().with_chain_id(42161u64.into())).await;
// Mine blocks and check properly returned by `eth_getBlockByNumber` API.
api.mine_one().await;
api.mine_one().await;
let first_block = api.block_by_number(1.into()).await.unwrap().unwrap();
assert_eq!(1, first_block.header.number);
let latest_block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap();
assert_eq!(2, latest_block.header.number);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Wouldn't that cause the same issue in fork mode?
E.g:
If anvil was forked at X
block number and then two blocks were mined i.e self.best_number() == X + 2
.
We call eth_getBlockByNumber(X)
, the resultant block.number
field would be X + 2
whereas it should be X
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I guess you're right, should be the same
There's a deeper issue with how we handle Arbitrum in anvil, which is causing the On arbitrum foundry/crates/evm/core/src/utils.rs Line 54 in 09824ad
So when we fork off of arbitrum the However, upon mining a new block we increment foundry/crates/anvil/src/eth/backend/mem/mod.rs Line 1102 in 09824ad
This Fix for this is a bit hacky: In @mattsse wdyt? |
Ignoring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, would be nice to provide a quick fix for #9152 too so we won't break the other use case
* fix(`anvil`): use header.number not best_number * test * ignore test_arbitrum_fork_block_number
Motivation
Closes #9143
Solution
While applying arb chain specifics in
convert_block
, we use theself.best_number()
to setheader.number
. This is wrong as best_number keeps increasing as the chain progresses.Hence, RPC call such as
eth_getBlockByNumber
would return the incorrect number field.Note that now
header.number
andl1BlockNumber
in case of Arbitrum will be the same.