Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support non-clean shutdown #1039

Merged
merged 28 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e762940
prune based on both time and height
rachel-bousfield Aug 22, 2022
32e74c8
deprecate node.archive
rachel-bousfield Aug 22, 2022
f6b6797
propagate node.archive
rachel-bousfield Aug 22, 2022
f3b3933
repin geth
rachel-bousfield Aug 22, 2022
a9a7511
repin geth
rachel-bousfield Aug 22, 2022
5514c7f
repin geth
rachel-bousfield Aug 22, 2022
d1d057e
improve comment
rachel-bousfield Aug 22, 2022
2934640
Merge branch 'master' into time-based-pruning
rachel-bousfield Aug 24, 2022
03a1daf
use shutdown markers for chainDb
tsahee Aug 28, 2022
e16237c
have occational wtied to trie cache
tsahee Aug 29, 2022
8822680
Merge branch 'master' into shutdown-markers
tsahee Aug 29, 2022
ab72d67
Merge remote-tracking branch 'origin/time-based-pruning' into shutdow…
tsahee Aug 30, 2022
ec8bdc2
rename config tocaching and add trie-time-limit
tsahee Aug 30, 2022
c63e00f
Merge remote-tracking branch 'origin/shutdown-markers' into shutdown-…
tsahee Aug 30, 2022
0404c4b
update geth
tsahee Aug 30, 2022
1b81ccc
Merge remote-tracking branch 'origin/master' into shutdown-markers
tsahee Aug 30, 2022
857208b
update geth
tsahee Aug 30, 2022
cf54b18
Merge branch 'master' into shutdown-markers
PlasmaPower Aug 30, 2022
2678001
Merge branch 'master' into shutdown-markers
PlasmaPower Aug 30, 2022
97ce700
Merge branch 'master' into shutdown-markers
PlasmaPower Aug 30, 2022
34300f1
use TrieTimeLimit config
tsahee Aug 30, 2022
df71118
update geth
tsahee Aug 30, 2022
e75d323
Merge branch 'master' into shutdown-markers
rachel-bousfield Aug 30, 2022
6766009
update geth
tsahee Aug 30, 2022
beb9fec
Merge branch 'master' into shutdown-markers
PlasmaPower Sep 1, 2022
7863f22
Update default TrieTimeLimit to an hour
PlasmaPower Sep 1, 2022
9788683
Merge branch 'master' into shutdown-markers
PlasmaPower Sep 1, 2022
f1a7d09
Merge branch 'master' into shutdown-markers
PlasmaPower Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 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 @@ -434,8 +435,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 @@ -456,6 +460,7 @@ var ConfigDefault = Config{
Dangerous: DefaultDangerousConfig,
Archive: false,
TxLookupLimit: 40_000_000,
Caching: DefaultCachingConfig,
}

func ConfigDefaultL1Test() *Config {
Expand Down Expand Up @@ -616,6 +621,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: 5 * time.Minute,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update this to an hour and then LGTM :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed up a commit changing this to an hour

}

type Node struct {
Backend *arbitrum.Backend
ArbInterface *ArbInterface
Expand Down Expand Up @@ -1318,10 +1344,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 @@ -1343,9 +1369,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 @@ -1355,8 +1381,10 @@ func DefaultCacheConfigFor(stack *node.Node, archiveMode bool) *core.CacheConfig
TrieCleanRejournal: baseConf.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: baseConf.NoPrefetch,
TrieDirtyLimit: baseConf.TrieDirtyCache,
TrieDirtyDisabled: baseConf.NoPruning,
TrieDirtyDisabled: cachingConfig.Archive,
TrieTimeLimit: baseConf.TrieTimeout,
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 @@ -214,7 +214,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 @@ -246,7 +250,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