Skip to content

Commit

Permalink
Merge pull request #389 from ava-labs/remove-buildir-flag-reloaded
Browse files Browse the repository at this point in the history
Revert "Revert "Remove buildir flag reloaded""
  • Loading branch information
felipemadero authored Jan 6, 2023
2 parents 113b02a + d64465d commit dc92b63
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 525 deletions.
11 changes: 9 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *client) Start(ctx context.Context, execPath string, opts ...OpOption) (
req.RootDataDir = &ret.rootDataDir
}
if ret.pluginDir != "" {
req.PluginDir = &ret.pluginDir
req.PluginDir = ret.pluginDir
}
if len(ret.blockchainSpecs) > 0 {
req.BlockchainSpecs = ret.blockchainSpecs
Expand Down Expand Up @@ -238,6 +238,10 @@ func (c *client) AddNode(ctx context.Context, name string, execPath string, opts
SubnetConfigs: ret.subnetConfigs,
}

if ret.pluginDir != "" {
req.PluginDir = ret.pluginDir
}

c.log.Info("add node", zap.String("name", name))
return c.controlc.AddNode(ctx, req)
}
Expand All @@ -255,6 +259,9 @@ func (c *client) RestartNode(ctx context.Context, name string, opts ...OpOption)
if ret.execPath != "" {
req.ExecPath = &ret.execPath
}
if ret.pluginDir != "" {
req.PluginDir = ret.pluginDir
}
if ret.whitelistedSubnets != "" {
req.WhitelistedSubnets = &ret.whitelistedSubnets
}
Expand Down Expand Up @@ -300,7 +307,7 @@ func (c *client) LoadSnapshot(ctx context.Context, snapshotName string, opts ...
req.ExecPath = &ret.execPath
}
if ret.pluginDir != "" {
req.PluginDir = &ret.pluginDir
req.PluginDir = ret.pluginDir
}
if ret.rootDataDir != "" {
req.RootDataDir = &ret.rootDataDir
Expand Down
17 changes: 16 additions & 1 deletion cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ func newAddNodeCommand() *cobra.Command {
"",
"node config as string",
)
cmd.PersistentFlags().StringVar(
&pluginDir,
"plugin-dir",
"",
"[optional] plugin directory",
)
cmd.PersistentFlags().StringVar(
&chainConfigs,
"chain-configs",
Expand Down Expand Up @@ -571,7 +577,9 @@ func addNodeFunc(_ *cobra.Command, args []string) error {
}
defer cli.Close()

opts := []client.OpOption{}
opts := []client.OpOption{
client.WithPluginDir(pluginDir),
}

if addNodeConfig != "" {
ux.Print(log, logging.Yellow.Wrap("WARNING: overriding node configs with custom provided config %s"), addNodeConfig)
Expand Down Expand Up @@ -640,6 +648,12 @@ func newRestartNodeCommand() *cobra.Command {
"",
"whitelisted subnets (comma-separated)",
)
cmd.PersistentFlags().StringVar(
&pluginDir,
"plugin-dir",
"",
"[optional] plugin directory",
)
cmd.PersistentFlags().StringVar(
&chainConfigs,
"chain-configs",
Expand Down Expand Up @@ -672,6 +686,7 @@ func restartNodeFunc(_ *cobra.Command, args []string) error {

opts := []client.OpOption{
client.WithExecPath(avalancheGoBinPath),
client.WithPluginDir(pluginDir),
client.WithWhitelistedSubnets(whitelistedSubnets),
}

Expand Down
2 changes: 1 addition & 1 deletion local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (ln *localNetwork) restartNodesWithWhitelistedSubnets(
delete(nodeConfig.Flags, config.WhitelistedSubnetsKey)

ln.log.Info("removing and adding back the node for whitelisted subnets", zap.String("node-name", nodeName))
if err := ln.restartNode(ctx, nodeName, "", "", nil, nil, nil); err != nil {
if err := ln.restartNode(ctx, nodeName, "", "", "", nil, nil, nil); err != nil {
return err
}

Expand Down
55 changes: 35 additions & 20 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
defaultLogsSubdir = "logs"
// difference between unlock schedule locktime and startime in original genesis
genesisLocktimeStartimeDelta = 2836800
// TODO: replace with config.PluginDirKey when included in avalanchego
PluginDirKey = "plugin-dir"
)

// interface compliance
Expand Down Expand Up @@ -603,7 +605,7 @@ func (ln *localNetwork) addNode(nodeConfig node.Config) (node.Node, error) {
dbDir: nodeData.dbDir,
logsDir: nodeData.logsDir,
config: nodeConfig,
buildDir: nodeData.buildDir,
pluginDir: nodeData.pluginDir,
httpHost: nodeData.httpHost,
attachedPeers: map[string]peer.Peer{},
}
Expand Down Expand Up @@ -791,11 +793,12 @@ func (ln *localNetwork) removeNode(ctx context.Context, nodeName string) error {
}

// Restart [nodeName] using the same config, optionally changing [binaryPath],
// [buildDir], [whitelistedSubnets]
// [whitelistedSubnets]
func (ln *localNetwork) RestartNode(
ctx context.Context,
nodeName string,
binaryPath string,
pluginDir string,
whitelistedSubnets string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
Expand All @@ -804,13 +807,23 @@ func (ln *localNetwork) RestartNode(
ln.lock.Lock()
defer ln.lock.Unlock()

return ln.restartNode(ctx, nodeName, binaryPath, whitelistedSubnets, chainConfigs, upgradeConfigs, subnetConfigs)
return ln.restartNode(
ctx,
nodeName,
binaryPath,
pluginDir,
whitelistedSubnets,
chainConfigs,
upgradeConfigs,
subnetConfigs,
)
}

func (ln *localNetwork) restartNode(
ctx context.Context,
nodeName string,
binaryPath string,
pluginDir string,
whitelistedSubnets string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
Expand All @@ -825,7 +838,9 @@ func (ln *localNetwork) restartNode(

if binaryPath != "" {
nodeConfig.BinaryPath = binaryPath
nodeConfig.Flags[config.BuildDirKey] = filepath.Dir(binaryPath)
}
if pluginDir != "" {
nodeConfig.Flags[PluginDirKey] = pluginDir
}

if whitelistedSubnets != "" {
Expand Down Expand Up @@ -891,13 +906,13 @@ func (ln *localNetwork) setNodeName(nodeConfig *node.Config) error {
}

type buildFlagsReturn struct {
flags []string
apiPort uint16
p2pPort uint16
dbDir string
logsDir string
buildDir string
httpHost string
flags []string
apiPort uint16
p2pPort uint16
dbDir string
logsDir string
pluginDir string
httpHost string
}

// buildFlags returns the:
Expand All @@ -918,8 +933,8 @@ func (ln *localNetwork) buildFlags(
return buildFlagsReturn{}, err
}

// buildDir from all configs for node
buildDir, err := getConfigEntry(nodeConfig.Flags, configFile, config.BuildDirKey, "")
// pluginDir from all configs for node
pluginDir, err := getConfigEntry(nodeConfig.Flags, configFile, PluginDirKey, "")
if err != nil {
return buildFlagsReturn{}, err
}
Expand Down Expand Up @@ -986,12 +1001,12 @@ func (ln *localNetwork) buildFlags(
}

return buildFlagsReturn{
flags: flags,
apiPort: apiPort,
p2pPort: p2pPort,
dbDir: dbDir,
logsDir: logsDir,
buildDir: buildDir,
httpHost: httpHost,
flags: flags,
apiPort: apiPort,
p2pPort: p2pPort,
dbDir: dbDir,
logsDir: logsDir,
pluginDir: pluginDir,
httpHost: httpHost,
}, nil
}
12 changes: 4 additions & 8 deletions local/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"net"
"path/filepath"
"time"

"github.com/ava-labs/avalanche-network-runner/api"
Expand Down Expand Up @@ -66,8 +65,8 @@ type localNode struct {
dbDir string
// The logs dir of the node
logsDir string
// The build dir of the node
buildDir string
// The plugin dir of the node
pluginDir string
// The node config
config node.Config
// The node httpHost
Expand Down Expand Up @@ -218,11 +217,8 @@ func (node *localNode) GetBinaryPath() string {
}

// See node.Node
func (node *localNode) GetBuildDir() string {
if node.buildDir == "" {
return filepath.Dir(node.GetBinaryPath())
}
return node.buildDir
func (node *localNode) GetPluginDir() string {
return node.pluginDir
}

// See node.Node
Expand Down
12 changes: 6 additions & 6 deletions local/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewNetworkFromSnapshot(
rootDir string,
snapshotsDir string,
binaryPath string,
buildDir string,
pluginDir string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
Expand All @@ -53,7 +53,7 @@ func NewNetworkFromSnapshot(
context.Background(),
snapshotName,
binaryPath,
buildDir,
pluginDir,
chainConfigs,
upgradeConfigs,
subnetConfigs,
Expand Down Expand Up @@ -170,7 +170,7 @@ func (ln *localNetwork) loadSnapshot(
ctx context.Context,
snapshotName string,
binaryPath string,
buildDir string,
pluginDir string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
Expand Down Expand Up @@ -219,10 +219,10 @@ func (ln *localNetwork) loadSnapshot(
networkConfig.NodeConfigs[i].BinaryPath = binaryPath
}
}
// replace build dir
if buildDir != "" {
// replace plugin dir
if pluginDir != "" {
for i := range networkConfig.NodeConfigs {
networkConfig.NodeConfigs[i].Flags[config.BuildDirKey] = buildDir
networkConfig.NodeConfigs[i].Flags[PluginDirKey] = pluginDir
}
}
// add chain configs and upgrade configs
Expand Down
2 changes: 1 addition & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Network interface {
// Restart a given node using the same config, optionally changing binary path,
// whitelisted subnets, a map of chain configs, a map of upgrade configs, and
// a map of subnet configs
RestartNode(context.Context, string, string, string, map[string]string, map[string]string, map[string]string) error
RestartNode(context.Context, string, string, string, string, map[string]string, map[string]string, map[string]string) error
// Create the specified blockchains
CreateBlockchains(context.Context, []BlockchainSpec) error
// Create the given numbers of subnets
Expand Down
4 changes: 2 additions & 2 deletions network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type Node interface {
GetDbDir() string
// Return this node's logs dir
GetLogsDir() string
// Return this node's build dir
GetBuildDir() string
// Return this node's plugin dir
GetPluginDir() string
// Return this node's config file contents
GetConfigFile() string
// Return this node's config
Expand Down
Loading

0 comments on commit dc92b63

Please sign in to comment.