Skip to content

Commit 8ef7ea8

Browse files
felipemaderogithub-actions[bot]meaghanfitzgeraldgithub-advanced-security[bot]
authored
Localclusters tmpnet (#2680)
* start/stop/clean start working for basic local network * add missing files * goimports * move network load and stop inside tmpnet file * improve bootstrapping status check and have better names for localnet info * centralize tmpnet usage. fix status partially * make network start to use given avalanchego * some refactors * more refactoring * cleanup * refactor * preparing to work on track * move blockchain boostrapping check to tmpnet * added blockchain config stuff * saving RPCs into sidecar * local network non sovereign flow kind of migrated * add missing file * adding health info to status * fixed output * lint * fix go.mod * fix licenses * make clean to not fail if no network up * add wait before setting aliases * only set aliases on validators * improve alias and bootstrap check functions to base on subnet id * rm debugging print * fix for a e2e * fix more e2e * more fixes * e2e fix attempt * fixes to pass e2e * use GetApp() on all tests * add some comments * move helpers to application * fix uris inside tmpnet wrapper * add some comments * avoid using latest on network restart * nit * e2e * fix e2e * chore: Update MD files [skip ci] * empty * chore: Update MD files [skip ci] * e2e * nit * chore: Update MD files [skip ci] * chore: Update MD files [skip ci] * use fixed ANR * chore: Update MD files [skip ci] * more fixes * chore: Update MD files [skip ci] * add back script * chore: Update MD files [skip ci] * reformatting and comments * rename app function to better reflect it is local clusters * i * Update cmd/networkcmd/start.go Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org> Signed-off-by: felipemadero <felipe.madero@gmail.com> * address PR comment * replace functions related to removal * preparing for start * put network connection info in separate struct * add network id to create params * further steps into connecting to local network * implemented cluster lists * save tracked subnets * add mising file * add log as param to db downloader * fuji connection working * improve stop * basic cluster load working, not same port * address RS comments * address MN comments part 1 * address MN comments 2 * mode blockchain info stuff to its own file * don't write avalanchego path into extra local network data * simplify running check * added deadline check to busy wait * add per node chain config * e2e fix * fix e2e * nit * lets make this work * fix e2e * fix e2e? * filter not running bootstrappers * addres MN comments * address MN comments * go run * lint * rename function * status * nit * status working * add port persistence * correctly pass in the local network genesis * sort out some avago binary def stuff * partial work * output improvements * remove ANR VMID usage * relayer reconf * mid work * lint * nit * adding node starts working * remove more stuff * nit * add mising file * Potential fix for code scanning alert no. 49: Incorrect conversion between integer types Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: felipemadero <felipe.madero@gmail.com> * fix network e2e * e2e * more e2e * e2e... * e2e * remove 2 anr refs * use latest relayer release * add migrate skel * nit * remove anr server start code * filtered clusters to migrate * migration working * migration * nit * almost working * migration added * disable migration for the moment * adding local network cluster migration * nit * nit * nit * start adding local relayer stop/start to migration * near * nit * also cp evm data * local network working * lint * add multiple relayer kinds to migration * stop/start relayer based on network kind * add port spec + alias to addValidator * prepare for review * nit * nit * lint * address RS comments * set up aliases only for local network clusters * avoid retrieving subnet validators * bump avago * fix e2e * address RS comments --------- Signed-off-by: felipemadero <felipe.madero@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 38d2a84 commit 8ef7ea8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2568
-2203
lines changed

.golangci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# https://golangci-lint.run/usage/configuration/
22
run:
3-
go: "1.21.7"
3+
go: "1.23.7"
44
timeout: 10m
55

66
issues:
@@ -19,7 +19,7 @@ linters:
1919
- depguard
2020
- errcheck
2121
- errorlint
22-
- exportloopref
22+
- copyloopvar
2323
- goconst
2424
- gocritic
2525
- gofmt
@@ -105,6 +105,7 @@ linters-settings:
105105
excludes:
106106
- G107 # https://securego.io/docs/rules/g107.html
107107
- G204
108+
- G115 # TODO: include it again
108109
depguard:
109110
rules:
110111
packages:

cmd/backendcmd/spawn_server.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

cmd/blockchaincmd/add_validator.go

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/ava-labs/avalanche-cli/pkg/contract"
1515
"github.com/ava-labs/avalanche-cli/pkg/evm"
1616
"github.com/ava-labs/avalanche-cli/pkg/keychain"
17+
"github.com/ava-labs/avalanche-cli/pkg/localnet"
1718
"github.com/ava-labs/avalanche-cli/pkg/models"
1819
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
19-
"github.com/ava-labs/avalanche-cli/pkg/node"
2020
"github.com/ava-labs/avalanche-cli/pkg/prompts"
2121
"github.com/ava-labs/avalanche-cli/pkg/subnet"
2222
"github.com/ava-labs/avalanche-cli/pkg/txutils"
@@ -25,7 +25,6 @@ import (
2525
"github.com/ava-labs/avalanche-cli/pkg/validatormanager"
2626
sdkutils "github.com/ava-labs/avalanche-cli/sdk/utils"
2727
"github.com/ava-labs/avalanche-cli/sdk/validator"
28-
"github.com/ava-labs/avalanchego/config"
2928
"github.com/ava-labs/avalanchego/ids"
3029
avagoconstants "github.com/ava-labs/avalanchego/utils/constants"
3130
"github.com/ava-labs/avalanchego/utils/formatting/address"
@@ -68,6 +67,8 @@ var (
6867
createLocalValidator bool
6968
externalValidatorManagerOwner bool
7069
validatorManagerOwner string
70+
httpPort uint32
71+
stakingPort uint32
7172
)
7273

7374
const (
@@ -129,6 +130,8 @@ Testnet or Mainnet.`,
129130
cmd.Flags().StringVar(&validatorManagerOwner, "validator-manager-owner", "", "force using this address to issue transactions to the validator manager")
130131
cmd.Flags().BoolVar(&externalValidatorManagerOwner, "external-evm-signature", false, "set this value to true when signing validator manager tx outside of cli (for multisig or ledger)")
131132
cmd.Flags().StringVar(&initiateTxHash, "initiate-tx-hash", "", "initiate tx is already issued, with the given hash")
133+
cmd.Flags().Uint32Var(&httpPort, "http-port", 0, "http port for node")
134+
cmd.Flags().Uint32Var(&stakingPort, "staking-port", 0, "staking port for node")
132135

133136
return cmd
134137
}
@@ -222,7 +225,7 @@ func addValidator(cmd *cobra.Command, args []string) error {
222225
sovereign := sc.Sovereign
223226

224227
if nodeEndpoint != "" {
225-
nodeIDStr, publicKey, pop, err = node.GetNodeData(nodeEndpoint)
228+
nodeIDStr, publicKey, pop, err = utils.GetNodeID(nodeEndpoint)
226229
if err != nil {
227230
return err
228231
}
@@ -264,53 +267,30 @@ func addValidator(cmd *cobra.Command, args []string) error {
264267
subnetID := sc.Networks[network.Name()].SubnetID
265268

266269
// if user chose to upsize a local node to add another local validator
270+
var localValidatorClusterName string
267271
if createLocalValidator {
268-
anrSettings := node.ANRSettings{}
269-
nodeConfig := map[string]interface{}{}
270-
ux.Logger.PrintToUser("Creating a new Avalanche node on local machine to add as a new validator to blockchain %s", blockchainName)
271-
if app.AvagoNodeConfigExists(blockchainName) {
272-
nodeConfig, err = utils.ReadJSON(app.GetAvagoNodeConfigPath(blockchainName))
273-
if err != nil {
274-
return err
275-
}
276-
}
277-
if partialSync {
278-
nodeConfig[config.PartialSyncPrimaryNetworkKey] = true
279-
}
280-
avalancheGoBinPath, err := node.GetLocalNodeAvalancheGoBinPath()
272+
// TODO: make this to work even if there is no local cluster for the blockchain and network
273+
targetClusters, err := localnet.GetFilteredLocalClusters(app, true, network, blockchainName)
281274
if err != nil {
282-
return fmt.Errorf("failed to get local node avalanche go bin path: %w", err)
283-
}
284-
285-
nodeName := ""
286-
blockchainID := sc.Networks[network.Name()].BlockchainID
287-
288-
if nodeName, err = node.UpsizeLocalNode(
289-
app,
290-
network,
291-
blockchainName,
292-
blockchainID,
293-
subnetID,
294-
avalancheGoBinPath,
295-
nodeConfig,
296-
anrSettings,
297-
); err != nil {
298275
return err
299276
}
300-
// get node data
301-
nodeInfo, err := node.GetNodeInfo(nodeName)
302-
if err != nil {
303-
return err
277+
if len(targetClusters) == 0 {
278+
return fmt.Errorf("no local cluster is running for network %s and blockchain %s", network.Name(), blockchainName)
279+
}
280+
if len(targetClusters) != 1 {
281+
return fmt.Errorf("too many local clusters running for network %s and blockchain %s", network.Name(), blockchainName)
304282
}
305-
nodeIDStr, publicKey, pop, err = node.GetNodeData(nodeInfo.Uri)
283+
localValidatorClusterName = targetClusters[0]
284+
node, err := localnet.AddNodeToLocalCluster(app, ux.Logger.PrintToUser, localValidatorClusterName, httpPort, stakingPort)
306285
if err != nil {
307286
return err
308287
}
309-
// update sidecar with new node
310-
if err := node.AddNodeInfoToSidecar(&sc, nodeInfo, network); err != nil {
288+
nodeIDStr, publicKey, pop, err = utils.GetNodeID(node.URI)
289+
if err != nil {
311290
return err
312291
}
313-
if err := app.UpdateSidecar(&sc); err != nil {
292+
sc, err = app.AddDefaultBlockchainRPCsToSidecar(blockchainName, network, []string{node.URI})
293+
if err != nil {
314294
return err
315295
}
316296
// make sure extra validator endpoint added for the new node
@@ -346,7 +326,7 @@ func addValidator(cmd *cobra.Command, args []string) error {
346326
if !sovereign {
347327
return CallAddValidatorNonSOV(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance)
348328
}
349-
return CallAddValidator(
329+
if err := CallAddValidator(
350330
deployer,
351331
network,
352332
kc,
@@ -360,7 +340,15 @@ func addValidator(cmd *cobra.Command, args []string) error {
360340
remainingBalanceOwnerAddr,
361341
disableOwnerAddr,
362342
sc,
363-
)
343+
); err != nil {
344+
return err
345+
}
346+
if createLocalValidator && network.Kind == models.Local {
347+
// For all blockchains validated by the cluster, set up an alias from blockchain name
348+
// into blockchain id, to be mainly used in the blockchain RPC
349+
return localnet.RefreshLocalClusterAliases(app, localValidatorClusterName)
350+
}
351+
return nil
364352
}
365353

366354
func promptValidatorBalanceAVAX(availableBalance float64) (float64, error) {
@@ -623,6 +611,7 @@ func CallAddValidator(
623611
ux.Logger.PrintToUser(" Weight: %d", weight)
624612
}
625613
ux.Logger.PrintToUser(" Balance: %.2f", balanceAVAX)
614+
626615
ux.Logger.GreenCheckmarkToUser("Validator successfully added to the L1")
627616

628617
return nil

cmd/blockchaincmd/change_weight.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/ava-labs/avalanche-cli/pkg/keychain"
1616
"github.com/ava-labs/avalanche-cli/pkg/models"
1717
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
18-
"github.com/ava-labs/avalanche-cli/pkg/node"
1918
"github.com/ava-labs/avalanche-cli/pkg/prompts"
2019
"github.com/ava-labs/avalanche-cli/pkg/subnet"
2120
"github.com/ava-labs/avalanche-cli/pkg/utils"
@@ -116,7 +115,7 @@ func setWeight(_ *cobra.Command, args []string) error {
116115
}
117116

118117
if nodeEndpoint != "" {
119-
nodeIDStr, publicKey, pop, err = node.GetNodeData(nodeEndpoint)
118+
nodeIDStr, publicKey, pop, err = utils.GetNodeID(nodeEndpoint)
120119
if err != nil {
121120
return err
122121
}

cmd/blockchaincmd/convert.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Sovereign L1s require bootstrap validators. avalanche blockchain convert command
8282
"set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain",
8383
)
8484
cmd.Flags().IntVar(&numLocalNodes, "num-local-nodes", 0, "number of nodes to be created on local machine")
85+
cmd.Flags().UintSliceVar(&httpPorts, "http-port", []uint{}, "http port for node(s)")
86+
cmd.Flags().UintSliceVar(&stakingPorts, "staking-port", []uint{}, "staking port for node(s)")
8587
cmd.Flags().StringVar(&changeOwnerAddress, "change-owner-address", "", "address that will receive change if node is no longer L1 validator")
8688

8789
cmd.Flags().Uint64Var(&poSMinimumStakeAmount, "pos-minimum-stake-amount", 1, "minimum stake amount")
@@ -109,6 +111,8 @@ func StartLocalMachine(
109111
blockchainName string,
110112
deployBalance,
111113
availableBalance uint64,
114+
httpPorts []uint,
115+
stakingPorts []uint,
112116
) (bool, error) {
113117
var err error
114118
if network.Kind == models.Local {
@@ -118,15 +122,10 @@ func StartLocalMachine(
118122
clusterName := fmt.Sprintf("%s-local-node-%s", blockchainName, networkNameComponent)
119123
if clusterNameFlagValue != "" {
120124
clusterName = clusterNameFlagValue
121-
clusterConfig, err := app.GetClusterConfig(clusterName)
122-
if err != nil {
123-
return false, err
124-
}
125-
// check if cluster is local
126-
if clusterConfig.Local {
125+
if localnet.LocalClusterExists(app, clusterName) {
127126
useLocalMachine = true
128127
if len(bootstrapEndpoints) == 0 {
129-
bootstrapEndpoints, err = getLocalBootstrapEndpoints()
128+
bootstrapEndpoints, err = localnet.GetLocalClusterURIs(app, clusterName)
130129
if err != nil {
131130
return false, fmt.Errorf("error getting local host bootstrap endpoints: %w, "+
132131
"please create your local node again and call blockchain deploy command again", err)
@@ -155,9 +154,7 @@ func StartLocalMachine(
155154
}
156155
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node-%s", blockchainName, networkNameComponent) name
157156
if useLocalMachine && clusterNameFlagValue == "" {
158-
if clusterExists, err := node.CheckClusterIsLocal(app, clusterName); err != nil {
159-
return false, err
160-
} else if clusterExists {
157+
if localnet.LocalClusterExists(app, clusterName) {
161158
ux.Logger.PrintToUser("")
162159
ux.Logger.PrintToUser(
163160
logging.Red.Wrap("A local machine L1 deploy already exists for %s L1 and network %s"),
@@ -173,7 +170,8 @@ func StartLocalMachine(
173170
if !yes {
174171
return true, nil
175172
}
176-
_ = node.DestroyLocalNode(app, clusterName)
173+
_ = localnet.LocalClusterRemove(app, clusterName)
174+
ux.Logger.GreenCheckmarkToUser("Local node %s cleaned up.", clusterName)
177175
}
178176
requiredBalance := deployBalance * uint64(numLocalNodes)
179177
if availableBalance < requiredBalance {
@@ -184,9 +182,6 @@ func StartLocalMachine(
184182
availableBalance,
185183
)
186184
}
187-
// stop local avalanchego process so that we can generate new local cluster
188-
_ = node.StopLocalNode(app)
189-
anrSettings := node.ANRSettings{}
190185
avagoVersionSettings := node.AvalancheGoVersionSettings{}
191186
// setup (install if needed) avalanchego binary
192187
avagoVersion := userProvidedAvagoVersion
@@ -224,22 +219,35 @@ func StartLocalMachine(
224219
if network.Kind == models.Mainnet {
225220
globalNetworkFlags.UseMainnet = true
226221
}
222+
nodeSettingsLen := max(len(httpPorts), len(stakingPorts))
223+
nodeSettings := make([]localnet.NodeSetting, nodeSettingsLen)
224+
for i := range nodeSettingsLen {
225+
nodeSetting := localnet.NodeSetting{}
226+
if i < len(httpPorts) {
227+
nodeSetting.HTTPPort = uint64(httpPorts[i])
228+
}
229+
if i < len(stakingPorts) {
230+
nodeSetting.StakingPort = uint64(stakingPorts[i])
231+
}
232+
nodeSettings[i] = nodeSetting
233+
}
227234
// anrSettings, avagoVersionSettings, globalNetworkFlags are empty
228235
if err = node.StartLocalNode(
229236
app,
230237
clusterName,
231238
avagoBinaryPath,
232239
uint32(numLocalNodes),
233240
nodeConfig,
234-
anrSettings,
241+
localnet.ConnectionSettings{},
242+
nodeSettings,
235243
avagoVersionSettings,
236244
network,
237245
); err != nil {
238246
return false, err
239247
}
240248
clusterNameFlagValue = clusterName
241249
if len(bootstrapEndpoints) == 0 {
242-
bootstrapEndpoints, err = getLocalBootstrapEndpoints()
250+
bootstrapEndpoints, err = localnet.GetLocalClusterURIs(app, clusterName)
243251
if err != nil {
244252
return false, fmt.Errorf("error getting local host bootstrap endpoints: %w, "+
245253
"please create your local node again and call blockchain deploy command again", err)
@@ -271,11 +279,11 @@ func InitializeValidatorManager(
271279
clusterName := clusterNameFlagValue
272280
switch {
273281
case useLocalMachine:
274-
if err := node.TrackSubnetWithLocalMachine(
282+
if err := localnet.LocalClusterTrackSubnet(
275283
app,
284+
ux.Logger.PrintToUser,
276285
clusterName,
277286
blockchainName,
278-
avagoBinaryPath,
279287
); err != nil {
280288
return false, err
281289
}
@@ -648,7 +656,15 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
648656
}
649657
}
650658
if !generateNodeID {
651-
if cancel, err := StartLocalMachine(network, sidecar, blockchainName, deployBalance, availableBalance); err != nil {
659+
if cancel, err := StartLocalMachine(
660+
network,
661+
sidecar,
662+
blockchainName,
663+
deployBalance,
664+
availableBalance,
665+
httpPorts,
666+
stakingPorts,
667+
); err != nil {
652668
return err
653669
} else if cancel {
654670
return nil

cmd/blockchaincmd/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
332332
deployICM = params.UseICM
333333
useExternalGasToken = params.UseExternalGasToken
334334
genesisBytes, err = vm.CreateEVMGenesis(
335+
app,
335336
params,
336337
icmInfo,
337338
createFlags.addICMRegistryToGenesis,

0 commit comments

Comments
 (0)