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

feat: Include missing block id in error responses #7416

Merged
merged 38 commits into from
Sep 7, 2024

Conversation

ryanschneider
Copy link
Contributor

@ryanschneider ryanschneider commented Apr 1, 2024

Fixes #7368 which explicitly mentions eth_call, but also updates:

  • eth_call
  • eth_getStorageAt
  • eth_getProof (see below)
  • eth_getTransactionCount
  • eth_getCode
  • eth_getBalance
  • eth_createAccessList
  • debug_traceCall
  • trace_rawTransaction
  • trace_callMany
  • trace_call

In each case, the error response is of the form:

{"jsonrpc":"2.0","error":{"code":-32001,"message":"unknown block id: number 0x230d842afd1face"},"id":"test"}

or

{"jsonrpc":"2.0","error":{"code":-32001,"message":"unknown block id: hash 0x230d842afd1faceaa3c5c0dacd24228747565c441ed5e1e3a9306c2c6b55d619"},"id":"test"}

Testing performed for the above w/ cast and curl here: https://gist.github.com/ryanschneider/20e8f78e46666d8249d266abec118f6a

For eth_getProof I opted not to interfere with the current situation where only block_id's that resolve to "latest" are supported.

I'm 100% open to hearing about better ways to implement this, one thing I don't like is that EthApiError::UnknownBlockNumber responses can still get through, if there's a good way to leverage Rust types to prevent that I'm all ears.

@ryanschneider ryanschneider force-pushed the fix-7368-error-response branch 3 times, most recently from a2ecd95 to e8a3335 Compare April 1, 2024 23:27
@ryanschneider ryanschneider marked this pull request as ready for review April 1, 2024 23:41
@onbjerg onbjerg added C-debt Refactor of code section that is hard to understand or maintain A-rpc Related to the RPC implementation labels Apr 2, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great, ty!

one pedantic style nit

do we always want to include the unknown block id prefix?
I don't think this matches geth?

Comment on lines 236 to 237
ProviderError::HeaderNotFound(_) => EthApiError::UnknownBlockId(at),
ProviderError::BlockHashNotFound(_) => EthApiError::UnknownBlockId(at),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: these can be combined into one arm: ProviderError::HeaderNotFound(_) | ProviderError::BlockHashNotFound(_)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @mattsse, fixed in 3a91c22, also rebased off latest main and retested locally.

@ryanschneider
Copy link
Contributor Author

do we always want to include the unknown block id prefix?
I don't think this matches geth?

Personally I'm not convinced we should try to sync up exact error messages, just codes (and as you pointed out EIP-1474 clearly shows we should return -32001), and try to provide the same semantic value the messages, but I can definitely be convinced otherwise.

@ryanschneider
Copy link
Contributor Author

Actually geth returns:

{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"header not found"}}
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"header for hash not found"}}

I suppose we could make the error message "header not found: {block_id}" e.g. "header not found: number 0x230d842afd1face", for substring-matching compatibility but that feels wrong to me.

@mattsse
Copy link
Collaborator

mattsse commented Apr 8, 2024

hmm, yeah rpc error inconsistencies are very annoying,
I'm not sure what to do here, but I'd lean towards just matching geth's error messages, or make it possible to match substrings.

I think we should mimic geth's messages but can include the number or hash

@onbjerg
Copy link
Member

onbjerg commented Apr 24, 2024

Hey @ryanschneider, any blocker here? Let me know so we can get this merged 😄

@ryanschneider
Copy link
Contributor Author

Sorry @onbjerg I've been away for a bit but am hoping to get back to this soon, however in rebasing off main I saw #8045 which definitely complicates this PR, seems like changing the error response might break. The comment in main mentions ethereum-optimism/optimism#10071 but that PR was closed w/ a mention of the issue being fixed in another PR, but I've lost the thread after that.

@mattsse I think we settled on the error text being:

header not found: number 0x131088f or header for hash not found: hash 0x3d9046bfd79e0d10404c01cf236a09806400233a8ca4761aba4c61cb3d888c11 is that still your opinion?

@gakonst gakonst requested a review from emhane as a code owner July 30, 2024 00:45
@emhane
Copy link
Member

emhane commented Jul 30, 2024

header not found: number 0x131088f or header for hash not found: hash 0x3d9046bfd79e0d10404c01cf236a09806400233a8ca4761aba4c61cb3d888c11 is that still your opinion?

latter can be simplified: header not found: hash <hash>

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, would you like help fixing merge conflicts?

@mattsse
Copy link
Collaborator

mattsse commented Jul 30, 2024

oh yeah, sorry we let this go stale...

we still want this, please take over @emhane

@emhane
Copy link
Member

emhane commented Aug 3, 2024

do we always want to include the unknown block id prefix?
I don't think this matches geth?

Personally I'm not convinced we should try to sync up exact error messages, just codes (and as you pointed out EIP-1474 clearly shows we should return -32001), and try to provide the same semantic value the messages, but I can definitely be convinced otherwise.

seems like a bug in geth or alloy then? Resource not found is correct here, not invalid input

https://github.com/alloy-rs/alloy/blob/3bf3618b111df609bafedbd648664e2d82122c47/crates/rpc-types-eth/src/error.rs#L27-L28

@emhane
Copy link
Member

emhane commented Aug 3, 2024

re-request review @mattsse @onbjerg

@emhane
Copy link
Member

emhane commented Aug 31, 2024

finally fixed all conflicts here!

re-request review also @mattsse

onbjerg
onbjerg previously requested changes Sep 2, 2024
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall lgtm but please remove the unrelated changes

crates/rpc/rpc-types-compat/src/block.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few nits, and I want to see full error messages in tests, otherwise it is now non trivial to reason about what we're actually returning as the error.

@@ -24,7 +24,7 @@ pub trait Otterscan {

/// Check if a certain address contains a deployed code.
#[method(name = "hasCode")]
async fn has_code(&self, address: Address, block_number: Option<u64>) -> RpcResult<bool>;
async fn has_code(&self, address: Address, block_id: Option<BlockId>) -> RpcResult<bool>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect, this makes it incompatible with the otterscan API this must be u64 not hex

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay this is actually no longer the case, so BlockId is correct now

https://otterscan.github.io/execution-apis/api-documentation/

crates/rpc/rpc-server-types/src/result.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-server-types/src/result.rs Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/block.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
Comment on lines -43 to -49
/// Thrown when querying for `finalized` or `safe` block before the merge transition is
/// finalized, <https://github.com/ethereum/execution-apis/blob/6d17705a875e52c26826124c2a8a15ed542aeca2/src/schemas/block.yaml#L109>
///
/// op-node now checks for either `Unknown block` OR `unknown block`:
/// <https://github.com/ethereum-optimism/optimism/blob/3b374c292e2b05cc51b52212ba68dd88ffce2a3b/op-service/sources/l2_client.go#L105>
///
/// TODO(#8045): Temporary, until a version of <https://github.com/ethereum-optimism/optimism/pull/10071> is pushed through that doesn't require this to figure out the EL sync status.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're changing the error now, does this affect op logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input pls @joshie as author of ethereum-optimism/optimism#10071

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emhane emhane added the S-blocked This cannot more forward until something else changes label Sep 5, 2024
@emhane
Copy link
Member

emhane commented Sep 5, 2024

blocked by ethereum-optimism/optimism#11759

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tysm @emhane 🙏

I think we shouldn't block on the op pr

@@ -24,7 +24,7 @@ pub trait Otterscan {

/// Check if a certain address contains a deployed code.
#[method(name = "hasCode")]
async fn has_code(&self, address: Address, block_number: Option<u64>) -> RpcResult<bool>;
async fn has_code(&self, address: Address, block_id: Option<BlockId>) -> RpcResult<bool>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay this is actually no longer the case, so BlockId is correct now

https://otterscan.github.io/execution-apis/api-documentation/

@ryanschneider
Copy link
Contributor Author

Yup thanks @emhane for getting this over the finish line!

@emhane emhane added this pull request to the merge queue Sep 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 6, 2024
@mattsse mattsse added this pull request to the merge queue Sep 7, 2024
Merged via the queue into paradigmxyz:main with commit 7a20b41 Sep 7, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior S-blocked This cannot more forward until something else changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eth_call targeting an unknown block hash returns "unknown block number"
5 participants