diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index a8e2524c2c..415a0f5442 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -442,10 +442,3 @@ func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscript func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription { return bc.scope.Track(bc.blockProcFeed.Subscribe(ch)) } - -// HistoryCutoff returns the tail of the block history. -func (bc *BlockChain) HistoryCutoff() uint64 { - // Only nofreezedb returns an error. - tail, _ := bc.db.Tail() - return tail -} diff --git a/eth/api_backend.go b/eth/api_backend.go index bce72aa806..a0a7068d0c 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -93,7 +93,7 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb } var bn uint64 if number == rpc.EarliestBlockNumber { - bn = b.eth.blockchain.HistoryCutoff() + bn = b.eth.blockchain.HistoryPruningCutoff() } else { bn = uint64(number) } @@ -151,9 +151,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe } bn := uint64(number) if number == rpc.EarliestBlockNumber { - bn = b.eth.blockchain.HistoryCutoff() + bn = b.eth.blockchain.HistoryPruningCutoff() } - if bn < b.eth.blockchain.HistoryCutoff() { + if bn < b.eth.blockchain.HistoryPruningCutoff() { return nil, &prunedHistoryError{} } return b.eth.blockchain.GetBlockByNumber(bn), nil @@ -164,7 +164,7 @@ func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*typ if number == nil { return nil, nil } - if *number < b.eth.blockchain.HistoryCutoff() { + if *number < b.eth.blockchain.HistoryPruningCutoff() { return nil, &prunedHistoryError{} } return b.eth.blockchain.GetBlock(hash, *number), nil @@ -193,7 +193,7 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r if blockNrOrHash.RequireCanonical && b.eth.blockchain.GetCanonicalHash(header.Number.Uint64()) != hash { return nil, errors.New("hash is not currently canonical") } - if header.Number.Uint64() < b.eth.blockchain.HistoryCutoff() { + if header.Number.Uint64() < b.eth.blockchain.HistoryPruningCutoff() { return nil, &prunedHistoryError{} } block := b.eth.blockchain.GetBlock(hash, header.Number.Uint64()) @@ -257,8 +257,8 @@ func (b *EthAPIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockN return nil, nil, errors.New("invalid arguments; neither block nor hash specified") } -func (b *EthAPIBackend) HistoryCutoff() uint64 { - return b.eth.blockchain.HistoryCutoff() +func (b *EthAPIBackend) HistoryPruningCutoff() uint64 { + return b.eth.blockchain.HistoryPruningCutoff() } func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { diff --git a/eth/filters/api.go b/eth/filters/api.go index 882b43511a..9558e36768 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -358,7 +358,7 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type if begin > 0 && end > 0 && begin > end { return nil, errInvalidBlockRange } - if begin < int64(api.events.backend.HistoryCutoff()) { + if begin < int64(api.events.backend.HistoryPruningCutoff()) { return nil, &prunedHistoryError{} } // Construct the range filter @@ -406,7 +406,7 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo if err != nil { return nil, err } - if header.Number.Uint64() < api.events.backend.HistoryCutoff() { + if header.Number.Uint64() < api.events.backend.HistoryPruningCutoff() { return nil, &prunedHistoryError{} } // Block filter requested, construct a single-shot filter diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index bf4f6559e0..9c2e45120b 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -64,7 +64,7 @@ type Backend interface { CurrentHeader() *types.Header ChainConfig() *params.ChainConfig - HistoryCutoff() uint64 + HistoryPruningCutoff() uint64 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 5670fb4a01..3bb019d105 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -181,15 +181,11 @@ func (b *testBackend) setPending(block *types.Block, receipts types.Receipts) { b.pendingReceipts = receipts } -<<<<<<< HEAD -func newTestFilterSystem(db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) { -======= -func (b *testBackend) HistoryCutoff() uint64 { +func (b *testBackend) HistoryPruningCutoff() uint64 { return 0 } -func newTestFilterSystem(t testing.TB, db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) { ->>>>>>> 7139f930b0 (return prunedHistoryError from GetLogs/FilterLogs if accessing pruned state. duplicate prunedHistoryError into eth/filters package. add HistoryCutoff method to eth backend) +func newTestFilterSystem(db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) { backend := &testBackend{db: db} sys := NewFilterSystem(backend, cfg) return backend, sys diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index eda19797ca..37210aa78b 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -623,7 +623,7 @@ func (b testBackend) NewMatcherBackend() filtermaps.MatcherBackend { panic("implement me") } -func (b testBackend) HistoryCutoff() uint64 { return b.chain.HistoryCutoff() } +func (b testBackend) HistoryPruningCutoff() uint64 { return b.chain.HistoryPruningCutoff() } func TestEstimateGas(t *testing.T) { t.Parallel() diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 31f0478c09..c4bf2e0591 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -85,7 +85,7 @@ type Backend interface { ChainConfig() *params.ChainConfig Engine() consensus.Engine - HistoryCutoff() uint64 + HistoryPruningCutoff() uint64 // This is copied from filters.Backend // eth/filters needs to be initialized from this backend type, so methods needed by diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 0c6901aa1e..b4d11a3033 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -403,4 +403,4 @@ func (b *backendMock) Engine() consensus.Engine { return nil } func (b *backendMock) NewMatcherBackend() filtermaps.MatcherBackend { return nil } -func (b *backendMock) HistoryCutoff() uint64 { return 0 } +func (b *backendMock) HistoryPruningCutoff() uint64 { return 0 }