Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PoA ACP99 + Externals EVM signatures for validator setup txs #2650

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
102 changes: 67 additions & 35 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"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/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
Expand All @@ -31,31 +32,31 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/units"
warpMessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message"

"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
)

var (
nodeIDStr string
nodeEndpoint string
balanceAVAX float64
weight uint64
startTimeStr string
duration time.Duration
defaultValidatorParams bool
useDefaultStartTime bool
useDefaultDuration bool
useDefaultWeight bool
waitForTxAcceptance bool
publicKey string
pop string
remainingBalanceOwnerAddr string
disableOwnerAddr string
rpcURL string
aggregatorLogLevel string
aggregatorLogToStdout bool
delegationFee uint16

nodeIDStr string
nodeEndpoint string
balanceAVAX float64
weight uint64
startTimeStr string
duration time.Duration
defaultValidatorParams bool
useDefaultStartTime bool
useDefaultDuration bool
useDefaultWeight bool
waitForTxAcceptance bool
publicKey string
pop string
remainingBalanceOwnerAddr string
disableOwnerAddr string
rpcURL string
aggregatorLogLevel string
aggregatorLogToStdout bool
delegationFee uint16
errNoSubnetID = errors.New("failed to find the subnet ID for this subnet, has it been deployed/created on this network?")
errMutuallyExclusiveDurationOptions = errors.New("--use-default-duration/--use-default-validator-params and --staking-period are mutually exclusive")
errMutuallyExclusiveStartOptions = errors.New("--use-default-start-time/--use-default-validator-params and --start-time are mutually exclusive")
Expand All @@ -65,6 +66,8 @@ var (
aggregatorAllowPrivatePeers bool
clusterNameFlagValue string
createLocalValidator bool
externalValidatorManagerOwner bool
validatorManagerOwner string
)

const (
Expand Down Expand Up @@ -122,8 +125,9 @@ Testnet or Mainnet.`,
cmd.Flags().BoolVar(&waitForTxAcceptance, "wait-for-tx-acceptance", true, "(for Subnets, not L1s) just issue the add validator tx, without waiting for its acceptance")
cmd.Flags().Uint16Var(&delegationFee, "delegation-fee", 100, "(PoS only) delegation fee (in bips)")
cmd.Flags().StringVar(&subnetIDstr, "subnet-id", "", "subnet ID (only if blockchain name is not provided)")
cmd.Flags().StringVar(&validatorManagerOwnerAddress, "validator-manager-owner", "", "validator manager owner address (only if blockchain name is not provided)")
cmd.Flags().Uint64Var(&weight, validatorWeightFlag, uint64(constants.DefaultStakeWeight), "set the weight of the validator")
cmd.Flags().StringVar(&validatorManagerOwner, "validator-manager-owner", "", "force using this address to issue transactions to the validator manager")
Copy link
Collaborator

@sukantoraymond sukantoraymond Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we technically dont even need to get validator manager using flag anymore. Currently we only get validator manager from on chain if user doesn't provide argument to add validator. But I think its better if we just do this for all cases -> meaning even if user provides argument to add validator. This means that we don't even need validator-manager-owner flag anymore in add_validator, same goes for remove_validator and change_weight

cmd.Flags().BoolVar(&externalValidatorManagerOwner, "external-validator-manager-owner", false, "validator manager owner is external, make hex dump of ech evm transactions, so they can be signed in a separate flow")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear what external-validator-manager-owner means, I think we can just rename this to generate-raw-tx-only, with desc as "set this value to true when signing validator manager tx outside of cli" or sth similar

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or i think sign-externally ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and say in description for multisig or ledger


return cmd
}
Expand Down Expand Up @@ -404,17 +408,26 @@ func CallAddValidator(
return fmt.Errorf("unable to find Validator Manager address")
}
validatorManagerAddress = sc.Networks[network.Name()].ValidatorManagerAddress
ownerPrivateKeyFound, _, _, ownerPrivateKey, err := contract.SearchForManagedKey(
app,
network,
common.HexToAddress(sc.ValidatorManagerOwner),
true,
)
if err != nil {
return err

if validatorManagerOwner == "" {
validatorManagerOwner = sc.ValidatorManagerOwner
}
if !ownerPrivateKeyFound {
return fmt.Errorf("private key for Validator manager owner %s is not found", sc.ValidatorManagerOwner)

var ownerPrivateKey string
if !externalValidatorManagerOwner {
var ownerPrivateKeyFound bool
ownerPrivateKeyFound, _, _, ownerPrivateKey, err = contract.SearchForManagedKey(
app,
network,
common.HexToAddress(validatorManagerOwner),
true,
)
if err != nil {
return err
}
if !ownerPrivateKeyFound {
return fmt.Errorf("private key for Validator manager owner %s is not found", validatorManagerOwner)
}
}

pos := sc.PoS()
Expand All @@ -428,7 +441,14 @@ func CallAddValidator(
}
}
}
ux.Logger.PrintToUser(logging.Yellow.Wrap("Validation manager owner %s pays for the initialization of the validator's registration (Blockchain gas token)"), sc.ValidatorManagerOwner)

if sc.UseACP99 {
ux.Logger.PrintToUser(logging.Yellow.Wrap("Validator Manager Protocol: ACP99"))
} else {
ux.Logger.PrintToUser(logging.Yellow.Wrap("Validator Manager Protocol: v1.0.0"))
}

ux.Logger.PrintToUser(logging.Yellow.Wrap("Validation manager owner %s pays for the initialization of the validator's registration (Blockchain gas token)"), validatorManagerOwner)

if rpcURL == "" {
rpcURL, _, err = contract.GetBlockchainEndpoints(
Expand Down Expand Up @@ -523,12 +543,14 @@ func CallAddValidator(
}
aggregatorCtx, aggregatorCancel := sdkutils.GetTimedContext(constants.SignatureAggregatorTimeout)
defer aggregatorCancel()
signedMessage, validationID, err := validatormanager.InitValidatorRegistration(
signedMessage, validationID, rawTx, err := validatormanager.InitValidatorRegistration(
aggregatorCtx,
app,
network,
rpcURL,
chainSpec,
externalValidatorManagerOwner,
validatorManagerOwner,
ownerPrivateKey,
nodeID,
blsInfo.PublicKey[:],
Expand All @@ -543,10 +565,14 @@ func CallAddValidator(
delegationFee,
duration,
validatorManagerAddress,
sc.UseACP99,
)
if err != nil {
return err
}
if rawTx != nil {
return evm.TxDump("Initializing Validator Registration", rawTx)
}
ux.Logger.PrintToUser("ValidationID: %s", validationID)

txID, _, err := deployer.RegisterL1Validator(balance, blsInfo, signedMessage)
Expand All @@ -566,21 +592,27 @@ func CallAddValidator(

aggregatorCtx, aggregatorCancel = sdkutils.GetTimedContext(constants.SignatureAggregatorTimeout)
defer aggregatorCancel()
if err := validatormanager.FinishValidatorRegistration(
rawTx, err = validatormanager.FinishValidatorRegistration(
aggregatorCtx,
app,
network,
rpcURL,
chainSpec,
externalValidatorManagerOwner,
validatorManagerOwner,
ownerPrivateKey,
validationID,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerAddress,
); err != nil {
)
if err != nil {
return err
}
if rawTx != nil {
return evm.TxDump("Finish Validator Registration", rawTx)
}

ux.Logger.PrintToUser(" NodeID: %s", nodeID)
ux.Logger.PrintToUser(" Network: %s", network.Name())
Expand Down
Loading
Loading