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

Genesis poa #2164

Merged
merged 82 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
63cb85b
prompt addresses
sukantoraymond Sep 11, 2024
22c18e8
fix lint
sukantoraymond Sep 11, 2024
ff53b08
fix lint
sukantoraymond Sep 11, 2024
39f17e0
fix lint
sukantoraymond Sep 11, 2024
aef7fc1
fix lint
sukantoraymond Sep 11, 2024
2866231
add flags
sukantoraymond Sep 11, 2024
6fd7726
adding teleporter contract to genesis
felipemadero Sep 12, 2024
4295956
validator prompt
sukantoraymond Sep 12, 2024
ee79685
bootstrap validators
sukantoraymond Sep 12, 2024
f586cb6
add mock
sukantoraymond Sep 12, 2024
d15757c
fix lint
sukantoraymond Sep 12, 2024
059519d
update prompt validator
sukantoraymond Sep 13, 2024
4809209
update prompt validator
sukantoraymond Sep 13, 2024
606c4fc
fixes for icm on genesis
felipemadero Sep 16, 2024
29966df
add icm from a given embedded file
felipemadero Sep 16, 2024
dfa8bfa
add function to deploy ICM registry
felipemadero Sep 16, 2024
26ef2fa
creating mapping values
felipemadero Sep 16, 2024
78c58a6
add consts
felipemadero Sep 16, 2024
d39a8e8
make local deploy to work
felipemadero Sep 16, 2024
857f815
do not print info for icm support addrs
felipemadero Sep 16, 2024
c868707
nit
felipemadero Sep 16, 2024
e87b8f1
implement prompts
sukantoraymond Sep 16, 2024
b12908d
fix prompt mock
sukantoraymond Sep 16, 2024
10a0377
update sidecar
sukantoraymond Sep 16, 2024
3d6ade0
update prompts
sukantoraymond Sep 16, 2024
1395511
update prompts
sukantoraymond Sep 17, 2024
b8a0a88
refactor
sukantoraymond Sep 17, 2024
e2757a7
nit
felipemadero Sep 17, 2024
d26b4b5
Merge branch 'main' into genesis-icm
felipemadero Sep 18, 2024
7d829d7
update prompts
sukantoraymond Sep 18, 2024
5cd3e16
fix wiz stuff
felipemadero Sep 18, 2024
4cbe6e7
update prompts
sukantoraymond Sep 18, 2024
3756c9d
use default balance and weight
sukantoraymond Sep 18, 2024
5042124
generate new node ids and bls
sukantoraymond Sep 18, 2024
f218939
fix lint
sukantoraymond Sep 18, 2024
773f313
add flags
sukantoraymond Sep 18, 2024
1dcf24c
add flags
sukantoraymond Sep 18, 2024
fcda44c
add a function to initialize PoA manager
felipemadero Sep 18, 2024
dc0b321
add lib folder
felipemadero Sep 19, 2024
c8c4e5c
address comments
sukantoraymond Sep 19, 2024
a66cb32
address comments
sukantoraymond Sep 19, 2024
890d6db
address comments
sukantoraymond Sep 19, 2024
b55a792
move validator prompt to deploy
sukantoraymond Sep 19, 2024
58bfdae
address comments
sukantoraymond Sep 19, 2024
9fe693e
address comments
sukantoraymond Sep 19, 2024
bfb0c67
fix lint
sukantoraymond Sep 19, 2024
9d7bac8
address comments
sukantoraymond Sep 19, 2024
e27cfb7
Merge branch 'acp-77' into subnet-create-acp77
sukantoraymond Sep 19, 2024
4c7ee6f
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 19, 2024
9e2a87c
address comments
sukantoraymond Sep 19, 2024
b7408b3
fix test
sukantoraymond Sep 19, 2024
0659211
address PR comments
felipemadero Sep 19, 2024
0663e48
Merge branch 'main' into genesis-icm
felipemadero Sep 19, 2024
03e79d5
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 19, 2024
a613ece
Merge branch 'acp-77' into genesis-icm
felipemadero Sep 19, 2024
a377ee1
Merge branch 'genesis-icm' into genesis-poa
felipemadero Sep 20, 2024
723f0b4
Merge branch 'validator-prompt-acp77' into genesis-poa
felipemadero Sep 20, 2024
4bc4e5d
basic PoA manager setting
felipemadero Sep 20, 2024
3f0eca7
lint
felipemadero Sep 20, 2024
2a8c14d
address comments
sukantoraymond Sep 20, 2024
3168a79
Merge branch 'acp-77' into subnet-create-acp77
sukantoraymond Sep 20, 2024
b39b4ea
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 20, 2024
1cc8146
fix lint
sukantoraymond Sep 20, 2024
1cf6851
Merge branch 'validator-prompt-acp77' into genesis-poa
felipemadero Sep 21, 2024
64580c9
fix e2e
felipemadero Sep 21, 2024
b2815f2
Merge branch 'acp-77' into genesis-poa
sukantoraymond Sep 23, 2024
b6f65ca
fix merge
sukantoraymond Sep 23, 2024
7bddc67
Merge branch 'acp-77' into genesis-poa
sukantoraymond Sep 23, 2024
3962f81
fix merge
sukantoraymond Sep 23, 2024
4152f68
filter based on balance
felipemadero Sep 26, 2024
0e054cb
add unit tests
felipemadero Sep 26, 2024
aee6228
Merge branch 'genesis-icm' into genesis-poa
felipemadero Sep 26, 2024
ae1893e
Merge branch 'main' into genesis-poa
felipemadero Sep 26, 2024
03389e6
nit
felipemadero Sep 26, 2024
64e070c
Merge branch 'acp-77' into genesis-poa
felipemadero Sep 26, 2024
e7bed94
address PR comments
felipemadero Sep 26, 2024
a24ae5b
Update cmd/blockchaincmd/describe.go
felipemadero Sep 26, 2024
e39d745
Merge branch 'genesis-icm' into genesis-poa
felipemadero Sep 26, 2024
723103e
Merge branch 'acp-77' into genesis-poa
felipemadero Sep 26, 2024
be54289
nit
felipemadero Sep 26, 2024
7426bdd
address PR comments
felipemadero Sep 26, 2024
f7d7573
lint
felipemadero Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ type CreateFlags struct {
useLatestReleasedVMVersion bool
useLatestPreReleasedVMVersion bool
useExternalGasToken bool
addICMRegistryToGenesis bool
proofOfStake bool
proofOfAuthority bool
poaValidatorManagerOwner string
}

var (
Expand Down Expand Up @@ -103,8 +105,10 @@ configuration, pass the -f flag.`,
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.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 for validator management")
cmd.Flags().BoolVar(&createFlags.proofOfStake, "proof-of-stake", false, "(coming soon) use proof of stake for validator management")
cmd.Flags().StringVar(&createFlags.poaValidatorManagerOwner, "poa-manager-owner", "", "EVM address that controls Validator Manager Owner (for Proof of Authority only)")
return cmd
}

Expand Down Expand Up @@ -202,7 +206,6 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {

var (
genesisBytes []byte
sc *models.Sidecar
useTeleporterFlag *bool
deployTeleporter bool
useExternalGasToken bool
Expand All @@ -220,7 +223,28 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
return err
}

sc := &models.Sidecar{}

if err = promptValidatorManagementType(app, sc); err != nil {
return err
}
felipemadero marked this conversation as resolved.
Show resolved Hide resolved

if sc.ValidatorManagement != models.ProofOfAuthority && createFlags.poaValidatorManagerOwner != "" {
return errors.New("--poa-manager-owner flag cannot be used when blockchain validator management type is not Proof of Authority")
}

if vmType == models.SubnetEvm {
if sc.ValidatorManagement == models.ProofOfAuthority {
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
if createFlags.poaValidatorManagerOwner == "" {
createFlags.poaValidatorManagerOwner, err = getValidatorContractManagerAddr()
if err != nil {
return err
}
}
sc.PoAValidatorManagerOwner = createFlags.poaValidatorManagerOwner
ux.Logger.GreenCheckmarkToUser("PoA Validator Manager Contract owner %s", createFlags.poaValidatorManagerOwner)
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
}

felipemadero marked this conversation as resolved.
Show resolved Hide resolved
if genesisFile == "" {
// Default
defaultsKind, err = vm.PromptDefaults(app, defaultsKind)
Expand Down Expand Up @@ -270,6 +294,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
var params vm.SubnetEVMGenesisParams
params, tokenSymbol, err = vm.PromptSubnetEVMGenesisParams(
app,
sc,
vmVersion,
createFlags.chainID,
createFlags.tokenSymbol,
Expand All @@ -288,19 +313,20 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
blockchainName,
params,
teleporterInfo,
createFlags.addICMRegistryToGenesis,
)
if err != nil {
return err
}
}
sc, err = vm.CreateEvmSidecar(
if err := vm.FillEvmSidecar(
sc,
app,
blockchainName,
vmVersion,
tokenSymbol,
true,
)
if err != nil {
); err != nil {
return err
}
} else {
Expand All @@ -319,7 +345,8 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
return err
}
}
sc, err = vm.CreateCustomSidecar(
if err := vm.FillCustomSidecar(
sc,
app,
blockchainName,
useRepo,
Expand All @@ -328,8 +355,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
customVMBuildScript,
vmFile,
tokenSymbol,
)
if err != nil {
); err != nil {
return err
}
}
Expand All @@ -352,9 +378,6 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
}
}
}
if err = promptValidatorManagementType(app, sc); err != nil {
return err
}

if err = app.WriteGenesisFile(blockchainName, genesisBytes); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-local-teleporter", false, "skip automatic teleporter deploy on local networks [to be deprecated]")
cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-teleporter-deploy", false, "skip automatic teleporter deploy")
cmd.Flags().BoolVar(&icmSpec.SkipRelayerDeploy, "skip-relayer", false, "skip relayer deploy")
cmd.Flags().StringVar(&icmSpec.Version, "teleporter-version", "latest", "teleporter version to deploy")
cmd.Flags().StringVar(&icmSpec.ICMVersion, "teleporter-version", "latest", "teleporter version to deploy")
cmd.Flags().StringVar(&icmSpec.RelayerVersion, "relayer-version", "latest", "relayer version to deploy")
cmd.Flags().StringVar(&icmSpec.MessengerContractAddressPath, "teleporter-messenger-contract-address-path", "", "path to an interchain messenger contract address file")
cmd.Flags().StringVar(&icmSpec.MessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to an interchain messenger deployer address file")
cmd.Flags().StringVar(&icmSpec.MessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to an interchain messenger deployer tx file")
Expand Down
11 changes: 9 additions & 2 deletions cmd/blockchaincmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/subnet"
icmgenesis "github.com/ava-labs/avalanche-cli/pkg/teleporter/genesis"
"github.com/ava-labs/avalanche-cli/pkg/txutils"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
Expand Down Expand Up @@ -275,8 +276,14 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error {
t.Style().Options.SeparateRows = true
t.SetTitle("Initial Token Allocation")
t.AppendHeader(table.Row{"Description", "Address and Private Key", "Amount (10^18)", "Amount (wei)"})
for address := range genesis.Alloc {
amount := genesis.Alloc[address].Balance
for address, allocation := range genesis.Alloc {
if len(allocation.Code) > 0 {
continue
}
if address == common.HexToAddress(icmgenesis.MessengerDeployerAddress) {
continue
}
amount := allocation.Balance
formattedAmount := new(big.Int).Div(amount, big.NewInt(params.Ether))
description := ""
privKey := ""
Expand Down
5 changes: 4 additions & 1 deletion cmd/blockchaincmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ava-labs/avalanche-cli/internal/mocks"
"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/prompts"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/vm"
Expand Down Expand Up @@ -40,7 +41,9 @@ func TestExportImportSubnet(t *testing.T) {
"../../"+utils.SubnetEvmGenesisPath,
)
require.NoError(err)
sc, err := vm.CreateEvmSidecar(
sc := &models.Sidecar{}
err = vm.FillEvmSidecar(
sc,
app,
testSubnet,
vmVersion,
Expand Down
14 changes: 14 additions & 0 deletions cmd/blockchaincmd/prompt_genesis_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
)

func getValidatorContractManagerAddr() (string, error) {
return prompts.PromptAddress(
app.Prompt,
"enable as controller of ValidatorManager contract",
app.GetKeyDir(),
app.GetKey,
"",
models.UndefinedNetwork,
prompts.EVMFormat,
"Enter address",
)
}

func promptProofOfPossession() (string, string, error) {
ux.Logger.PrintToUser("Next, we need the public key and proof of possession of the node's BLS")
ux.Logger.PrintToUser("Check https://docs.avax.network/api-reference/info-api#infogetnodeid for instructions on calling info.getNodeID API")
Expand Down Expand Up @@ -49,6 +62,7 @@ func promptValidatorManagementType(
sidecar.ValidatorManagement = models.ProofOfAuthority
return nil
}

options := []string{models.ProofOfAuthority, models.ProofOfStake, explainOption}
for {
option, err := app.Prompt.CaptureList(
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchaincmd/upgradecmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func promptAdminManagerAndEnabledAddresses(
sc *models.Sidecar,
action string,
) ([]common.Address, []common.Address, []common.Address, bool, error) {
allowList, cancelled, err := vm.GenerateAllowList(app, action, sc.VMVersion)
allowList, cancelled, err := vm.GenerateAllowList(app, vm.AllowList{}, action, sc.VMVersion)
if cancelled || err != nil {
return nil, nil, nil, cancelled, err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/nodecmd/wiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func wiz(cmd *cobra.Command, args []string) error {
},
DeployMessenger: deployTeleporterMessenger,
DeployRegistry: deployTeleporterRegistry,
ForceRegistryDeploy: true,
Version: teleporterVersion,
MessengerContractAddressPath: teleporterMessengerContractAddressPath,
MessengerDeployerAddressPath: teleporterMessengerDeployerAddressPath,
Expand Down
4 changes: 4 additions & 0 deletions cmd/teleportercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DeployFlags struct {
GenesisKey bool
DeployMessenger bool
DeployRegistry bool
ForceRegistryDeploy bool
RPCURL string
Version string
MessengerContractAddressPath string
Expand Down Expand Up @@ -62,6 +63,7 @@ func newDeployCmd() *cobra.Command {
deployFlags.ChainFlags.AddToCmd(cmd, "deploy ICM", true)
cmd.Flags().BoolVar(&deployFlags.DeployMessenger, "deploy-messenger", true, "deploy Teleporter Messenger")
cmd.Flags().BoolVar(&deployFlags.DeployRegistry, "deploy-registry", true, "deploy Teleporter Registry")
cmd.Flags().BoolVar(&deployFlags.ForceRegistryDeploy, "force-registry-deploy", false, "deploy Teleporter Registry even if Messenger has already been deployed")
cmd.Flags().StringVar(&deployFlags.RPCURL, "rpc-url", "", "use the given RPC URL to connect to the subnet")
cmd.Flags().StringVar(&deployFlags.Version, "version", "latest", "version to deploy")
cmd.Flags().StringVar(&deployFlags.MessengerContractAddressPath, "messenger-contract-address-path", "", "path to a messenger contract address file")
Expand Down Expand Up @@ -188,6 +190,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
privateKey,
flags.DeployMessenger,
flags.DeployRegistry,
flags.ForceRegistryDeploy,
)
if err != nil {
return err
Expand Down Expand Up @@ -224,6 +227,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
ewoq.PrivKeyHex(),
flags.DeployMessenger,
flags.DeployRegistry,
false,
)
if err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions pkg/contract/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,39 @@ func GetEVMSubnetGenesisNativeMinterAdmin(
}
return getGenesisNativeMinterAdmin(app, network, genesisData)
}

func ContractAddressIsInBlockchainGenesis(
app *application.Avalanche,
network models.Network,
chainSpec ChainSpec,
contractAddress common.Address,
) (bool, error) {
genesisData, err := GetBlockchainGenesis(
app,
network,
chainSpec,
)
if err != nil {
return false, err
}
if !utils.ByteSliceIsSubnetEvmGenesis(genesisData) {
return false, fmt.Errorf("only EVM based vms support genesis contract checks")
}
return ContractAddressIsInGenesisData(genesisData, contractAddress)
}

func ContractAddressIsInGenesisData(
genesisData []byte,
contractAddress common.Address,
) (bool, error) {
genesis, err := utils.ByteSliceToSubnetEvmGenesis(genesisData)
if err != nil {
return false, err
}
for address, allocation := range genesis.Alloc {
if address == contractAddress {
return len(allocation.Code) > 0, nil
}
}
return false, nil
}
3 changes: 2 additions & 1 deletion pkg/models/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Sidecar struct {
// SubnetEVM based VM's only
SubnetEVMMainnetChainID uint
// TODO: remove if not needed for subnet acp 77 create flow once avalnache go releases etna
ValidatorManagement ValidatorManagementType
ValidatorManagement ValidatorManagementType
PoAValidatorManagerOwner string
}

func (sc Sidecar) GetVMID() (string, error) {
Expand Down
Loading
Loading