diff --git a/core/rawdb/ancient_scheme.go b/core/rawdb/ancient_scheme.go index 1563d11e98..f042ffeefe 100644 --- a/core/rawdb/ancient_scheme.go +++ b/core/rawdb/ancient_scheme.go @@ -48,7 +48,7 @@ var chainFreezerTableConfigs = map[string]freezerTableConfig{ type freezerTableConfig struct { noSnappy bool // disables item compression - prunable bool // true for tables that can be truncated by TruncateTailBlocks + prunable bool // true for tables that can be pruned by TruncateTail } const ( @@ -65,11 +65,11 @@ const ( // stateFreezerTableConfigs configures whether compression is disabled for the state freezer. var stateFreezerTableConfigs = map[string]freezerTableConfig{ - stateHistoryMeta: {noSnappy: true, prunable: false}, - stateHistoryAccountIndex: {noSnappy: false, prunable: false}, - stateHistoryStorageIndex: {noSnappy: false, prunable: false}, - stateHistoryAccountData: {noSnappy: false, prunable: false}, - stateHistoryStorageData: {noSnappy: false, prunable: false}, + stateHistoryMeta: {noSnappy: true, prunable: true}, + stateHistoryAccountIndex: {noSnappy: false, prunable: true}, + stateHistoryStorageIndex: {noSnappy: false, prunable: true}, + stateHistoryAccountData: {noSnappy: false, prunable: true}, + stateHistoryStorageData: {noSnappy: false, prunable: true}, } // The list of identifiers of ancient stores. diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 4ea1e9d798..bc29347324 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -126,11 +126,6 @@ func (db *nofreezedb) TruncateTail(items uint64) (uint64, error) { return 0, errNotSupported } -// TruncateTailBlock returns an error as we don't have a backing chain freezer. -func (db *nofreezedb) TruncateTailBlocks(items uint64) (uint64, error) { - return 0, errNotSupported -} - // Sync returns an error as we don't have a backing chain freezer. func (db *nofreezedb) Sync() error { return errNotSupported diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index eceada1681..4862256c79 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -301,32 +301,9 @@ func (f *Freezer) TruncateHead(items uint64) (uint64, error) { return oitems, nil } -// TruncateTailBlocks discards all data below the provided threshold block number. -// This is intended to be used with the chain freezer. Unlike TruncateTail, it -// only truncates blocks and receipts, leaving the header table where it is. -func (f *Freezer) TruncateTailBlocks(tailBlock uint64) (uint64, error) { - if f.readonly { - return 0, errReadOnly - } - f.writeLock.Lock() - defer f.writeLock.Unlock() - - old := f.tail.Load() - if old >= tailBlock { - return old, nil - } - for _, table := range f.tables { - if table.config.prunable { - if err := table.truncateTail(tailBlock); err != nil { - return 0, err - } - } - } - f.tail.Store(tailBlock) - return old, nil -} - -// TruncateTail discards all data below the provided threshold number. +// TruncateTail discards all data below the provided threshold number +// Note this will only truncate 'prunable' tables. Block headers and canonical +// hashes cannot be truncated at this time. func (f *Freezer) TruncateTail(tail uint64) (uint64, error) { if f.readonly { return 0, errReadOnly @@ -339,8 +316,10 @@ func (f *Freezer) TruncateTail(tail uint64) (uint64, error) { return old, nil } for _, table := range f.tables { - if err := table.truncateTail(tail); err != nil { - return 0, err + if table.config.prunable { + if err := table.truncateTail(tail); err != nil { + return 0, err + } } } f.tail.Store(tail) diff --git a/core/rawdb/freezer_memory.go b/core/rawdb/freezer_memory.go index 0f94f5d459..4274546de5 100644 --- a/core/rawdb/freezer_memory.go +++ b/core/rawdb/freezer_memory.go @@ -370,33 +370,13 @@ func (f *MemoryFreezer) TruncateHead(items uint64) (uint64, error) { return old, nil } -// TruncateTail discards any recent data below the provided threshold number. +// TruncateTail discards all data below the provided threshold number. +// Note this will only truncate 'prunable' tables. Block headers and canonical +// hashes cannot be truncated at this time. func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) { f.lock.Lock() defer f.lock.Unlock() - if f.readonly { - return 0, errReadOnly - } - old := f.tail - if old >= tail { - return old, nil - } - for _, table := range f.tables { - if err := table.truncateTail(tail); err != nil { - return 0, err - } - } - f.tail = tail - return old, nil -} - -// TruncateTailBlocks discards all data below the provided block. -// Only truncates blocks and receipts. -func (f *MemoryFreezer) TruncateTailBlocks(tail uint64) (uint64, error) { - f.lock.Lock() - defer f.lock.Unlock() - if f.readonly { return 0, errReadOnly } diff --git a/core/rawdb/freezer_resettable.go b/core/rawdb/freezer_resettable.go index f550337bc0..2e64e6074c 100644 --- a/core/rawdb/freezer_resettable.go +++ b/core/rawdb/freezer_resettable.go @@ -194,15 +194,6 @@ func (f *resettableFreezer) TruncateTail(tail uint64) (uint64, error) { return f.freezer.TruncateTail(tail) } -// TruncateTailBlocks discards any recent data below the provided threshold number. -// It returns the previous value -func (f *resettableFreezer) TruncateTailBlocks(tail uint64) (uint64, error) { - f.lock.RLock() - defer f.lock.RUnlock() - - return f.freezer.TruncateTailBlocks(tail) -} - // Sync flushes all data tables to disk. func (f *resettableFreezer) Sync() error { f.lock.RLock() diff --git a/core/rawdb/table.go b/core/rawdb/table.go index 96452534c6..1a9060b636 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -107,12 +107,6 @@ func (t *table) TruncateTail(items uint64) (uint64, error) { return t.db.TruncateTail(items) } -// TruncateTailBlocks is a noop passthrough that just forwards the request to the underlying -// database. -func (t *table) TruncateTailBlocks(items uint64) (uint64, error) { - return t.db.TruncateTailBlocks(items) -} - // Sync is a noop passthrough that just forwards the request to the underlying // database. func (t *table) Sync() error { diff --git a/ethdb/database.go b/ethdb/database.go index 8c6f68ddbb..2b0fe9c307 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -128,13 +128,11 @@ type AncientWriter interface { // is item_n(start from 0). The deleted items may not be removed from the ancient store // immediately, but only when the accumulated deleted data reach the threshold then // will be removed all together. + // + // Note this will only truncate 'prunable' tables. Block headers and canonical + // hashes cannot be truncated at this time. TruncateTail(n uint64) (uint64, error) - // TruncateTailBlocks discards all blocks and receipts below the given number from the - // ancient store. Headers are left as-is. This is intended to be used with the chain - // freezer specifically. - TruncateTailBlocks(tailBlock uint64) (uint64, error) - // Sync flushes all in-memory ancient store data to disk. Sync() error } diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go index 5734fda500..247a4392db 100644 --- a/ethdb/remotedb/remotedb.go +++ b/ethdb/remotedb/remotedb.go @@ -110,10 +110,6 @@ func (db *Database) TruncateTail(n uint64) (uint64, error) { panic("not supported") } -func (db *Database) TruncateTailBlocks(n uint64) (uint64, error) { - panic("not supported") -} - func (db *Database) Sync() error { return nil }