diff --git a/cmd/juno/juno.go b/cmd/juno/juno.go index 08ce3f840e..ba291e7dff 100644 --- a/cmd/juno/juno.go +++ b/cmd/juno/juno.go @@ -47,6 +47,7 @@ const ( dbPathF = "db-path" networkF = "network" ethNodeF = "eth-node" + noEthNodeF = "no-eth-node" pprofF = "pprof" pprofHostF = "pprof-host" pprofPortF = "pprof-port" @@ -91,6 +92,7 @@ const ( defaultWS = false defaultWSPort = 6061 defaultEthNode = "" + defaultNoEthNode = false defaultPprof = false defaultPprofPort = 6062 defaultColour = true @@ -145,6 +147,7 @@ const ( colourUsage = "Use `--colour=false` command to disable colourized outputs (ANSI Escape Codes)." ethNodeUsage = "WebSocket endpoint of the Ethereum node. To verify the correctness of the L2 chain, " + "Juno must connect to an Ethereum node and parse events in the Starknet contract." + noEthNodeUsage = "Disables the connection to the Ethereum node." pendingPollIntervalUsage = "Sets how frequently pending block will be updated (0s will disable fetching of pending block)." p2pUsage = "EXPERIMENTAL: Enables p2p server." p2pAddrUsage = "EXPERIMENTAL: Specify p2p listening source address as multiaddr. Example: /ip4/0.0.0.0/tcp/7777" @@ -327,6 +330,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr junoCmd.Flags().String(cnCoreContractAddressF, defaultCNCoreContractAddressStr, networkCustomCoreContractAddressUsage) junoCmd.Flags().IntSlice(cnUnverifiableRangeF, defaultCNUnverifiableRange, networkCustomUnverifiableRange) junoCmd.Flags().String(ethNodeF, defaultEthNode, ethNodeUsage) + junoCmd.Flags().Bool(noEthNodeF, defaultNoEthNode, noEthNodeUsage) junoCmd.Flags().Bool(pprofF, defaultPprof, pprofUsage) junoCmd.Flags().String(pprofHostF, defaulHost, pprofHostUsage) junoCmd.Flags().Uint16(pprofPortF, defaultPprofPort, pprofPortUsage) diff --git a/node/node.go b/node/node.go index 63f0bb132a..52d810d56b 100644 --- a/node/node.go +++ b/node/node.go @@ -60,6 +60,7 @@ type Config struct { DatabasePath string `mapstructure:"db-path"` Network utils.Network `mapstructure:"network"` EthNode string `mapstructure:"eth-node"` + NoEthNode bool `mapstructure:"no-eth-node"` Pprof bool `mapstructure:"pprof"` PprofHost string `mapstructure:"pprof-host"` PprofPort uint16 `mapstructure:"pprof-port"` @@ -273,10 +274,14 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen } if n.cfg.EthNode == "" { - n.log.Warnw("Ethereum node address not found; will not verify against L1") + if n.cfg.NoEthNode { + n.log.Warnw("Ethereum node address not found; will not verify against L1") + } else { + return nil, fmt.Errorf("--eth-node flag is required, you can use --no-eth-node to disable L1 verification") + } } else { var l1Client *l1.Client - l1Client, err = newL1Client(cfg, n.blockchain, n.log) + l1Client, err = newL1Client(cfg.EthNode, cfg.Metrics, n.blockchain, n.log) if err != nil { return nil, fmt.Errorf("create L1 client: %w", err) } @@ -293,26 +298,26 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen return n, nil } -func newL1Client(cfg *Config, chain *blockchain.Blockchain, log utils.SimpleLogger) (*l1.Client, error) { - ethNodeURL, err := url.Parse(cfg.EthNode) +func newL1Client(ethNode string, includeMetrics bool, chain *blockchain.Blockchain, log utils.SimpleLogger) (*l1.Client, error) { + ethNodeURL, err := url.Parse(ethNode) if err != nil { return nil, fmt.Errorf("parse Ethereum node URL: %w", err) } if ethNodeURL.Scheme != "wss" && ethNodeURL.Scheme != "ws" { - return nil, errors.New("non-websocket Ethereum node URL (need wss://... or ws://...): " + cfg.EthNode) + return nil, errors.New("non-websocket Ethereum node URL (need wss://... or ws://...): " + ethNode) } network := chain.Network() var ethSubscriber *l1.EthSubscriber - ethSubscriber, err = l1.NewEthSubscriber(cfg.EthNode, network.CoreContractAddress) + ethSubscriber, err = l1.NewEthSubscriber(ethNode, network.CoreContractAddress) if err != nil { return nil, fmt.Errorf("set up ethSubscriber: %w", err) } l1Client := l1.NewClient(ethSubscriber, chain, log) - if cfg.Metrics { + if includeMetrics { l1Client.WithEventListener(makeL1Metrics()) } return l1Client, nil