-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(eth): tighten block range handling for filter APIs #13561
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package gateway | ||
|
|
||
| // Block tag resolution utilities for gateway-level range checking. | ||
| // | ||
| // The "finalized" tag is not resolved here because its true height depends on | ||
| // F3 consensus and/or the EC probability calculator, which cannot be determined | ||
| // from head height alone. A static estimate like head-ChainFinality would | ||
| // undercount the range when "finalized" is a toBlock (actual finalized height | ||
| // is typically much closer to head). If trace_filter gains "finalized" support, | ||
| // the gateway will need to query the node for the real finalized height to | ||
| // perform accurate range checks. | ||
|
|
||
| import ( | ||
| "github.com/filecoin-project/go-state-types/abi" | ||
|
|
||
| "github.com/filecoin-project/lotus/api" | ||
| "github.com/filecoin-project/lotus/chain/types/ethtypes" | ||
| ) | ||
|
|
||
| // checkEthTraceFilterBlockRange checks whether the block range in the given | ||
| // trace filter criteria exceeds the gateway's configured maximum. | ||
| func (gw *Node) checkEthTraceFilterBlockRange(headHeight abi.ChainEpoch, filter ethtypes.EthTraceFilterCriteria) error { | ||
| if gw.ethTraceFilterMaxBlockRange <= 0 { | ||
| return nil | ||
| } | ||
| fromBlk := ethtypes.BlockTagLatest | ||
| if filter.FromBlock != nil { | ||
| fromBlk = *filter.FromBlock | ||
| } | ||
| toBlk := ethtypes.BlockTagLatest | ||
| if filter.ToBlock != nil { | ||
| toBlk = *filter.ToBlock | ||
| } | ||
| // Default for omitted fromBlock/toBlock is "latest", matching trace_filter | ||
| // and eth_getLogs semantics (OpenEthereum/Erigon trace_filter spec). | ||
| from, fromOk := resolveTraceFilterBlockTag(fromBlk, headHeight) | ||
| to, toOk := resolveTraceFilterBlockTag(toBlk, headHeight) | ||
| // If either tag couldn't be resolved (e.g. "finalized"), skip the range | ||
| // check and let the node handle validation. If from >= to the node's | ||
| // iteration is a no-op. | ||
| maxRange := uint64(gw.ethTraceFilterMaxBlockRange) | ||
| if fromOk && toOk && to > from && uint64(to-from) > maxRange { | ||
|
rjan90 marked this conversation as resolved.
|
||
| return api.NewErrBlockRangeExceeded(maxRange, uint64(to-from)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // resolveTraceFilterBlockTag resolves the block tags supported by trace_filter | ||
| // to a numeric height. Returns (0, false) for unsupported or unparseable tags. | ||
| func resolveTraceFilterBlockTag(tag string, headHeight abi.ChainEpoch) (ethtypes.EthUint64, bool) { | ||
| switch tag { | ||
| case ethtypes.BlockTagPending: | ||
| return ethtypes.EthUint64(headHeight), true | ||
| case ethtypes.BlockTagLatest: | ||
| if headHeight > 0 { | ||
| return ethtypes.EthUint64(headHeight - 1), true | ||
| } | ||
| return 0, true | ||
| case ethtypes.BlockTagSafe: | ||
| // Matches trace.go's getEthBlockNumberFromString which uses (head-1)-SafeEpochDelay. | ||
| // Note: the authoritative TipSetResolver uses head-SafeEpochDelay (no -1); if this | ||
| // function is reused beyond trace_filter, revisit this. | ||
| if headHeight > ethtypes.SafeEpochDelay+1 { | ||
| return ethtypes.EthUint64(headHeight - 1 - ethtypes.SafeEpochDelay), true | ||
| } | ||
| return 0, true | ||
| default: | ||
| var num ethtypes.EthUint64 | ||
| if err := num.UnmarshalJSON([]byte(`"` + tag + `"`)); err != nil { | ||
| return 0, false | ||
| } | ||
| return num, true | ||
|
rvagg marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.