Skip to content

Commit

Permalink
Removed the ENABLE_ARCHIVE flag and gcmode feature from codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Dec 19, 2023
1 parent e85f4b1 commit 66e670d
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 127 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ BASE_CMD += --ws --ws.addr $(WS_ADDR) --ws.api $(WS_API)
BASE_CMD += --slices $(SLICES)
BASE_CMD += --db.engine $(DB_ENGINE)
BASE_CMD += $(if $(MAX_PEERS),--maxpeers $(MAX_PEERS))
ifeq ($(ENABLE_ARCHIVE),true)
BASE_CMD += --gcmode archive
endif
ifeq ($(ENABLE_NAT),true)
BASE_CMD += --nat extip:$(EXT_IP)
endif
Expand Down
1 change: 0 additions & 1 deletion cmd/go-quai/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
utils.DataDirFlag,
utils.CacheFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
utils.SnapshotFlag,
utils.CacheDatabaseFlag,
utils.CacheGCFlag,
Expand Down
1 change: 0 additions & 1 deletion cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ var (
utils.ExitWhenSyncedFlag,
utils.ExternalSignerFlag,
utils.FakePoWFlag,
utils.GCModeFlag,
utils.LighthouseFlag,
utils.GardenFlag,
utils.GenesisNonceFlag,
Expand Down
1 change: 0 additions & 1 deletion cmd/go-quai/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.GenesisNonceFlag,
utils.SyncModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.TxLookupLimitFlag,
utils.QuaiStatsURLFlag,
utils.SendFullStatsFlag,
Expand Down
24 changes: 0 additions & 24 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ var (
Usage: `Blockchain sync mode ("fast", "full", "snap" or "light")`,
Value: &defaultSyncMode,
}
GCModeFlag = cli.StringFlag{
Name: "gcmode",
Usage: `Blockchain garbage collection mode ("full", "archive")`,
Value: "full",
}
SnapshotFlag = cli.BoolTFlag{
Name: "snapshot",
Usage: `Enables snapshot-database mode (default = enable)`,
Expand Down Expand Up @@ -1395,11 +1390,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
CheckExclusive(ctx, ColosseumFlag, DeveloperFlag, GardenFlag, OrchardFlag, LocalFlag, LighthouseFlag)
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer

if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
ctx.GlobalSet(TxLookupLimitFlag.Name, "0")
log.Warn("Disable transaction unindexing for archive node")
}

// only set etherbase if its a zone chain
if ctx.GlobalIsSet(RegionFlag.Name) && ctx.GlobalIsSet(ZoneFlag.Name) {
setEtherbase(ctx, cfg)
Expand Down Expand Up @@ -1463,12 +1453,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.DatabaseFreezer = ctx.GlobalString(AncientFlag.Name)
}

if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
if ctx.GlobalIsSet(GCModeFlag.Name) {
cfg.NoPruning = ctx.GlobalString(GCModeFlag.Name) == "archive"
}
if ctx.GlobalIsSet(CacheNoPrefetchFlag.Name) {
cfg.NoPrefetch = ctx.GlobalBool(CacheNoPrefetchFlag.Name)
}
Expand Down Expand Up @@ -1744,22 +1728,14 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (*core.Core, ethdb.Database)
engine = blake3pow.New(blake3pow.Config{}, nil, false)
}

if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
cache := &core.CacheConfig{
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
TrieCleanNoPrefetch: ctx.GlobalBool(CacheNoPrefetchFlag.Name),
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
TrieDirtyDisabled: ctx.GlobalString(GCModeFlag.Name) == "archive",
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
SnapshotLimit: ethconfig.Defaults.SnapshotCache,
Preimages: ctx.GlobalBool(CachePreimagesFlag.Name),
}
if cache.TrieDirtyDisabled && !cache.Preimages {
cache.Preimages = true
log.Info("Enabling recording of key preimages since archive mode is used")
}
if !ctx.GlobalBool(SnapshotFlag.Name) {
cache.SnapshotLimit = 0 // Disabled
}
Expand Down
97 changes: 3 additions & 94 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ type CacheConfig struct {
TrieCleanRejournal time.Duration // Time interval to dump clean cache to disk periodically
TrieCleanNoPrefetch bool // Whether to disable heuristic state prefetching for followup blocks
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
TrieDirtyDisabled bool // Whether to disable trie write caching and GC altogether (archive node)
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
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
Expand Down Expand Up @@ -431,61 +430,10 @@ func (p *StateProcessor) Apply(batch ethdb.Batch, block *types.Block, newInbound
var time9 common.PrettyDuration
var time10 common.PrettyDuration
var time11 common.PrettyDuration
// If we're running an archive node, always flush
if p.cacheConfig.TrieDirtyDisabled {
if err := triedb.Commit(root, false, nil); err != nil {
return nil, err
}
time8 = common.PrettyDuration(time.Since(start))
} else {
// Full but not archive node, do proper garbage collection
triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive
p.triegc.Push(root, -int64(block.NumberU64()))
time8 = common.PrettyDuration(time.Since(start))
if current := block.NumberU64(); current > TriesInMemory {
// If we exceeded our memory allowance, flush matured singleton nodes to disk
var (
nodes, imgs = triedb.Size()
limit = common.StorageSize(p.cacheConfig.TrieDirtyLimit) * 1024 * 1024
)
if nodes > limit || imgs > 4*1024*1024 {
triedb.Cap(limit - ethdb.IdealBatchSize)
}
// Find the next state trie we need to commit
chosen := current - TriesInMemory
time9 = common.PrettyDuration(time.Since(start))
// If we exceeded out time allowance, flush an entire trie to disk
if p.gcproc > p.cacheConfig.TrieTimeLimit {
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
header := p.hc.GetHeaderByNumber(chosen)
if header == nil {
log.Warn("Reorg in progress, trie commit postponed", "number", chosen)
} else {
// If we're exceeding limits but haven't reached a large enough memory gap,
// warn the user that the system is becoming unstable.
if chosen < lastWrite+TriesInMemory && p.gcproc >= 2*p.cacheConfig.TrieTimeLimit {
log.Info("State in memory for too long, committing", "time", p.gcproc, "allowance", p.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/TriesInMemory)
}
// Flush an entire trie and restart the counters
triedb.Commit(header.Root(), true, nil)
lastWrite = chosen
p.gcproc = 0
}
}
time10 = common.PrettyDuration(time.Since(start))
// Garbage collect anything below our required write retention
for !p.triegc.Empty() {
root, number := p.triegc.Pop()
if uint64(-number) > chosen {
p.triegc.Push(root, number)
break
}
triedb.Dereference(root.(common.Hash))
}
time11 = common.PrettyDuration(time.Since(start))
}
if err := triedb.Commit(root, false, nil); err != nil {
return nil, err
}
time8 = common.PrettyDuration(time.Since(start))
rawdb.WriteEtxSet(batch, header.Hash(), header.NumberU64(), etxSet)
time12 := common.PrettyDuration(time.Since(start))

Expand Down Expand Up @@ -779,45 +727,6 @@ func (p *StateProcessor) StateAtTransaction(block *types.Block, txIndex int, ree
}

func (p *StateProcessor) Stop() {
// Ensure that the entirety of the state snapshot is journalled to disk.
var snapBase common.Hash
if p.snaps != nil {
var err error
if snapBase, err = p.snaps.Journal(p.hc.CurrentBlock().Root()); err != nil {
log.Error("Failed to journal state snapshot", "err", err)
}
}
// Ensure the state of a recent block is also stored to disk before exiting.
// We're writing three different states to catch different restart scenarios:
// - HEAD: So we don't need to reprocess any blocks in the general case
// - HEAD-1: So we don't do large reorgs if our HEAD becomes an uncle
// - HEAD-127: So we have a hard limit on the number of blocks reexecuted
if !p.cacheConfig.TrieDirtyDisabled {
triedb := p.stateCache.TrieDB()

for _, offset := range []uint64{0, 1, TriesInMemory - 1} {
if number := p.hc.CurrentBlock().NumberU64(); number > offset {
recent := p.hc.GetBlockByNumber(number - offset)

log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root())
if err := triedb.Commit(recent.Root(), true, nil); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
}
}
}
if snapBase != (common.Hash{}) {
log.Info("Writing snapshot state to disk", "root", snapBase)
if err := triedb.Commit(snapBase, true, nil); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
}
}
for !p.triegc.Empty() {
triedb.Dereference(p.triegc.PopItem().(common.Hash))
}
if size, _ := triedb.Size(); size != 0 {
log.Error("Dangling trie nodes after full cleanup")
}
}
// Ensure all live cached entries be saved into disk, so that we can skip
// cache warmup when node restarts.
if p.cacheConfig.TrieCleanJournal != "" {
Expand Down
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, error) {
TrieCleanRejournal: config.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
Expand Down
3 changes: 1 addition & 2 deletions network.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ SLICES="[0 0],[0 1],[0 2],[1 0],[1 1],[1 2],[2 0],[2 1],[2 2]"
ENABLE_HTTP=true
ENABLE_WS=true
ENABLE_UNLOCK=false
ENABLE_ARCHIVE=false

#Input Variable Definition
#http.addr options include 0.0.0.0 and 127.0.0.1 (local host)
Expand Down Expand Up @@ -135,4 +134,4 @@ DB_ENGINE=leveldb

# Optional set database directory
CUSTOM_DATA_DIR=false
DATA_DIR=
DATA_DIR=

0 comments on commit 66e670d

Please sign in to comment.