diff --git a/eth/api_backend.go b/eth/api_backend.go index a0a7068d0c..8e2af684d1 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -42,6 +42,12 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// ErrorPrunedHistory is returned when the requested history is pruned. +type ErrorPrunedHistory struct{} + +func (e *ErrorPrunedHistory) Error() string { return "Pruned history unavailable" } +func (e *ErrorPrunedHistory) ErrorCode() int { return 4444 } + // EthAPIBackend implements ethapi.Backend and tracers.Backend for full nodes type EthAPIBackend struct { extRPCEnabled bool @@ -154,7 +160,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe bn = b.eth.blockchain.HistoryPruningCutoff() } if bn < b.eth.blockchain.HistoryPruningCutoff() { - return nil, &prunedHistoryError{} + return nil, &ErrorPrunedHistory{} } return b.eth.blockchain.GetBlockByNumber(bn), nil } @@ -165,7 +171,7 @@ func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*typ return nil, nil } if *number < b.eth.blockchain.HistoryPruningCutoff() { - return nil, &prunedHistoryError{} + return nil, &ErrorPrunedHistory{} } return b.eth.blockchain.GetBlock(hash, *number), nil } @@ -194,7 +200,7 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r return nil, errors.New("hash is not currently canonical") } if header.Number.Uint64() < b.eth.blockchain.HistoryPruningCutoff() { - return nil, &prunedHistoryError{} + return nil, &ErrorPrunedHistory{} } block := b.eth.blockchain.GetBlock(hash, header.Number.Uint64()) if block == nil { @@ -448,8 +454,3 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*types.Transaction, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) { return b.eth.stateAtTransaction(ctx, block, txIndex, reexec) } - -type prunedHistoryError struct{} - -func (e *prunedHistoryError) Error() string { return "Pruned history unavailable" } -func (e *prunedHistoryError) ErrorCode() int { return 4444 } diff --git a/eth/filters/api.go b/eth/filters/api.go index 5c2efaba32..c2f700ace8 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/rpc" ) @@ -359,7 +360,7 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type return nil, errInvalidBlockRange } if begin > 0 && begin < int64(api.events.backend.HistoryPruningCutoff()) { - return nil, &prunedHistoryError{} + return nil, ð.ErrorPrunedHistory{} } // Construct the range filter filter = api.sys.NewRangeFilter(begin, end, crit.Addresses, crit.Topics) diff --git a/eth/filters/filter.go b/eth/filters/filter.go index e9bc6ac1a4..9cd885b127 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/filtermaps" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" ) @@ -87,7 +88,7 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) { return nil, errors.New("unknown block") } if header.Number.Uint64() < f.sys.backend.HistoryPruningCutoff() { - return nil, &prunedHistoryError{} + return nil, ð.ErrorPrunedHistory{} } return f.blockLogs(ctx, header) } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 42ffe69059..c8edec5351 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/filtermaps" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" @@ -140,11 +141,6 @@ func (sys *FilterSystem) cachedGetBody(ctx context.Context, elem *logCacheElem, return body, nil } -type prunedHistoryError struct{} - -func (e *prunedHistoryError) Error() string { return "Pruned history unavailable" } -func (e *prunedHistoryError) ErrorCode() int { return 4444 } - // Type determines the kind of filter and is used to put the filter in to // the correct bucket when added. type Type byte @@ -315,7 +311,7 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ } // Queries beyond the pruning cutoff are not supported. if uint64(from) < es.backend.HistoryPruningCutoff() { - return nil, &prunedHistoryError{} + return nil, ð.ErrorPrunedHistory{} } // only interested in new mined logs