Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Sep 26, 2024
1 parent be54289 commit 7426bdd
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 48 deletions.
9 changes: 5 additions & 4 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
return err
}

if sc.ValidatorManagement != models.ProofOfAuthority && createFlags.poaValidatorManagerOwner != "" {
if !sc.PoA() && 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 {
if sc.PoA() {
if createFlags.poaValidatorManagerOwner == "" {
createFlags.poaValidatorManagerOwner, err = getValidatorContractManagerAddr()
if err != nil {
Expand Down Expand Up @@ -319,7 +319,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
return err
}
}
if err := vm.FillEvmSidecar(
if sc, err = vm.CreateEvmSidecar(
sc,
app,
blockchainName,
Expand All @@ -345,7 +345,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
return err
}
}
if err := vm.FillCustomSidecar(
if sc, err = vm.CreateCustomSidecar(
sc,
app,
blockchainName,
Expand Down Expand Up @@ -393,6 +393,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
}
}
ux.Logger.GreenCheckmarkToUser("Successfully created blockchain configuration")
ux.Logger.PrintToUser("Run 'avalanche blockchain describe' to view all created addresses and what their roles are")
return nil
}

Expand Down
49 changes: 33 additions & 16 deletions cmd/blockchaincmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error {
}
t.AppendRow(table.Row{"VM ID", vmIDstr, vmIDstr}, rowConfig)
t.AppendRow(table.Row{"VM Version", sc.VMVersion, sc.VMVersion}, rowConfig)
t.AppendRow(table.Row{"Validation", sc.ValidatorManagement, sc.ValidatorManagement}, rowConfig)

locallyDeployed, err := localnet.Deployed(sc.Name)
if err != nil {
Expand Down Expand Up @@ -218,7 +219,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error {
if err := printAllocations(sc, genesis); err != nil {
return err
}
printSmartContracts(genesis)
printSmartContracts(sc, genesis)
printPrecompiles(genesis)
}

Expand Down Expand Up @@ -257,16 +258,14 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error {

func printAllocations(sc models.Sidecar, genesis core.Genesis) error {
teleporterKeyAddress := ""
teleporterPrivKey := ""
if sc.TeleporterReady {
k, err := key.LoadSoft(models.NewLocalNetwork().ID, app.GetKeyPath(sc.TeleporterKey))
if err != nil {
return err
}
teleporterKeyAddress = k.C()
teleporterPrivKey = k.PrivKeyHex()
}
subnetAirdropKeyName, subnetAirdropAddress, subnetAirdropPrivKey, err := subnet.GetDefaultSubnetAirdropKeyInfo(app, sc.Name)
_, subnetAirdropAddress, _, err := subnet.GetDefaultSubnetAirdropKeyInfo(app, sc.Name)
if err != nil {
return err
}
Expand All @@ -277,7 +276,12 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error {
t.Style().Title.Format = text.FormatUpper
t.Style().Options.SeparateRows = true
t.SetTitle("Initial Token Allocation")
t.AppendHeader(table.Row{"Description", "Address and Private Key", "Amount (10^18)", "Amount (wei)"})
t.AppendHeader(table.Row{
"Description",
"Address and Private Key",
fmt.Sprintf("Amount (%s)", sc.TokenSymbol),
"Amount (wei)",
})
for address, allocation := range genesis.Alloc {
amount := allocation.Balance
// we are only interested in supply distribution here
Expand All @@ -289,14 +293,24 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error {
privKey := ""
switch address.Hex() {
case teleporterKeyAddress:
description = fmt.Sprintf("%s\n%s", sc.TeleporterKey, logging.Orange.Wrap("Teleporter Deploys"))
privKey = teleporterPrivKey
description = logging.Orange.Wrap("Used by ICM")
case subnetAirdropAddress:
description = fmt.Sprintf("%s\n%s", subnetAirdropKeyName, logging.Orange.Wrap("Main funded account"))
privKey = subnetAirdropPrivKey
description = logging.Orange.Wrap("Main funded account")
case vm.PrefundedEwoqAddress.Hex():
description = "Main funded account EWOQ"
privKey = vm.PrefundedEwoqPrivate
description = logging.Orange.Wrap("Main funded account")
case sc.PoAValidatorManagerOwner:
description = logging.Orange.Wrap("PoA Validator Manager Owner")
}
var (
found bool
name string
)
found, name, _, privKey, err = contract.SearchForManagedKey(app, models.NewLocalNetwork(), address, true)
if err != nil {
return err
}
if found {
description = fmt.Sprintf("%s\n%s", description, name)
}
t.AppendRow(table.Row{description, address.Hex() + "\n" + privKey, formattedAmount.String(), amount.String()})
}
Expand All @@ -305,7 +319,7 @@ func printAllocations(sc models.Sidecar, genesis core.Genesis) error {
return nil
}

func printSmartContracts(genesis core.Genesis) {
func printSmartContracts(sc models.Sidecar, genesis core.Genesis) {
if len(genesis.Alloc) == 0 {
return
}
Expand All @@ -325,10 +339,13 @@ func printSmartContracts(genesis core.Genesis) {
case address == common.HexToAddress(icmgenesis.MessengerContractAddress):
description = "ICM Messenger"
deployer = icmgenesis.MessengerDeployerAddress
case address == common.HexToAddress(validatormanager.PoAValidarorMessengerContractAddress):
description = "PoA Validator Manager"
case address == common.HexToAddress(validatormanager.PoSValidarorMessengerContractAddress):
description = "PoS Validator Manager"
case address == common.HexToAddress(validatormanager.ValidatorContractAddress):
if sc.PoA() {
description = "PoA Validator Manager"
} else {
description = "PoS Validator Manager"

}
}
t.AppendRow(table.Row{description, address.Hex(), deployer})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/contract/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func GetBlockchainAirdropKeyInfo(
}
}
for address := range genesis.Alloc {
found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, address, false)
found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, address, false)
if err != nil {
return "", "", "", err
}
Expand All @@ -82,7 +82,7 @@ func GetBlockchainAirdropKeyInfo(
return "", "", "", nil
}

func searchForManagedKey(
func SearchForManagedKey(
app *application.Avalanche,
network models.Network,
address common.Address,
Expand Down Expand Up @@ -204,7 +204,7 @@ func getGenesisNativeMinterAdmin(
return false, false, "", "", "", nil
}
for _, admin := range allowListCfg.AllowListConfig.AdminAddresses {
found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, admin, true)
found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, admin, true)
if err != nil {
return false, false, "", "", "", err
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func getGenesisNativeMinterManager(
return false, false, "", "", "", nil
}
for _, admin := range allowListCfg.AllowListConfig.ManagerAddresses {
found, keyName, addressStr, privKey, err := searchForManagedKey(app, network, admin, true)
found, keyName, addressStr, privKey, err := SearchForManagedKey(app, network, admin, true)
if err != nil {
return false, false, "", "", "", err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/models/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ func (sc Sidecar) NetworkDataIsEmpty(network string) bool {
_, networkExists := sc.Networks[network]
return !networkExists
}

func (sc Sidecar) PoA() bool {
return sc.ValidatorManagement == ProofOfAuthority
}

func (sc Sidecar) PoS() bool {
return sc.ValidatorManagement == ProofOfStake
}
5 changes: 2 additions & 3 deletions pkg/validatormanager/validatormanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
)

const (
PoAValidarorMessengerContractAddress = "0x5F584C2D56B4c356e7d82EC6129349393dc5df17"
PoSValidarorMessengerContractAddress = "0x6E584C2D56B4c356e7d82EC6129349393dc5df17"
ValidatorContractAddress = "0x5F584C2D56B4c356e7d82EC6129349393dc5df17"
)

//go:embed deployed_poa_validator_manager_bytecode.txt
Expand All @@ -25,7 +24,7 @@ func AddPoAValidatorManagerContractToAllocations(
allocs core.GenesisAlloc,
) {
deployedPoaValidatorManagerBytes := common.FromHex(strings.TrimSpace(string(deployedPoAValidatorManagerBytecode)))
allocs[common.HexToAddress(PoAValidarorMessengerContractAddress)] = core.GenesisAccount{
allocs[common.HexToAddress(ValidatorContractAddress)] = core.GenesisAccount{
Balance: big.NewInt(0),
Code: deployedPoaValidatorManagerBytes,
Nonce: 1,
Expand Down
22 changes: 13 additions & 9 deletions pkg/vm/create_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/ux"
)

func FillCustomSidecar(
func CreateCustomSidecar(
sc *models.Sidecar,
app *application.Avalanche,
subnetName string,
Expand All @@ -26,9 +26,13 @@ func FillCustomSidecar(
customVMBuildScript string,
vmPath string,
tokenSymbol string,
) error {
) (*models.Sidecar, error) {
ux.Logger.PrintToUser("creating custom VM subnet %s", subnetName)

if sc == nil {
sc = &models.Sidecar{}
}

sc.Name = subnetName
sc.VM = models.CustomVM
sc.Subnet = subnetName
Expand All @@ -47,39 +51,39 @@ func FillCustomSidecar(
options := []string{githubOption, localOption}
option, err := app.Prompt.CaptureList("How do you want to set up the VM binary?", options)
if err != nil {
return err
return nil, err
}
if option == githubOption {
useRepo = true
} else {
vmPath, err = app.Prompt.CaptureExistingFilepath("Enter path to VM binary")
if err != nil {
return err
return nil, err
}
}
}
if useRepo {
if err := SetCustomVMSourceCodeFields(app, sc, customVMRepoURL, customVMBranch, customVMBuildScript); err != nil {
return err
return nil, err
}
if err := BuildCustomVM(app, sc); err != nil {
return err
return nil, err
}
vmPath = app.GetCustomVMPath(subnetName)
} else {
if err := app.CopyVMBinary(vmPath, subnetName); err != nil {
return err
return nil, err
}
}

rpcVersion, err := GetVMBinaryProtocolVersion(vmPath)
if err != nil {
return fmt.Errorf("unable to get RPC version: %w", err)
return nil, fmt.Errorf("unable to get RPC version: %w", err)
}

sc.RPCVersion = rpcVersion

return nil
return sc, nil
}

func LoadCustomGenesis(app *application.Avalanche, genesisPath string) ([]byte, error) {
Expand Down
19 changes: 10 additions & 9 deletions pkg/vm/create_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
icmgenesis "github.com/ava-labs/avalanche-cli/pkg/teleporter/genesis"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/validatormanager"
blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain"
"github.com/ava-labs/subnet-evm/core"
Expand All @@ -32,32 +31,36 @@ var (
externalGasTokenBalance = big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(1000))
)

func FillEvmSidecar(
func CreateEvmSidecar(
sc *models.Sidecar,
app *application.Avalanche,
subnetName string,
subnetEVMVersion string,
tokenSymbol string,
getRPCVersionFromBinary bool,
) error {
) (*models.Sidecar, error) {
var (
err error
rpcVersion int
)

if sc == nil {
sc = &models.Sidecar{}
}

if getRPCVersionFromBinary {
_, vmBin, err := binutils.SetupSubnetEVM(app, subnetEVMVersion)
if err != nil {
return fmt.Errorf("failed to install subnet-evm: %w", err)
return nil, fmt.Errorf("failed to install subnet-evm: %w", err)
}
rpcVersion, err = GetVMBinaryProtocolVersion(vmBin)
if err != nil {
return fmt.Errorf("unable to get RPC version: %w", err)
return nil, fmt.Errorf("unable to get RPC version: %w", err)
}
} else {
rpcVersion, err = GetRPCProtocolVersion(app, models.SubnetEvm, subnetEVMVersion)
if err != nil {
return err
return nil, err
}
}

Expand All @@ -69,7 +72,7 @@ func FillEvmSidecar(
sc.TokenSymbol = tokenSymbol
sc.TokenName = tokenSymbol + " Token"

return nil
return sc, nil
}

func CreateEVMGenesis(
Expand All @@ -78,8 +81,6 @@ func CreateEVMGenesis(
teleporterInfo *teleporter.Info,
addICMRegistryToGenesis bool,
) ([]byte, error) {
ux.Logger.PrintToUser("creating genesis for blockchain %s", blockchainName)

feeConfig := getFeeConfig(params)

// Validity checks on the parameter settings.
Expand Down
6 changes: 3 additions & 3 deletions pkg/vm/evm_prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ func PromptSubnetEVMGenesisParams(
)
params.initialTokenAllocation = core.GenesisAlloc{}

if sc.ValidatorManagement == models.ProofOfAuthority {
if sc.PoA() {
params.UsePoAValidatorManager = true
params.initialTokenAllocation[common.HexToAddress(sc.PoAValidatorManagerOwner)] = core.GenesisAccount{
Balance: defaultPoAOwnerBalance,
}
}

if sc.ValidatorManagement == models.ProofOfStake {
if sc.PoS() {
params.enableNativeMinterPrecompile = true
params.nativeMinterPrecompileAllowList.EnabledAddresses = []common.Address{
common.HexToAddress(validatormanager.PoSValidarorMessengerContractAddress),
common.HexToAddress(validatormanager.ValidatorContractAddress),
}
}

Expand Down

0 comments on commit 7426bdd

Please sign in to comment.