Skip to content

Commit

Permalink
Merge pull request #1039 from OffchainLabs/shutdown-markers
Browse files Browse the repository at this point in the history
support non-clean shutdown
  • Loading branch information
PlasmaPower authored Sep 1, 2022
2 parents f68775b + f1a7d09 commit a30288d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
40 changes: 34 additions & 6 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ type Config struct {
DataAvailability das.DataAvailabilityConfig `koanf:"data-availability"`
Wasm WasmConfig `koanf:"wasm"`
Dangerous DangerousConfig `koanf:"dangerous"`
Caching CachingConfig `koanf:"caching"`
Archive bool `koanf:"archive"`
TxLookupLimit uint64 `koanf:"tx-lookup-limit"`
}
Expand Down Expand Up @@ -442,8 +443,11 @@ func ConfigAddOptions(prefix string, f *flag.FlagSet, feedInputEnable bool, feed
das.DataAvailabilityConfigAddOptions(prefix+".data-availability", f)
WasmConfigAddOptions(prefix+".wasm", f)
DangerousConfigAddOptions(prefix+".dangerous", f)
f.Bool(prefix+".archive", ConfigDefault.Archive, "retain past block state")
CachingConfigAddOptions(prefix+".caching", f)
f.Uint64(prefix+".tx-lookup-limit", ConfigDefault.TxLookupLimit, "retain the ability to lookup transactions by hash for the past N blocks (0 = all blocks)")

archiveMsg := fmt.Sprintf("retain past block state (deprecated, please use %v.caching.archive)", prefix)
f.Bool(prefix+".archive", ConfigDefault.Archive, archiveMsg)
}

var ConfigDefault = Config{
Expand All @@ -464,6 +468,7 @@ var ConfigDefault = Config{
Dangerous: DefaultDangerousConfig,
Archive: false,
TxLookupLimit: 40_000_000,
Caching: DefaultCachingConfig,
}

func ConfigDefaultL1Test() *Config {
Expand Down Expand Up @@ -630,6 +635,27 @@ func (w *WasmConfig) FindMachineDir() (string, bool) {
return "", false
}

type CachingConfig struct {
Archive bool `koanf:"archive"`
BlockCount uint64 `koanf:"block-count"`
BlockAge time.Duration `koanf:"block-age"`
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
}

func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".archive", DefaultCachingConfig.Archive, "retain past block state")
f.Uint64(prefix+".block-count", DefaultCachingConfig.BlockCount, "minimum number of recent blocks to keep in memory")
f.Duration(prefix+".block-age", DefaultCachingConfig.BlockAge, "minimum age a block must be to be pruned")
f.Duration(prefix+".trie-time-limit", DefaultCachingConfig.TrieTimeLimit, "maximum block processing time before trie is written to hard-disk")
}

var DefaultCachingConfig = CachingConfig{
Archive: false,
BlockCount: 128,
BlockAge: 30 * time.Minute,
TrieTimeLimit: time.Hour,
}

type Node struct {
Backend *arbitrum.Backend
ArbInterface *ArbInterface
Expand Down Expand Up @@ -1350,10 +1376,10 @@ func (n *Node) StopAndWait() {
n.SeqCoordinator.StopAndWait()
}
n.TxStreamer.StopAndWait()
n.ArbInterface.BlockChain().Stop()
if err := n.Backend.Stop(); err != nil {
log.Error("backend stop", "err", err)
}
n.ArbInterface.BlockChain().Stop()
if n.DASLifecycleManager != nil {
n.DASLifecycleManager.StopAndWaitUntil(2 * time.Second)
}
Expand All @@ -1375,9 +1401,9 @@ func CreateDefaultStackForTest(dataDir string) (*node.Node, error) {
return stack, nil
}

func DefaultCacheConfigFor(stack *node.Node, archiveMode bool) *core.CacheConfig {
func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core.CacheConfig {
baseConf := ethconfig.Defaults
if archiveMode {
if cachingConfig.Archive {
baseConf = ethconfig.ArchiveDefaults
}

Expand All @@ -1387,8 +1413,10 @@ func DefaultCacheConfigFor(stack *node.Node, archiveMode bool) *core.CacheConfig
TrieCleanRejournal: baseConf.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: baseConf.NoPrefetch,
TrieDirtyLimit: baseConf.TrieDirtyCache,
TrieDirtyDisabled: baseConf.NoPruning,
TrieTimeLimit: baseConf.TrieTimeout,
TrieDirtyDisabled: cachingConfig.Archive,
TrieTimeLimit: cachingConfig.TrieTimeLimit,
TriesInMemory: cachingConfig.BlockCount,
TrieRetention: cachingConfig.BlockAge,
SnapshotLimit: baseConf.SnapshotCache,
Preimages: baseConf.Preimages,
}
Expand Down
6 changes: 4 additions & 2 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ func (s *TransactionStreamer) SequenceTransactions(header *arbos.L1IncomingMessa
delayedMessagesRead = lastMsg.DelayedMessagesRead
}

startTime := time.Now()
block, receipts, err := arbos.ProduceBlockAdvanced(
header,
txes,
Expand Down Expand Up @@ -550,7 +551,7 @@ func (s *TransactionStreamer) SequenceTransactions(header *arbos.L1IncomingMessa
for _, receipt := range receipts {
logs = append(logs, receipt.Logs...)
}
status, err := s.bc.WriteBlockAndSetHead(block, receipts, logs, statedb, true)
status, err := s.bc.WriteBlockAndSetHeadWithTime(block, receipts, logs, statedb, true, time.Since(startTime))
if err != nil {
return err
}
Expand Down Expand Up @@ -753,6 +754,7 @@ func (s *TransactionStreamer) createBlocks(ctx context.Context) error {
return err
}

startTime := time.Now()
block, receipts, err := arbos.ProduceBlock(
msg.Message,
msg.DelayedMessagesRead,
Expand All @@ -773,7 +775,7 @@ func (s *TransactionStreamer) createBlocks(ctx context.Context) error {
for _, receipt := range receipts {
logs = append(logs, receipt.Logs...)
}
status, err := s.bc.WriteBlockAndSetHead(block, receipts, logs, statedb, true)
status, err := s.bc.WriteBlockAndSetHeadWithTime(block, receipts, logs, statedb, true, time.Since(startTime))
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ func main() {
return
}

if nodeConfig.Node.Archive && nodeConfig.Node.TxLookupLimit != 0 {
if nodeConfig.Node.Archive {
log.Warn("node.archive has been deprecated. Please use node.caching.archive instead.")
nodeConfig.Node.Caching.Archive = true
}
if nodeConfig.Node.Caching.Archive && nodeConfig.Node.TxLookupLimit != 0 {
log.Info("retaining ability to lookup full transaction history as archive mode is enabled")
nodeConfig.Node.TxLookupLimit = 0
}
Expand Down Expand Up @@ -251,7 +255,7 @@ func main() {
}
}

chainDb, l2BlockChain, err := openInitializeChainDb(ctx, stack, nodeConfig, new(big.Int).SetUint64(nodeConfig.L2.ChainID), arbnode.DefaultCacheConfigFor(stack, nodeConfig.Node.Archive))
chainDb, l2BlockChain, err := openInitializeChainDb(ctx, stack, nodeConfig, new(big.Int).SetUint64(nodeConfig.L2.ChainID), arbnode.DefaultCacheConfigFor(stack, &nodeConfig.Node.Caching))
if err != nil {
printSampleUsage(os.Args[0])
fmt.Printf("%s\n", err.Error())
Expand Down

0 comments on commit a30288d

Please sign in to comment.