diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-03-03 07:52:39 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-03-03 07:52:39 +0800 |
commit | ca64a122d33008c155c35a9d0e78cfbcafb1820a (patch) | |
tree | d82ca9f07ba8eadd116d08861e96c3283b1b76e4 /core | |
parent | 12f4d284114a719e9a0779933e8770c352ed1767 (diff) | |
download | dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar.gz dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar.bz2 dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar.lz dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar.xz dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.tar.zst dexon-ca64a122d33008c155c35a9d0e78cfbcafb1820a.zip |
eth/downloader: save and load trie sync progress (#16224)
Diffstat (limited to 'core')
-rw-r--r-- | core/database_util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/database_util.go b/core/database_util.go index 61ab70134..8c4698985 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -47,6 +47,7 @@ var ( headHeaderKey = []byte("LastHeader") headBlockKey = []byte("LastBlock") headFastKey = []byte("LastFast") + trieSyncKey = []byte("TrieSync") // Data item prefixes (use single byte to avoid mixing data types, avoid `i`). headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header @@ -146,6 +147,16 @@ func GetHeadFastBlockHash(db DatabaseReader) common.Hash { return common.BytesToHash(data) } +// GetTrieSyncProgress retrieves the number of tries nodes fast synced to allow +// reportinc correct numbers across restarts. +func GetTrieSyncProgress(db DatabaseReader) uint64 { + data, _ := db.Get(trieSyncKey) + if len(data) == 0 { + return 0 + } + return new(big.Int).SetBytes(data).Uint64() +} + // GetHeaderRLP retrieves a block header in its raw RLP database encoding, or nil // if the header's not found. func GetHeaderRLP(db DatabaseReader, hash common.Hash, number uint64) rlp.RawValue { @@ -374,6 +385,15 @@ func WriteHeadFastBlockHash(db ethdb.Putter, hash common.Hash) error { return nil } +// WriteTrieSyncProgress stores the fast sync trie process counter to support +// retrieving it across restarts. +func WriteTrieSyncProgress(db ethdb.Putter, count uint64) error { + if err := db.Put(trieSyncKey, new(big.Int).SetUint64(count).Bytes()); err != nil { + log.Crit("Failed to store fast sync trie progress", "err", err) + } + return nil +} + // WriteHeader serializes a block header into the database. func WriteHeader(db ethdb.Putter, header *types.Header) error { data, err := rlp.EncodeToBytes(header) |