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

Acp 77 PoS using sdk/validatorManager #2308

Open
wants to merge 52 commits into
base: acp-77
Choose a base branch
from
Open

Acp 77 PoS using sdk/validatorManager #2308

wants to merge 52 commits into from

Conversation

arturrez
Copy link
Collaborator

@arturrez arturrez commented Nov 1, 2024

Why this should be merged

it adds PoS L1 support to CLI - Native Token for now (ERC20 token - to be added)
it adds transparent proxy to both PoS and PoA validator manager.

How this works

based on PoA/PoS choice it deploys needed smart contracts including transparentProxy.
flows are very similar to PoA except some additional parameters specific to PoS ValidationManagement.
Some params have reasonable defaults to make UX better.

How this was tested

./bin/avalanche blockchain create pos7 --proof-of-stake  --force
./bin/avalanche node local start  --num-nodes 7 --etna-devnet --avalanchego-path ~/src/github.com/ava-labs/avalanchego/build/avalanchego local7
./bin/avalanche blockchain deploy pos7 --cluster local7 --bootstrap-endpoints http://127.0.0.1:9650,http://127.0.0.1:9652,http://127.0.0.1:9654,http://127.0.0.1:9656,http://127.0.0.1:9658 --convert-only
./bin/avalanche node local track local7 pos7
./bin/avalanche contract initPosManager pos7  --cluster local7 --rpc http://127.0.0.1:9650/ext/bc/<BLOCKCHAINID>/rpc
./bin/avalanche blockchain addValidator pos7  --cluster local7 --node-endpoint http://127.0.0.1:9660
./bin/avalanche blockchain addValidator pos7  --cluster local7 --node-endpoint http://127.0.0.1:9662

How is this documented

not yet. Relevant document created by @owenwahlgren https://github.com/ava-labs/etna-devnet-resources/blob/main/guides/deploy-sovereign-pos-l1.md.

It's based on https://github.com/ava-labs/avalanche-cli/tree/acp-77-pos branch created by @owenwahlgren 🙌

@arturrez arturrez self-assigned this Nov 1, 2024
@arturrez arturrez changed the base branch from main to acp-77 November 1, 2024 03:30
@arturrez arturrez added the DO NOT MERGE This PR is not meant to be merged in its current state label Nov 1, 2024
Comment on lines +128 to +139
if p.MinimumStakeAmount.Cmp(big.NewInt(0)) < 0 {
return fmt.Errorf("minimum stake amount cannot be negative")
}
if p.MaximumStakeAmount.Cmp(big.NewInt(0)) < 0 {
return fmt.Errorf("maximum stake amount cannot be negative")
}
if p.MaximumStakeAmount.Cmp(p.MinimumStakeAmount) < 0 {
return fmt.Errorf("maximum stake amount cannot be less than minimum stake amount")
}
if p.WeightToValueFactor.Cmp(big.NewInt(0)) < 0 {
return fmt.Errorf("weight to value factor cannot be negative")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can they be 0?

Copy link
Collaborator Author

@arturrez arturrez Nov 15, 2024

Choose a reason for hiding this comment

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

this means that WeightToValueFactor can't be 0 and this is what we want

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for all these, better error is has to be greater than 0, or cannot be empty , compared to cannot be negative

@@ -47,7 +48,9 @@ jobs:
- os: macos-14
suite: "\\[Public Subnet non SOV\\]"
- os: ubuntu-latest
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we excluding ubuntu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because we relay on avalanchego binary as part of the assets as it's custom build of poc.6 branch.
We can add ubuntu if we replace this prebuilt binary with avalanchego git repo checkout and build as part of the e2e

@@ -207,6 +214,17 @@ func promptValidatorBalance(availableBalance uint64) (uint64, error) {
return app.Prompt.CaptureValidatorBalance(txt, availableBalance)
}

func GetNetworkBalanceForKey(kc *keychain.Keychain, network models.Network) (uint64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can go somewhere to utils

Copy link
Collaborator

Choose a reason for hiding this comment

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

name is misleaving because it is a list of keys, that is a keychain

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved to utils. fixed name. good idea

if err != nil {
return err
}
stakeAmount, err = app.Prompt.CaptureUint64(fmt.Sprintf("Enter the amount of tokens to stake. Available: %d[%s]", avaliableTokens, sc.TokenName))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use a capture that disables choosing more than available tokens? (by the way, nit, avaliableTokens should be availableTokens)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added.

cmd/blockchaincmd/create.go Outdated Show resolved Hide resolved
cmd/blockchaincmd/create.go Outdated Show resolved Hide resolved
includeXChain bool,
includeCChain bool,
avoidBlockchainName string,
avoidPChain bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why changing the logic to all avoids?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we double careful this may broke some calls to this func

Copy link
Collaborator

Choose a reason for hiding this comment

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

probably used on key transfer. should check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my bad. fixed

@@ -1063,11 +1109,6 @@ func PromptAddress(
if err != nil {
return "", err
}
case XChainFormat:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why removing X-Chain?

Copy link
Collaborator Author

@arturrez arturrez Nov 15, 2024

Choose a reason for hiding this comment

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

my bad. not sure how it happened. checking and putting it back

if params.UsePoAValidatorManager {
validatormanager.AddPoAValidatorManagerContractToAllocations(params.initialTokenAllocation)
validatormanager.AddTransparentProxyContractToAllocations(params.initialTokenAllocation, proxyOwner)
} else {
validatormanager.AddPoSValidatorManagerContractToAllocations(params.initialTokenAllocation)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can it be this case that it is neither poa neither pos (old stuff)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch. replaced with else if

@@ -233,6 +238,10 @@ func PromptSubnetEVMGenesisParams(
return SubnetEVMGenesisParams{}, "", err
}

if sc.PoS() || sc.PoA() { // Teleporter bytecode makes genesis too big given the current max size (we include the bytecode for ValidatorManager, a proxy, and proxy admin)
params.UseTeleporter = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not enough, you can still use teleporter, the only thing is that it is not going to be included in genesis
can we keep the teleporter flag on but avoid genesis deploy? but instead deploy afterwards

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree. I suggest not fixing it in the scope of this PR and do it as part of the teleporter after blockchain creation deployment PR as we discussed

params.nativeMinterPrecompileAllowList.EnabledAddresses = []common.Address{
common.HexToAddress(validatormanager.ValidatorContractAddress),
}
params.nativeMinterPrecompileAllowList.AdminAddresses = append(
Copy link
Collaborator

Choose a reason for hiding this comment

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

why admin? is not enough to use enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to enabled

@sukantoraymond
Copy link
Collaborator

sukantoraymond commented Nov 18, 2024

Screenshot 2024-11-18 at 11 47 04 AM

For deploy, No need to print proxy admin contract address here imo

@sukantoraymond
Copy link
Collaborator

sukantoraymond commented Nov 18, 2024

Screenshot 2024-11-18 at 12 11 50 PM

For addvalidator, Can be 869 AVAX Token, no need for [AVAX Token]

@sukantoraymond
Copy link
Collaborator

sukantoraymond commented Nov 18, 2024

Screenshot 2024-11-18 at 12 13 06 PM
For addvalidator, Dont think we have a minimum duration of 14 days here?

@sukantoraymond
Copy link
Collaborator

Screenshot 2024-11-18 at 12 17 14 PM
For addvalidator -> lets edit the prompt since now its saying bootstrap validator

arturrez and others added 3 commits November 18, 2024 12:17
* add pos validator removal
debug

* continue debugging pos validator removal

* r4r

* lint

* fix e2e Error: failure initializing validator removal: min stake duration not passed (tx failed to be submitted)

* wait 90sec for min validation period

* min stake duration is 100

* update sidecar after bootstrap validator removed

* disable e2e for removing PoS bootstrap validator

* use 100s

* remove pos non bootstrap validator e2e

* add validator and remove it

* use 60s staking period

* go back to 90 and 120s

* small refactor

* fix duration prompt

* use minimum 100s

* add prompt check for minimum validator staking timr

* fix etna duration input

* use etna for name

* add debug info

* rm debug
force validator removal for PoS

* no need to updatePchainHeight

---------

Signed-off-by: arturrez <[email protected]>
cmd.Flags().BoolVar(&useDefaultStartTime, "default-start-time", false, "(for non sovereign blockchain) use default start time for subnet validator (5 minutes later for fuji & mainnet, 30 seconds later for devnet)")
cmd.Flags().StringVar(&startTimeStr, "start-time", "", "(for non sovereign blockchain) UTC start time when this validator starts validating, in 'YYYY-MM-DD HH:MM:SS' format")
cmd.Flags().BoolVar(&useDefaultDuration, "default-duration", false, "(for non sovereign blockchain) set duration so as to validate until primary validator ends its period")
cmd.Flags().BoolVar(&defaultValidatorParams, "default-validator-params", false, "(for non sovereign blockchain) use default weight/start/duration params for subnet validator")
cmd.Flags().StringSliceVar(&subnetAuthKeys, "subnet-auth-keys", nil, "(for non sovereign blockchain) control keys that will be used to authenticate add validator tx")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "(for non sovereign blockchain) file path of the add validator tx")
cmd.Flags().BoolVar(&waitForTxAcceptance, "wait-for-tx-acceptance", true, "(for non sovereign blockchain) just issue the add validator tx, without waiting for its acceptance")
cmd.Flags().BoolVar(&forcePoS, "pos", false, "(PoS only) force validator initialization as PoS validator")
Copy link
Collaborator

Choose a reason for hiding this comment

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

whats this flag for?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems that its for adding to a pos / poa? We can't get from sidecar instead if its poa / pos?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review 👀
Development

Successfully merging this pull request may close these issues.

4 participants