Skip to content

Commit

Permalink
Add flag to configure L1 chainID for docker nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel committed Sep 21, 2023
1 parent 67c7597 commit 9afbc06
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/node/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type NodeConfigCLI struct {
isInboundP2PDisabled bool
batchInterval string // format like 500ms or 2s (any time parsable by time.ParseDuration())
rollupInterval string // format like 500ms or 2s (any time parsable by time.ParseDuration())
l1ChainID int
}

// ParseConfigCLI returns a NodeConfigCLI based the cli params and defaults.
Expand Down Expand Up @@ -77,6 +78,7 @@ func ParseConfigCLI() *NodeConfigCLI {
isInboundP2PDisabled := flag.Bool(isInboundP2PDisabledFlag, false, flagUsageMap[isInboundP2PDisabledFlag])
batchInterval := flag.String(batchIntervalFlag, "1s", flagUsageMap[batchIntervalFlag])
rollupInterval := flag.String(rollupIntervalFlag, "3s", flagUsageMap[rollupIntervalFlag])
l1ChainID := flag.Int(l1ChainIDFlag, 1337, flagUsageMap[l1ChainIDFlag])

flag.Parse()
cfg.nodeName = *nodeName
Expand Down Expand Up @@ -106,6 +108,7 @@ func ParseConfigCLI() *NodeConfigCLI {
cfg.isInboundP2PDisabled = *isInboundP2PDisabled
cfg.batchInterval = *batchInterval
cfg.rollupInterval = *rollupInterval
cfg.l1ChainID = *l1ChainID

cfg.nodeAction = flag.Arg(0)
if !validateNodeAction(cfg.nodeAction) {
Expand Down
2 changes: 2 additions & 0 deletions go/node/cmd/cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
isInboundP2PDisabledFlag = "is_inbound_p2p_disabled"
batchIntervalFlag = "batch_interval"
rollupIntervalFlag = "rollup_interval"
l1ChainIDFlag = "l1_chain_id"
)

// Returns a map of the flag usages.
Expand Down Expand Up @@ -62,5 +63,6 @@ func getFlagUsageMap() map[string]string {
isInboundP2PDisabledFlag: "Disables inbound p2p (for testing)",
batchIntervalFlag: "Duration between each batch. Can be formatted like 500ms or 1s",
rollupIntervalFlag: "Duration between each rollup. Can be formatted like 500ms or 1s",
l1ChainIDFlag: "Chain ID of the L1 network",
}
}
1 change: 1 addition & 0 deletions go/node/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
node.WithInboundP2PDisabled(cliConfig.isInboundP2PDisabled),
node.WithBatchInterval(cliConfig.batchInterval),
node.WithRollupInterval(cliConfig.rollupInterval),
node.WithL1ChainID(cliConfig.l1ChainID),
)

dockerNode := node.NewDockerNode(nodeCfg)
Expand Down
8 changes: 8 additions & 0 deletions go/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Config struct {
l1BlockTime time.Duration
batchInterval string
rollupInterval string
l1ChainID int
}

func NewNodeConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -114,6 +115,7 @@ func (c *Config) ToHostConfig() *config.HostInputConfig {
cfg.SequencerID = gethcommon.HexToAddress(c.sequencerID)
cfg.IsInboundP2PDisabled = c.isInboundP2PDisabled
cfg.L1BlockTime = c.l1BlockTime
cfg.L1ChainID = int64(c.l1ChainID)

return cfg
}
Expand Down Expand Up @@ -311,3 +313,9 @@ func WithRollupInterval(d string) Option {
c.rollupInterval = d
}
}

func WithL1ChainID(i int) Option {
return func(c *Config) {
c.l1ChainID = i
}
}
1 change: 1 addition & 0 deletions go/node/docker_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (d *DockerNode) startHost() error {
fmt.Sprintf("-rollupInterval=%s", d.cfg.rollupInterval),
fmt.Sprintf("-logLevel=%d", d.cfg.logLevel),
fmt.Sprintf("-isInboundP2PDisabled=%t", d.cfg.isInboundP2PDisabled),
fmt.Sprintf("-l1ChainID=%d", d.cfg.l1ChainID),
}
if !d.cfg.hostInMemDB {
cmd = append(cmd, "-levelDBPath", _hostDataDir)
Expand Down

0 comments on commit 9afbc06

Please sign in to comment.