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

Finalized always return block 0 #7245

Closed
2 tasks done
kamiyaa opened this issue Feb 27, 2024 · 7 comments
Closed
2 tasks done

Finalized always return block 0 #7245

kamiyaa opened this issue Feb 27, 2024 · 7 comments
Labels
good first issue Good for newcomers T-bug Type: bug

Comments

@kamiyaa
Copy link

kamiyaa commented Feb 27, 2024

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (4f00ec6 2024-02-17T00:16:39.754919679Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

JSON RPC call to get_block(BlockNumber::Finalized) always returns the 0th block for some reason.

@kamiyaa kamiyaa added the T-bug Type: bug label Feb 27, 2024
@mattsse
Copy link
Member

mattsse commented Feb 27, 2024

how should we handle these tags, use the latest or do a mod 32 on the chain height?

@sveitser
Copy link

sveitser commented Mar 5, 2024

We've also ran into this. I think for us both would but fine, but if it's not too cumbersome: how about mod N with N being a parameter passed to Anvil at startup?

@mattsse
Copy link
Member

mattsse commented Mar 5, 2024

I think we should do:

  • configure an epoch number, default 32 blocks
  • make it configurable via CLI

@mattsse mattsse added the good first issue Good for newcomers label Mar 5, 2024
@mattsse
Copy link
Member

mattsse commented Mar 6, 2024

@yash-atreya adding this to anvil cli args would be simple

turns out we already do a mod 32:

BlockNumber::Safe => {
if storage.best_number > (slots_in_an_epoch) {
*storage.hashes.get(&(storage.best_number - (slots_in_an_epoch)))?
} else {
storage.genesis_hash // treat the genesis block as safe "by definition"
}
}
BlockNumber::Finalized => {
if storage.best_number > (slots_in_an_epoch * U64::from(2)) {
*storage
.hashes
.get(&(storage.best_number - (slots_in_an_epoch * U64::from(2))))?
} else {
storage.genesis_hash
}
}

but we can move the constant into a field and add a simple test for this:
manuyll mine a bunch of blocks, the request via Safe/Finalized tags

@yash-atreya
Copy link
Member

@mattsse Thanks for the tag. I'll look into it.

@kamiyaa
Copy link
Author

kamiyaa commented Mar 6, 2024

Kind of related, but the reason this was an issue for us is because
in solidity (running in anvil), blockHash of block 0 is 0x0
but getting the block through RPC provider returns the correct blockHash
and this causes a discrepancy in our tests specifically for block 0.
If this wasn't the case, we would be okay with finalized returning 0.

@mattsse
Copy link
Member

mattsse commented Mar 6, 2024

ah I think I know what this is, will check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

5 participants