diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 2664687b..fce96402 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -4,8 +4,6 @@ on: push: branches: - main - tags: - - "*" pull_request: permissions: diff --git a/local/network.go b/local/network.go index d07660a0..6bcbc761 100644 --- a/local/network.go +++ b/local/network.go @@ -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 @@ -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{}, } @@ -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, @@ -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 != "" { @@ -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: @@ -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 } @@ -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 } diff --git a/local/node.go b/local/node.go index ed364582..6b6dbf4c 100644 --- a/local/node.go +++ b/local/node.go @@ -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 @@ -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 diff --git a/local/snapshot.go b/local/snapshot.go index d7b250d3..181ac280 100644 --- a/local/snapshot.go +++ b/local/snapshot.go @@ -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, @@ -53,7 +53,7 @@ func NewNetworkFromSnapshot( context.Background(), snapshotName, binaryPath, - buildDir, + pluginDir, chainConfigs, upgradeConfigs, subnetConfigs, @@ -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, @@ -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 diff --git a/network/node/node.go b/network/node/node.go index 90ab6c2d..a8dcfa2e 100644 --- a/network/node/node.go +++ b/network/node/node.go @@ -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 diff --git a/server/network.go b/server/network.go index 2430b9ed..24053129 100644 --- a/server/network.go +++ b/server/network.go @@ -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 @@ -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` @@ -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) @@ -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 } @@ -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 @@ -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 { @@ -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, @@ -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(), @@ -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, } @@ -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 diff --git a/server/server.go b/server/server.go index 2fa1fe49..115c8a1d 100644 --- a/server/server.go +++ b/server/server.go @@ -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)) @@ -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,