Skip to content

Commit

Permalink
Integrate ConvertSubnetTx AvalancheGo (#2213)
Browse files Browse the repository at this point in the history
* complete implementation of avalanche go convertsubnet

* update relayer

* update convertsubnettx

* update avalanchego

* update avalanche go

* update avalanche go

* dont prompt control key for sov

* add tx cases for convert subnet tx (#2218)

* Poa integration (#2212)

* use latest contract

* point to latest convert subnet avago PR

* nit

* use fixed anr

* nit

* add subnet conversion id calculation

* created unsigned warp message

* fixed local network deploy

* added signing

* now this is working

* using latest avago master + awm relayer

* working pretty well

* ready

* lint

* address PR comments

* nit

---------

Signed-off-by: sukantoraymond <[email protected]>
Co-authored-by: sukantoraymond <[email protected]>

* fix lint

* reverse sidecar sov logic

* fix merge

* add poa setup to blockchain deploy (#2219)

* add setup poa to blockchain deploy

* add command

* add proposervm update

* proposervm flag for nodes

* nit

* nit

* fixed dynamic fees params calculation

* only adding tracked apis to apis in sidecar

* improve prompts

* fixing various stuff

* add upgrade file

* use anr etna enabled

* keep upgrade on sync

* workin

* almost working

* working1

* Update cmd/keycmd/transfer.go

Co-authored-by: Meaghan FitzGerald <[email protected]>
Signed-off-by: felipemadero <[email protected]>

* fix some lint

* address PR comments

* missing file

* nit

---------

Signed-off-by: felipemadero <[email protected]>
Signed-off-by: sukantoraymond <[email protected]>
Co-authored-by: Meaghan FitzGerald <[email protected]>
Co-authored-by: sukantoraymond <[email protected]>

---------

Signed-off-by: sukantoraymond <[email protected]>
Signed-off-by: felipemadero <[email protected]>
Co-authored-by: felipemadero <[email protected]>
Co-authored-by: Meaghan FitzGerald <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent 0d35df5 commit 0f92a40
Show file tree
Hide file tree
Showing 46 changed files with 1,280 additions and 219 deletions.
150 changes: 126 additions & 24 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

"github.com/ava-labs/avalanche-cli/pkg/utils"

"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
Expand All @@ -29,6 +32,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/subnet"
"github.com/ava-labs/avalanche-cli/pkg/txutils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/validatormanager"
"github.com/ava-labs/avalanche-cli/pkg/vm"
anrutils "github.com/ava-labs/avalanche-network-runner/utils"
"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -67,6 +71,7 @@ var (
icmSpec subnet.ICMSpec
generateNodeID bool
bootstrapValidatorsJSONFilePath string
privateKeyFlags contract.PrivateKeyFlags

errMutuallyExlusiveControlKeys = errors.New("--control-keys and --same-control-key are mutually exclusive")
ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive")
Expand Down Expand Up @@ -94,6 +99,8 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
Args: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, deploySupportedNetworkOptions)
privateKeyFlags.SetFlagNames("blockchain-private-key", "blockchain-key", "blockchain-genesis-key")
privateKeyFlags.AddToCmd(cmd, "to fund validator manager initialization")
cmd.Flags().StringVar(&userProvidedAvagoVersion, "avalanchego-version", "latest", "use this version of avalanchego (ex: v1.17.12)")
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet deploy only]")
cmd.Flags().BoolVarP(&sameControlKey, "same-control-key", "s", false, "use the fee-paying key as control key")
Expand Down Expand Up @@ -337,8 +344,8 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}

if sidecar.NotSOV && bootstrapValidatorsJSONFilePath != "" {
return fmt.Errorf("--bootstrap-filepath flag is only applicable to SOV (Subnet Only Validator) blockchains")
if !sidecar.Sovereign && bootstrapValidatorsJSONFilePath != "" {
return fmt.Errorf("--bootstrap-filepath flag is only applicable to sovereign blockchains")
}

network, err := networkoptions.GetNetworkFromCmdLineFlags(
Expand Down Expand Up @@ -385,7 +392,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}

if !sidecar.NotSOV {
if sidecar.Sovereign {
if bootstrapValidatorsJSONFilePath == "" {
bootstrapValidators, err = promptBootstrapValidators(network)
if err != nil {
Expand Down Expand Up @@ -500,6 +507,9 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
network.HandlePublicNetworkSimulation()

if createSubnet {
if sidecar.Sovereign {
sameControlKey = true
}
controlKeys, threshold, err = promptOwners(
kc,
controlKeys,
Expand Down Expand Up @@ -556,6 +566,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
deployer.CleanCacheWallet()
// get the control keys in the same order as the tx
_, controlKeys, threshold, err = txutils.GetOwners(network, subnetID)
if err != nil {
Expand Down Expand Up @@ -606,23 +617,26 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}

if !sidecar.NotSOV {
//avaGoBootstrapValidators, err := convertToAvalancheGoSubnetValidator(bootstrapValidators)
//if err != nil {
// return err
//}
// TODO: replace with avalanchego subnetValidators once implemented
if sidecar.Sovereign {
avaGoBootstrapValidators, err := ConvertToAvalancheGoSubnetValidator(bootstrapValidators)
if err != nil {
return err
}
deployer.CleanCacheWallet()
managerAddress := common.HexToAddress(validatormanager.ValidatorContractAddress)
isFullySigned, ConvertL1TxID, tx, remainingSubnetAuthKeys, err := deployer.ConvertL1(
controlKeys,
subnetAuthKeys,
subnetID,
blockchainID,
// avaGoBootstrapValidators,
managerAddress,
avaGoBootstrapValidators,
)
if err != nil {
ux.Logger.PrintToUser(logging.Red.Wrap(
fmt.Sprintf("error converting blockchain: %s. fix the issue and try again with a new convert cmd", err),
))
return err
}

savePartialTx = !isFullySigned && err == nil
Expand All @@ -641,6 +655,93 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}

bar, err := ux.TimedProgressBar(
30*time.Second,
"Waiting for Blockchain to be converted into Subnet Only Validator (SOV) Blockchain ...",
2,
)
if err != nil {
return err
}

// Issue random transaction >30s after ConverSubnetTx to evict its block from the block map
_, _, err = deployer.PChainTransfer(kc.Addresses().List()[0], 1)
if err != nil {
return err
}
if err := ux.ExtraStepExecuted(bar); err != nil {
return err
}
// Issue random transaction to advance the p-chain height now that the
// ConvertSubnetTx block isn't in the block map
_, _, err = deployer.PChainTransfer(kc.Addresses().List()[0], 1)
if err != nil {
return err
}
if err := ux.ExtraStepExecuted(bar); err != nil {
return err
}
fmt.Println()

if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators); err != nil {
return err
}

if false {
chainSpec := contract.ChainSpec{
BlockchainName: blockchainName,
}
genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey(
app,
network,
chainSpec,
)
if err != nil {
return err
}
privateKey, err := privateKeyFlags.GetPrivateKey(app, genesisPrivateKey)
if err != nil {
return err
}
if privateKey == "" {
privateKey, err = prompts.PromptPrivateKey(
app.Prompt,
"Which key to you want to use to pay for initializing Validator Manager contract? (Uses Blockchain gas token)",
app.GetKeyDir(),
app.GetKey,
genesisAddress,
genesisPrivateKey,
)
if err != nil {
return err
}
}
rpcURL, _, err := contract.GetBlockchainEndpoints(
app,
network,
chainSpec,
true,
false,
)
if err != nil {
return err
}
if err := validatormanager.SetupPoA(
app,
network,
rpcURL,
contract.ChainSpec{
BlockchainName: blockchainName,
},
privateKey,
common.HexToAddress(sidecar.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
); err != nil {
return err
}
ux.Logger.GreenCheckmarkToUser("Subnet is successfully converted into Subnet Only Validator")
}
}

flags := make(map[string]string)
Expand All @@ -649,10 +750,10 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

// update sidecar
// TODO: need to do something for backwards compatibility?
return app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators)
return nil
}

func getBLSInfo(publicKey, proofOfPossesion string) (signer.Signer, error) {
func getBLSInfo(publicKey, proofOfPossesion string) (signer.ProofOfPossession, error) {
type jsonProofOfPossession struct {
PublicKey string
ProofOfPossession string
Expand All @@ -663,18 +764,19 @@ func getBLSInfo(publicKey, proofOfPossesion string) (signer.Signer, error) {
}
popBytes, err := json.Marshal(jsonPop)
if err != nil {
return nil, err
return signer.ProofOfPossession{}, err
}
pop := &signer.ProofOfPossession{}
err = pop.UnmarshalJSON(popBytes)
if err != nil {
return nil, err
return signer.ProofOfPossession{}, err
}
return pop, nil
return *pop, nil
}

func convertToAvalancheGoSubnetValidator(subnetValidators []models.SubnetValidator) ([]SubnetValidator, error) {
bootstrapValidators := []SubnetValidator{}
// TODO: add deactivation owner?
func ConvertToAvalancheGoSubnetValidator(subnetValidators []models.SubnetValidator) ([]*txs.ConvertSubnetValidator, error) {
bootstrapValidators := []*txs.ConvertSubnetValidator{}
for _, validator := range subnetValidators {
nodeID, err := ids.NodeIDFromString(validator.NodeID)
if err != nil {
Expand All @@ -688,14 +790,14 @@ func convertToAvalancheGoSubnetValidator(subnetValidators []models.SubnetValidat
if err != nil {
return nil, fmt.Errorf("failure parsing change owner address: %w", err)
}
bootstrapValidator := SubnetValidator{
NodeID: nodeID,
bootstrapValidator := &txs.ConvertSubnetValidator{
NodeID: nodeID[:],
Weight: validator.Weight,
Balance: validator.Balance,
Signer: blsInfo,
ChangeOwner: &secp256k1fx.OutputOwners{
RemainingBalanceOwner: message.PChainOwner{
Threshold: 1,
Addrs: addrs,
Addresses: addrs,
},
}
bootstrapValidators = append(bootstrapValidators, bootstrapValidator)
Expand Down
13 changes: 13 additions & 0 deletions cmd/blockchaincmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error {
t.AppendRow(table.Row{net, "BlockchainID (CB58)", data.BlockchainID.String()})
t.AppendRow(table.Row{net, "BlockchainID (HEX)", hexEncoding})
}
endpoint, _, err := contract.GetBlockchainEndpoints(
app,
network,
contract.ChainSpec{
BlockchainName: sc.Name,
},
false,
false,
)
if err != nil {
return err
}
t.AppendRow(table.Row{net, "RPC Endpoint", endpoint})
}
ux.Logger.PrintToUser(t.Render())

Expand Down
1 change: 1 addition & 0 deletions cmd/blockchaincmd/prompt_genesis_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func promptBootstrapValidators(network models.Network) ([]models.SubnetValidator
var subnetValidators []models.SubnetValidator
numBootstrapValidators, err := app.Prompt.CaptureInt(
"How many bootstrap validators do you want to set up?",
prompts.ValidatePositiveInt,
)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchaincmd/upgradecmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func applyPublicNetworkUpgrade(blockchainName, networkKey string, sc *models.Sid

ux.Logger.PrintToUser("Trying to install the upgrade files at the provided %s path", avalanchegoChainConfigDir)
chainDir := filepath.Join(avalanchegoChainConfigDir, sc.Networks[networkKey].BlockchainID.String())
destPath := filepath.Join(chainDir, constants.UpgradeBytesFileName)
destPath := filepath.Join(chainDir, constants.UpgradeFileName)
if err = os.Mkdir(chainDir, constants.DefaultPerms755); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to create blockchain directory: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/contractcmd/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ and interacting with smart contracts.`,
app = injectedApp
// contract deploy
cmd.AddCommand(newDeployCmd())
// contract initpoamanager
cmd.AddCommand(newInitPOAManagerCmd())
return cmd
}
Loading

0 comments on commit 0f92a40

Please sign in to comment.