Skip to content

Commit

Permalink
Move p-chain Validator and SubnetValidator to the txs package (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 authored Feb 24, 2023
1 parent e4e41f2 commit e25eea0
Show file tree
Hide file tree
Showing 37 changed files with 136 additions and 243 deletions.
10 changes: 5 additions & 5 deletions tests/e2e/p/permissionless_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
Expand Down Expand Up @@ -195,8 +195,8 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
ginkgo.By("add permissionless validator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
addSubnetValidatorTxID, err := pWallet.IssueAddPermissionlessValidatorTx(
&validator.SubnetValidator{
Validator: validator.Validator{
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: genesis.LocalConfig.InitialStakers[0].NodeID,
Start: uint64(validatorStartTime.Unix()),
End: uint64(validatorStartTime.Add(5 * time.Second).Unix()),
Expand Down Expand Up @@ -224,8 +224,8 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
ginkgo.By("add permissionless delegator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
addSubnetDelegatorTxID, err := pWallet.IssueAddPermissionlessDelegatorTx(
&validator.SubnetValidator{
Validator: validator.Validator{
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: genesis.LocalConfig.InitialStakers[0].NodeID,
Start: uint64(delegatorStartTime.Unix()),
End: uint64(delegatorStartTime.Add(5 * time.Second).Unix()),
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
Expand Down Expand Up @@ -97,7 +97,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
validatorStartTimeDiff := 30 * time.Second
vdrStartTime := time.Now().Add(validatorStartTimeDiff)

vdr := &validator.Validator{
vdr := &txs.Validator{
NodeID: ids.GenerateTestNodeID(),
Start: uint64(vdrStartTime.Unix()),
End: uint64(vdrStartTime.Add(72 * time.Hour).Unix()),
Expand Down
3 changes: 1 addition & 2 deletions vms/platformvm/api/static_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/stakeable"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txheap"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand Down Expand Up @@ -307,7 +306,7 @@ func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, repl
NetworkID: uint32(args.NetworkID),
BlockchainID: ids.Empty,
}},
Validator: validator.Validator{
Validator: txs.Validator{
NodeID: vdr.NodeID,
Start: uint64(args.Time),
End: uint64(vdr.EndTime),
Expand Down
3 changes: 1 addition & 2 deletions vms/platformvm/blocks/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/blocks/executor"
Expand Down Expand Up @@ -325,7 +324,7 @@ func TestBuildBlock(t *testing.T) {
}},
Outs: []*avax.TransferableOutput{output},
}},
Validator: validator.Validator{
Validator: txs.Validator{
// Shouldn't be dropped
Start: uint64(now.Add(2 * txexecutor.SyncBound).Unix()),
},
Expand Down
5 changes: 2 additions & 3 deletions vms/platformvm/blocks/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand Down Expand Up @@ -66,7 +65,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) {
// create a proposal transaction to be included into proposal block
utx := &txs.AddValidatorTx{
BaseTx: txs.BaseTx{},
Validator: validator.Validator{End: uint64(chainTime.Unix())},
Validator: txs.Validator{End: uint64(chainTime.Unix())},
StakeOuts: []*avax.TransferableOutput{
{
Asset: avax.Asset{
Expand Down Expand Up @@ -192,7 +191,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) {
nextStakerTime := chainTime.Add(executor.SyncBound).Add(-1 * time.Second)
unsignedNextStakerTx := &txs.AddValidatorTx{
BaseTx: txs.BaseTx{},
Validator: validator.Validator{End: uint64(nextStakerTime.Unix())},
Validator: txs.Validator{End: uint64(nextStakerTime.Unix())},
StakeOuts: []*avax.TransferableOutput{
{
Asset: avax.Asset{
Expand Down
5 changes: 2 additions & 3 deletions vms/platformvm/blocks/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand All @@ -33,7 +32,7 @@ func TestNewBanffProposalBlock(t *testing.T) {
},
},
StakeOuts: []*avax.TransferableOutput{},
Validator: validator.Validator{},
Validator: txs.Validator{},
RewardsOwner: &secp256k1fx.OutputOwners{
Addrs: []ids.ShortID{},
},
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestNewApricotProposalBlock(t *testing.T) {
},
},
StakeOuts: []*avax.TransferableOutput{},
Validator: validator.Validator{},
Validator: txs.Validator{},
RewardsOwner: &secp256k1fx.OutputOwners{
Addrs: []ids.ShortID{},
},
Expand Down
5 changes: 2 additions & 3 deletions vms/platformvm/blocks/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand All @@ -33,7 +32,7 @@ func TestNewBanffStandardBlock(t *testing.T) {
},
},
StakeOuts: []*avax.TransferableOutput{},
Validator: validator.Validator{},
Validator: txs.Validator{},
RewardsOwner: &secp256k1fx.OutputOwners{
Addrs: []ids.ShortID{},
},
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestNewApricotStandardBlock(t *testing.T) {
},
},
StakeOuts: []*avax.TransferableOutput{},
Validator: validator.Validator{},
Validator: txs.Validator{},
RewardsOwner: &secp256k1fx.OutputOwners{
Addrs: []ids.ShortID{},
},
Expand Down
3 changes: 1 addition & 2 deletions vms/platformvm/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand Down Expand Up @@ -425,7 +424,7 @@ func newInitializedState(require *require.Assertions) (State, database.Database)
s, db := newUninitializedState(require)

initialValidator := &txs.AddValidatorTx{
Validator: validator.Validator{
Validator: txs.Validator{
NodeID: initialNodeID,
Start: uint64(initialTime.Unix()),
End: uint64(initialValidatorEndTime.Unix()),
Expand Down
9 changes: 4 additions & 5 deletions vms/platformvm/txs/add_delegator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/stakeable"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand Down Expand Up @@ -83,7 +82,7 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) {
Ins: inputs,
Memo: []byte{1, 2, 3, 4, 5, 6, 7, 8},
}},
Validator: validator.Validator{
Validator: Validator{
NodeID: ctx.NodeID,
Start: uint64(clk.Time().Unix()),
End: uint64(clk.Time().Add(time.Hour).Unix()),
Expand Down Expand Up @@ -117,11 +116,11 @@ func TestAddDelegatorTxSyntacticVerify(t *testing.T) {

// Case: delegator weight is not equal to total stake weight
addDelegatorTx.SyntacticallyVerified = false
addDelegatorTx.Validator.Wght = 2 * validatorWeight
addDelegatorTx.Wght = 2 * validatorWeight
stx, err = NewSigned(addDelegatorTx, Codec, signers)
require.NoError(err)
require.ErrorIs(stx.SyntacticVerify(ctx), errDelegatorWeightMismatch)
addDelegatorTx.Validator.Wght = validatorWeight
addDelegatorTx.Wght = validatorWeight
}

func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) {
Expand Down Expand Up @@ -181,7 +180,7 @@ func TestAddDelegatorTxSyntacticVerifyNotAVAX(t *testing.T) {
Ins: inputs,
Memo: []byte{1, 2, 3, 4, 5, 6, 7, 8},
}},
Validator: validator.Validator{
Validator: Validator{
NodeID: ctx.NodeID,
Start: uint64(clk.Time().Unix()),
End: uint64(clk.Time().Add(time.Hour).Unix()),
Expand Down
20 changes: 3 additions & 17 deletions vms/platformvm/txs/add_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package txs
import (
"errors"
"fmt"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand All @@ -16,7 +15,6 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand All @@ -31,7 +29,7 @@ type AddDelegatorTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// Describes the delegatee
Validator validator.Validator `serialize:"true" json:"validator"`
Validator `serialize:"true" json:"validator"`
// Where to send staked tokens when done validating
StakeOuts []*avax.TransferableOutput `serialize:"true" json:"stake"`
// Where to send staking rewards when done validating
Expand Down Expand Up @@ -62,18 +60,6 @@ func (*AddDelegatorTx) PublicKey() (*bls.PublicKey, bool, error) {
return nil, false, nil
}

func (tx *AddDelegatorTx) StartTime() time.Time {
return tx.Validator.StartTime()
}

func (tx *AddDelegatorTx) EndTime() time.Time {
return tx.Validator.EndTime()
}

func (tx *AddDelegatorTx) Weight() uint64 {
return tx.Validator.Wght
}

func (*AddDelegatorTx) PendingPriority() Priority {
return PrimaryNetworkDelegatorApricotPendingPriority
}
Expand Down Expand Up @@ -126,10 +112,10 @@ func (tx *AddDelegatorTx) SyntacticVerify(ctx *snow.Context) error {
switch {
case !avax.IsSortedTransferableOutputs(tx.StakeOuts, Codec):
return errOutputsNotSorted
case totalStakeWeight != tx.Validator.Wght:
case totalStakeWeight != tx.Wght:
return fmt.Errorf("%w, delegator weight %d total stake weight %d",
errDelegatorWeightMismatch,
tx.Validator.Wght,
tx.Wght,
totalStakeWeight,
)
}
Expand Down
20 changes: 3 additions & 17 deletions vms/platformvm/txs/add_permissionless_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package txs

import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand All @@ -15,7 +14,6 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/validator"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand All @@ -26,7 +24,7 @@ type AddPermissionlessDelegatorTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// Describes the validator
Validator validator.Validator `serialize:"true" json:"validator"`
Validator `serialize:"true" json:"validator"`
// ID of the subnet this validator is validating
Subnet ids.ID `serialize:"true" json:"subnetID"`
// Where to send staked tokens when done validating
Expand Down Expand Up @@ -59,18 +57,6 @@ func (*AddPermissionlessDelegatorTx) PublicKey() (*bls.PublicKey, bool, error) {
return nil, false, nil
}

func (tx *AddPermissionlessDelegatorTx) StartTime() time.Time {
return tx.Validator.StartTime()
}

func (tx *AddPermissionlessDelegatorTx) EndTime() time.Time {
return tx.Validator.EndTime()
}

func (tx *AddPermissionlessDelegatorTx) Weight() uint64 {
return tx.Validator.Wght
}

func (tx *AddPermissionlessDelegatorTx) PendingPriority() Priority {
if tx.Subnet == constants.PrimaryNetworkID {
return PrimaryNetworkDelegatorBanffPendingPriority
Expand Down Expand Up @@ -136,10 +122,10 @@ func (tx *AddPermissionlessDelegatorTx) SyntacticVerify(ctx *snow.Context) error
switch {
case !avax.IsSortedTransferableOutputs(tx.StakeOuts, Codec):
return errOutputsNotSorted
case totalStakeWeight != tx.Validator.Wght:
case totalStakeWeight != tx.Wght:
return fmt.Errorf("%w, delegator weight %d total stake weight %d",
errDelegatorWeightMismatch,
tx.Validator.Wght,
tx.Wght,
totalStakeWeight,
)
}
Expand Down
Loading

0 comments on commit e25eea0

Please sign in to comment.