From 64af16de4efc7449a043271b99a6f57ba1f544ea Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 18 Nov 2024 14:40:05 +0800 Subject: [PATCH] core, consensus, cmd/utils: bump the database version --- cmd/utils/cmd.go | 3 --- consensus/beacon/consensus.go | 4 ++-- core/blockchain.go | 5 ++++- core/rawdb/database.go | 5 +++-- core/rawdb/schema.go | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 0b75c92518..2891e66fbb 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -450,9 +450,6 @@ func ExportHistory(bc *core.BlockChain, dir string, first, last, step uint64) er return fmt.Errorf("export failed on #%d: receipts not found", n) } td.Add(td, block.Difficulty()) - if td == nil { - return fmt.Errorf("export failed on #%d: total difficulty not found", n) - } if err := w.Add(block, receipts, td); err != nil { return err } diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 4ceaa9a452..36b98ad95d 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -140,7 +140,7 @@ func errOut(n int, err error) chan error { // td are stored correctly in chain. If ttd is not configured yet, all headers // will be treated legacy PoW headers. // Note, this function will not verify the header validity but just split them. -func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) ([]*types.Header, []*types.Header, error) { +func (beacon *Beacon) splitHeaders(headers []*types.Header) ([]*types.Header, []*types.Header, error) { var ( preHeaders = headers postHeaders []*types.Header @@ -160,7 +160,7 @@ func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers [] // a results channel to retrieve the async verifications. // VerifyHeaders expect the headers to be ordered and continuous. func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) { - preHeaders, postHeaders, err := beacon.splitHeaders(chain, headers) + preHeaders, postHeaders, err := beacon.splitHeaders(headers) if err != nil { return make(chan struct{}), errOut(len(headers), err) } diff --git a/core/blockchain.go b/core/blockchain.go index b7738c6349..ab88f4b68e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -127,7 +127,10 @@ const ( // - Version 8 // The following incompatible database changes were added: // * New scheme for contract code in order to separate the codes and trie nodes - BlockChainVersion uint64 = 8 + // - Version 9 + // Total difficulty has been removed from both the key-value store and the + // ancient store, the td freezer table has been deprecated since that. + BlockChainVersion uint64 = 9 ) // CacheConfig contains the configuration values for the trie database diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 5eb2eaa2e8..2b9f5d08ed 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -363,7 +363,6 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { headers stat bodies stat receipts stat - tds stat numHashPairings stat hashNumPairings stat legacyTries stat @@ -408,6 +407,9 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { bodies.Add(size) case bytes.HasPrefix(key, blockReceiptsPrefix) && len(key) == (len(blockReceiptsPrefix)+8+common.HashLength): receipts.Add(size) + case bytes.HasPrefix(key, headerPrefix) && bytes.HasSuffix(key, headerTDSuffix): + // The TD has been removed, but we still count it here + // to avoid overusing the unknown data counter. case bytes.HasPrefix(key, headerPrefix) && bytes.HasSuffix(key, headerHashSuffix): numHashPairings.Add(size) case bytes.HasPrefix(key, headerNumberPrefix) && len(key) == (len(headerNumberPrefix)+common.HashLength): @@ -498,7 +500,6 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { {"Key-Value store", "Headers", headers.Size(), headers.Count()}, {"Key-Value store", "Bodies", bodies.Size(), bodies.Count()}, {"Key-Value store", "Receipt lists", receipts.Size(), receipts.Count()}, - {"Key-Value store", "Difficulties", tds.Size(), tds.Count()}, {"Key-Value store", "Block number->hash", numHashPairings.Size(), numHashPairings.Count()}, {"Key-Value store", "Block hash->number", hashNumPairings.Size(), hashNumPairings.Count()}, {"Key-Value store", "Transaction index", txLookups.Size(), txLookups.Count()}, diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index e5fde64994..3d5d757a86 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -98,6 +98,7 @@ var ( // Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes). headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header + headerTDSuffix = []byte("t") // headerPrefix + num (uint64 big endian) + hash + headerTDSuffix -> td (deprecated) headerHashSuffix = []byte("n") // headerPrefix + num (uint64 big endian) + headerHashSuffix -> hash headerNumberPrefix = []byte("H") // headerNumberPrefix + hash -> num (uint64 big endian)