go-ethereum/eth/filters
locoholy 5569759238 eth/filters: cap polling filter queues to prevent unbounded memory growth
Polling filters (eth_newFilter, eth_newBlockFilter,
eth_newPendingTransactionFilter) buffer incoming events between
GetFilterChanges calls. If a client polls infrequently the internal
slices (f.logs, f.hashes, f.txs) grow without bound, potentially
consuming hundreds of MB of RAM under high event traffic.

Add MaxPendingItems to Config (default 10 000). When a filter's queue
exceeds this limit the oldest items are dropped to make room for new
ones, keeping memory bounded at the cost of silently losing stale data.

The drop-oldest policy is appropriate here because:
- Events that exceed the cap are already "stale" relative to chain head
- Clients that care about every event should use eth_subscribe instead
  of polling (which is the recommended pattern)

Add a debug log line when items are dropped so operators can detect
clients that poll too infrequently in their logs.

Three new tests verify the cap behaviour for each filter type:
  TestPendingTxFilterQueueCap
  TestBlockFilterQueueCap
  TestLogFilterQueueCap
2026-02-24 11:59:40 +05:00
..
api.go eth/filters: cap polling filter queues to prevent unbounded memory growth 2026-02-24 11:59:40 +05:00
api_test.go eth/filters, cmd: add config of eth_getLogs address limit (#32327) 2025-09-19 00:53:40 +02:00
filter.go rpc: add a rpc.rangelimit flag (#33163) 2026-01-17 14:34:08 +01:00
filter_system.go eth/filters: cap polling filter queues to prevent unbounded memory growth 2026-02-24 11:59:40 +05:00
filter_system_test.go eth/filters: cap polling filter queues to prevent unbounded memory growth 2026-02-24 11:59:40 +05:00
filter_test.go rpc: add a rpc.rangelimit flag (#33163) 2026-01-17 14:34:08 +01:00