Skip to content

Commit

Permalink
Fix convert (#2625)
Browse files Browse the repository at this point in the history
* fix convert

* Fix assignment mismatch (#2627)

Signed-off-by: Martin Eckardt <[email protected]>

---------

Signed-off-by: Martin Eckardt <[email protected]>
Co-authored-by: Martin Eckardt <[email protected]>
  • Loading branch information
sukantoraymond and martineckardt authored Feb 24, 2025
1 parent 394ce8e commit d36296b
Showing 1 changed file with 67 additions and 62 deletions.
129 changes: 67 additions & 62 deletions cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
globalNetworkFlags,
true,
false,
networkoptions.DefaultSupportedNetworkOptions,
networkoptions.GetNetworkFromSidecar(sidecar, networkoptions.DefaultSupportedNetworkOptions),
"",
)
if err != nil {
Expand All @@ -492,21 +492,24 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
subnetID := sidecar.Networks[network.Name()].SubnetID
blockchainID := sidecar.Networks[network.Name()].BlockchainID

if validatorManagerAddress == "" {
validatorManagerAddressAddrFmt, err := app.Prompt.CaptureAddress("What is the address of the Validator Manager?")
if err != nil {
if !convertOnly {
if validatorManagerAddress == "" {
validatorManagerAddressAddrFmt, err := app.Prompt.CaptureAddress("What is the address of the Validator Manager?")
if err != nil {
return err
}
validatorManagerAddress = validatorManagerAddressAddrFmt.String()
}

if err = promptValidatorManagementType(app, &sidecar); err != nil {
return err
}
validatorManagerAddress = validatorManagerAddressAddrFmt.String()
if err := setSidecarValidatorManageOwner(&sidecar, createFlags); err != nil {
return err
}
sidecar.UpdateValidatorManagerAddress(network.Name(), validatorManagerAddress)
}

if err = promptValidatorManagementType(app, &sidecar); err != nil {
return err
}
if err := setSidecarValidatorManageOwner(&sidecar, createFlags); err != nil {
return err
}
sidecar.UpdateValidatorManagerAddress(network.Name(), validatorManagerAddress)
sidecar.Sovereign = true
fee := uint64(0)

Expand All @@ -531,63 +534,65 @@ func convertBlockchain(_ *cobra.Command, args []string) error {

deployBalance := uint64(deployBalanceAVAX * float64(units.Avax))

if changeOwnerAddress == "" {
// use provided key as change owner unless already set
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
changeOwnerAddress = pAddr[0]
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
}
}
if !generateNodeID {
if err = StartLocalMachine(network, sidecar, blockchainName, deployBalance, availableBalance); err != nil {
return err
}
}
switch {
case len(bootstrapEndpoints) > 0:
if len(bootstrapValidators) == 0 {
if changeOwnerAddress == "" {
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
if err != nil {
return err
// use provided key as change owner unless already set
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
changeOwnerAddress = pAddr[0]
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
}
}
for _, endpoint := range bootstrapEndpoints {
infoClient := info.NewClient(endpoint)
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
if err != nil {
if !generateNodeID {
if err = StartLocalMachine(network, sidecar, blockchainName, deployBalance, availableBalance); err != nil {
return err
}
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])

bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
NodeID: nodeID.String(),
Weight: constants.BootstrapValidatorWeight,
Balance: deployBalance,
BLSPublicKey: publicKey,
BLSProofOfPossession: pop,
ChangeOwnerAddr: changeOwnerAddress,
})
}
case clusterNameFlagValue != "":
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
if err != nil {
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
}
switch {
case len(bootstrapEndpoints) > 0:
if changeOwnerAddress == "" {
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
if err != nil {
return err
}
}
for _, endpoint := range bootstrapEndpoints {
infoClient := info.NewClient(endpoint)
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
if err != nil {
return err
}
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])

bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
NodeID: nodeID.String(),
Weight: constants.BootstrapValidatorWeight,
Balance: deployBalance,
BLSPublicKey: publicKey,
BLSProofOfPossession: pop,
ChangeOwnerAddr: changeOwnerAddress,
})
}
case clusterNameFlagValue != "":
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
if err != nil {
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
}

default:
bootstrapValidators, err = promptBootstrapValidators(
network,
changeOwnerAddress,
numBootstrapValidators,
deployBalance,
availableBalance,
)
if err != nil {
return err
default:
bootstrapValidators, err = promptBootstrapValidators(
network,
changeOwnerAddress,
numBootstrapValidators,
deployBalance,
availableBalance,
)
if err != nil {
return err
}
}
}

Expand Down

0 comments on commit d36296b

Please sign in to comment.