Skip to content

Commit a67443b

Browse files
authored
Merge pull request #728 from ava-labs/fuji-subnets
Fuji subnets
2 parents 5042342 + b4600b2 commit a67443b

File tree

16 files changed

+1265
-1043
lines changed

16 files changed

+1265
-1043
lines changed

client/client.go

+13
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ func (c *client) Start(ctx context.Context, execPath string, opts ...OpOption) (
146146
if ret.customNodeConfigs != nil {
147147
req.CustomNodeConfigs = ret.customNodeConfigs
148148
}
149+
if ret.walletPrivateKey != "" {
150+
req.WalletPrivateKey = ret.walletPrivateKey
151+
}
149152
req.ReassignPortsIfUsed = &ret.reassignPortsIfUsed
150153
req.DynamicPorts = &ret.dynamicPorts
151154

@@ -396,6 +399,9 @@ func (c *client) LoadSnapshot(ctx context.Context, snapshotName string, inPlace
396399
if ret.globalNodeConfig != "" {
397400
req.GlobalNodeConfig = &ret.globalNodeConfig
398401
}
402+
if ret.walletPrivateKey != "" {
403+
req.WalletPrivateKey = ret.walletPrivateKey
404+
}
399405
req.ReassignPortsIfUsed = &ret.reassignPortsIfUsed
400406
return c.controlc.LoadSnapshot(ctx, &req)
401407
}
@@ -474,6 +480,7 @@ type Op struct {
474480
reassignPortsIfUsed bool
475481
dynamicPorts bool
476482
networkID uint32
483+
walletPrivateKey string
477484
}
478485

479486
type OpOption func(*Op)
@@ -591,6 +598,12 @@ func WithDynamicPorts(dynamicPorts bool) OpOption {
591598
}
592599
}
593600

601+
func WithWalletPrivateKey(walletPrivateKey string) OpOption {
602+
return func(op *Op) {
603+
op.walletPrivateKey = walletPrivateKey
604+
}
605+
}
606+
594607
func isClientCanceled(ctxErr error, err error) bool {
595608
if ctxErr != nil {
596609
return true

cmd/control/control.go

+94-16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/ava-labs/avalanchego/utils/logging"
2323
"github.com/spf13/cobra"
2424
"go.uber.org/zap"
25+
26+
avagoConstants "github.com/ava-labs/avalanchego/utils/constants"
2527
)
2628

2729
func init() {
@@ -91,22 +93,25 @@ func NewCommand() *cobra.Command {
9193
}
9294

9395
var (
94-
avalancheGoBinPath string
95-
numNodes uint32
96-
pluginDir string
97-
globalNodeConfig string
98-
addNodeConfig string
99-
blockchainSpecsStr string
100-
customNodeConfigs string
101-
rootDataDir string
102-
chainConfigs string
103-
upgradeConfigs string
104-
subnetConfigs string
105-
reassignPortsIfUsed bool
106-
dynamicPorts bool
107-
networkID uint32
108-
force bool
109-
inPlace bool
96+
avalancheGoBinPath string
97+
numNodes uint32
98+
pluginDir string
99+
globalNodeConfig string
100+
addNodeConfig string
101+
blockchainSpecsStr string
102+
customNodeConfigs string
103+
rootDataDir string
104+
chainConfigs string
105+
upgradeConfigs string
106+
subnetConfigs string
107+
reassignPortsIfUsed bool
108+
dynamicPorts bool
109+
networkID uint32
110+
force bool
111+
inPlace bool
112+
fuji bool
113+
walletPrivateKey string
114+
walletPrivateKeyPath string
110115
)
111116

112117
func setLogs() error {
@@ -191,6 +196,12 @@ func newStartCommand() *cobra.Command {
191196
constants.DefaultNumNodes,
192197
"number of nodes of the network",
193198
)
199+
cmd.PersistentFlags().Uint32Var(
200+
&numNodes,
201+
"num-nodes",
202+
constants.DefaultNumNodes,
203+
"number of nodes of the network",
204+
)
194205
cmd.PersistentFlags().StringVar(
195206
&pluginDir,
196207
"plugin-dir",
@@ -257,16 +268,63 @@ func newStartCommand() *cobra.Command {
257268
false,
258269
"true to assign dynamic ports",
259270
)
271+
cmd.PersistentFlags().BoolVar(
272+
&fuji,
273+
"fuji",
274+
false,
275+
"true to set all nodes to join fuji network",
276+
)
277+
cmd.PersistentFlags().StringVar(
278+
&walletPrivateKey,
279+
"wallet-private-key",
280+
"",
281+
"[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern.",
282+
)
283+
cmd.PersistentFlags().StringVar(
284+
&walletPrivateKeyPath,
285+
"wallet-private-key-path",
286+
"",
287+
"[optional] funding wallet private key path",
288+
)
260289
return cmd
261290
}
262291

292+
func setWalletPrivateKeyOptions(opts *[]client.OpOption) error {
293+
if walletPrivateKeyPath != "" && walletPrivateKey != "" {
294+
return fmt.Errorf("only one of wallet-private-key and wallet-private-key-path can be provided")
295+
}
296+
if walletPrivateKey != "" {
297+
ux.Print(log, logging.Yellow.Wrap("funding wallet private key provided: %s"), walletPrivateKey)
298+
*opts = append(*opts, client.WithWalletPrivateKey(walletPrivateKey))
299+
}
300+
if walletPrivateKeyPath != "" {
301+
ux.Print(log, logging.Yellow.Wrap("funding wallet private key path provided: %s"), walletPrivateKeyPath)
302+
// validate if it's a valid private key
303+
if _, err := os.Stat(walletPrivateKey); err != nil {
304+
return fmt.Errorf("wallet private key doesn't exist: %w", err)
305+
}
306+
// read the private key
307+
keyBytes, err := os.ReadFile(walletPrivateKey)
308+
if err != nil {
309+
return fmt.Errorf("failed to read wallet private key: %w", err)
310+
}
311+
*opts = append(*opts, client.WithWalletPrivateKey(string(keyBytes)))
312+
}
313+
return nil
314+
}
315+
263316
func startFunc(*cobra.Command, []string) error {
264317
cli, err := newClient()
265318
if err != nil {
266319
return err
267320
}
268321
defer cli.Close()
269322

323+
if fuji {
324+
networkID = avagoConstants.FujiID
325+
requestTimeout = 5 * time.Hour // increase timeout for fuji network
326+
ux.Print(log, logging.Yellow.Wrap("setting request timeout to "+requestTimeout.String()))
327+
}
270328
opts := []client.OpOption{
271329
client.WithNumNodes(numNodes),
272330
client.WithPluginDir(pluginDir),
@@ -277,6 +335,10 @@ func startFunc(*cobra.Command, []string) error {
277335
client.WithNetworkID(networkID),
278336
}
279337

338+
if err := setWalletPrivateKeyOptions(&opts); err != nil {
339+
return err
340+
}
341+
280342
if globalNodeConfig != "" {
281343
ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes: %s"), globalNodeConfig)
282344
// validate it's valid JSON
@@ -1288,6 +1350,18 @@ func newLoadSnapshotCommand() *cobra.Command {
12881350
false,
12891351
"load snapshot in place, so as it always auto save",
12901352
)
1353+
cmd.PersistentFlags().StringVar(
1354+
&walletPrivateKey,
1355+
"wallet-private-key",
1356+
"",
1357+
"[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern.",
1358+
)
1359+
cmd.PersistentFlags().StringVar(
1360+
&walletPrivateKeyPath,
1361+
"wallet-private-key-path",
1362+
"",
1363+
"[optional] funding wallet private key path",
1364+
)
12911365
return cmd
12921366
}
12931367

@@ -1305,6 +1379,10 @@ func loadSnapshotFunc(_ *cobra.Command, args []string) error {
13051379
client.WithReassignPortsIfUsed(reassignPortsIfUsed),
13061380
}
13071381

1382+
if err := setWalletPrivateKeyOptions(&opts); err != nil {
1383+
return err
1384+
}
1385+
13081386
if chainConfigs != "" {
13091387
chainConfigsMap := make(map[string]string)
13101388
if err := json.Unmarshal([]byte(chainConfigs), &chainConfigsMap); err != nil {

0 commit comments

Comments
 (0)