Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7a0dfda
Author: Joshua Kim <[email protected]>
Date:   Tue Dec 12 03:29:47 2023 -0500

    testing structs

    Signed-off-by: Joshua Kim <[email protected]>

commit 58d2779
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 14:01:16 2023 -0500

    Dedupe secp256k1 key usage in tests (#2511)

commit 6c64372
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 11:45:58 2023 -0500

    Remove unused `AcceptorTracker` struct (#2508)

commit 7a9bdad
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 10:44:20 2023 -0500

    Remove unused `BuildGenesisTest` function (#2503)

commit 44d71db
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Dec 18 19:05:26 2023 -0500

    Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#2502)

    Signed-off-by: dependabot[bot] <[email protected]>
    Signed-off-by: Stephen Buttolph <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit aa764bb
Author: Alberto Benegiamo <[email protected]>
Date:   Mon Dec 18 16:00:17 2023 -0700

    Drop Pending Stakers 5 - validated PostDurango StakerTxs (#2314)

    Co-authored-by: Stephen Buttolph <[email protected]>
    Co-authored-by: dhrubabasu <[email protected]>

Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 19, 2023
1 parent 83b11cc commit c8866e6
Show file tree
Hide file tree
Showing 28 changed files with 401 additions and 398 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
go.uber.org/goleak v1.2.1
go.uber.org/mock v0.2.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/net v0.19.0
golang.org/x/sync v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
28 changes: 0 additions & 28 deletions snow/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

var (
_ Acceptor = noOpAcceptor{}
_ Acceptor = (*AcceptorTracker)(nil)
_ Acceptor = acceptorWrapper{}

_ AcceptorGroup = (*acceptorGroup)(nil)
Expand All @@ -38,33 +37,6 @@ func (noOpAcceptor) Accept(*ConsensusContext, ids.ID, []byte) error {
return nil
}

// AcceptorTracker tracks the dispatched accept events by its ID and counts.
// Useful for testing.
type AcceptorTracker struct {
lock sync.RWMutex
accepted map[ids.ID]int
}

func NewAcceptorTracker() *AcceptorTracker {
return &AcceptorTracker{
accepted: make(map[ids.ID]int),
}
}

func (a *AcceptorTracker) Accept(_ *ConsensusContext, containerID ids.ID, _ []byte) error {
a.lock.Lock()
a.accepted[containerID]++
a.lock.Unlock()
return nil
}

func (a *AcceptorTracker) IsAccepted(containerID ids.ID) (int, bool) {
a.lock.RLock()
count, ok := a.accepted[containerID]
a.lock.RUnlock()
return count, ok
}

type acceptorWrapper struct {
Acceptor

Expand Down
17 changes: 3 additions & 14 deletions tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
nodeID, nodePOP, err := infoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

// Adding a validator should not break interchain transfer.
endTime := time.Now().Add(30 * time.Second)
ginkgo.By("adding the new node as a validator", func() {
startTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
// Validation duration doesn't actually matter to this
// test - it is only ensuring that adding a validator
// doesn't break interchain transfer.
endTime := startTime.Add(30 * time.Second)

rewardKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

Expand All @@ -114,7 +110,6 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: nodeID,
Start: uint64(startTime.Unix()),
End: uint64(endTime.Unix()),
Wght: weight,
},
Expand All @@ -136,21 +131,15 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
require.NoError(err)
})

// Adding a delegator should not break interchain transfer.
ginkgo.By("adding a delegator to the new node", func() {
startTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
// Delegation duration doesn't actually matter to this
// test - it is only ensuring that adding a delegator
// doesn't break interchain transfer.
endTime := startTime.Add(15 * time.Second)

rewardKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

_, err = pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: nodeID,
Start: uint64(startTime.Unix()),
End: uint64(endTime.Unix()),
Wght: weight,
},
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/p/permissionless_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
require.NoError(err)
})

validatorStartTime := time.Now().Add(time.Minute)
endTime := time.Now().Add(time.Minute)
ginkgo.By("add permissionless validator", func() {
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
Start: uint64(validatorStartTime.Unix()),
End: uint64(validatorStartTime.Add(5 * time.Second).Unix()),
End: uint64(endTime.Unix()),
Wght: 25 * units.MegaAvax,
},
Subnet: subnetID,
Expand All @@ -156,14 +155,12 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
require.NoError(err)
})

delegatorStartTime := validatorStartTime
ginkgo.By("add permissionless delegator", func() {
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
Start: uint64(delegatorStartTime.Unix()),
End: uint64(delegatorStartTime.Add(5 * time.Second).Unix()),
End: uint64(endTime.Unix()),
Wght: 25 * units.MegaAvax,
},
Subnet: subnetID,
Expand Down
73 changes: 39 additions & 34 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
)

const (
delegationPeriod = 15 * time.Second
validationPeriod = 30 * time.Second
targetDelegationPeriod = 15 * time.Second
targetValidationPeriod = 30 * time.Second
)

var _ = ginkgo.Describe("[Staking Rewards]", func() {
Expand All @@ -58,6 +58,16 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
ginkgo.By("waiting until beta node is healthy")
e2e.WaitForHealthy(betaNode)

ginkgo.By("retrieving alpha node id and pop")
alphaInfoClient := info.NewClient(alphaNode.URI)
alphaNodeID, alphaPOP, err := alphaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

ginkgo.By("retrieving beta node id and pop")
betaInfoClient := info.NewClient(betaNode.URI)
betaNodeID, betaPOP, err := betaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

ginkgo.By("generating reward keys")

alphaValidationRewardKey, err := secp256k1.NewPrivateKey()
Expand Down Expand Up @@ -89,43 +99,34 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
keychain := secp256k1fx.NewKeychain(rewardKeys...)
fundedKey := e2e.Env.AllocatePreFundedKey()
keychain.Add(fundedKey)
nodeURI := e2e.Env.GetRandomNodeURI()
nodeURI := tmpnet.NodeURI{
NodeID: alphaNodeID,
URI: alphaNode.URI,
}
baseWallet := e2e.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()

ginkgo.By("retrieving alpha node id and pop")
alphaInfoClient := info.NewClient(alphaNode.URI)
alphaNodeID, alphaPOP, err := alphaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

ginkgo.By("retrieving beta node id and pop")
betaInfoClient := info.NewClient(betaNode.URI)
betaNodeID, betaPOP, err := betaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

pvmClient := platformvm.NewClient(alphaNode.URI)

const (
delegationPercent = 0.10 // 10%
delegationShare = reward.PercentDenominator * delegationPercent
weight = 2_000 * units.Avax
)

pvmClient := platformvm.NewClient(alphaNode.URI)

ginkgo.By("retrieving supply before inserting validators")
supplyAtValidatorsStart, _, err := pvmClient.GetCurrentSupply(e2e.DefaultContext(), constants.PrimaryNetworkID)
require.NoError(err)

alphaValidatorStartTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
alphaValidatorEndTime := alphaValidatorStartTime.Add(validationPeriod)
tests.Outf("alpha node validation period starting at: %v\n", alphaValidatorStartTime)
alphaValidatorsEndTime := time.Now().Add(targetValidationPeriod)
tests.Outf("alpha node validation period ending at: %v\n", alphaValidatorsEndTime)

ginkgo.By("adding alpha node as a validator", func() {
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: alphaNodeID,
Start: uint64(alphaValidatorStartTime.Unix()),
End: uint64(alphaValidatorEndTime.Unix()),
End: uint64(alphaValidatorsEndTime.Unix()),
Wght: weight,
},
Subnet: constants.PrimaryNetworkID,
Expand All @@ -146,16 +147,14 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
require.NoError(err)
})

betaValidatorStartTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
betaValidatorEndTime := betaValidatorStartTime.Add(validationPeriod)
tests.Outf("beta node validation period starting at: %v\n", betaValidatorStartTime)
betaValidatorEndTime := time.Now().Add(targetValidationPeriod)
tests.Outf("beta node validation period ending at: %v\n", betaValidatorEndTime)

ginkgo.By("adding beta node as a validator", func() {
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: betaNodeID,
Start: uint64(betaValidatorStartTime.Unix()),
End: uint64(betaValidatorEndTime.Unix()),
Wght: weight,
},
Expand All @@ -181,16 +180,15 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
supplyAtDelegatorsStart, _, err := pvmClient.GetCurrentSupply(e2e.DefaultContext(), constants.PrimaryNetworkID)
require.NoError(err)

gammaDelegatorStartTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
tests.Outf("gamma delegation period starting at: %v\n", gammaDelegatorStartTime)
gammaDelegatorEndTime := time.Now().Add(targetDelegationPeriod)
tests.Outf("gamma delegation period ending at: %v\n", gammaDelegatorEndTime)

ginkgo.By("adding gamma as delegator to the alpha node", func() {
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: alphaNodeID,
Start: uint64(gammaDelegatorStartTime.Unix()),
End: uint64(gammaDelegatorStartTime.Add(delegationPeriod).Unix()),
End: uint64(gammaDelegatorEndTime.Unix()),
Wght: weight,
},
Subnet: constants.PrimaryNetworkID,
Expand All @@ -205,16 +203,15 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
require.NoError(err)
})

deltaDelegatorStartTime := time.Now().Add(e2e.DefaultValidatorStartTimeDiff)
tests.Outf("delta delegation period starting at: %v\n", deltaDelegatorStartTime)
deltaDelegatorEndTime := time.Now().Add(targetDelegationPeriod)
tests.Outf("delta delegation period ending at: %v\n", deltaDelegatorEndTime)

ginkgo.By("adding delta as delegator to the beta node", func() {
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: betaNodeID,
Start: uint64(deltaDelegatorStartTime.Unix()),
End: uint64(deltaDelegatorStartTime.Add(delegationPeriod).Unix()),
End: uint64(deltaDelegatorEndTime.Unix()),
Wght: weight,
},
Subnet: constants.PrimaryNetworkID,
Expand All @@ -232,6 +229,14 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
ginkgo.By("stopping beta node to prevent it and its delegator from receiving a validation reward")
require.NoError(betaNode.Stop())

ginkgo.By("retrieving staking periods from the chain")
data, err := pvmClient.GetCurrentValidators(e2e.DefaultContext(), constants.PlatformChainID, []ids.NodeID{alphaNodeID})
require.NoError(err)
require.Len(data, 1)
actualAlphaValidationPeriod := time.Duration(data[0].EndTime-data[0].StartTime) * time.Second
delegatorData := data[0].Delegators[0]
actualGammaDelegationPeriod := time.Duration(delegatorData.EndTime-delegatorData.StartTime) * time.Second

ginkgo.By("waiting until all validation periods are over")
// The beta validator was the last added and so has the latest end time. The
// delegation periods are shorter than the validation periods.
Expand Down Expand Up @@ -279,8 +284,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {

ginkgo.By("determining expected validation and delegation rewards")
calculator := reward.NewCalculator(rewardConfig)
expectedValidationReward := calculator.Calculate(validationPeriod, weight, supplyAtValidatorsStart)
potentialDelegationReward := calculator.Calculate(delegationPeriod, weight, supplyAtDelegatorsStart)
expectedValidationReward := calculator.Calculate(actualAlphaValidationPeriod, weight, supplyAtValidatorsStart)
potentialDelegationReward := calculator.Calculate(actualGammaDelegationPeriod, weight, supplyAtDelegatorsStart)
expectedDelegationFee, expectedDelegatorReward := reward.Split(potentialDelegationReward, delegationShare)

ginkgo.By("checking expected rewards against actual rewards")
Expand Down
6 changes: 1 addition & 5 deletions tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
require.NoError(err)
require.GreaterOrEqual(pBalance, minBalance)
})
// create validator data
validatorStartTimeDiff := 30 * time.Second
vdrStartTime := time.Now().Add(validatorStartTimeDiff)

// Use a random node ID to ensure that repeated test runs
// will succeed against a network that persists across runs.
Expand All @@ -79,8 +76,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {

vdr := &txs.Validator{
NodeID: validatorID,
Start: uint64(vdrStartTime.Unix()),
End: uint64(vdrStartTime.Add(72 * time.Hour).Unix()),
End: uint64(time.Now().Add(72 * time.Hour).Unix()),
Wght: minValStake,
}
rewardOwner := &secp256k1fx.OutputOwners{
Expand Down
16 changes: 1 addition & 15 deletions tests/e2e/static-handlers/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/utils/cb58"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/formatting"
Expand Down Expand Up @@ -114,20 +113,7 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() {
})

ginkgo.It("can make calls to platformvm static api", func() {
keys := []*secp256k1.PrivateKey{}
for _, key := range []string{
"24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5",
"2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY",
"cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35",
"ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN",
"2RWLv6YVEXDiWLpaCbXhhqxtLbnFaKQsWPSSMSPhpWo47uJAeV",
} {
privKeyBytes, err := cb58.Decode(key)
require.NoError(err)
pk, err := secp256k1.ToPrivateKey(privKeyBytes)
require.NoError(err)
keys = append(keys, pk)
}
keys := secp256k1.TestKeys()

genesisUTXOs := make([]api.UTXO, len(keys))
hrp := constants.NetworkIDToHRP[constants.UnitTestID]
Expand Down
6 changes: 0 additions & 6 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"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 All @@ -44,11 +43,6 @@ const (
// development.
SkipBootstrapChecksEnvName = "E2E_SKIP_BOOTSTRAP_CHECKS"

// Validator start time must be a minimum of SyncBound from the
// current time for validator addition to succeed, and adding 20
// seconds provides a buffer in case of any delay in processing.
DefaultValidatorStartTimeDiff = executor.SyncBound + 20*time.Second

DefaultGasLimit = uint64(21000) // Standard gas limit

// An empty string prompts the use of the default path which ensures a
Expand Down
Loading

0 comments on commit c8866e6

Please sign in to comment.