diff --git a/vms/platformvm/txs/convert_subnet_tx.go b/vms/platformvm/txs/convert_subnet_tx.go index c6d8791a5a6..7f76c962a20 100644 --- a/vms/platformvm/txs/convert_subnet_tx.go +++ b/vms/platformvm/txs/convert_subnet_tx.go @@ -21,8 +21,8 @@ import ( const MaxSubnetAddressLength = 4096 var ( - _ UnsignedTx = (*ConvertSubnetTx)(nil) - _ utils.Sortable[ConvertSubnetValidator] = ConvertSubnetValidator{} + _ UnsignedTx = (*ConvertSubnetTx)(nil) + _ utils.Sortable[*ConvertSubnetValidator] = (*ConvertSubnetValidator)(nil) ErrConvertPermissionlessSubnet = errors.New("cannot convert a permissionless subnet") ErrAddressTooLong = errors.New("address is too long") @@ -41,7 +41,7 @@ type ConvertSubnetTx struct { // Address of the Subnet manager Address types.JSONByteSlice `serialize:"true" json:"address"` // Initial pay-as-you-go validators for the Subnet - Validators []ConvertSubnetValidator `serialize:"true" json:"validators"` + Validators []*ConvertSubnetValidator `serialize:"true" json:"validators"` // Authorizes this conversion SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` } @@ -102,7 +102,7 @@ type ConvertSubnetValidator struct { DeactivationOwner message.PChainOwner `serialize:"true" json:"deactivationOwner"` } -func (v ConvertSubnetValidator) Compare(o ConvertSubnetValidator) int { +func (v *ConvertSubnetValidator) Compare(o *ConvertSubnetValidator) int { return bytes.Compare(v.NodeID, o.NodeID) } diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index 27c63b663b8..709ef27467d 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -350,7 +350,7 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { // ConvertSubnetValidatorComplexity returns the complexity the validators add to // a transaction. -func ConvertSubnetValidatorComplexity(sovs ...txs.ConvertSubnetValidator) (gas.Dimensions, error) { +func ConvertSubnetValidatorComplexity(sovs ...*txs.ConvertSubnetValidator) (gas.Dimensions, error) { var complexity gas.Dimensions for _, sov := range sovs { sovComplexity, err := convertSubnetValidatorComplexity(sov) @@ -366,7 +366,7 @@ func ConvertSubnetValidatorComplexity(sovs ...txs.ConvertSubnetValidator) (gas.D return complexity, nil } -func convertSubnetValidatorComplexity(sov txs.ConvertSubnetValidator) (gas.Dimensions, error) { +func convertSubnetValidatorComplexity(sov *txs.ConvertSubnetValidator) (gas.Dimensions, error) { complexity := gas.Dimensions{ gas.Bandwidth: intrinsicConvertSubnetValidatorBandwidth, gas.DBRead: 0, diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index e582f997c95..2e67faa6346 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -27,7 +27,7 @@ const ( validatorSetsCacheSize = 64 maxRecentlyAcceptedWindowSize = 64 minRecentlyAcceptedWindowSize = 0 - recentlyAcceptedWindowTTL = 15 * time.Second + recentlyAcceptedWindowTTL = 30 * time.Second ) var ( diff --git a/wallet/chain/p/builder/builder.go b/wallet/chain/p/builder/builder.go index 8e2b075a3e9..e9879fdf1a0 100644 --- a/wallet/chain/p/builder/builder.go +++ b/wallet/chain/p/builder/builder.go @@ -161,7 +161,7 @@ type Builder interface { subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.ConvertSubnetTx, error) @@ -829,7 +829,7 @@ func (b *builder) NewConvertSubnetTx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.ConvertSubnetTx, error) { var ( diff --git a/wallet/chain/p/builder/builder_with_options.go b/wallet/chain/p/builder/builder_with_options.go index ec52d99d7fa..c537ef4f722 100644 --- a/wallet/chain/p/builder/builder_with_options.go +++ b/wallet/chain/p/builder/builder_with_options.go @@ -160,7 +160,7 @@ func (b *builderWithOptions) NewConvertSubnetTx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.ConvertSubnetTx, error) { return b.builder.NewConvertSubnetTx( diff --git a/wallet/chain/p/wallet/wallet.go b/wallet/chain/p/wallet/wallet.go index 4c5fa0b8604..fd85e837b78 100644 --- a/wallet/chain/p/wallet/wallet.go +++ b/wallet/chain/p/wallet/wallet.go @@ -147,7 +147,7 @@ type Wallet interface { subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.Tx, error) @@ -442,7 +442,7 @@ func (w *wallet) IssueConvertSubnetTx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.Tx, error) { utx, err := w.builder.NewConvertSubnetTx(subnetID, chainID, address, validators, options...) diff --git a/wallet/chain/p/wallet/with_options.go b/wallet/chain/p/wallet/with_options.go index a5b2e17e928..5dc460e8b32 100644 --- a/wallet/chain/p/wallet/with_options.go +++ b/wallet/chain/p/wallet/with_options.go @@ -148,7 +148,7 @@ func (w *withOptions) IssueConvertSubnetTx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetValidator, options ...common.Option, ) (*txs.Tx, error) { return w.wallet.IssueConvertSubnetTx( diff --git a/wallet/subnet/primary/examples/convert-subnet/main.go b/wallet/subnet/primary/examples/convert-subnet/main.go index ef6d751a3a9..b7133488f6e 100644 --- a/wallet/subnet/primary/examples/convert-subnet/main.go +++ b/wallet/subnet/primary/examples/convert-subnet/main.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/platformvm/txs" + "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" ) @@ -23,7 +24,7 @@ func main() { uri := "http://localhost:9700" kc := secp256k1fx.NewKeychain(key) subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof") - chainID := ids.FromStringOrPanic("21G9Uqg2R7hYa81kZK7oMCgstsHEiNGbkpB9kdBLUeWx3wWMsV") + chainID := ids.FromStringOrPanic("E8nTR9TtRwfkS7XFjTYUYHENQ91mkPMtDUwwCeu7rNgBBtkqu") addressHex := "" weight := units.Schmeckle @@ -42,6 +43,23 @@ func main() { } log.Printf("fetched node ID %s in %s\n", nodeID, time.Since(nodeInfoStartTime)) + validationID := subnetID.Append(0) + conversionID, err := message.SubnetConversionID(message.SubnetConversionData{ + SubnetID: subnetID, + ManagerChainID: chainID, + ManagerAddress: address, + Validators: []message.SubnetConversionValidatorData{ + { + NodeID: nodeID.Bytes(), + BLSPublicKey: nodePoP.PublicKey, + Weight: weight, + }, + }, + }) + if err != nil { + log.Fatalf("failed to calculate conversionID: %s\n", err) + } + // MakeWallet fetches the available UTXOs owned by [kc] on the network that // [uri] is hosting and registers [subnetID]. walletSyncStartTime := time.Now() @@ -60,22 +78,29 @@ func main() { pWallet := wallet.P() convertSubnetStartTime := time.Now() - addValidatorTx, err := pWallet.IssueConvertSubnetTx( + convertSubnetTx, err := pWallet.IssueConvertSubnetTx( subnetID, chainID, address, - []txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetValidator{ { - NodeID: nodeID, + NodeID: nodeID.Bytes(), Weight: weight, Balance: units.Avax, - Signer: nodePoP, - RemainingBalanceOwner: &secp256k1fx.OutputOwners{}, + Signer: *nodePoP, + RemainingBalanceOwner: message.PChainOwner{}, + DeactivationOwner: message.PChainOwner{}, }, }, ) if err != nil { - log.Fatalf("failed to issue add subnet validator transaction: %s\n", err) + log.Fatalf("failed to issue subnet conversion transaction: %s\n", err) } - log.Printf("added new subnet validator %s to %s with %s in %s\n", nodeID, subnetID, addValidatorTx.ID(), time.Since(convertSubnetStartTime)) + log.Printf("converted subnet %s with transactionID %s, validationID %s, and conversionID %s in %s\n", + subnetID, + convertSubnetTx.ID(), + validationID, + conversionID, + time.Since(convertSubnetStartTime), + ) }