Skip to content

Commit

Permalink
Merge branch 'implement-acp-77-increase-balance-tx' into implement-ac…
Browse files Browse the repository at this point in the history
…p-77-disable-subnet-validator-tx
  • Loading branch information
StephenButtolph authored Oct 3, 2024
2 parents 8da2f93 + b6bdb85 commit 9b378cf
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 21 deletions.
8 changes: 4 additions & 4 deletions vms/platformvm/txs/convert_subnet_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"`
}
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/fee/complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
validatorSetsCacheSize = 64
maxRecentlyAcceptedWindowSize = 64
minRecentlyAcceptedWindowSize = 0
recentlyAcceptedWindowTTL = 15 * time.Second
recentlyAcceptedWindowTTL = 30 * time.Second
)

var (
Expand Down
4 changes: 2 additions & 2 deletions wallet/chain/p/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion wallet/chain/p/builder/builder_with_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions wallet/chain/p/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion wallet/chain/p/wallet/with_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
41 changes: 33 additions & 8 deletions wallet/subnet/primary/examples/convert-subnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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

Expand All @@ -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()
Expand All @@ -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),
)
}

0 comments on commit 9b378cf

Please sign in to comment.