mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
use historyPruningCutoff method
This commit is contained in:
parent
440eb9ad90
commit
e4c649a3c3
8 changed files with 15 additions and 26 deletions
|
|
@ -442,10 +442,3 @@ func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscript
|
||||||
func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription {
|
func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription {
|
||||||
return bc.scope.Track(bc.blockProcFeed.Subscribe(ch))
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
|
||||||
}
|
}
|
||||||
var bn uint64
|
var bn uint64
|
||||||
if number == rpc.EarliestBlockNumber {
|
if number == rpc.EarliestBlockNumber {
|
||||||
bn = b.eth.blockchain.HistoryCutoff()
|
bn = b.eth.blockchain.HistoryPruningCutoff()
|
||||||
} else {
|
} else {
|
||||||
bn = uint64(number)
|
bn = uint64(number)
|
||||||
}
|
}
|
||||||
|
|
@ -151,9 +151,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
|
||||||
}
|
}
|
||||||
bn := uint64(number)
|
bn := uint64(number)
|
||||||
if number == rpc.EarliestBlockNumber {
|
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 nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetBlockByNumber(bn), nil
|
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 {
|
if number == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if *number < b.eth.blockchain.HistoryCutoff() {
|
if *number < b.eth.blockchain.HistoryPruningCutoff() {
|
||||||
return nil, &prunedHistoryError{}
|
return nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetBlock(hash, *number), nil
|
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 {
|
if blockNrOrHash.RequireCanonical && b.eth.blockchain.GetCanonicalHash(header.Number.Uint64()) != hash {
|
||||||
return nil, errors.New("hash is not currently canonical")
|
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{}
|
return nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
block := b.eth.blockchain.GetBlock(hash, header.Number.Uint64())
|
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")
|
return nil, nil, errors.New("invalid arguments; neither block nor hash specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) HistoryCutoff() uint64 {
|
func (b *EthAPIBackend) HistoryPruningCutoff() uint64 {
|
||||||
return b.eth.blockchain.HistoryCutoff()
|
return b.eth.blockchain.HistoryPruningCutoff()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
||||||
if begin > 0 && end > 0 && begin > end {
|
if begin > 0 && end > 0 && begin > end {
|
||||||
return nil, errInvalidBlockRange
|
return nil, errInvalidBlockRange
|
||||||
}
|
}
|
||||||
if begin < int64(api.events.backend.HistoryCutoff()) {
|
if begin < int64(api.events.backend.HistoryPruningCutoff()) {
|
||||||
return nil, &prunedHistoryError{}
|
return nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
// Construct the range filter
|
// Construct the range filter
|
||||||
|
|
@ -406,7 +406,7 @@ func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Lo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if header.Number.Uint64() < api.events.backend.HistoryCutoff() {
|
if header.Number.Uint64() < api.events.backend.HistoryPruningCutoff() {
|
||||||
return nil, &prunedHistoryError{}
|
return nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
// Block filter requested, construct a single-shot filter
|
// Block filter requested, construct a single-shot filter
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ type Backend interface {
|
||||||
|
|
||||||
CurrentHeader() *types.Header
|
CurrentHeader() *types.Header
|
||||||
ChainConfig() *params.ChainConfig
|
ChainConfig() *params.ChainConfig
|
||||||
HistoryCutoff() uint64
|
HistoryPruningCutoff() uint64
|
||||||
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
||||||
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
|
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
|
||||||
SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
|
SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
|
||||||
|
|
|
||||||
|
|
@ -181,15 +181,11 @@ func (b *testBackend) setPending(block *types.Block, receipts types.Receipts) {
|
||||||
b.pendingReceipts = receipts
|
b.pendingReceipts = receipts
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
func (b *testBackend) HistoryPruningCutoff() uint64 {
|
||||||
func newTestFilterSystem(db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) {
|
|
||||||
=======
|
|
||||||
func (b *testBackend) HistoryCutoff() uint64 {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestFilterSystem(t testing.TB, db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) {
|
func newTestFilterSystem(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)
|
|
||||||
backend := &testBackend{db: db}
|
backend := &testBackend{db: db}
|
||||||
sys := NewFilterSystem(backend, cfg)
|
sys := NewFilterSystem(backend, cfg)
|
||||||
return backend, sys
|
return backend, sys
|
||||||
|
|
|
||||||
|
|
@ -623,7 +623,7 @@ func (b testBackend) NewMatcherBackend() filtermaps.MatcherBackend {
|
||||||
panic("implement me")
|
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) {
|
func TestEstimateGas(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ type Backend interface {
|
||||||
|
|
||||||
ChainConfig() *params.ChainConfig
|
ChainConfig() *params.ChainConfig
|
||||||
Engine() consensus.Engine
|
Engine() consensus.Engine
|
||||||
HistoryCutoff() uint64
|
HistoryPruningCutoff() uint64
|
||||||
|
|
||||||
// This is copied from filters.Backend
|
// This is copied from filters.Backend
|
||||||
// eth/filters needs to be initialized from this backend type, so methods needed by
|
// eth/filters needs to be initialized from this backend type, so methods needed by
|
||||||
|
|
|
||||||
|
|
@ -403,4 +403,4 @@ func (b *backendMock) Engine() consensus.Engine { return nil }
|
||||||
|
|
||||||
func (b *backendMock) NewMatcherBackend() filtermaps.MatcherBackend { return nil }
|
func (b *backendMock) NewMatcherBackend() filtermaps.MatcherBackend { return nil }
|
||||||
|
|
||||||
func (b *backendMock) HistoryCutoff() uint64 { return 0 }
|
func (b *backendMock) HistoryPruningCutoff() uint64 { return 0 }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue