Skip to content

Commit

Permalink
Revert "Revert "Remove buildir flag reloaded""
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Jan 5, 2023
1 parent 6d39aae commit 6fae305
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 80 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- main
tags:
- "*"
pull_request:

permissions:
Expand Down
41 changes: 22 additions & 19 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,7 +793,7 @@ 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,
Expand Down Expand Up @@ -825,7 +827,8 @@ func (ln *localNetwork) restartNode(

if binaryPath != "" {
nodeConfig.BinaryPath = binaryPath
nodeConfig.Flags[config.BuildDirKey] = filepath.Dir(binaryPath)
// remove old value if present, to look for vm binaries in new binary path location
delete(nodeConfig.Flags, PluginDirKey)
}

if whitelistedSubnets != "" {
Expand Down Expand Up @@ -891,13 +894,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 +921,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 +989,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: 6 additions & 6 deletions local/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,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 @@ -223,11 +223,11 @@ func (node *localNode) GetBinaryPath() string {
}

// See node.Node
func (node *localNode) GetBuildDir() string {
if node.buildDir == "" {
return filepath.Dir(node.GetBinaryPath())
func (node *localNode) GetPluginDir() string {
if node.pluginDir == "" {
return filepath.Join(filepath.Dir(node.GetBinaryPath()), "plugins")
}
return node.buildDir
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
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
55 changes: 15 additions & 40 deletions server/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
)

const (
// TODO: replace with config.PluginDirKey when included in avalanchego
PluginDirKey = "plugin-dir"
)

type localNetwork struct {
log logging.Logger

Expand Down Expand Up @@ -140,6 +145,12 @@ func (lc *localNetwork) createConfig() error {
for k, v := range globalConfig {
cfg.Flags[k] = v
}
if lc.pluginDir != "" {
cfg.Flags[PluginDirKey] = lc.pluginDir
}
if lc.options.whitelistedSubnets != "" {
cfg.Flags[config.WhitelistedSubnetsKey] = lc.options.whitelistedSubnets
}

for i := range cfg.NodeConfigs {
// NOTE: Naming convention for node names is currently `node` + number, i.e. `node1,node2,node3,...node101`
Expand All @@ -164,12 +175,6 @@ func (lc *localNetwork) createConfig() error {
cfg.NodeConfigs[i].Flags = map[string]interface{}{}
}

// avalanchego expects buildDir (parent dir of pluginDir) to be provided at cmdline
buildDir, err := getBuildDir(lc.execPath, lc.pluginDir)
if err != nil {
return err
}

if lc.options.dynamicPorts {
// remove http port defined in local network config, to get dynamic port generation
delete(cfg.NodeConfigs[i].Flags, config.HTTPPortKey)
Expand All @@ -178,9 +183,7 @@ func (lc *localNetwork) createConfig() error {

cfg.NodeConfigs[i].Flags[config.LogsDirKey] = logDir
cfg.NodeConfigs[i].Flags[config.DBPathKey] = dbDir
if buildDir != "" {
cfg.NodeConfigs[i].Flags[config.BuildDirKey] = buildDir
}

if lc.options.whitelistedSubnets != "" {
cfg.NodeConfigs[i].Flags[config.WhitelistedSubnetsKey] = lc.options.whitelistedSubnets
}
Expand All @@ -205,24 +208,6 @@ func (lc *localNetwork) createConfig() error {
return nil
}

// generates buildDir from pluginDir, and if not available, from execPath
// returns error if pluginDir is non empty and invalid
func getBuildDir(execPath string, pluginDir string) (string, error) {
buildDir := ""
if execPath != "" {
buildDir = filepath.Dir(execPath)
}
if pluginDir != "" {
pluginDir := filepath.Clean(pluginDir)
if filepath.Base(pluginDir) != "plugins" {
return "", fmt.Errorf("plugin dir %q is not named plugins", pluginDir)
}
buildDir = filepath.Dir(pluginDir)
}

return buildDir, nil
}

func (lc *localNetwork) start() error {
if err := lc.createConfig(); err != nil {
return err
Expand Down Expand Up @@ -361,11 +346,6 @@ func (lc *localNetwork) loadSnapshot(
) error {
ux.Print(lc.log, logging.Blue.Wrap(logging.Bold.Wrap("create and run local network from snapshot")))

buildDir, err := getBuildDir(lc.execPath, lc.pluginDir)
if err != nil {
return err
}

var globalNodeConfig map[string]interface{}
if lc.options.globalNodeConfig != "" {
if err := json.Unmarshal([]byte(lc.options.globalNodeConfig), &globalNodeConfig); err != nil {
Expand All @@ -379,7 +359,7 @@ func (lc *localNetwork) loadSnapshot(
lc.options.rootDataDir,
lc.options.snapshotsDir,
lc.execPath,
buildDir,
lc.pluginDir,
lc.options.chainConfigs,
lc.options.upgradeConfigs,
lc.options.subnetConfigs,
Expand Down Expand Up @@ -482,15 +462,10 @@ func (lc *localNetwork) updateNodeInfo() error {
lc.nodeInfos = make(map[string]*rpcpb.NodeInfo)
for _, name := range lc.nodeNames {
node := nodes[name]
var pluginDir string
whitelistedSubnets, err := node.GetFlag(config.WhitelistedSubnetsKey)
if err != nil {
return err
}
buildDir := node.GetBuildDir()
if buildDir != "" {
pluginDir = filepath.Join(buildDir, "plugins")
}

lc.nodeInfos[name] = &rpcpb.NodeInfo{
Name: node.GetName(),
Expand All @@ -500,7 +475,7 @@ func (lc *localNetwork) updateNodeInfo() error {
LogDir: node.GetLogsDir(),
DbDir: node.GetDbDir(),
Config: []byte(node.GetConfigFile()),
PluginDir: pluginDir,
PluginDir: node.GetPluginDir(),
WhitelistedSubnets: whitelistedSubnets,
}

Expand All @@ -509,7 +484,7 @@ func (lc *localNetwork) updateNodeInfo() error {
lc.execPath = node.GetBinaryPath()
}
if lc.pluginDir == "" {
lc.pluginDir = pluginDir
lc.pluginDir = node.GetPluginDir()
}
}
return nil
Expand Down
7 changes: 2 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,10 @@ func (s *server) Start(ctx context.Context, req *rpcpb.StartRequest) (*rpcpb.Sta
if err := utils.CheckExecPath(req.GetExecPath()); err != nil {
return nil, err
}
pluginDir := ""
pluginDir := filepath.Join(filepath.Dir(req.GetExecPath()), "plugins")
if req.GetPluginDir() != "" {
pluginDir = req.GetPluginDir()
}
if pluginDir == "" {
pluginDir = filepath.Join(filepath.Dir(req.GetExecPath()), "plugins")
}
chainSpecs := []network.BlockchainSpec{}
if len(req.GetBlockchainSpecs()) > 0 {
s.log.Info("plugin-dir:", zap.String("plugin-dir", pluginDir))
Expand Down Expand Up @@ -331,7 +328,7 @@ func (s *server) Start(ctx context.Context, req *rpcpb.StartRequest) (*rpcpb.Sta
numNodes: numNodes,
whitelistedSubnets: whitelistedSubnets,
redirectNodesOutput: s.cfg.RedirectNodesOutput,
pluginDir: pluginDir,
pluginDir: req.GetPluginDir(),
globalNodeConfig: globalNodeConfig,
customNodeConfigs: customNodeConfigs,
chainConfigs: req.ChainConfigs,
Expand Down

0 comments on commit 6fae305

Please sign in to comment.