-
Notifications
You must be signed in to change notification settings - Fork 886
fix(giga): fail-fast broadcast_tx_commit and feed newBlockFilter from the notifier #4012
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
Open
shemnon
wants to merge
3
commits into
main
Choose a base branch
from
shemnon/remove-dash-b-block-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+628
−121
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package evmrpc | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types" | ||
| abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types" | ||
| tmproto "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/types" | ||
| ) | ||
|
|
||
| func newTestFilterAPI(t *testing.T, notifier *BlockHeaderNotifier) *FilterAPI { | ||
| t.Helper() | ||
| // Setup: FilterAPI with unused log/store deps; only the notifier path is exercised. | ||
| api := NewFilterAPI( | ||
| nil, | ||
| nil, | ||
| func(int64) sdk.Context { return sdk.Context{} }, | ||
| nil, | ||
| &FilterConfig{timeout: time.Hour, maxLog: 1, maxLogBytes: 1, maxBlock: 1}, | ||
| ConnectionTypeHTTP, | ||
| "eth", | ||
| make(chan struct{}, 1), | ||
| NewBlockCache(1), | ||
| &sync.Mutex{}, | ||
| NewLogSlicePool(), | ||
| nil, | ||
| notifier, | ||
| ) | ||
| t.Cleanup(api.shutdown) | ||
| return api | ||
| } | ||
|
|
||
| func TestFilterAPI_NewBlockFilterUsesNotifierHash(t *testing.T) { | ||
| // Setup: FilterAPI subscribed to a private notifier. | ||
| n := NewBlockHeaderNotifier(4) | ||
| api := newTestFilterAPI(t, n) | ||
| ctx := context.Background() | ||
|
|
||
| // Setup: create a block filter before any commits. | ||
| id, err := api.NewBlockFilter(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Test: poll before any commit. | ||
| empty, err := api.GetFilterChanges(ctx, id) | ||
| // Verify: empty slice, not nil. | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{}, empty) | ||
|
|
||
| // Test: publish one Autobahn hash, then poll twice. | ||
| hash := common.HexToHash("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | ||
| n.OnBlockCommitted(hash.Bytes(), &tmproto.Header{Height: 9}, &abci.ResponseFinalizeBlock{}) | ||
|
|
||
| got, err := api.GetFilterChanges(ctx, id) | ||
| // Verify: first poll returns that hash. | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{hash}, got) | ||
|
|
||
| again, err := api.GetFilterChanges(ctx, id) | ||
| // Verify: second poll is drained. | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{}, again) | ||
| } | ||
|
|
||
| func TestFilterAPI_NewBlockFilterAccumulatesUntilPoll(t *testing.T) { | ||
| // Setup: FilterAPI with one live block filter. | ||
| n := NewBlockHeaderNotifier(4) | ||
| api := newTestFilterAPI(t, n) | ||
| ctx := context.Background() | ||
| id, err := api.NewBlockFilter(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Test: commit two blocks before the client polls. | ||
| first := common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111") | ||
| second := common.HexToHash("0x2222222222222222222222222222222222222222222222222222222222222222") | ||
| n.OnBlockCommitted(first.Bytes(), &tmproto.Header{Height: 1}, &abci.ResponseFinalizeBlock{}) | ||
| n.OnBlockCommitted(second.Bytes(), &tmproto.Header{Height: 2}, &abci.ResponseFinalizeBlock{}) | ||
|
|
||
| // Verify: one poll returns both hashes in order. | ||
| got, err := api.GetFilterChanges(ctx, id) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{first, second}, got) | ||
| } | ||
|
|
||
| func TestFilterAPI_NewBlockFilterFanOutToEachFilter(t *testing.T) { | ||
| // Setup: two live block filters on the same notifier. | ||
| n := NewBlockHeaderNotifier(4) | ||
| api := newTestFilterAPI(t, n) | ||
| ctx := context.Background() | ||
| idA, err := api.NewBlockFilter(ctx) | ||
| require.NoError(t, err) | ||
| idB, err := api.NewBlockFilter(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Test: publish one hash. | ||
| hash := common.HexToHash("0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") | ||
| n.OnBlockCommitted(hash.Bytes(), &tmproto.Header{Height: 3}, &abci.ResponseFinalizeBlock{}) | ||
|
|
||
| // Verify: each filter independently returns that hash. | ||
| gotA, err := api.GetFilterChanges(ctx, idA) | ||
| require.NoError(t, err) | ||
| gotB, err := api.GetFilterChanges(ctx, idB) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{hash}, gotA) | ||
| require.Equal(t, []common.Hash{hash}, gotB) | ||
| } | ||
|
|
||
| func TestFilterAPI_NewBlockFilterIgnoresBlocksBeforeCreate(t *testing.T) { | ||
| // Setup: FilterAPI with a commit that happens before the filter exists. | ||
| n := NewBlockHeaderNotifier(4) | ||
| api := newTestFilterAPI(t, n) | ||
| ctx := context.Background() | ||
| before := common.HexToHash("0x0101010101010101010101010101010101010101010101010101010101010101") | ||
| n.OnBlockCommitted(before.Bytes(), &tmproto.Header{Height: 1}, &abci.ResponseFinalizeBlock{}) | ||
|
|
||
| // Test: create the filter, then commit a later block. | ||
| id, err := api.NewBlockFilter(ctx) | ||
| require.NoError(t, err) | ||
| after := common.HexToHash("0x0202020202020202020202020202020202020202020202020202020202020202") | ||
| n.OnBlockCommitted(after.Bytes(), &tmproto.Header{Height: 2}, &abci.ResponseFinalizeBlock{}) | ||
|
|
||
| // Verify: only the post-create hash is returned. | ||
| got, err := api.GetFilterChanges(ctx, id) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []common.Hash{after}, got) | ||
| } |
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.
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.
[suggestion]
blockHashesgrows without bound and the growth happens on the consensus commit goroutine.appendBlockHashis reached fromApp.Commit→PublishStashed→publish, so every committed block does O(#filters) work while holdingfiltersMu(also taken bycleanupExpiredFilters,NewBlockFilter, and the log branch ofGetFilterChanges). Before this PR aBlocksSubscriptionheld only a cursor string and all the work was on the RPC goroutine.A block filter that is created and never polled accumulates one 32-byte hash per block until the 120s
FilterTimeout(evmrpc/config/config.go:331) expires it, andNewBlockFilteris unauthenticated with no cap on filter count and noglobalRPSLimitercheck. At Autobahn block rates that is a few tens of KB per idle filter, so it is amplification rather than an outright DoS — but it is new memory proportional to (block rate × filters) that nothing bounds.Capping the slice and dropping the oldest entries on overflow would match the overwrite-on-full philosophy the notifier already documents for
recv(), e.g. bound it bya.filterConfig.maxBlock.