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 2, 2024
2 parents 689512c + e647235 commit 1145367
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
14 changes: 11 additions & 3 deletions vms/platformvm/txs/convert_subnet_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package txs

import (
"bytes"
"errors"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -83,8 +84,8 @@ func (tx *ConvertSubnetTx) Visit(visitor Visitor) error {
}

type ConvertSubnetValidator struct {
// TODO: Should be a variable length nodeID
NodeID ids.NodeID `serialize:"true" json:"nodeID"`
// NodeID of this validator
NodeID types.JSONByteSlice `serialize:"true" json:"nodeID"`
// Weight of this validator used when sampling
Weight uint64 `serialize:"true" json:"weight"`
// Initial balance for this validator
Expand All @@ -102,13 +103,20 @@ type ConvertSubnetValidator struct {
}

func (v ConvertSubnetValidator) Compare(o ConvertSubnetValidator) int {
return v.NodeID.Compare(o.NodeID)
return bytes.Compare(v.NodeID, o.NodeID)
}

func (v *ConvertSubnetValidator) Verify() error {
if v.Weight == 0 {
return ErrZeroWeight
}
nodeID, err := ids.ToNodeID(v.NodeID)
if err != nil {
return err
}
if nodeID == ids.EmptyNodeID {
return errEmptyNodeID
}
return verify.All(
&v.Signer,
&secp256k1fx.OutputOwners{
Expand Down
50 changes: 23 additions & 27 deletions vms/platformvm/txs/convert_subnet_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/units"
Expand Down Expand Up @@ -296,10 +297,10 @@ func TestConvertSubnetTxSerialization(t *testing.T) {
Address: managerAddress,
Validators: []ConvertSubnetValidator{
{
NodeID: nodeID,
NodeID: nodeID[:],
Weight: 0x0102030405060708,
Balance: units.Avax,
Signer: signer.NewProofOfPossession(sk),
Signer: *signer.NewProofOfPossession(sk),
RemainingBalanceOwner: message.PChainOwner{
Threshold: 1,
Addresses: []ids.ShortID{
Expand Down Expand Up @@ -559,10 +560,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
invalidAddress = make(types.JSONByteSlice, MaxSubnetAddressLength+1)
validValidators = []ConvertSubnetValidator{
{
NodeID: ids.GenerateTestNodeID(),
NodeID: utils.RandomBytes(ids.NodeIDLen),
Weight: 1,
Balance: 1,
Signer: signer.NewProofOfPossession(sk),
Signer: *signer.NewProofOfPossession(sk),
RemainingBalanceOwner: message.PChainOwner{},
DeactivationOwner: message.PChainOwner{},
},
Expand Down Expand Up @@ -636,10 +637,18 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
NodeID: ids.NodeID{1},
NodeID: []byte{
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
},
{
NodeID: ids.NodeID{0},
NodeID: []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
},
},
SubnetAuth: validSubnetAuth,
Expand All @@ -653,8 +662,9 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
NodeID: utils.RandomBytes(ids.NodeIDLen),
Weight: 0,
Signer: signer.NewProofOfPossession(sk),
Signer: *signer.NewProofOfPossession(sk),
RemainingBalanceOwner: message.PChainOwner{},
DeactivationOwner: message.PChainOwner{},
},
Expand All @@ -670,8 +680,9 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
NodeID: utils.RandomBytes(ids.NodeIDLen),
Weight: 1,
Signer: &signer.ProofOfPossession{},
Signer: signer.ProofOfPossession{},
RemainingBalanceOwner: message.PChainOwner{},
DeactivationOwner: message.PChainOwner{},
},
Expand All @@ -687,8 +698,9 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
NodeID: utils.RandomBytes(ids.NodeIDLen),
Weight: 1,
Signer: signer.NewProofOfPossession(sk),
Signer: *signer.NewProofOfPossession(sk),
RemainingBalanceOwner: message.PChainOwner{
Threshold: 1,
},
Expand All @@ -706,8 +718,9 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
NodeID: utils.RandomBytes(ids.NodeIDLen),
Weight: 1,
Signer: signer.NewProofOfPossession(sk),
Signer: *signer.NewProofOfPossession(sk),
RemainingBalanceOwner: message.PChainOwner{},
DeactivationOwner: message.PChainOwner{
Threshold: 1,
Expand All @@ -718,23 +731,6 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) {
},
expectedErr: secp256k1fx.ErrOutputUnspendable,
},
{
name: "invalid validator signer",
tx: &ConvertSubnetTx{
BaseTx: validBaseTx,
Subnet: validSubnetID,
Validators: []ConvertSubnetValidator{
{
Weight: 1,
Signer: &signer.Empty{},
RemainingBalanceOwner: message.PChainOwner{},
DeactivationOwner: message.PChainOwner{},
},
},
SubnetAuth: validSubnetAuth,
},
expectedErr: ErrMissingPublicKey,
},
{
name: "invalid BaseTx",
tx: &ConvertSubnetTx{
Expand Down
3 changes: 2 additions & 1 deletion vms/platformvm/txs/fee/complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const (
intrinsicSECP256k1FxSignatureBandwidth = wrappers.IntLen + // signature index
secp256k1.SignatureLen // signature length

intrinsicConvertSubnetValidatorBandwidth = ids.NodeIDLen + // nodeID
intrinsicConvertSubnetValidatorBandwidth = wrappers.IntLen + // nodeID length
ids.NodeIDLen + // nodeID
wrappers.LongLen + // weight
wrappers.LongLen + // balance
wrappers.IntLen + // remaining balance owner threshold
Expand Down

0 comments on commit 1145367

Please sign in to comment.