From 2fe8f088ed87171a731867bb240d709033883f36 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 16 Aug 2024 17:58:27 +0530 Subject: [PATCH 1/3] Start node only after the block containing rollup creation tx has been finalized (if supported) --- cmd/nitro/nitro.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index 2c7d07cf3b..a5f6c1028e 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -638,6 +638,38 @@ func mainImpl() int { } } } + + // Before starting the node, wait until the transaction that deployed rollup is finalized + if nodeConfig.Node.ParentChainReader.Enable && rollupAddrs.DeployedAt > 0 { + currentFinalized, err := l1Reader.LatestFinalizedBlockNr(ctx) + if err != nil && errors.Is(err, headerreader.ErrBlockNumberNotSupported) { + log.Info("Finality not supported by parent chain, disabling the check to verify if rollup deployment tx was finalized", "err", err) + } else { + newHeaders, unsubscribe := l1Reader.Subscribe(false) + retriesOnError := 10 + for currentFinalized < rollupAddrs.DeployedAt && retriesOnError > 0 { + select { + case <-newHeaders: + if finalized, err := l1Reader.LatestFinalizedBlockNr(ctx); err != nil { + if errors.Is(err, headerreader.ErrBlockNumberNotSupported) { + log.Error("Finality support was removed from parent chain mid way, disabling the check to verify if the rollup deployment tx was finalized", "err", err) + retriesOnError = 0 // Break out of for loop as well + break + } + log.Error("Error getting latestFinalizedBlockNr from l1Reader", "err", err) + retriesOnError-- + } else { + currentFinalized = finalized + } + case <-ctx.Done(): + log.Error("Context done while checking if the rollup deployment tx was finalized") + return 1 + } + } + unsubscribe() + } + } + gqlConf := nodeConfig.GraphQL if gqlConf.Enable { if err := graphql.New(stack, execNode.Backend.APIBackend(), execNode.FilterSystem, gqlConf.CORSDomain, gqlConf.VHosts); err != nil { From 9e7a43a5de41982a294de12a122d1d29237fc2b1 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Mon, 19 Aug 2024 17:35:57 +0530 Subject: [PATCH 2/3] address PR comments --- cmd/nitro/nitro.go | 100 +++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index a5f6c1028e..8d419ce835 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -640,13 +640,17 @@ func mainImpl() int { } // Before starting the node, wait until the transaction that deployed rollup is finalized - if nodeConfig.Node.ParentChainReader.Enable && rollupAddrs.DeployedAt > 0 { + if nodeConfig.EnsureRollupDeployment && + nodeConfig.Node.ParentChainReader.Enable && + rollupAddrs.DeployedAt > 0 { currentFinalized, err := l1Reader.LatestFinalizedBlockNr(ctx) if err != nil && errors.Is(err, headerreader.ErrBlockNumberNotSupported) { log.Info("Finality not supported by parent chain, disabling the check to verify if rollup deployment tx was finalized", "err", err) } else { newHeaders, unsubscribe := l1Reader.Subscribe(false) retriesOnError := 10 + sigint := make(chan os.Signal, 1) + signal.Notify(sigint, os.Interrupt, syscall.SIGTERM) for currentFinalized < rollupAddrs.DeployedAt && retriesOnError > 0 { select { case <-newHeaders: @@ -664,6 +668,9 @@ func mainImpl() int { case <-ctx.Done(): log.Error("Context done while checking if the rollup deployment tx was finalized") return 1 + case <-sigint: + log.Info("shutting down because of sigint") + return 0 } } unsubscribe() @@ -733,53 +740,55 @@ func mainImpl() int { } type NodeConfig struct { - Conf genericconf.ConfConfig `koanf:"conf" reload:"hot"` - Node arbnode.Config `koanf:"node" reload:"hot"` - Execution gethexec.Config `koanf:"execution" reload:"hot"` - Validation valnode.Config `koanf:"validation" reload:"hot"` - ParentChain conf.ParentChainConfig `koanf:"parent-chain" reload:"hot"` - Chain conf.L2Config `koanf:"chain"` - LogLevel string `koanf:"log-level" reload:"hot"` - LogType string `koanf:"log-type" reload:"hot"` - FileLogging genericconf.FileLoggingConfig `koanf:"file-logging" reload:"hot"` - Persistent conf.PersistentConfig `koanf:"persistent"` - HTTP genericconf.HTTPConfig `koanf:"http"` - WS genericconf.WSConfig `koanf:"ws"` - IPC genericconf.IPCConfig `koanf:"ipc"` - Auth genericconf.AuthRPCConfig `koanf:"auth"` - GraphQL genericconf.GraphQLConfig `koanf:"graphql"` - Metrics bool `koanf:"metrics"` - MetricsServer genericconf.MetricsServerConfig `koanf:"metrics-server"` - PProf bool `koanf:"pprof"` - PprofCfg genericconf.PProf `koanf:"pprof-cfg"` - Init conf.InitConfig `koanf:"init"` - Rpc genericconf.RpcConfig `koanf:"rpc"` - BlocksReExecutor blocksreexecutor.Config `koanf:"blocks-reexecutor"` + Conf genericconf.ConfConfig `koanf:"conf" reload:"hot"` + Node arbnode.Config `koanf:"node" reload:"hot"` + Execution gethexec.Config `koanf:"execution" reload:"hot"` + Validation valnode.Config `koanf:"validation" reload:"hot"` + ParentChain conf.ParentChainConfig `koanf:"parent-chain" reload:"hot"` + Chain conf.L2Config `koanf:"chain"` + LogLevel string `koanf:"log-level" reload:"hot"` + LogType string `koanf:"log-type" reload:"hot"` + FileLogging genericconf.FileLoggingConfig `koanf:"file-logging" reload:"hot"` + Persistent conf.PersistentConfig `koanf:"persistent"` + HTTP genericconf.HTTPConfig `koanf:"http"` + WS genericconf.WSConfig `koanf:"ws"` + IPC genericconf.IPCConfig `koanf:"ipc"` + Auth genericconf.AuthRPCConfig `koanf:"auth"` + GraphQL genericconf.GraphQLConfig `koanf:"graphql"` + Metrics bool `koanf:"metrics"` + MetricsServer genericconf.MetricsServerConfig `koanf:"metrics-server"` + PProf bool `koanf:"pprof"` + PprofCfg genericconf.PProf `koanf:"pprof-cfg"` + Init conf.InitConfig `koanf:"init"` + Rpc genericconf.RpcConfig `koanf:"rpc"` + BlocksReExecutor blocksreexecutor.Config `koanf:"blocks-reexecutor"` + EnsureRollupDeployment bool `koanf:"ensure-rollup-deployment" reload:"hot"` } var NodeConfigDefault = NodeConfig{ - Conf: genericconf.ConfConfigDefault, - Node: arbnode.ConfigDefault, - Execution: gethexec.ConfigDefault, - Validation: valnode.DefaultValidationConfig, - ParentChain: conf.L1ConfigDefault, - Chain: conf.L2ConfigDefault, - LogLevel: "INFO", - LogType: "plaintext", - FileLogging: genericconf.DefaultFileLoggingConfig, - Persistent: conf.PersistentConfigDefault, - HTTP: genericconf.HTTPConfigDefault, - WS: genericconf.WSConfigDefault, - IPC: genericconf.IPCConfigDefault, - Auth: genericconf.AuthRPCConfigDefault, - GraphQL: genericconf.GraphQLConfigDefault, - Metrics: false, - MetricsServer: genericconf.MetricsServerConfigDefault, - Init: conf.InitConfigDefault, - Rpc: genericconf.DefaultRpcConfig, - PProf: false, - PprofCfg: genericconf.PProfDefault, - BlocksReExecutor: blocksreexecutor.DefaultConfig, + Conf: genericconf.ConfConfigDefault, + Node: arbnode.ConfigDefault, + Execution: gethexec.ConfigDefault, + Validation: valnode.DefaultValidationConfig, + ParentChain: conf.L1ConfigDefault, + Chain: conf.L2ConfigDefault, + LogLevel: "INFO", + LogType: "plaintext", + FileLogging: genericconf.DefaultFileLoggingConfig, + Persistent: conf.PersistentConfigDefault, + HTTP: genericconf.HTTPConfigDefault, + WS: genericconf.WSConfigDefault, + IPC: genericconf.IPCConfigDefault, + Auth: genericconf.AuthRPCConfigDefault, + GraphQL: genericconf.GraphQLConfigDefault, + Metrics: false, + MetricsServer: genericconf.MetricsServerConfigDefault, + Init: conf.InitConfigDefault, + Rpc: genericconf.DefaultRpcConfig, + PProf: false, + PprofCfg: genericconf.PProfDefault, + BlocksReExecutor: blocksreexecutor.DefaultConfig, + EnsureRollupDeployment: true, } func NodeConfigAddOptions(f *flag.FlagSet) { @@ -806,6 +815,7 @@ func NodeConfigAddOptions(f *flag.FlagSet) { conf.InitConfigAddOptions("init", f) genericconf.RpcConfigAddOptions("rpc", f) blocksreexecutor.ConfigAddOptions("blocks-reexecutor", f) + f.Bool("ensure-rollup-deployment", NodeConfigDefault.EnsureRollupDeployment, "before starting the node, wait until the transaction that deployed rollup is finalized") } func (c *NodeConfig) ResolveDirectoryNames() error { From e580afd2ef7347e15b9968421b2c4c4364c37321 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Mon, 26 Aug 2024 14:07:21 +0530 Subject: [PATCH 3/3] address PR comments --- cmd/nitro/nitro.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index f5c37b1643..a6aaf85b05 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -674,6 +674,7 @@ func mainImpl() int { retriesOnError-- } else { currentFinalized = finalized + log.Debug("Finalized block number updated", "finalized", finalized) } case <-ctx.Done(): log.Error("Context done while checking if the rollup deployment tx was finalized")