2018-05-07 14:35:06 +03:00
|
|
|
// Copyright 2018 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// Package rawdb contains a collection of low level database accessors.
|
|
|
|
package rawdb
|
|
|
|
|
|
|
|
import (
|
2020-08-21 20:10:40 +08:00
|
|
|
"bytes"
|
2018-05-07 14:35:06 +03:00
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2023-05-09 15:11:04 +08:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-05-07 14:35:06 +03:00
|
|
|
"github.com/ethereum/go-ethereum/metrics"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The fields below define the low level database schema prefixing.
|
|
|
|
var (
|
2020-12-11 15:56:00 +01:00
|
|
|
// databaseVersionKey tracks the current database version.
|
|
|
|
databaseVersionKey = []byte("DatabaseVersion")
|
2018-05-07 14:35:06 +03:00
|
|
|
|
2019-05-04 19:17:47 +09:00
|
|
|
// headHeaderKey tracks the latest known header's hash.
|
2018-05-07 14:35:06 +03:00
|
|
|
headHeaderKey = []byte("LastHeader")
|
|
|
|
|
2019-05-04 19:17:47 +09:00
|
|
|
// headBlockKey tracks the latest known full block's hash.
|
2018-05-07 14:35:06 +03:00
|
|
|
headBlockKey = []byte("LastBlock")
|
|
|
|
|
2018-11-09 18:51:07 +08:00
|
|
|
// headFastBlockKey tracks the latest known incomplete block's hash during fast sync.
|
2018-05-07 14:35:06 +03:00
|
|
|
headFastBlockKey = []byte("LastFast")
|
|
|
|
|
2023-08-01 20:17:32 +08:00
|
|
|
// persistentStateIDKey tracks the id of latest stored state(for path-based only).
|
|
|
|
persistentStateIDKey = []byte("LastStateID")
|
|
|
|
|
2020-08-20 13:01:24 +03:00
|
|
|
// lastPivotKey tracks the last pivot block used by fast sync (to reenable on sethead).
|
|
|
|
lastPivotKey = []byte("LastPivot")
|
|
|
|
|
2018-05-07 14:35:06 +03:00
|
|
|
// fastTrieProgressKey tracks the number of trie entries imported during fast sync.
|
|
|
|
fastTrieProgressKey = []byte("TrieSync")
|
|
|
|
|
2021-04-29 17:33:45 +03:00
|
|
|
// snapshotDisabledKey flags that the snapshot should not be maintained due to initial sync.
|
|
|
|
snapshotDisabledKey = []byte("SnapshotDisabled")
|
|
|
|
|
2021-11-02 18:31:45 +08:00
|
|
|
// SnapshotRootKey tracks the hash of the last snapshot.
|
|
|
|
SnapshotRootKey = []byte("SnapshotRoot")
|
2019-08-06 13:40:28 +03:00
|
|
|
|
2019-12-02 13:27:20 +02:00
|
|
|
// snapshotJournalKey tracks the in-memory diff layers across restarts.
|
|
|
|
snapshotJournalKey = []byte("SnapshotJournal")
|
|
|
|
|
2020-10-30 03:01:58 +08:00
|
|
|
// snapshotGeneratorKey tracks the snapshot generation marker across restarts.
|
|
|
|
snapshotGeneratorKey = []byte("SnapshotGenerator")
|
|
|
|
|
|
|
|
// snapshotRecoveryKey tracks the snapshot recovery marker across restarts.
|
|
|
|
snapshotRecoveryKey = []byte("SnapshotRecovery")
|
|
|
|
|
2020-12-14 11:27:15 +02:00
|
|
|
// snapshotSyncStatusKey tracks the snapshot sync status across restarts.
|
|
|
|
snapshotSyncStatusKey = []byte("SnapshotSyncStatus")
|
|
|
|
|
all: activate pbss as experimental feature from eth (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-11 03:21:36 +08:00
|
|
|
// skeletonSyncStatusKey tracks the skeleton sync status across restarts.
|
|
|
|
skeletonSyncStatusKey = []byte("SkeletonSyncStatus")
|
|
|
|
|
2023-08-01 20:17:32 +08:00
|
|
|
// trieJournalKey tracks the in-memory trie node layers across restarts.
|
|
|
|
trieJournalKey = []byte("TrieJournal")
|
|
|
|
|
2020-05-11 17:58:43 +02:00
|
|
|
// txIndexTailKey tracks the oldest block whose transactions have been indexed.
|
|
|
|
txIndexTailKey = []byte("TransactionIndexTail")
|
|
|
|
|
|
|
|
// fastTxLookupLimitKey tracks the transaction lookup limit during fast sync.
|
|
|
|
fastTxLookupLimitKey = []byte("FastTransactionLookupLimit")
|
|
|
|
|
2022-07-05 11:14:21 +08:00
|
|
|
//offSet of new updated ancientDB.
|
|
|
|
offSetOfCurrentAncientFreezer = []byte("offSetOfCurrentAncientFreezer")
|
|
|
|
|
|
|
|
//offSet of the ancientDB before updated version.
|
|
|
|
offSetOfLastAncientFreezer = []byte("offSetOfLastAncientFreezer")
|
|
|
|
|
|
|
|
//frozenOfAncientDBKey tracks the block number for ancientDB to save.
|
|
|
|
frozenOfAncientDBKey = []byte("FrozenOfAncientDB")
|
|
|
|
|
|
|
|
//LastSafePointBlockKey tracks the block number for block state that write disk
|
|
|
|
LastSafePointBlockKey = []byte("LastSafePointBlockNumber")
|
|
|
|
|
|
|
|
//PruneAncientFlag flag whether prune ancient
|
|
|
|
pruneAncientKey = []byte("PruneAncientFlag")
|
|
|
|
|
2021-01-10 19:54:15 +08:00
|
|
|
// badBlockKey tracks the list of bad blocks seen by local
|
|
|
|
badBlockKey = []byte("InvalidBlock")
|
|
|
|
|
|
|
|
// uncleanShutdownKey tracks the list of local crashes
|
|
|
|
uncleanShutdownKey = []byte("unclean-shutdown") // config prefix for the db
|
|
|
|
|
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition
* consensus/beacon, eth: change beacon difficulty to 0
* eth: updates
* all: add terminalBlockDifficulty config, fix rebasing issues
* eth: implemented merge interop spec
* internal/ethapi: update to v1.0.0.alpha.2
This commit updates the code to the new spec, moving payloadId into
it's own object. It also fixes an issue with finalizing an empty blockhash.
It also properly sets the basefee
* all: sync polishes, other fixes + refactors
* core, eth: correct semantics for LeavePoW, EnterPoS
* core: fixed rebasing artifacts
* core: light: performance improvements
* core: use keyed field (f)
* core: eth: fix compilation issues + tests
* eth/catalyst: dbetter error codes
* all: move Merger to consensus/, remove reliance on it in bc
* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS
* core: make mergelogs a function
* core: use InsertChain instead of InsertBlock
* les: drop merger from lightchain object
* consensus: add merger
* core: recoverAncestors in catalyst mode
* core: fix nitpick
* all: removed merger from beacon, use TTD, nitpicks
* consensus: eth: add docstring, removed unnecessary code duplication
* consensus/beacon: better comment
* all: easy to fix nitpicks by karalabe
* consensus/beacon: verify known headers to be sure
* core: comments
* core: eth: don't drop peers who advertise blocks, nitpicks
* core: never add beacon blocks to the future queue
* core: fixed nitpicks
* consensus/beacon: simplify IsTTDReached check
* consensus/beacon: correct IsTTDReached check
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 12:23:02 +01:00
|
|
|
// transitionStatusKey tracks the eth2 transition status.
|
|
|
|
transitionStatusKey = []byte("eth2-transition")
|
|
|
|
|
2018-05-07 14:35:06 +03:00
|
|
|
// 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
|
|
|
|
headerHashSuffix = []byte("n") // headerPrefix + num (uint64 big endian) + headerHashSuffix -> hash
|
|
|
|
headerNumberPrefix = []byte("H") // headerNumberPrefix + hash -> num (uint64 big endian)
|
|
|
|
|
|
|
|
blockBodyPrefix = []byte("b") // blockBodyPrefix + num (uint64 big endian) + hash -> block body
|
|
|
|
blockReceiptsPrefix = []byte("r") // blockReceiptsPrefix + num (uint64 big endian) + hash -> block receipts
|
|
|
|
|
2019-11-26 09:48:29 +02:00
|
|
|
txLookupPrefix = []byte("l") // txLookupPrefix + hash -> transaction/receipt lookup metadata
|
|
|
|
bloomBitsPrefix = []byte("B") // bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash -> bloom bits
|
|
|
|
SnapshotAccountPrefix = []byte("a") // SnapshotAccountPrefix + account hash -> account trie value
|
2020-03-06 13:05:44 +01:00
|
|
|
SnapshotStoragePrefix = []byte("o") // SnapshotStoragePrefix + account hash + storage hash -> storage trie value
|
all: bloom-filter based pruning mechanism (#21724)
* cmd, core, tests: initial state pruner
core: fix db inspector
cmd/geth: add verify-state
cmd/geth: add verification tool
core/rawdb: implement flatdb
cmd, core: fix rebase
core/state: use new contract code layout
core/state/pruner: avoid deleting genesis state
cmd/geth: add helper function
core, cmd: fix extract genesis
core: minor fixes
contracts: remove useless
core/state/snapshot: plugin stacktrie
core: polish
core/state/snapshot: iterate storage concurrently
core/state/snapshot: fix iteration
core: add comments
core/state/snapshot: polish code
core/state: polish
core/state/snapshot: rebase
core/rawdb: add comments
core/rawdb: fix tests
core/rawdb: improve tests
core/state/snapshot: fix concurrent iteration
core/state: run pruning during the recovery
core, trie: implement martin's idea
core, eth: delete flatdb and polish pruner
trie: fix import
core/state/pruner: add log
core/state/pruner: fix issues
core/state/pruner: don't read back
core/state/pruner: fix contract code write
core/state/pruner: check root node presence
cmd, core: polish log
core/state: use HEAD-127 as the target
core/state/snapshot: improve tests
cmd/geth: fix verification tool
cmd/geth: use HEAD as the verification default target
all: replace the bloomfilter with martin's fork
cmd, core: polish code
core, cmd: forcibly delete state root
core/state/pruner: add hash64
core/state/pruner: fix blacklist
core/state: remove blacklist
cmd, core: delete trie clean cache before pruning
cmd, core: fix lint
cmd, core: fix rebase
core/state: fix the special case for clique networks
core/state/snapshot: remove useless code
core/state/pruner: capping the snapshot after pruning
cmd, core, eth: fixes
core/rawdb: update db inspector
cmd/geth: polish code
core/state/pruner: fsync bloom filter
cmd, core: print warning log
core/state/pruner: adjust the parameters for bloom filter
cmd, core: create the bloom filter by size
core: polish
core/state/pruner: sanitize invalid bloomfilter size
cmd: address comments
cmd/geth: address comments
cmd/geth: address comment
core/state/pruner: address comments
core/state/pruner: rename homedir to datadir
cmd, core: address comments
core/state/pruner: address comment
core/state: address comments
core, cmd, tests: address comments
core: address comments
core/state/pruner: release the iterator after each commit
core/state/pruner: improve pruner
cmd, core: adjust bloom paramters
core/state/pruner: fix lint
core/state/pruner: fix tests
core: fix rebase
core/state/pruner: remove atomic rename
core/state/pruner: address comments
all: run go mod tidy
core/state/pruner: avoid false-positive for the middle state roots
core/state/pruner: add checks for middle roots
cmd/geth: replace crit with error
* core/state/pruner: fix lint
* core: drop legacy bloom filter
* core/state/snapshot: improve pruner
* core/state/snapshot: polish concurrent logs to report ETA vs. hashes
* core/state/pruner: add progress report for pruning and compaction too
* core: fix snapshot test API
* core/state: fix some pruning logs
* core/state/pruner: support recovering from bloom flush fail
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-02-08 19:16:30 +08:00
|
|
|
CodePrefix = []byte("c") // CodePrefix + code hash -> account code
|
2018-05-07 14:35:06 +03:00
|
|
|
|
2022-07-05 11:14:21 +08:00
|
|
|
// difflayer database
|
|
|
|
diffLayerPrefix = []byte("d") // diffLayerPrefix + hash -> diffLayer
|
|
|
|
|
2023-05-09 15:11:04 +08:00
|
|
|
// Path-based storage scheme of merkle patricia trie.
|
2023-02-06 10:28:40 -05:00
|
|
|
trieNodeAccountPrefix = []byte("A") // trieNodeAccountPrefix + hexPath -> trie node
|
|
|
|
trieNodeStoragePrefix = []byte("O") // trieNodeStoragePrefix + accountHash + hexPath -> trie node
|
2023-08-01 20:17:32 +08:00
|
|
|
stateIDPrefix = []byte("L") // stateIDPrefix + state root -> state id
|
2018-05-07 14:35:06 +03:00
|
|
|
|
2022-03-22 17:53:22 +08:00
|
|
|
PreimagePrefix = []byte("secure-key-") // PreimagePrefix + hash -> preimage
|
|
|
|
configPrefix = []byte("ethereum-config-") // config prefix for the db
|
|
|
|
genesisPrefix = []byte("ethereum-genesis-") // genesis state prefix for the db
|
2018-05-07 14:35:06 +03:00
|
|
|
|
2022-10-04 08:44:05 +02:00
|
|
|
// BloomBitsIndexPrefix is the data table of a chain indexer to track its progress
|
|
|
|
BloomBitsIndexPrefix = []byte("iB")
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 22:59:48 +08:00
|
|
|
|
2022-10-19 15:53:09 +08:00
|
|
|
ChtPrefix = []byte("chtRootV2-") // ChtPrefix + chtNum (uint64 big endian) -> trie root hash
|
|
|
|
ChtTablePrefix = []byte("cht-")
|
|
|
|
ChtIndexTablePrefix = []byte("chtIndexV2-")
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 22:59:48 +08:00
|
|
|
|
2022-10-19 15:53:09 +08:00
|
|
|
BloomTriePrefix = []byte("bltRoot-") // BloomTriePrefix + bloomTrieNum (uint64 big endian) -> trie root hash
|
|
|
|
BloomTrieTablePrefix = []byte("blt-")
|
|
|
|
BloomTrieIndexPrefix = []byte("bltIndex-")
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 22:59:48 +08:00
|
|
|
|
2022-10-19 15:53:09 +08:00
|
|
|
CliqueSnapshotPrefix = []byte("clique-")
|
2023-08-23 17:46:08 +08:00
|
|
|
ParliaSnapshotPrefix = []byte("parlia-")
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 22:59:48 +08:00
|
|
|
|
2018-05-07 14:35:06 +03:00
|
|
|
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
|
|
|
|
preimageHitCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
|
all: integrate the freezer with fast sync
* all: freezer style syncing
core, eth, les, light: clean up freezer relative APIs
core, eth, les, trie, ethdb, light: clean a bit
core, eth, les, light: add unit tests
core, light: rewrite setHead function
core, eth: fix downloader unit tests
core: add receipt chain insertion test
core: use constant instead of hardcoding table name
core: fix rollback
core: fix setHead
core/rawdb: remove canonical block first and then iterate side chain
core/rawdb, ethdb: add hasAncient interface
eth/downloader: calculate ancient limit via cht first
core, eth, ethdb: lots of fixes
* eth/downloader: print ancient disable log only for fast sync
2019-04-25 22:59:48 +08:00
|
|
|
)
|
|
|
|
|
2019-02-21 21:14:35 +08:00
|
|
|
// LegacyTxLookupEntry is the legacy TxLookupEntry definition with some unnecessary
|
|
|
|
// fields.
|
|
|
|
type LegacyTxLookupEntry struct {
|
2018-05-07 14:35:06 +03:00
|
|
|
BlockHash common.Hash
|
|
|
|
BlockIndex uint64
|
|
|
|
Index uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// encodeBlockNumber encodes a block number as big endian uint64
|
|
|
|
func encodeBlockNumber(number uint64) []byte {
|
|
|
|
enc := make([]byte, 8)
|
|
|
|
binary.BigEndian.PutUint64(enc, number)
|
|
|
|
return enc
|
|
|
|
}
|
2018-06-11 21:06:26 +08:00
|
|
|
|
2018-09-24 15:57:49 +03:00
|
|
|
// headerKeyPrefix = headerPrefix + num (uint64 big endian)
|
|
|
|
func headerKeyPrefix(number uint64) []byte {
|
|
|
|
return append(headerPrefix, encodeBlockNumber(number)...)
|
|
|
|
}
|
|
|
|
|
2018-06-11 21:06:26 +08:00
|
|
|
// headerKey = headerPrefix + num (uint64 big endian) + hash
|
|
|
|
func headerKey(number uint64, hash common.Hash) []byte {
|
|
|
|
return append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// headerTDKey = headerPrefix + num (uint64 big endian) + hash + headerTDSuffix
|
|
|
|
func headerTDKey(number uint64, hash common.Hash) []byte {
|
|
|
|
return append(headerKey(number, hash), headerTDSuffix...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
|
|
|
|
func headerHashKey(number uint64) []byte {
|
|
|
|
return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// headerNumberKey = headerNumberPrefix + hash
|
|
|
|
func headerNumberKey(hash common.Hash) []byte {
|
|
|
|
return append(headerNumberPrefix, hash.Bytes()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// blockBodyKey = blockBodyPrefix + num (uint64 big endian) + hash
|
|
|
|
func blockBodyKey(number uint64, hash common.Hash) []byte {
|
|
|
|
return append(append(blockBodyPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash
|
|
|
|
func blockReceiptsKey(number uint64, hash common.Hash) []byte {
|
|
|
|
return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
|
|
|
}
|
|
|
|
|
2022-07-05 11:14:21 +08:00
|
|
|
// diffLayerKey = diffLayerKeyPrefix + hash
|
|
|
|
func diffLayerKey(hash common.Hash) []byte {
|
2023-05-06 05:43:44 +03:00
|
|
|
return append(diffLayerPrefix, hash.Bytes()...)
|
2022-07-05 11:14:21 +08:00
|
|
|
}
|
|
|
|
|
2018-06-11 21:06:26 +08:00
|
|
|
// txLookupKey = txLookupPrefix + hash
|
|
|
|
func txLookupKey(hash common.Hash) []byte {
|
|
|
|
return append(txLookupPrefix, hash.Bytes()...)
|
|
|
|
}
|
|
|
|
|
2019-11-26 09:48:29 +02:00
|
|
|
// accountSnapshotKey = SnapshotAccountPrefix + hash
|
2019-08-06 13:40:28 +03:00
|
|
|
func accountSnapshotKey(hash common.Hash) []byte {
|
2019-11-26 09:48:29 +02:00
|
|
|
return append(SnapshotAccountPrefix, hash.Bytes()...)
|
2019-08-06 13:40:28 +03:00
|
|
|
}
|
|
|
|
|
2019-11-26 09:48:29 +02:00
|
|
|
// storageSnapshotKey = SnapshotStoragePrefix + account hash + storage hash
|
2019-08-06 13:40:28 +03:00
|
|
|
func storageSnapshotKey(accountHash, storageHash common.Hash) []byte {
|
2023-08-23 21:41:56 +02:00
|
|
|
buf := make([]byte, len(SnapshotStoragePrefix)+common.HashLength+common.HashLength)
|
|
|
|
n := copy(buf, SnapshotStoragePrefix)
|
|
|
|
n += copy(buf[n:], accountHash.Bytes())
|
|
|
|
copy(buf[n:], storageHash.Bytes())
|
|
|
|
return buf
|
2019-08-06 13:40:28 +03:00
|
|
|
}
|
|
|
|
|
2019-11-26 09:48:29 +02:00
|
|
|
// storageSnapshotsKey = SnapshotStoragePrefix + account hash + storage hash
|
2019-08-06 13:40:28 +03:00
|
|
|
func storageSnapshotsKey(accountHash common.Hash) []byte {
|
2019-11-26 09:48:29 +02:00
|
|
|
return append(SnapshotStoragePrefix, accountHash.Bytes()...)
|
2019-08-06 13:40:28 +03:00
|
|
|
}
|
|
|
|
|
2018-06-11 21:06:26 +08:00
|
|
|
// bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash
|
|
|
|
func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte {
|
|
|
|
key := append(append(bloomBitsPrefix, make([]byte, 10)...), hash.Bytes()...)
|
|
|
|
|
|
|
|
binary.BigEndian.PutUint16(key[1:], uint16(bit))
|
|
|
|
binary.BigEndian.PutUint64(key[3:], section)
|
|
|
|
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
2021-11-02 18:31:45 +08:00
|
|
|
// preimageKey = PreimagePrefix + hash
|
2018-06-11 21:06:26 +08:00
|
|
|
func preimageKey(hash common.Hash) []byte {
|
2021-11-02 18:31:45 +08:00
|
|
|
return append(PreimagePrefix, hash.Bytes()...)
|
2018-06-11 21:06:26 +08:00
|
|
|
}
|
|
|
|
|
all: bloom-filter based pruning mechanism (#21724)
* cmd, core, tests: initial state pruner
core: fix db inspector
cmd/geth: add verify-state
cmd/geth: add verification tool
core/rawdb: implement flatdb
cmd, core: fix rebase
core/state: use new contract code layout
core/state/pruner: avoid deleting genesis state
cmd/geth: add helper function
core, cmd: fix extract genesis
core: minor fixes
contracts: remove useless
core/state/snapshot: plugin stacktrie
core: polish
core/state/snapshot: iterate storage concurrently
core/state/snapshot: fix iteration
core: add comments
core/state/snapshot: polish code
core/state: polish
core/state/snapshot: rebase
core/rawdb: add comments
core/rawdb: fix tests
core/rawdb: improve tests
core/state/snapshot: fix concurrent iteration
core/state: run pruning during the recovery
core, trie: implement martin's idea
core, eth: delete flatdb and polish pruner
trie: fix import
core/state/pruner: add log
core/state/pruner: fix issues
core/state/pruner: don't read back
core/state/pruner: fix contract code write
core/state/pruner: check root node presence
cmd, core: polish log
core/state: use HEAD-127 as the target
core/state/snapshot: improve tests
cmd/geth: fix verification tool
cmd/geth: use HEAD as the verification default target
all: replace the bloomfilter with martin's fork
cmd, core: polish code
core, cmd: forcibly delete state root
core/state/pruner: add hash64
core/state/pruner: fix blacklist
core/state: remove blacklist
cmd, core: delete trie clean cache before pruning
cmd, core: fix lint
cmd, core: fix rebase
core/state: fix the special case for clique networks
core/state/snapshot: remove useless code
core/state/pruner: capping the snapshot after pruning
cmd, core, eth: fixes
core/rawdb: update db inspector
cmd/geth: polish code
core/state/pruner: fsync bloom filter
cmd, core: print warning log
core/state/pruner: adjust the parameters for bloom filter
cmd, core: create the bloom filter by size
core: polish
core/state/pruner: sanitize invalid bloomfilter size
cmd: address comments
cmd/geth: address comments
cmd/geth: address comment
core/state/pruner: address comments
core/state/pruner: rename homedir to datadir
cmd, core: address comments
core/state/pruner: address comment
core/state: address comments
core, cmd, tests: address comments
core: address comments
core/state/pruner: release the iterator after each commit
core/state/pruner: improve pruner
cmd, core: adjust bloom paramters
core/state/pruner: fix lint
core/state/pruner: fix tests
core: fix rebase
core/state/pruner: remove atomic rename
core/state/pruner: address comments
all: run go mod tidy
core/state/pruner: avoid false-positive for the middle state roots
core/state/pruner: add checks for middle roots
cmd/geth: replace crit with error
* core/state/pruner: fix lint
* core: drop legacy bloom filter
* core/state/snapshot: improve pruner
* core/state/snapshot: polish concurrent logs to report ETA vs. hashes
* core/state/pruner: add progress report for pruning and compaction too
* core: fix snapshot test API
* core/state: fix some pruning logs
* core/state/pruner: support recovering from bloom flush fail
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-02-08 19:16:30 +08:00
|
|
|
// codeKey = CodePrefix + hash
|
2020-08-21 20:10:40 +08:00
|
|
|
func codeKey(hash common.Hash) []byte {
|
all: bloom-filter based pruning mechanism (#21724)
* cmd, core, tests: initial state pruner
core: fix db inspector
cmd/geth: add verify-state
cmd/geth: add verification tool
core/rawdb: implement flatdb
cmd, core: fix rebase
core/state: use new contract code layout
core/state/pruner: avoid deleting genesis state
cmd/geth: add helper function
core, cmd: fix extract genesis
core: minor fixes
contracts: remove useless
core/state/snapshot: plugin stacktrie
core: polish
core/state/snapshot: iterate storage concurrently
core/state/snapshot: fix iteration
core: add comments
core/state/snapshot: polish code
core/state: polish
core/state/snapshot: rebase
core/rawdb: add comments
core/rawdb: fix tests
core/rawdb: improve tests
core/state/snapshot: fix concurrent iteration
core/state: run pruning during the recovery
core, trie: implement martin's idea
core, eth: delete flatdb and polish pruner
trie: fix import
core/state/pruner: add log
core/state/pruner: fix issues
core/state/pruner: don't read back
core/state/pruner: fix contract code write
core/state/pruner: check root node presence
cmd, core: polish log
core/state: use HEAD-127 as the target
core/state/snapshot: improve tests
cmd/geth: fix verification tool
cmd/geth: use HEAD as the verification default target
all: replace the bloomfilter with martin's fork
cmd, core: polish code
core, cmd: forcibly delete state root
core/state/pruner: add hash64
core/state/pruner: fix blacklist
core/state: remove blacklist
cmd, core: delete trie clean cache before pruning
cmd, core: fix lint
cmd, core: fix rebase
core/state: fix the special case for clique networks
core/state/snapshot: remove useless code
core/state/pruner: capping the snapshot after pruning
cmd, core, eth: fixes
core/rawdb: update db inspector
cmd/geth: polish code
core/state/pruner: fsync bloom filter
cmd, core: print warning log
core/state/pruner: adjust the parameters for bloom filter
cmd, core: create the bloom filter by size
core: polish
core/state/pruner: sanitize invalid bloomfilter size
cmd: address comments
cmd/geth: address comments
cmd/geth: address comment
core/state/pruner: address comments
core/state/pruner: rename homedir to datadir
cmd, core: address comments
core/state/pruner: address comment
core/state: address comments
core, cmd, tests: address comments
core: address comments
core/state/pruner: release the iterator after each commit
core/state/pruner: improve pruner
cmd, core: adjust bloom paramters
core/state/pruner: fix lint
core/state/pruner: fix tests
core: fix rebase
core/state/pruner: remove atomic rename
core/state/pruner: address comments
all: run go mod tidy
core/state/pruner: avoid false-positive for the middle state roots
core/state/pruner: add checks for middle roots
cmd/geth: replace crit with error
* core/state/pruner: fix lint
* core: drop legacy bloom filter
* core/state/snapshot: improve pruner
* core/state/snapshot: polish concurrent logs to report ETA vs. hashes
* core/state/pruner: add progress report for pruning and compaction too
* core: fix snapshot test API
* core/state: fix some pruning logs
* core/state/pruner: support recovering from bloom flush fail
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-02-08 19:16:30 +08:00
|
|
|
return append(CodePrefix, hash.Bytes()...)
|
2020-08-21 20:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsCodeKey reports whether the given byte slice is the key of contract code,
|
|
|
|
// if so return the raw code hash as well.
|
|
|
|
func IsCodeKey(key []byte) (bool, []byte) {
|
all: bloom-filter based pruning mechanism (#21724)
* cmd, core, tests: initial state pruner
core: fix db inspector
cmd/geth: add verify-state
cmd/geth: add verification tool
core/rawdb: implement flatdb
cmd, core: fix rebase
core/state: use new contract code layout
core/state/pruner: avoid deleting genesis state
cmd/geth: add helper function
core, cmd: fix extract genesis
core: minor fixes
contracts: remove useless
core/state/snapshot: plugin stacktrie
core: polish
core/state/snapshot: iterate storage concurrently
core/state/snapshot: fix iteration
core: add comments
core/state/snapshot: polish code
core/state: polish
core/state/snapshot: rebase
core/rawdb: add comments
core/rawdb: fix tests
core/rawdb: improve tests
core/state/snapshot: fix concurrent iteration
core/state: run pruning during the recovery
core, trie: implement martin's idea
core, eth: delete flatdb and polish pruner
trie: fix import
core/state/pruner: add log
core/state/pruner: fix issues
core/state/pruner: don't read back
core/state/pruner: fix contract code write
core/state/pruner: check root node presence
cmd, core: polish log
core/state: use HEAD-127 as the target
core/state/snapshot: improve tests
cmd/geth: fix verification tool
cmd/geth: use HEAD as the verification default target
all: replace the bloomfilter with martin's fork
cmd, core: polish code
core, cmd: forcibly delete state root
core/state/pruner: add hash64
core/state/pruner: fix blacklist
core/state: remove blacklist
cmd, core: delete trie clean cache before pruning
cmd, core: fix lint
cmd, core: fix rebase
core/state: fix the special case for clique networks
core/state/snapshot: remove useless code
core/state/pruner: capping the snapshot after pruning
cmd, core, eth: fixes
core/rawdb: update db inspector
cmd/geth: polish code
core/state/pruner: fsync bloom filter
cmd, core: print warning log
core/state/pruner: adjust the parameters for bloom filter
cmd, core: create the bloom filter by size
core: polish
core/state/pruner: sanitize invalid bloomfilter size
cmd: address comments
cmd/geth: address comments
cmd/geth: address comment
core/state/pruner: address comments
core/state/pruner: rename homedir to datadir
cmd, core: address comments
core/state/pruner: address comment
core/state: address comments
core, cmd, tests: address comments
core: address comments
core/state/pruner: release the iterator after each commit
core/state/pruner: improve pruner
cmd, core: adjust bloom paramters
core/state/pruner: fix lint
core/state/pruner: fix tests
core: fix rebase
core/state/pruner: remove atomic rename
core/state/pruner: address comments
all: run go mod tidy
core/state/pruner: avoid false-positive for the middle state roots
core/state/pruner: add checks for middle roots
cmd/geth: replace crit with error
* core/state/pruner: fix lint
* core: drop legacy bloom filter
* core/state/snapshot: improve pruner
* core/state/snapshot: polish concurrent logs to report ETA vs. hashes
* core/state/pruner: add progress report for pruning and compaction too
* core: fix snapshot test API
* core/state: fix some pruning logs
* core/state/pruner: support recovering from bloom flush fail
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-02-08 19:16:30 +08:00
|
|
|
if bytes.HasPrefix(key, CodePrefix) && len(key) == common.HashLength+len(CodePrefix) {
|
|
|
|
return true, key[len(CodePrefix):]
|
2020-08-21 20:10:40 +08:00
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2018-06-11 21:06:26 +08:00
|
|
|
// configKey = configPrefix + hash
|
|
|
|
func configKey(hash common.Hash) []byte {
|
|
|
|
return append(configPrefix, hash.Bytes()...)
|
|
|
|
}
|
2022-03-22 17:53:22 +08:00
|
|
|
|
2022-08-09 17:44:39 +08:00
|
|
|
// genesisStateSpecKey = genesisPrefix + hash
|
|
|
|
func genesisStateSpecKey(hash common.Hash) []byte {
|
2022-03-22 17:53:22 +08:00
|
|
|
return append(genesisPrefix, hash.Bytes()...)
|
|
|
|
}
|
2023-02-06 10:28:40 -05:00
|
|
|
|
2023-08-01 20:17:32 +08:00
|
|
|
// stateIDKey = stateIDPrefix + root (32 bytes)
|
|
|
|
func stateIDKey(root common.Hash) []byte {
|
|
|
|
return append(stateIDPrefix, root.Bytes()...)
|
|
|
|
}
|
|
|
|
|
2023-02-06 10:28:40 -05:00
|
|
|
// accountTrieNodeKey = trieNodeAccountPrefix + nodePath.
|
|
|
|
func accountTrieNodeKey(path []byte) []byte {
|
|
|
|
return append(trieNodeAccountPrefix, path...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// storageTrieNodeKey = trieNodeStoragePrefix + accountHash + nodePath.
|
|
|
|
func storageTrieNodeKey(accountHash common.Hash, path []byte) []byte {
|
2023-08-23 21:41:56 +02:00
|
|
|
buf := make([]byte, len(trieNodeStoragePrefix)+common.HashLength+len(path))
|
|
|
|
n := copy(buf, trieNodeStoragePrefix)
|
|
|
|
n += copy(buf[n:], accountHash.Bytes())
|
|
|
|
copy(buf[n:], path)
|
|
|
|
return buf
|
2023-02-06 10:28:40 -05:00
|
|
|
}
|
2023-05-09 15:11:04 +08:00
|
|
|
|
|
|
|
// IsLegacyTrieNode reports whether a provided database entry is a legacy trie
|
|
|
|
// node. The characteristics of legacy trie node are:
|
|
|
|
// - the key length is 32 bytes
|
|
|
|
// - the key is the hash of val
|
|
|
|
func IsLegacyTrieNode(key []byte, val []byte) bool {
|
|
|
|
if len(key) != common.HashLength {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return bytes.Equal(key, crypto.Keccak256(val))
|
|
|
|
}
|
|
|
|
|
all: activate pbss as experimental feature from eth (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-11 03:21:36 +08:00
|
|
|
// ResolveAccountTrieNodeKey reports whether a provided database entry is an
|
|
|
|
// account trie node in path-based state scheme, and returns the resolved
|
|
|
|
// node path if so.
|
|
|
|
func ResolveAccountTrieNodeKey(key []byte) (bool, []byte) {
|
2023-05-09 15:11:04 +08:00
|
|
|
if !bytes.HasPrefix(key, trieNodeAccountPrefix) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
// The remaining key should only consist a hex node path
|
|
|
|
// whose length is in the range 0 to 64 (64 is excluded
|
|
|
|
// since leaves are always wrapped with shortNode).
|
|
|
|
if len(key) >= len(trieNodeAccountPrefix)+common.HashLength*2 {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return true, key[len(trieNodeAccountPrefix):]
|
|
|
|
}
|
|
|
|
|
all: activate pbss as experimental feature from eth (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-11 03:21:36 +08:00
|
|
|
// IsAccountTrieNode reports whether a provided database entry is an account
|
2023-05-09 15:11:04 +08:00
|
|
|
// trie node in path-based state scheme.
|
all: activate pbss as experimental feature from eth (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-11 03:21:36 +08:00
|
|
|
func IsAccountTrieNode(key []byte) bool {
|
|
|
|
ok, _ := ResolveAccountTrieNodeKey(key)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResolveStorageTrieNode reports whether a provided database entry is a storage
|
|
|
|
// trie node in path-based state scheme, and returns the resolved account hash
|
|
|
|
// and node path if so.
|
|
|
|
func ResolveStorageTrieNode(key []byte) (bool, common.Hash, []byte) {
|
2023-05-09 15:11:04 +08:00
|
|
|
if !bytes.HasPrefix(key, trieNodeStoragePrefix) {
|
|
|
|
return false, common.Hash{}, nil
|
|
|
|
}
|
|
|
|
// The remaining key consists of 2 parts:
|
|
|
|
// - 32 bytes account hash
|
|
|
|
// - hex node path whose length is in the range 0 to 64
|
|
|
|
if len(key) < len(trieNodeStoragePrefix)+common.HashLength {
|
|
|
|
return false, common.Hash{}, nil
|
|
|
|
}
|
|
|
|
if len(key) >= len(trieNodeStoragePrefix)+common.HashLength+common.HashLength*2 {
|
|
|
|
return false, common.Hash{}, nil
|
|
|
|
}
|
|
|
|
accountHash := common.BytesToHash(key[len(trieNodeStoragePrefix) : len(trieNodeStoragePrefix)+common.HashLength])
|
|
|
|
return true, accountHash, key[len(trieNodeStoragePrefix)+common.HashLength:]
|
|
|
|
}
|
all: activate pbss as experimental feature from eth (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-11 03:21:36 +08:00
|
|
|
|
|
|
|
// IsStorageTrieNode reports whether a provided database entry is a storage
|
|
|
|
// trie node in path-based state scheme.
|
|
|
|
func IsStorageTrieNode(key []byte) bool {
|
|
|
|
ok, _, _ := ResolveStorageTrieNode(key)
|
|
|
|
return ok
|
|
|
|
}
|