Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuji subnets #728

Merged
merged 26 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func (c *client) Start(ctx context.Context, execPath string, opts ...OpOption) (
if ret.customNodeConfigs != nil {
req.CustomNodeConfigs = ret.customNodeConfigs
}
if ret.walletPrivateKey != "" {
req.WalletPrivateKey = ret.walletPrivateKey
}
req.ReassignPortsIfUsed = &ret.reassignPortsIfUsed
req.DynamicPorts = &ret.dynamicPorts

Expand Down Expand Up @@ -396,6 +399,9 @@ func (c *client) LoadSnapshot(ctx context.Context, snapshotName string, inPlace
if ret.globalNodeConfig != "" {
req.GlobalNodeConfig = &ret.globalNodeConfig
}
if ret.walletPrivateKey != "" {
req.WalletPrivateKey = ret.walletPrivateKey
}
req.ReassignPortsIfUsed = &ret.reassignPortsIfUsed
return c.controlc.LoadSnapshot(ctx, &req)
}
Expand Down Expand Up @@ -474,6 +480,7 @@ type Op struct {
reassignPortsIfUsed bool
dynamicPorts bool
networkID uint32
walletPrivateKey string
}

type OpOption func(*Op)
Expand Down Expand Up @@ -591,6 +598,12 @@ func WithDynamicPorts(dynamicPorts bool) OpOption {
}
}

func WithWalletPrivateKey(walletPrivateKey string) OpOption {
return func(op *Op) {
op.walletPrivateKey = walletPrivateKey
}
}

func isClientCanceled(ctxErr error, err error) bool {
if ctxErr != nil {
return true
Expand Down
110 changes: 94 additions & 16 deletions cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
"go.uber.org/zap"

avagoConstants "github.com/ava-labs/avalanchego/utils/constants"
)

func init() {
Expand Down Expand Up @@ -91,22 +93,25 @@ func NewCommand() *cobra.Command {
}

var (
avalancheGoBinPath string
numNodes uint32
pluginDir string
globalNodeConfig string
addNodeConfig string
blockchainSpecsStr string
customNodeConfigs string
rootDataDir string
chainConfigs string
upgradeConfigs string
subnetConfigs string
reassignPortsIfUsed bool
dynamicPorts bool
networkID uint32
force bool
inPlace bool
avalancheGoBinPath string
numNodes uint32
pluginDir string
globalNodeConfig string
addNodeConfig string
blockchainSpecsStr string
customNodeConfigs string
rootDataDir string
chainConfigs string
upgradeConfigs string
subnetConfigs string
reassignPortsIfUsed bool
dynamicPorts bool
networkID uint32
force bool
inPlace bool
fuji bool
walletPrivateKey string
walletPrivateKeyPath string
)

func setLogs() error {
Expand Down Expand Up @@ -191,6 +196,12 @@ func newStartCommand() *cobra.Command {
constants.DefaultNumNodes,
"number of nodes of the network",
)
cmd.PersistentFlags().Uint32Var(
&numNodes,
"num-nodes",
constants.DefaultNumNodes,
"number of nodes of the network",
)
cmd.PersistentFlags().StringVar(
&pluginDir,
"plugin-dir",
Expand Down Expand Up @@ -257,16 +268,63 @@ func newStartCommand() *cobra.Command {
false,
"true to assign dynamic ports",
)
cmd.PersistentFlags().BoolVar(
&fuji,
"fuji",
false,
"true to set all nodes to join fuji network",
)
cmd.PersistentFlags().StringVar(
&walletPrivateKey,
"wallet-private-key",
"",
"[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern.",
)
cmd.PersistentFlags().StringVar(
&walletPrivateKeyPath,
"wallet-private-key-path",
"",
"[optional] funding wallet private key path",
)
return cmd
}

func setWalletPrivateKeyOptions(opts *[]client.OpOption) error {
if walletPrivateKeyPath != "" && walletPrivateKey != "" {
return fmt.Errorf("only one of wallet-private-key and wallet-private-key-path can be provided")
}
if walletPrivateKey != "" {
ux.Print(log, logging.Yellow.Wrap("funding wallet private key provided: %s"), walletPrivateKey)
*opts = append(*opts, client.WithWalletPrivateKey(walletPrivateKey))
}
if walletPrivateKeyPath != "" {
ux.Print(log, logging.Yellow.Wrap("funding wallet private key path provided: %s"), walletPrivateKeyPath)
// validate if it's a valid private key
if _, err := os.Stat(walletPrivateKey); err != nil {
return fmt.Errorf("wallet private key doesn't exist: %w", err)
}
// read the private key
keyBytes, err := os.ReadFile(walletPrivateKey)
if err != nil {
return fmt.Errorf("failed to read wallet private key: %w", err)
}
*opts = append(*opts, client.WithWalletPrivateKey(string(keyBytes)))
}
return nil
}

func startFunc(*cobra.Command, []string) error {
cli, err := newClient()
if err != nil {
return err
}
defer cli.Close()

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

if err := setWalletPrivateKeyOptions(&opts); err != nil {
return err
}

if globalNodeConfig != "" {
ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes: %s"), globalNodeConfig)
// validate it's valid JSON
Expand Down Expand Up @@ -1288,6 +1350,18 @@ func newLoadSnapshotCommand() *cobra.Command {
false,
"load snapshot in place, so as it always auto save",
)
cmd.PersistentFlags().StringVar(
&walletPrivateKey,
"wallet-private-key",
"",
"[optional] funding wallet private key. Please consider using `wallet-private-key-path` if security is a concern.",
)
cmd.PersistentFlags().StringVar(
&walletPrivateKeyPath,
"wallet-private-key-path",
"",
"[optional] funding wallet private key path",
)
return cmd
}

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

if err := setWalletPrivateKeyOptions(&opts); err != nil {
return err
}

if chainConfigs != "" {
chainConfigsMap := make(map[string]string)
if err := json.Unmarshal([]byte(chainConfigs), &chainConfigsMap); err != nil {
Expand Down
Loading
Loading