From 3eb4212a5657bb7bdb60602136c7989843d905fc Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sat, 2 Dec 2023 12:04:30 -0700 Subject: [PATCH 1/4] Always initialize staker wallet --- arbnode/node.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arbnode/node.go b/arbnode/node.go index e52a698e4e..c6e117e700 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -615,10 +615,8 @@ func createNodeImpl( if err != nil { return nil, err } - if stakerObj.Strategy() == staker.WatchtowerStrategy { - if err := wallet.Initialize(ctx); err != nil { - return nil, err - } + if err := wallet.Initialize(ctx); err != nil { + return nil, err } var txValidatorSenderPtr *common.Address if txOptsValidator != nil { From 511d97493ad20b4f9876dbf1f7313fd5d14c332a Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Sun, 3 Dec 2023 20:31:49 -0700 Subject: [PATCH 2/4] Use chain info if only given one chain info If no chain ID, no chain name, and only a single chain info is specified, use that single chain info. --- cmd/chaininfo/chain_info.go | 10 +++++++++- cmd/nitro/nitro.go | 22 ++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cmd/chaininfo/chain_info.go b/cmd/chaininfo/chain_info.go index c0d6b3d005..13e586ced2 100644 --- a/cmd/chaininfo/chain_info.go +++ b/cmd/chaininfo/chain_info.go @@ -6,6 +6,7 @@ package chaininfo import ( _ "embed" "encoding/json" + "errors" "fmt" "math/big" "os" @@ -86,7 +87,10 @@ func ProcessChainInfo(chainId uint64, chainName string, l2ChainInfoFiles []strin if chainId != 0 { return nil, fmt.Errorf("unsupported chain ID %v", chainId) } - return nil, fmt.Errorf("unsupported chain name %v", chainName) + if chainName != "" { + return nil, fmt.Errorf("unsupported chain name %v", chainName) + } + return nil, errors.New("must specify --chain.id or --chain.name to choose rollup") } func findChainInfo(chainId uint64, chainName string, chainsInfoBytes []byte) (*ChainInfo, error) { @@ -95,6 +99,10 @@ func findChainInfo(chainId uint64, chainName string, chainsInfoBytes []byte) (*C if err != nil { return nil, err } + if chainId == 0 && chainName == "" && len(chainsInfo) == 1 { + // If single chain info and no chain id/name given, default to single chain info + return &chainsInfo[0], nil + } for _, chainInfo := range chainsInfo { if (chainId == 0 || chainInfo.ChainConfig.ChainID.Uint64() == chainId) && (chainName == "" || chainInfo.ChainName == chainName) { return &chainInfo, nil diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index 4089508a14..e50bc960ae 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -718,12 +718,9 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa l2ChainName := k.String("chain.name") l2ChainInfoIpfsUrl := k.String("chain.info-ipfs-url") l2ChainInfoIpfsDownloadPath := k.String("chain.info-ipfs-download-path") - if l2ChainId == 0 && l2ChainName == "" { - return nil, nil, nil, errors.New("must specify --chain.id or --chain.name to choose rollup") - } l2ChainInfoFiles := k.Strings("chain.info-files") l2ChainInfoJson := k.String("chain.info-json") - chainFound, err := applyChainParameters(ctx, k, uint64(l2ChainId), l2ChainName, l2ChainInfoFiles, l2ChainInfoJson, l2ChainInfoIpfsUrl, l2ChainInfoIpfsDownloadPath) + err = applyChainParameters(ctx, k, uint64(l2ChainId), l2ChainName, l2ChainInfoFiles, l2ChainInfoJson, l2ChainInfoIpfsUrl, l2ChainInfoIpfsDownloadPath) if err != nil { return nil, nil, nil, err } @@ -752,13 +749,6 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa } if nodeConfig.Persistent.Chain == "" { - if !chainFound { - // If persistent-chain not defined, user not creating custom chain - if l2ChainId != 0 { - return nil, nil, nil, fmt.Errorf("Unknown chain id: %d, L2ChainInfoFiles: %v. update chain id, modify --chain.info-files or provide --persistent.chain\n", l2ChainId, l2ChainInfoFiles) - } - return nil, nil, nil, fmt.Errorf("Unknown chain name: %s, L2ChainInfoFiles: %v. update chain name, modify --chain.info-files or provide --persistent.chain\n", l2ChainName, l2ChainInfoFiles) - } return nil, nil, nil, errors.New("--persistent.chain not specified") } @@ -783,7 +773,7 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa return &nodeConfig, &l1Wallet, &l2DevWallet, nil } -func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, chainName string, l2ChainInfoFiles []string, l2ChainInfoJson string, l2ChainInfoIpfsUrl string, l2ChainInfoIpfsDownloadPath string) (bool, error) { +func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, chainName string, l2ChainInfoFiles []string, l2ChainInfoJson string, l2ChainInfoIpfsUrl string, l2ChainInfoIpfsDownloadPath string) error { combinedL2ChainInfoFiles := l2ChainInfoFiles if l2ChainInfoIpfsUrl != "" { l2ChainInfoIpfsFile, err := util.GetL2ChainInfoIpfsFile(ctx, l2ChainInfoIpfsUrl, l2ChainInfoIpfsDownloadPath) @@ -794,7 +784,7 @@ func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, c } chainInfo, err := chaininfo.ProcessChainInfo(chainId, chainName, combinedL2ChainInfoFiles, l2ChainInfoJson) if err != nil { - return false, err + return err } var parentChainIsArbitrum bool if chainInfo.ParentChainIsArbitrum != nil { @@ -835,7 +825,7 @@ func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, c l2MaxTxSize := gethexec.DefaultSequencerConfig.MaxTxDataSize bufferSpace := 5000 if l2MaxTxSize < bufferSpace*2 { - return false, fmt.Errorf("not enough room in parent chain max tx size %v for bufferSpace %v * 2", l2MaxTxSize, bufferSpace) + return fmt.Errorf("not enough room in parent chain max tx size %v for bufferSpace %v * 2", l2MaxTxSize, bufferSpace) } safeBatchSize := l2MaxTxSize - bufferSpace chainDefaults["node.batch-poster.max-size"] = safeBatchSize @@ -846,9 +836,9 @@ func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, c } err = k.Load(confmap.Provider(chainDefaults, "."), nil) if err != nil { - return false, err + return err } - return true, nil + return nil } type NodeConfigFetcher struct { From a9721ace85f1d54bce44411e4d979452ffc46d93 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Mon, 4 Dec 2023 16:10:38 -0700 Subject: [PATCH 3/4] Clear out the channel when resetting feed timers --- broadcastclients/broadcastclients.go | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/broadcastclients/broadcastclients.go b/broadcastclients/broadcastclients.go index ed11ab87da..1997c6d21a 100644 --- a/broadcastclients/broadcastclients.go +++ b/broadcastclients/broadcastclients.go @@ -120,6 +120,18 @@ func (bcs *BroadcastClients) adjustCount(delta int32) { } } +// Clears out a ticker's channel and resets it to the interval +func clearAndResetTicker(timer *time.Ticker, interval time.Duration) { + timer.Stop() + // Clear out any previous ticks + // A ticker's channel is only buffers one tick, so we don't need a loop here + select { + case <-timer.C: + default: + } + timer.Reset(interval) +} + func (bcs *BroadcastClients) Start(ctx context.Context) { bcs.primaryRouter.StopWaiter.Start(ctx, bcs.primaryRouter) bcs.secondaryRouter.StopWaiter.Start(ctx, bcs.secondaryRouter) @@ -182,46 +194,46 @@ func (bcs *BroadcastClients) Start(ctx context.Context) { return // Primary feeds case msg := <-bcs.primaryRouter.messageChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) - primaryFeedIsDownTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) if err := msgHandler(msg, bcs.primaryRouter); err != nil { log.Error("Error routing message from Primary Sequencer Feeds", "err", err) } case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) - primaryFeedIsDownTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) confSeqHandler(cs, bcs.primaryRouter) // Failed to get messages from primary feed for ~5 seconds, reset the timer responsible for stopping a secondary case <-primaryFeedIsDownTimer.C: - stopSecondaryFeedTimer.Reset(PRIMARY_FEED_UPTIME) + clearAndResetTicker(stopSecondaryFeedTimer, PRIMARY_FEED_UPTIME) default: select { case <-ctx.Done(): return // Secondary Feeds case msg := <-bcs.secondaryRouter.messageChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) if err := msgHandler(msg, bcs.secondaryRouter); err != nil { log.Error("Error routing message from Secondary Sequencer Feeds", "err", err) } case cs := <-bcs.secondaryRouter.confirmedSequenceNumberChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) confSeqHandler(cs, bcs.secondaryRouter) case msg := <-bcs.primaryRouter.messageChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) - primaryFeedIsDownTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) if err := msgHandler(msg, bcs.primaryRouter); err != nil { log.Error("Error routing message from Primary Sequencer Feeds", "err", err) } case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: - startSecondaryFeedTimer.Reset(MAX_FEED_INACTIVE_TIME) - primaryFeedIsDownTimer.Reset(MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) confSeqHandler(cs, bcs.primaryRouter) case <-startSecondaryFeedTimer.C: bcs.startSecondaryFeed(ctx) case <-primaryFeedIsDownTimer.C: - stopSecondaryFeedTimer.Reset(PRIMARY_FEED_UPTIME) + clearAndResetTicker(stopSecondaryFeedTimer, PRIMARY_FEED_UPTIME) } } } From 135f5dd7549e8b3a555cc91ca00365b368103371 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Tue, 5 Dec 2023 00:24:22 -0700 Subject: [PATCH 4/4] Move clearAndResetTicker calls to after effects --- broadcastclients/broadcastclients.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/broadcastclients/broadcastclients.go b/broadcastclients/broadcastclients.go index 1997c6d21a..16c465b9bf 100644 --- a/broadcastclients/broadcastclients.go +++ b/broadcastclients/broadcastclients.go @@ -194,15 +194,15 @@ func (bcs *BroadcastClients) Start(ctx context.Context) { return // Primary feeds case msg := <-bcs.primaryRouter.messageChan: - clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) - clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) if err := msgHandler(msg, bcs.primaryRouter); err != nil { log.Error("Error routing message from Primary Sequencer Feeds", "err", err) } - case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) + case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: confSeqHandler(cs, bcs.primaryRouter) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) // Failed to get messages from primary feed for ~5 seconds, reset the timer responsible for stopping a secondary case <-primaryFeedIsDownTimer.C: clearAndResetTicker(stopSecondaryFeedTimer, PRIMARY_FEED_UPTIME) @@ -212,24 +212,23 @@ func (bcs *BroadcastClients) Start(ctx context.Context) { return // Secondary Feeds case msg := <-bcs.secondaryRouter.messageChan: - clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) if err := msgHandler(msg, bcs.secondaryRouter); err != nil { log.Error("Error routing message from Secondary Sequencer Feeds", "err", err) } - case cs := <-bcs.secondaryRouter.confirmedSequenceNumberChan: clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + case cs := <-bcs.secondaryRouter.confirmedSequenceNumberChan: confSeqHandler(cs, bcs.secondaryRouter) - - case msg := <-bcs.primaryRouter.messageChan: clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) - clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) + case msg := <-bcs.primaryRouter.messageChan: if err := msgHandler(msg, bcs.primaryRouter); err != nil { log.Error("Error routing message from Primary Sequencer Feeds", "err", err) } - case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) + case cs := <-bcs.primaryRouter.confirmedSequenceNumberChan: confSeqHandler(cs, bcs.primaryRouter) + clearAndResetTicker(startSecondaryFeedTimer, MAX_FEED_INACTIVE_TIME) + clearAndResetTicker(primaryFeedIsDownTimer, MAX_FEED_INACTIVE_TIME) case <-startSecondaryFeedTimer.C: bcs.startSecondaryFeed(ctx) case <-primaryFeedIsDownTimer.C: