Skip to content

Commit

Permalink
Merge branch 'main' into version191
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond authored Dec 13, 2024
2 parents 31c650d + ae77533 commit 9417341
Show file tree
Hide file tree
Showing 85 changed files with 1,408 additions and 783 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ jobs:
go-version-file: 'go.mod'

- name: Lint Golang
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
working-directory: .
args: --timeout 5m
run: ./scripts/lint.sh

- name: Check License
run: |
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ WORKDIR /
# Copy the executables into the container
COPY --from=builder /build/bin/avalanche .
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
RUN /avalanche config update disable
ENTRYPOINT [ "./avalanche" ]
1 change: 1 addition & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM debian:11-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY avalanche /
RUN /avalanche config update disable
ENTRYPOINT [ "/avalanche" ]
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
52 changes: 28 additions & 24 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ import (
"strings"
"unicode"

"github.com/ava-labs/avalanche-cli/pkg/key"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/avalanche-cli/cmd/flags"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/interchain"
"github.com/ava-labs/avalanche-cli/pkg/key"
"github.com/ava-labs/avalanche-cli/pkg/metrics"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/vm"
"github.com/ava-labs/avalanchego/utils/formatting/address"

"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
)
Expand All @@ -44,7 +43,7 @@ type CreateFlags struct {
useTestDefaults bool
useProductionDefaults bool
useWarp bool
useTeleporter bool
useICM bool
vmVersion string
useLatestReleasedVMVersion bool
useLatestPreReleasedVMVersion bool
Expand Down Expand Up @@ -111,8 +110,9 @@ configuration, pass the -f flag.`,
cmd.Flags().StringVar(&customVMBranch, "custom-vm-branch", "", "custom vm branch or commit")
cmd.Flags().StringVar(&customVMBuildScript, "custom-vm-build-script", "", "custom vm build-script")
cmd.Flags().BoolVar(&useRepo, "from-github-repo", false, "generate custom VM binary from github repository")
cmd.Flags().BoolVar(&createFlags.useWarp, "warp", true, "generate a vm with warp support (needed for teleporter)")
cmd.Flags().BoolVar(&createFlags.useTeleporter, "teleporter", false, "interoperate with other blockchains using teleporter")
cmd.Flags().BoolVar(&createFlags.useWarp, "warp", true, "generate a vm with warp support (needed for ICM)")
cmd.Flags().BoolVar(&createFlags.useICM, "teleporter", false, "interoperate with other blockchains using ICM")
cmd.Flags().BoolVar(&createFlags.useICM, "icm", false, "interoperate with other blockchains using ICM")
cmd.Flags().BoolVar(&createFlags.useExternalGasToken, "external-gas-token", false, "use a gas token from another blockchain")
cmd.Flags().BoolVar(&createFlags.addICMRegistryToGenesis, "icm-registry-at-genesis", false, "setup ICM registry smart contract on genesis [experimental]")
cmd.Flags().BoolVar(&createFlags.proofOfAuthority, "proof-of-authority", false, "use proof of authority(PoA) for validator management")
Expand Down Expand Up @@ -228,19 +228,23 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {

var (
genesisBytes []byte
useTeleporterFlag *bool
deployTeleporter bool
useICMFlag *bool
deployICM bool
useExternalGasToken bool
)

// get teleporter flag as a pointer (3 values: undef/true/false)
// get ICM flag as a pointer (3 values: undef/true/false)
flagName := "teleporter"
if flag := cmd.Flags().Lookup(flagName); flag != nil && flag.Changed {
useTeleporterFlag = &createFlags.useTeleporter
useICMFlag = &createFlags.useICM
}
flagName = "icm"
if flag := cmd.Flags().Lookup(flagName); flag != nil && flag.Changed {
useICMFlag = &createFlags.useICM
}

// get teleporter info
teleporterInfo, err := teleporter.GetInfo(app)
// get ICM info
icmInfo, err := interchain.GetICMInfo(app)
if err != nil {
return err
}
Expand Down Expand Up @@ -317,7 +321,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
deployTeleporter, err = vm.PromptInterop(app, useTeleporterFlag, defaultsKind, false)
deployICM, err = vm.PromptInterop(app, useICMFlag, defaultsKind, false)
if err != nil {
return err
}
Expand All @@ -335,19 +339,19 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
createFlags.chainID,
createFlags.tokenSymbol,
blockchainName,
useTeleporterFlag,
useICMFlag,
defaultsKind,
createFlags.useWarp,
createFlags.useExternalGasToken,
)
if err != nil {
return err
}
deployTeleporter = params.UseTeleporter
deployICM = params.UseICM
useExternalGasToken = params.UseExternalGasToken
genesisBytes, err = vm.CreateEVMGenesis(
params,
teleporterInfo,
icmInfo,
createFlags.addICMRegistryToGenesis,
sc.ProxyContractOwner,
createFlags.rewardBasisPoints,
Expand Down Expand Up @@ -384,7 +388,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
deployTeleporter, err = vm.PromptInterop(app, useTeleporterFlag, defaultsKind, false)
deployICM, err = vm.PromptInterop(app, useICMFlag, defaultsKind, false)
if err != nil {
return err
}
Expand All @@ -405,21 +409,21 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
}
}

if deployTeleporter || useExternalGasToken {
if deployICM || useExternalGasToken {
sc.TeleporterReady = true
sc.RunRelayer = true // TODO: remove this once deploy asks if deploying relayer
sc.ExternalToken = useExternalGasToken
sc.TeleporterKey = constants.ICMKeyName
sc.TeleporterVersion = teleporterInfo.Version
sc.TeleporterVersion = icmInfo.Version
if genesisPath != "" {
if evmCompatibleGenesis, err := utils.FileIsSubnetEVMGenesis(genesisPath); err != nil {
return err
} else if evmCompatibleGenesis {
// evm genesis file was given. make appropriate checks and customizations for teleporter
// evm genesis file was given. make appropriate checks and customizations for ICM
genesisBytes, err = addSubnetEVMGenesisPrefundedAddress(
genesisBytes,
teleporterInfo.FundedAddress,
teleporterInfo.FundedBalance.String(),
icmInfo.FundedAddress,
icmInfo.FundedBalance.String(),
)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 9417341

Please sign in to comment.