From 06c70d32fa9fb8ae907add398acf04ce0fba083d Mon Sep 17 00:00:00 2001 From: maks Date: Sat, 21 Mar 2026 12:26:03 +0100 Subject: [PATCH] eth, eth/filters: allow queries to fall through to era files on pruned nodes Remove premature HistoryPruningCutoff checks that returned PrunedHistoryError before block-number-based queries could reach the era file fallback in the chain freezer. The chain freezer's Ancient() method already has logic to consult era files when data has been pruned from the main ancient store. This enables eth_getBlockByNumber, eth_getLogs, and other block-number-based RPC methods to serve historical data from era files when the corresponding blocks have been pruned from ancients. Fixes #33666 --- eth/api_backend.go | 19 ++----------------- eth/filters/api.go | 7 ------- eth/filters/filter.go | 4 ---- eth/filters/filter_system.go | 5 ----- 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index 726d8316a0..4c73bed45d 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -29,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/filtermaps" - "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/txpool" @@ -155,11 +154,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe if number == rpc.EarliestBlockNumber { bn = b.HistoryPruningCutoff() } - block := b.eth.blockchain.GetBlockByNumber(bn) - if block == nil && bn < b.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } - return block, nil + return b.eth.blockchain.GetBlockByNumber(bn), nil } func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { @@ -167,11 +162,7 @@ func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*typ if number == nil { return nil, nil } - block := b.eth.blockchain.GetBlock(hash, *number) - if block == nil && *number < b.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } - return block, nil + return b.eth.blockchain.GetBlock(hash, *number), nil } // GetBody returns body of a block. It does not resolve special block numbers. @@ -181,9 +172,6 @@ func (b *EthAPIBackend) GetBody(ctx context.Context, hash common.Hash, number rp } body := b.eth.blockchain.GetBody(hash) if body == nil { - if uint64(number) < b.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } return nil, errors.New("block body not found") } return body, nil @@ -205,9 +193,6 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r } block := b.eth.blockchain.GetBlock(hash, header.Number.Uint64()) if block == nil { - if header.Number.Uint64() < b.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } return nil, errors.New("header found, but block body is missing") } return block, nil diff --git a/eth/filters/api.go b/eth/filters/api.go index e4ade96598..96d27e908c 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/rpc" @@ -481,9 +480,6 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type if begin > 0 && end > 0 && begin > end { return nil, errInvalidBlockRange } - if begin >= 0 && begin < int64(api.events.backend.HistoryPruningCutoff()) { - return nil, &history.PrunedHistoryError{} - } // Construct the range filter filter = api.sys.NewRangeFilter(begin, end, crit.Addresses, crit.Topics, api.rangeLimit) } @@ -536,9 +532,6 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo if f.crit.ToBlock != nil { end = f.crit.ToBlock.Int64() } - if begin >= 0 && begin < int64(api.events.backend.HistoryPruningCutoff()) { - return nil, &history.PrunedHistoryError{} - } // Construct the range filter filter = api.sys.NewRangeFilter(begin, end, f.crit.Addresses, f.crit.Topics, api.rangeLimit) } diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 04e11f0475..d3b52b2721 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/filtermaps" - "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" @@ -91,9 +90,6 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) { if header == nil { return nil, errUnknownBlock } - if header.Number.Uint64() < f.sys.backend.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } return f.blockLogs(ctx, header) } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 1f92c4e36f..2b80b6f68b 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -30,7 +30,6 @@ import ( "github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/filtermaps" - "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -328,10 +327,6 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ if from == rpc.EarliestBlockNumber { from = rpc.BlockNumber(es.backend.HistoryPruningCutoff()) } - // Queries beyond the pruning cutoff are not supported. - if uint64(from) < es.backend.HistoryPruningCutoff() { - return nil, &history.PrunedHistoryError{} - } // only interested in new mined logs if from == rpc.LatestBlockNumber && to == rpc.LatestBlockNumber {