Skip to content

Commit

Permalink
Merge branch 'main' into local-cluster-to-join-to-local-network
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Dec 14, 2024
2 parents 933d761 + 506142e commit fa222e6
Show file tree
Hide file tree
Showing 47 changed files with 803 additions and 286 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.22.8-bullseye AS builder
FROM golang:1.22.10-bookworm AS builder

WORKDIR /build
# Copy and download avalanche dependencies using go mod
Expand All @@ -12,7 +12,7 @@ COPY . .
RUN ./scripts/build.sh

# ============= Cleanup Stage ================
FROM debian:11-slim
FROM debian:12-slim
WORKDIR /

# Copy the executables into the container
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:11-slim
FROM debian:12-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY avalanche /
RUN /avalanche config update disable
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.0
1.8.1
28 changes: 7 additions & 21 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Testnet or Mainnet.`,

cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]")
cmd.Flags().Uint64Var(&weight, "weight", constants.NonBootstrapValidatorWeight, "set the staking weight of the validator to add")
cmd.Flags().Uint64Var(&balance, "balance", 0, "set the AVAX balance of the validator that will be used for continuous fee to P-Chain")
cmd.Flags().Uint64Var(&balance, "balance", 0, "set the AVAX balance of the validator that will be used for continuous fee on P-Chain")
cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [fuji/devnet only]")
cmd.Flags().BoolVarP(&useLedger, "ledger", "g", false, "use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)")
cmd.Flags().StringSliceVar(&ledgerAddresses, "ledger-addrs", []string{}, "use the given ledger addresses")
Expand Down Expand Up @@ -285,6 +285,7 @@ func addValidator(_ *cobra.Command, args []string) error {
if err := prompts.ValidateNodeID(nodeIDStr); err != nil {
return err
}

if sovereign && publicKey == "" && pop == "" {
publicKey, pop, err = promptProofOfPossession(true, true)
if err != nil {
Expand Down Expand Up @@ -404,13 +405,14 @@ func CallAddValidator(
if err != nil {
return err
}
balance, err = promptValidatorBalance(availableBalance)
balance, err = promptValidatorBalance(availableBalance / units.Avax)
if err != nil {
return err
}
} else {
// convert to nanoAVAX
balance *= units.Avax
}
// convert to nanoAVAX
balance *= units.Avax

if remainingBalanceOwnerAddr == "" {
remainingBalanceOwnerAddr, err = getKeyForChangeOwner(network)
Expand Down Expand Up @@ -680,22 +682,6 @@ func PromptDuration(start time.Time, network models.Network) (time.Duration, err
}
}

func getMaxValidationTime(network models.Network, nodeID ids.NodeID, startTime time.Time) (time.Duration, error) {
ctx, cancel := utils.GetAPIContext()
defer cancel()
platformCli := platformvm.NewClient(network.Endpoint)
vs, err := platformCli.GetCurrentValidators(ctx, avagoconstants.PrimaryNetworkID, nil)
if err != nil {
return 0, err
}
for _, v := range vs {
if v.NodeID == nodeID {
return time.Unix(int64(v.EndTime), 0).Sub(startTime), nil
}
}
return 0, errors.New("nodeID not found in validator set: " + nodeID.String())
}

func getBlockchainTimestamp(network models.Network) (time.Time, error) {
ctx, cancel := utils.GetAPIContext()
defer cancel()
Expand Down Expand Up @@ -781,7 +767,7 @@ func getTimeParameters(network models.Network, nodeID ids.NodeID, isValidator bo
var selectedDuration time.Duration
if useDefaultDuration {
// avoid setting both globals useDefaultDuration and duration
selectedDuration, err = getMaxValidationTime(network, nodeID, start)
selectedDuration, err = utils.GetRemainingValidationTime(network.Endpoint, nodeID, avagoconstants.PrimaryNetworkID, start)
if err != nil {
return time.Time{}, 0, err
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func setWeight(_ *cobra.Command, args []string) error {
return err
}

if network.Kind == models.Mainnet && sc.Sovereign {
return errNotSupportedOnMainnet
}

if outputTxPath != "" {
if _, err := os.Stat(outputTxPath); err == nil {
return fmt.Errorf("outputTxPath %q already exists", outputTxPath)
Expand Down Expand Up @@ -152,6 +148,8 @@ func setWeight(_ *cobra.Command, args []string) error {
network,
blockchainName,
nodeID,
0, // automatic uptime
isBootstrapValidatorForNetwork(nodeID, sc.Networks[network.Name()]),
false, // don't force
)
if err != nil {
Expand Down
127 changes: 91 additions & 36 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,44 @@ import (
"path/filepath"
"time"

blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain"
validatorManagerSDK "github.com/ava-labs/avalanche-cli/sdk/validatormanager"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/network/peer"

"github.com/ava-labs/avalanche-cli/cmd/interchaincmd/messengercmd"
"github.com/ava-labs/avalanche-cli/cmd/interchaincmd/relayercmd"
"github.com/ava-labs/avalanche-cli/cmd/networkcmd"
"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanche-cli/pkg/keychain"
"github.com/ava-labs/avalanche-cli/pkg/node"
avagoutils "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"

"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanche-cli/pkg/keychain"
"github.com/ava-labs/avalanche-cli/pkg/localnet"
"github.com/ava-labs/avalanche-cli/pkg/metrics"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/node"
"github.com/ava-labs/avalanche-cli/pkg/prompts"
"github.com/ava-labs/avalanche-cli/pkg/subnet"
"github.com/ava-labs/avalanche-cli/pkg/txutils"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/vm"
blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain"
validatorManagerSDK "github.com/ava-labs/avalanche-cli/sdk/validatormanager"
anrutils "github.com/ava-labs/avalanche-network-runner/utils"
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/peer"
avagoutils "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"

"github.com/ethereum/go-ethereum/common"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -101,13 +99,15 @@ var (
cChainFundingKey string
icmKeyName string
cchainIcmKeyName string
relayerAllowPrivateIPs bool

poSMinimumStakeAmount uint64
poSMaximumStakeAmount uint64
poSMinimumStakeDuration uint64
poSMinimumDelegationFee uint16
poSMaximumStakeMultiplier uint8
poSWeightToValueFactor uint64
deployBalanceAVAX float64

errMutuallyExlusiveControlKeys = errors.New("--control-keys and --same-control-key are mutually exclusive")
ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive")
Expand Down Expand Up @@ -187,6 +187,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().StringVar(&cchainIcmKeyName, "cchain-icm-key", "", "key to be used to pay for ICM deploys on C-Chain")
cmd.Flags().BoolVar(&relayCChain, "relay-cchain", true, "relay C-Chain as source and destination")
cmd.Flags().StringVar(&cChainFundingKey, "cchain-funding-key", "", "key to be used to fund relayer account on cchain")
cmd.Flags().BoolVar(&relayerAllowPrivateIPs, "relayer-allow-private-ips", true, "allow relayer to connec to private ips")
cmd.Flags().StringVar(&icmSpec.MessengerContractAddressPath, "teleporter-messenger-contract-address-path", "", "path to an ICM Messenger contract address file")
cmd.Flags().StringVar(&icmSpec.MessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to an ICM Messenger deployer address file")
cmd.Flags().StringVar(&icmSpec.MessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to an ICM Messenger deployer tx file")
Expand All @@ -200,6 +201,12 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().BoolVar(&aggregatorAllowPrivatePeers, "aggregator-allow-private-peers", true, "allow the signature aggregator to connect to peers with private IP")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().IntVar(&numBootstrapValidators, "num-bootstrap-validators", 0, "(only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)")
cmd.Flags().Float64Var(
&deployBalanceAVAX,
"balance",
float64(constants.BootstrapValidatorBalanceNanoAVAX)/float64(units.Avax),
"set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain",
)
cmd.Flags().IntVar(&numLocalNodes, "num-local-nodes", 0, "number of nodes to be created on local machine")
cmd.Flags().StringVar(&changeOwnerAddress, "change-owner-address", "", "address that will receive change if node is no longer L1 validator")

Expand Down Expand Up @@ -450,12 +457,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
clusterNameFlagValue = globalNetworkFlags.ClusterName

if !simulatedPublicNetwork() {
if network.Kind == models.Mainnet && sidecar.Sovereign {
return errNotSupportedOnMainnet
}
}

isEVMGenesis, validationErr, err := app.HasSubnetEVMGenesis(chain)
if err != nil {
return err
Expand Down Expand Up @@ -589,6 +590,13 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}

availableBalance, err := utils.GetNetworkBalance(kc.Addresses().List(), network.Endpoint)
if err != nil {
return err
}

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

if sidecar.Sovereign {
if changeOwnerAddress == "" {
// use provided key as change owner unless already set
Expand Down Expand Up @@ -653,6 +661,15 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node", blockchainName) name
if useLocalMachine && clusterNameFlagValue == "" {
requiredBalance := deployBalance * uint64(numLocalNodes)
if availableBalance < requiredBalance {
return fmt.Errorf(
"required balance for %d validators dynamic fee on PChain is %d but the given key has %d",
numLocalNodes,
requiredBalance,
availableBalance,
)
}
// stop local avalanchego process so that we can generate new local cluster
_ = node.StopLocalNode(app)
anrSettings := node.ANRSettings{}
Expand Down Expand Up @@ -695,6 +712,9 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
if network.Kind == models.Fuji {
globalNetworkFlags.UseFuji = true
}
if network.Kind == models.Mainnet {
globalNetworkFlags.UseMainnet = true
}
// anrSettings, avagoVersionSettings, globalNetworkFlags are empty
if err = node.StartLocalNode(
app,
Expand Down Expand Up @@ -742,21 +762,27 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
NodeID: nodeID.String(),
Weight: constants.BootstrapValidatorWeight,
Balance: constants.BootstrapValidatorBalance,
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)
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)
bootstrapValidators, err = promptBootstrapValidators(
network,
changeOwnerAddress,
numBootstrapValidators,
deployBalance,
availableBalance,
)
if err != nil {
return err
}
Expand All @@ -770,6 +796,18 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return errMutuallyExlusiveSubnetFlags
}

if sidecar.Sovereign {
requiredBalance := deployBalance * uint64(len(bootstrapValidators))
if availableBalance < requiredBalance {
return fmt.Errorf(
"required balance for %d validators dynamic fee on PChain is %d but the given key has %d",
len(bootstrapValidators),
requiredBalance,
availableBalance,
)
}
}

network.HandlePublicNetworkSimulation()

if createSubnet {
Expand Down Expand Up @@ -931,7 +969,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
ux.Logger.PrintToUser("")

setBootstrapValidatorValidationID(avaGoBootstrapValidators, bootstrapValidators, subnetID)
if err := app.UpdateSidecarNetworks(
&sidecar,
network,
Expand Down Expand Up @@ -1050,8 +1088,8 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
aggregatorAllowPrivatePeers,
logLvl,
validatorManagerSDK.PoSParams{
MinimumStakeAmount: utils.ApplyDefaultDenomination(poSMinimumStakeAmount),
MaximumStakeAmount: utils.ApplyDefaultDenomination(poSMaximumStakeAmount),
MinimumStakeAmount: big.NewInt(int64(poSMinimumStakeAmount)),
MaximumStakeAmount: big.NewInt(int64(poSMaximumStakeAmount)),
MinimumStakeDuration: poSMinimumStakeDuration,
MinimumDelegationFee: poSMinimumDelegationFee,
MaximumStakeMultiplier: poSMaximumStakeMultiplier,
Expand Down Expand Up @@ -1143,7 +1181,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
icmSpec.SkipRelayerDeploy = !yes
}
}
if !icmSpec.SkipRelayerDeploy && (network.Kind != models.Fuji && network.Kind != models.Mainnet) {
if !icmSpec.SkipRelayerDeploy && network.Kind != models.Mainnet {
deployRelayerFlags := relayercmd.DeployFlags{
Version: icmSpec.RelayerVersion,
BinPath: icmSpec.RelayerBinPath,
Expand All @@ -1153,6 +1191,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
BlockchainsToRelay: []string{blockchainName},
Key: relayerKeyName,
Amount: relayerAmount,
AllowPrivateIPs: relayerAllowPrivateIPs,
}
if network.Kind == models.Local || useLocalMachine {
deployRelayerFlags.Key = constants.ICMRelayerKeyName
Expand Down Expand Up @@ -1180,7 +1219,23 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return nil
}

func getClusterBootstrapValidators(clusterName string, network models.Network) ([]models.SubnetValidator, error) {
func setBootstrapValidatorValidationID(avaGoBootstrapValidators []*txs.ConvertSubnetToL1Validator, bootstrapValidators []models.SubnetValidator, subnetID ids.ID) {
for index, avagoValidator := range avaGoBootstrapValidators {
for bootstrapValidatorIndex, validator := range bootstrapValidators {
avagoValidatorNodeID, _ := ids.ToNodeID(avagoValidator.NodeID)
if validator.NodeID == avagoValidatorNodeID.String() {
validationID := subnetID.Append(uint32(index))
bootstrapValidators[bootstrapValidatorIndex].ValidationID = validationID.String()
}
}
}
}

func getClusterBootstrapValidators(
clusterName string,
network models.Network,
deployBalance uint64,
) ([]models.SubnetValidator, error) {
clusterConf, err := app.GetClusterConfig(clusterName)
if err != nil {
return nil, err
Expand All @@ -1204,7 +1259,7 @@ func getClusterBootstrapValidators(clusterName string, network models.Network) (
subnetValidators = append(subnetValidators, models.SubnetValidator{
NodeID: nodeID.String(),
Weight: constants.BootstrapValidatorWeight,
Balance: constants.BootstrapValidatorBalance,
Balance: deployBalance,
BLSPublicKey: fmt.Sprintf("%s%s", "0x", hex.EncodeToString(pub)),
BLSProofOfPossession: fmt.Sprintf("%s%s", "0x", hex.EncodeToString(pop)),
ChangeOwnerAddr: changeAddr,
Expand Down
Loading

0 comments on commit fa222e6

Please sign in to comment.