Skip to content

Commit 7690238

Browse files
committed
feat: introduce bootstrap command and move previous commands to raft
1 parent dc05f43 commit 7690238

13 files changed

Lines changed: 2182 additions & 87 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package bootstrap
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/urfave/cli/v2"
8+
9+
"github.com/ethereum-optimism/optimism/op-conductor/conductor"
10+
opcflags "github.com/ethereum-optimism/optimism/op-conductor/flags"
11+
opservice "github.com/ethereum-optimism/optimism/op-service"
12+
"github.com/ethereum-optimism/optimism/op-service/cliapp"
13+
oplog "github.com/ethereum-optimism/optimism/op-service/log"
14+
bootstrapconductor "github.com/golem-base/op-conductor-init/pkg/conductor"
15+
)
16+
17+
func Command() *cli.Command {
18+
return &cli.Command{
19+
Name: "bootstrap",
20+
Usage: "Bootstrap commands for op-conductor initialization",
21+
Description: "Commands for bootstrapping op-conductor clusters and related operations",
22+
Subcommands: []*cli.Command{
23+
{
24+
Name: "cluster",
25+
Usage: "Bootstrap a new op-conductor cluster",
26+
Description: "Initialize and bootstrap a new op-conductor cluster with the specified configuration",
27+
Action: cliapp.LifecycleCmd(BootstrapClusterMain),
28+
Flags: cliapp.ProtectFlags(opcflags.Flags),
29+
},
30+
},
31+
}
32+
}
33+
34+
// BootstrapClusterMain handles the bootstrap cluster subcommand with lifecycle management
35+
func BootstrapClusterMain(ctx *cli.Context, closeApp context.CancelCauseFunc) (cliapp.Lifecycle, error) {
36+
logCfg := oplog.ReadCLIConfig(ctx)
37+
log := oplog.NewLogger(oplog.AppOut(ctx), logCfg)
38+
oplog.SetGlobalLogHandler(log.Handler())
39+
opservice.ValidateEnvVars(opcflags.EnvVarPrefix, opcflags.Flags, log)
40+
41+
cfg, err := conductor.NewConfig(ctx, log)
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to read config: %w", err)
44+
}
45+
46+
// We don't need the RaftAutoBootstrapNetwork flag anymore
47+
// Our custom OpConductor always auto-bootstraps when there's no unsafe head
48+
log.Info("Bootstrap operation will auto-bootstrap from execution layer when needed")
49+
50+
// Metrics are created internally by our custom OpConductor
51+
52+
// Use our custom OpConductor from service.go that has auto-bootstrap built in
53+
c, err := bootstrapconductor.New(
54+
ctx.Context,
55+
cfg,
56+
log,
57+
"bootstrap-v1.0.0", // Version string for bootstrap
58+
)
59+
if err != nil {
60+
return nil, fmt.Errorf("failed to create conductor: %w", err)
61+
}
62+
63+
return c, nil
64+
}

cmd/op-conductor-init/main.go

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package main
22

33
import (
4+
"context"
45
"os"
56

67
"github.com/ethereum/go-ethereum/log"
78
"github.com/urfave/cli/v2"
89

910
opservice "github.com/ethereum-optimism/optimism/op-service"
10-
"github.com/ethereum-optimism/optimism/op-service/cliapp"
11+
"github.com/ethereum-optimism/optimism/op-service/ctxinterrupt"
1112
oplog "github.com/ethereum-optimism/optimism/op-service/log"
12-
"github.com/golem-base/op-conductor-init/pkg/flags"
13+
"github.com/golem-base/op-conductor-init/cmd/op-conductor-init/bootstrap"
14+
"github.com/golem-base/op-conductor-init/cmd/op-conductor-init/raft"
1315
)
1416

1517
var (
@@ -27,83 +29,12 @@ func main() {
2729
app.Usage = "Initialize Raft state for op-conductor clusters"
2830
app.Description = "Tool to initialize Raft state files for op-conductor high-availability clusters"
2931
app.Commands = []*cli.Command{
30-
{
31-
Name: "generate",
32-
Usage: "Generate pre-configured Raft state",
33-
Description: "Generate Raft state files for all nodes in the cluster",
34-
Action: GenerateAction,
35-
Flags: cliapp.ProtectFlags(flags.Flags),
36-
},
37-
{
38-
Name: "verify",
39-
Usage: "Verify generated Raft state",
40-
Description: "Inspect and verify the contents of generated Raft state files",
41-
Action: VerifyAction,
42-
Flags: cliapp.ProtectFlags([]cli.Flag{
43-
&cli.StringFlag{
44-
Name: "state-dir",
45-
Usage: "Directory containing raft state files to verify",
46-
Required: true,
47-
},
48-
}),
49-
},
50-
{
51-
Name: "info",
52-
Usage: "Show detailed information about Raft state",
53-
Description: "Display comprehensive information about the Raft state including term, leader, and configuration",
54-
Action: InfoAction,
55-
Flags: cliapp.ProtectFlags([]cli.Flag{
56-
&cli.StringFlag{
57-
Name: "state-dir",
58-
Usage: "Directory containing raft state files",
59-
Required: true,
60-
},
61-
}),
62-
},
63-
{
64-
Name: "backup",
65-
Usage: "Backup Raft state files",
66-
Description: "Create a timestamped backup of Raft state files",
67-
Action: BackupAction,
68-
Flags: cliapp.ProtectFlags([]cli.Flag{
69-
&cli.StringFlag{
70-
Name: "state-dir",
71-
Usage: "Directory containing raft state files to backup",
72-
Required: true,
73-
},
74-
&cli.StringFlag{
75-
Name: "backup-dir",
76-
Usage: "Directory where backup will be created",
77-
Required: true,
78-
},
79-
}),
80-
},
81-
{
82-
Name: "restore",
83-
Usage: "Restore Raft state from backup",
84-
Description: "Restore Raft state files from a previous backup",
85-
Action: RestoreAction,
86-
Flags: cliapp.ProtectFlags([]cli.Flag{
87-
&cli.StringFlag{
88-
Name: "backup-dir",
89-
Usage: "Directory containing the backup to restore",
90-
Required: true,
91-
},
92-
&cli.StringFlag{
93-
Name: "state-dir",
94-
Usage: "Directory where state will be restored",
95-
Required: true,
96-
},
97-
&cli.BoolFlag{
98-
Name: "force",
99-
Usage: "Force restore without confirmation prompts",
100-
Value: false,
101-
},
102-
}),
103-
},
32+
raft.Command(),
33+
bootstrap.Command(),
10434
}
10535

106-
err := app.Run(os.Args)
36+
ctx := ctxinterrupt.WithSignalWaiterMain(context.Background())
37+
err := app.RunContext(ctx, os.Args)
10738
if err != nil {
10839
log.Crit("Application failed", "message", err)
10940
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package raft
22

33
import (
44
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package raft
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package raft
22

33
import (
44
"encoding/binary"

cmd/op-conductor-init/raft/raft.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package raft
2+
3+
import (
4+
"github.com/urfave/cli/v2"
5+
6+
"github.com/ethereum-optimism/optimism/op-service/cliapp"
7+
"github.com/golem-base/op-conductor-init/pkg/flags"
8+
)
9+
10+
func Command() *cli.Command {
11+
return &cli.Command{
12+
Name: "raft",
13+
Usage: "Raft state management commands",
14+
Description: "Commands for initializing and managing Raft state files for op-conductor high-availability clusters",
15+
Subcommands: []*cli.Command{
16+
{
17+
Name: "generate",
18+
Usage: "Generate pre-configured Raft state",
19+
Description: "Generate Raft state files for all nodes in the cluster",
20+
Action: GenerateAction,
21+
Flags: cliapp.ProtectFlags(flags.Flags),
22+
},
23+
{
24+
Name: "verify",
25+
Usage: "Verify generated Raft state",
26+
Description: "Inspect and verify the contents of generated Raft state files",
27+
Action: VerifyAction,
28+
Flags: cliapp.ProtectFlags([]cli.Flag{
29+
flags.StateDirFlag,
30+
}),
31+
},
32+
{
33+
Name: "info",
34+
Usage: "Show detailed information about Raft state",
35+
Description: "Display comprehensive information about the Raft state including term, leader, and configuration",
36+
Action: InfoAction,
37+
Flags: cliapp.ProtectFlags([]cli.Flag{
38+
flags.StateDirFlag,
39+
}),
40+
},
41+
{
42+
Name: "backup",
43+
Usage: "Backup Raft state files",
44+
Description: "Create a timestamped backup of Raft state files",
45+
Action: BackupAction,
46+
Flags: cliapp.ProtectFlags([]cli.Flag{
47+
flags.StateDirFlag,
48+
flags.BackupDirFlag,
49+
}),
50+
},
51+
{
52+
Name: "restore",
53+
Usage: "Restore Raft state from backup",
54+
Description: "Restore Raft state files from a previous backup",
55+
Action: RestoreAction,
56+
Flags: cliapp.ProtectFlags([]cli.Flag{
57+
flags.BackupDirFlag,
58+
flags.StateDirFlag,
59+
flags.RestoreForceFlag,
60+
}),
61+
},
62+
},
63+
}
64+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package raft
22

33
import (
44
"bufio"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package raft
22

33
import (
44
"encoding/binary"

0 commit comments

Comments
 (0)