all: disable recording preimage of trie keys ()

* cmd, core, eth, light, trie: disable recording preimage by default

* core, eth: fix unit tests

* core: fix import

* all: change to nopreimage

* cmd, core, eth, trie: use cache.preimages flag

* cmd: enable preimages for archive node

* cmd/utils, trie: simplify preimage tracking a bit

* core: fix linter

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
# Conflicts:
#	cmd/geth/main.go
#	cmd/geth/usage.go
#	cmd/utils/flags.go
#	core/blockchain.go
#	core/genesis.go
#	core/state/database.go
#	core/state/state_test.go
#	eth/api_test.go
#	eth/api_tracer.go
#	eth/backend.go
#	light/postprocess.go
#	trie/secure_trie.go
#	turbo/trie/database.go
This commit is contained in:
gary rong 2020-11-18 17:51:33 +08:00 committed by Igor Mandrigin
parent 74e0b2cc36
commit b2351da9d6
4 changed files with 19 additions and 5 deletions

View File

@ -1488,9 +1488,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
cfg.BlocksToPrune = ctx.GlobalUint64(GCModeBlockToPruneFlag.Name)
cfg.PruningTimeout = ctx.GlobalDuration(GCModeTickTimeout.Name)
// Read the value from the flag no matter if it's set or not.
cfg.DownloadOnly = ctx.GlobalBoolT(DownloadOnlyFlag.Name)
cfg.EnableDebugProtocol = ctx.GlobalBool(DebugProtocolFlag.Name)
log.Info("Enabling recording of key preimages since archive mode is used")
cfg.ArchiveSyncInterval = ctx.GlobalInt(ArchiveSyncInterval.Name)

View File

@ -172,6 +172,7 @@ type Config struct {
TrieDirtyCache int
TrieTimeout time.Duration
SnapshotCache int
Preimages bool
// Mining options
Miner miner.Config

View File

@ -43,6 +43,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
TrieDirtyCache int
TrieTimeout time.Duration
SnapshotCache int
Preimages bool
Miner miner.Config
Ethash ethash.Config
TxPool core.TxPoolConfig
@ -81,6 +82,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.TrieDirtyCache = c.TrieDirtyCache
enc.TrieTimeout = c.TrieTimeout
enc.SnapshotCache = c.SnapshotCache
enc.Preimages = c.Preimages
enc.Miner = c.Miner
enc.Ethash = c.Ethash
enc.TxPool = c.TxPool
@ -124,6 +126,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
TrieDirtyCache *int
TrieTimeout *time.Duration
SnapshotCache *int
Preimages *bool
Miner *miner.Config
Ethash *ethash.Config
TxPool *core.TxPoolConfig
@ -217,6 +220,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.SnapshotCache != nil {
c.SnapshotCache = *dec.SnapshotCache
}
if dec.Preimages != nil {
c.Preimages = *dec.Preimages
}
if dec.Miner != nil {
c.Miner = *dec.Miner
}

View File

@ -208,16 +208,16 @@ func NewDatabase(diskdb ethdb.Database) *Database {
return NewDatabaseWithCache(diskdb, 0, "")
}
// NewDatabaseWithCache creates a new trie database to store ephemeral trie content
// NewDatabaseWithConfig creates a new trie database to store ephemeral trie content
// before its written out to disk or garbage collected. It also acts as a read cache
// for nodes loaded from disk.
func NewDatabaseWithCache(diskdb ethdb.Database, cache int, journal string) *Database {
var cleans *fastcache.Cache
if cache > 0 {
if journal == "" {
cleans = fastcache.New(cache * 1024 * 1024)
if config != nil && config.Cache > 0 {
if config.Journal == "" {
cleans = fastcache.New(config.Cache * 1024 * 1024)
} else {
cleans = fastcache.LoadFromFileOrNew(journal, cache*1024*1024)
cleans = fastcache.LoadFromFileOrNew(config.Journal, config.Cache*1024*1024)
}
}
return &Database{
@ -250,6 +250,11 @@ func (db *Database) InsertBlob(hash common.Hash, blob []byte) {
//
// Note, this method assumes that the database's lock is held!
func (db *Database) insertPreimage(hash common.Hash, preimage []byte) {
// Short circuit if preimage collection is disabled
if db.preimages == nil {
return
}
// Track the preimage if a yet unknown one
if _, ok := db.preimages[hash]; ok {
return
}