pallet-revive: implement the eth_newFilter polling filter API#12685
Open
soloking1412 wants to merge 2 commits into
Open
pallet-revive: implement the eth_newFilter polling filter API#12685soloking1412 wants to merge 2 commits into
soloking1412 wants to merge 2 commits into
Conversation
Contributor
Author
|
/cmd label T7-smart_contracts |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements the standard Ethereum polling filter API for
pallet-revive's eth-rpc server:eth_newFiltereth_newBlockFiltereth_getFilterChangeseth_getFilterLogseth_uninstallFilterUntil now the server only offered
eth_subscribe(a WebSocket push API) for watchinglogs and new blocks. The HTTP polling filter family — its counterpart, used by clients
that cannot hold a WebSocket open (many indexers, serverless functions, and the default
transports of several Ethereum client libraries) — was unimplemented, so that tooling
could not watch the chain.
Behaviour (matches go-ethereum)
eth_newFilter(filter)installs a log filter (address / topics / range) and returns an id.eth_newBlockFilter()installs a filter reporting the hashes of blocks added after install.eth_getFilterChanges(id)returns the logs (log filter) or block hashes (block filter)seen since the previous poll, advancing the filter's cursor.
eth_getFilterLogs(id)returns all logs matching a log filter over its full range.eth_uninstallFilter(id)removes a filter, returning whether it existed.An unknown or expired id returns
-32000 "filter not found", as in go-ethereum.Design
Filters are pull-based rather than backed by a live stream. A new
FilterManager(
src/filters.rs) keeps, per filter, only the next block to report from;eth_getFilterChangescomputes the delta on demand by reusing the existing
eth_getLogsrange query (log filters)or resolving block hashes (block filters), then advances the cursor. The registry lock is
never held across an
.await.Two deliberate hardening choices:
does not own (same rationale as go-ethereum's random ids).
can retain (mirrors go-ethereum's filter deadline).
eth_newPendingTransactionFilteris intentionally out of scope: the server does not expose apending-transaction pool (the same reason
eth_subscribehas nonewPendingTransactionskind).Testing
FilterManagerregistry (install / poll / advance / uninstall / expiry,unique ids).
test_filter_lifecycleintegration test (in the node-backedrun_all_eth_rpc_testssuite) that deploys a log-emitting contract and exerciseseth_newFilter→eth_getFilterChanges→eth_getFilterLogs, the empty second poll,eth_uninstallFilter(including the "filter not found" error afterwards), and a block filter.cargo fmt,cargo clippy --all-targets, and the unit tests are clean; the integration testruns in CI like the rest of this crate's suite.
Part of the RFC-0172 effort to make
pallet-revive's RPC conform toexecution-apis/ go-ethereum.