From aeb010799437efb4845e9be488263067522af2ca Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Aug 2025 08:18:47 +0800 Subject: [PATCH 1/3] fix: cleanup unused cancel function in filter --- CHANGELOG.md | 1 + rpc/namespaces/ethereum/eth/filters/api.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f099f6f93..f0a4da70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - [\#376](https://github.com/cosmos/evm/pull/376) Fix precompile initialization for local node development script - [\#384](https://github.com/cosmos/evm/pull/384) Fix debug_traceTransaction RPC failing with block height mismatch errors - [\#441](https://github.com/cosmos/evm/pull/441) Align precompiles map with available static check to Prague. +- [\#](https://github.com/cosmos/evm/pull/) Cleanup unused cancel function in filter. ### IMPROVEMENTS diff --git a/rpc/namespaces/ethereum/eth/filters/api.go b/rpc/namespaces/ethereum/eth/filters/api.go index d902ec400..baab8532e 100644 --- a/rpc/namespaces/ethereum/eth/filters/api.go +++ b/rpc/namespaces/ethereum/eth/filters/api.go @@ -65,7 +65,6 @@ type filter struct { typ filters.Type deadline *time.Timer // filter is inactive when deadline triggers crit filters.FilterCriteria - cancel context.CancelFunc offset int // offset for stream subscription } @@ -128,7 +127,6 @@ func (api *PublicFilterAPI) timeoutLoop() { for id, f := range api.filters { select { case <-f.deadline.C: - f.cancel() delete(api.filters, id) default: continue From 5680a7f2efc3cb95cea117b13d2f0fd74c4d1847 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Aug 2025 08:19:51 +0800 Subject: [PATCH 2/3] doc --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a4da70a..c9ec4dcae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - [\#376](https://github.com/cosmos/evm/pull/376) Fix precompile initialization for local node development script - [\#384](https://github.com/cosmos/evm/pull/384) Fix debug_traceTransaction RPC failing with block height mismatch errors - [\#441](https://github.com/cosmos/evm/pull/441) Align precompiles map with available static check to Prague. -- [\#](https://github.com/cosmos/evm/pull/) Cleanup unused cancel function in filter. +- [\#452](https://github.com/cosmos/evm/pull/452) Cleanup unused cancel function in filter. ### IMPROVEMENTS From 8a2b7c3b315cc66ad2ec40f8715efde0fcfcd4dd Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Aug 2025 09:12:46 +0800 Subject: [PATCH 3/3] test --- .../ethereum/eth/filters/api_test.go | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 rpc/namespaces/ethereum/eth/filters/api_test.go diff --git a/rpc/namespaces/ethereum/eth/filters/api_test.go b/rpc/namespaces/ethereum/eth/filters/api_test.go new file mode 100644 index 000000000..be15dc763 --- /dev/null +++ b/rpc/namespaces/ethereum/eth/filters/api_test.go @@ -0,0 +1,40 @@ +package filters + +import ( + "sync" + "testing" + "time" + + "github.com/ethereum/go-ethereum/eth/filters" + "github.com/ethereum/go-ethereum/rpc" + "github.com/stretchr/testify/require" +) + +func TestTimeoutLoop_PanicOnNilCancel(t *testing.T) { + api := &PublicFilterAPI{ + filters: make(map[rpc.ID]*filter), + filtersMu: sync.Mutex{}, + deadline: 10 * time.Millisecond, + } + api.filters[rpc.NewID()] = &filter{ + typ: filters.BlocksSubscription, + deadline: time.NewTimer(0), + } + done := make(chan struct{}) + go func() { + defer func() { + if r := recover(); r == nil { + t.Errorf("cancel panic") + } + close(done) + }() + api.timeoutLoop() + }() + panicked := false + select { + case <-done: + panicked = true + case <-time.After(100 * time.Millisecond): + } + require.False(t, panicked) +}