diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 0b09344bf0..54271e11fd 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -192,7 +192,7 @@ func initGenesis(ctx *cli.Context) error { stack, _ := makeConfigNode(ctx) defer stack.Close() for _, name := range []string{"chaindata", "lightchaindata"} { - chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.GlobalString(utils.AncientFlag.Name), "", false, ctx.GlobalUint64(utils.AncientRecentLimitFlag.Name)) + chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.GlobalString(utils.AncientFlag.Name), "", false, ctx.GlobalBool(utils.AncientPruneFlag.Name)) if err != nil { utils.Fatalf("Failed to open database: %v", err) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c80de61104..a0363ee8fd 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -122,10 +122,9 @@ var ( Name: "datadir.ancient", Usage: "Data directory for ancient chain segments (default = inside chaindata)", } - AncientRecentLimitFlag = cli.Uint64Flag{ - Name: "ancient.recentlimit", - Usage: "Keep only the specified amount of recent ancient blocks and won't do ancient related checks on startup (default = 0, means keep all)", - Value: 0, + AncientPruneFlag = cli.BoolFlag{ + Name: "ancient.prune", + Usage: "Totally discard the ancient blocks instead of writting them to the freezer db", } MinFreeDiskSpaceFlag = DirectoryFlag{ Name: "datadir.minfreedisk", @@ -854,7 +853,7 @@ var ( DatabasePathFlags = []cli.Flag{ DataDirFlag, AncientFlag, - AncientRecentLimitFlag, + AncientPruneFlag, RemoteDBFlag, } ) @@ -1595,8 +1594,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { ctx.GlobalSet(TxLookupLimitFlag.Name, "0") log.Warn("Disable transaction unindexing for archive node") } - if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(AncientRecentLimitFlag.Name) != 0 { - ctx.GlobalSet(AncientRecentLimitFlag.Name, "0") + if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(AncientPruneFlag.Name) != 0 { + ctx.GlobalSet(AncientPruneFlag.Name, "false") log.Warn("Disable ancient prunning for archive node") } if ctx.GlobalIsSet(LightServeFlag.Name) && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 { @@ -1665,8 +1664,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(TxLookupLimitFlag.Name) { cfg.TxLookupLimit = ctx.GlobalUint64(TxLookupLimitFlag.Name) } - if ctx.GlobalIsSet(AncientRecentLimitFlag.Name) { - cfg.AncientRecentLimit = ctx.GlobalUint64(AncientRecentLimitFlag.Name) + if ctx.GlobalIsSet(AncientPruneFlag.Name) { + cfg.AncientPrune = ctx.GlobalBool(AncientPruneFlag.Name) } if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheTrieFlag.Name) { cfg.TrieCleanCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheTrieFlag.Name) / 100 @@ -1991,7 +1990,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb. case ctx.GlobalString(SyncModeFlag.Name) == "light": chainDb, err = stack.OpenDatabase("lightchaindata", cache, handles, "", readonly) default: - chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly, ctx.GlobalUint64(AncientRecentLimitFlag.Name)) + chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly, ctx.GlobalBool(AncientPruneFlag.Name)) } if err != nil { Fatalf("Could not open database: %v", err) diff --git a/core/blockchain.go b/core/blockchain.go index 92331c6bea..3d38b5f9f3 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -140,8 +140,7 @@ type CacheConfig struct { SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory Preimages bool // Whether to store preimage of trie key to the disk - AncientRecentLimit uint64 - + AncientPrune bool SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it } @@ -406,7 +405,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par // Start tx indexer/unindexer. if txLookupLimit != nil { bc.txLookupLimit = *txLookupLimit - if bc.cacheConfig.AncientRecentLimit != 0 { + if bc.cacheConfig.AncientPrune { bc.txLookupLimit = params.FullImmutabilityThreshold } @@ -940,7 +939,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ bc.wg.Add(1) defer bc.wg.Done() - if bc.cacheConfig.AncientRecentLimit != 0 { + if bc.cacheConfig.AncientPrune { ancientLimit = 0 } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index adf9d0f2f0..e660189f8b 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -165,7 +165,7 @@ func NewDatabase(db ethdb.KeyValueStore) ethdb.Database { // NewDatabaseWithFreezer creates a high level database on top of a given key- // value data store with a freezer moving immutable chain segments into cold // storage. -func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace string, readonly, discardAncient bool) (ethdb.Database, error) { +func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace string, readonly, ancientPrune bool) (ethdb.Database, error) { // Create the idle freezer instance frdb, err := newChainFreezer(freezer, namespace, readonly, freezerTableSize, FreezerNoSnappy) if err != nil { @@ -237,7 +237,7 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st } } // Freezer is consistent with the key-value database, permit combining the two - if !frdb.readonly && !discardAncient { + if !frdb.readonly && !ancientPrune { frdb.wg.Add(1) go func() { frdb.freeze(db) @@ -275,13 +275,13 @@ func NewLevelDBDatabase(file string, cache int, handles int, namespace string, r // NewLevelDBDatabaseWithFreezer creates a persistent key-value database with a // freezer moving immutable chain segments into cold storage. -func NewLevelDBDatabaseWithFreezer(file string, cache int, handles int, freezer string, namespace string, readonly bool, ancientRecentLimit uint64) (ethdb.Database, error) { +func NewLevelDBDatabaseWithFreezer(file string, cache int, handles int, freezer string, namespace string, readonly, ancientPrune bool) (ethdb.Database, error) { kvdb, err := leveldb.New(file, cache, handles, namespace, readonly) if err != nil { return nil, err } - frdb, err := NewDatabaseWithFreezer(kvdb, freezer, namespace, readonly, ancientRecentLimit != 0) + frdb, err := NewDatabaseWithFreezer(kvdb, freezer, namespace, readonly, ancientPrune) if err != nil { kvdb.Close() return nil, err diff --git a/eth/backend.go b/eth/backend.go index 4016ce5848..3ed4114b25 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -133,7 +133,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { ethashConfig.NotifyFull = config.Miner.NotifyFull // Assemble the Ethereum object - chainDb, err := stack.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/", false, config.AncientRecentLimit) + chainDb, err := stack.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/", false, config.AncientPrune) if err != nil { return nil, err } @@ -202,7 +202,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { TrieTimeLimit: config.TrieTimeout, SnapshotLimit: config.SnapshotCache, Preimages: config.Preimages, - AncientRecentLimit: config.AncientRecentLimit, + AncientPrune: config.AncientPrune, } ) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit) @@ -215,7 +215,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { eth.blockchain.SetHead(compat.RewindTo) rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig) } - if config.AncientRecentLimit == 0 { + if !config.AncientPrune { eth.bloomIndexer.Start(eth.blockchain) } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index c37faa1688..0da200eca8 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -163,7 +163,7 @@ type Config struct { DatabaseHandles int `toml:"-"` DatabaseCache int DatabaseFreezer string - AncientRecentLimit uint64 + AncientPrune bool TrieCleanCache int TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts diff --git a/node/node.go b/node/node.go index c67bbd01d8..a3f559588e 100644 --- a/node/node.go +++ b/node/node.go @@ -717,7 +717,7 @@ func (n *Node) OpenDatabase(name string, cache, handles int, namespace string, r // also attaching a chain freezer to it that moves ancient chain data from the // database to immutable append-only files. If the node is an ephemeral one, a // memory database is returned. -func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, namespace string, readonly bool, ancientRecentLimit uint64) (ethdb.Database, error) { +func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, namespace string, readonly, ancientPrune bool) (ethdb.Database, error) { n.lock.Lock() defer n.lock.Unlock() if n.state == closedState { @@ -736,7 +736,7 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, case !filepath.IsAbs(freezer): freezer = n.ResolvePath(freezer) } - db, err = rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace, readonly, ancientRecentLimit) + db, err = rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace, readonly, ancientPrune) } if err == nil {