core, consensus, cmd/utils: bump the database version

This commit is contained in:
Gary Rong 2024-11-18 14:40:05 +08:00
parent 27766d0a99
commit 64af16de4e
5 changed files with 10 additions and 8 deletions

View file

@ -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) return fmt.Errorf("export failed on #%d: receipts not found", n)
} }
td.Add(td, block.Difficulty()) 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 { if err := w.Add(block, receipts, td); err != nil {
return err return err
} }

View file

@ -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 // td are stored correctly in chain. If ttd is not configured yet, all headers
// will be treated legacy PoW headers. // will be treated legacy PoW headers.
// Note, this function will not verify the header validity but just split them. // 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 ( var (
preHeaders = headers preHeaders = headers
postHeaders []*types.Header postHeaders []*types.Header
@ -160,7 +160,7 @@ func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []
// a results channel to retrieve the async verifications. // a results channel to retrieve the async verifications.
// VerifyHeaders expect the headers to be ordered and continuous. // VerifyHeaders expect the headers to be ordered and continuous.
func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) { 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 { if err != nil {
return make(chan struct{}), errOut(len(headers), err) return make(chan struct{}), errOut(len(headers), err)
} }

View file

@ -127,7 +127,10 @@ const (
// - Version 8 // - Version 8
// The following incompatible database changes were added: // The following incompatible database changes were added:
// * New scheme for contract code in order to separate the codes and trie nodes // * 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 // CacheConfig contains the configuration values for the trie database

View file

@ -363,7 +363,6 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
headers stat headers stat
bodies stat bodies stat
receipts stat receipts stat
tds stat
numHashPairings stat numHashPairings stat
hashNumPairings stat hashNumPairings stat
legacyTries stat legacyTries stat
@ -408,6 +407,9 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
bodies.Add(size) bodies.Add(size)
case bytes.HasPrefix(key, blockReceiptsPrefix) && len(key) == (len(blockReceiptsPrefix)+8+common.HashLength): case bytes.HasPrefix(key, blockReceiptsPrefix) && len(key) == (len(blockReceiptsPrefix)+8+common.HashLength):
receipts.Add(size) 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): case bytes.HasPrefix(key, headerPrefix) && bytes.HasSuffix(key, headerHashSuffix):
numHashPairings.Add(size) numHashPairings.Add(size)
case bytes.HasPrefix(key, headerNumberPrefix) && len(key) == (len(headerNumberPrefix)+common.HashLength): 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", "Headers", headers.Size(), headers.Count()},
{"Key-Value store", "Bodies", bodies.Size(), bodies.Count()}, {"Key-Value store", "Bodies", bodies.Size(), bodies.Count()},
{"Key-Value store", "Receipt lists", receipts.Size(), receipts.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 number->hash", numHashPairings.Size(), numHashPairings.Count()},
{"Key-Value store", "Block hash->number", hashNumPairings.Size(), hashNumPairings.Count()}, {"Key-Value store", "Block hash->number", hashNumPairings.Size(), hashNumPairings.Count()},
{"Key-Value store", "Transaction index", txLookups.Size(), txLookups.Count()}, {"Key-Value store", "Transaction index", txLookups.Size(), txLookups.Count()},

View file

@ -98,6 +98,7 @@ var (
// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes). // 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 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 headerHashSuffix = []byte("n") // headerPrefix + num (uint64 big endian) + headerHashSuffix -> hash
headerNumberPrefix = []byte("H") // headerNumberPrefix + hash -> num (uint64 big endian) headerNumberPrefix = []byte("H") // headerNumberPrefix + hash -> num (uint64 big endian)