@@ -31,8 +31,8 @@ import (
31
31
)
32
32
33
33
const (
34
- delegationPeriod = 15 * time .Second
35
- validationPeriod = 30 * time .Second
34
+ targetDelegationPeriod = 15 * time .Second
35
+ targetValidationPeriod = 30 * time .Second
36
36
)
37
37
38
38
var _ = ginkgo .Describe ("[Staking Rewards]" , func () {
@@ -58,6 +58,16 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
58
58
ginkgo .By ("waiting until beta node is healthy" )
59
59
e2e .WaitForHealthy (betaNode )
60
60
61
+ ginkgo .By ("retrieving alpha node id and pop" )
62
+ alphaInfoClient := info .NewClient (alphaNode .URI )
63
+ alphaNodeID , alphaPOP , err := alphaInfoClient .GetNodeID (e2e .DefaultContext ())
64
+ require .NoError (err )
65
+
66
+ ginkgo .By ("retrieving beta node id and pop" )
67
+ betaInfoClient := info .NewClient (betaNode .URI )
68
+ betaNodeID , betaPOP , err := betaInfoClient .GetNodeID (e2e .DefaultContext ())
69
+ require .NoError (err )
70
+
61
71
ginkgo .By ("generating reward keys" )
62
72
63
73
alphaValidationRewardKey , err := secp256k1 .NewPrivateKey ()
@@ -89,43 +99,34 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
89
99
keychain := secp256k1fx .NewKeychain (rewardKeys ... )
90
100
fundedKey := e2e .Env .AllocatePreFundedKey ()
91
101
keychain .Add (fundedKey )
92
- nodeURI := e2e .Env .GetRandomNodeURI ()
102
+ nodeURI := tmpnet.NodeURI {
103
+ NodeID : alphaNodeID ,
104
+ URI : alphaNode .URI ,
105
+ }
93
106
baseWallet := e2e .NewWallet (keychain , nodeURI )
94
107
pWallet := baseWallet .P ()
95
108
96
- ginkgo .By ("retrieving alpha node id and pop" )
97
- alphaInfoClient := info .NewClient (alphaNode .URI )
98
- alphaNodeID , alphaPOP , err := alphaInfoClient .GetNodeID (e2e .DefaultContext ())
99
- require .NoError (err )
100
-
101
- ginkgo .By ("retrieving beta node id and pop" )
102
- betaInfoClient := info .NewClient (betaNode .URI )
103
- betaNodeID , betaPOP , err := betaInfoClient .GetNodeID (e2e .DefaultContext ())
104
- require .NoError (err )
105
-
106
- pvmClient := platformvm .NewClient (alphaNode .URI )
107
-
108
109
const (
109
110
delegationPercent = 0.10 // 10%
110
111
delegationShare = reward .PercentDenominator * delegationPercent
111
112
weight = 2_000 * units .Avax
112
113
)
113
114
115
+ pvmClient := platformvm .NewClient (alphaNode .URI )
116
+
114
117
ginkgo .By ("retrieving supply before inserting validators" )
115
118
supplyAtValidatorsStart , _ , err := pvmClient .GetCurrentSupply (e2e .DefaultContext (), constants .PrimaryNetworkID )
116
119
require .NoError (err )
117
120
118
- alphaValidatorStartTime := time .Now ().Add (e2e .DefaultValidatorStartTimeDiff )
119
- alphaValidatorEndTime := alphaValidatorStartTime .Add (validationPeriod )
120
- tests .Outf ("alpha node validation period starting at: %v\n " , alphaValidatorStartTime )
121
+ alphaValidatorsEndTime := time .Now ().Add (targetValidationPeriod )
122
+ tests .Outf ("alpha node validation period ending at: %v\n " , alphaValidatorsEndTime )
121
123
122
124
ginkgo .By ("adding alpha node as a validator" , func () {
123
125
_ , err := pWallet .IssueAddPermissionlessValidatorTx (
124
126
& txs.SubnetValidator {
125
127
Validator : txs.Validator {
126
128
NodeID : alphaNodeID ,
127
- Start : uint64 (alphaValidatorStartTime .Unix ()),
128
- End : uint64 (alphaValidatorEndTime .Unix ()),
129
+ End : uint64 (alphaValidatorsEndTime .Unix ()),
129
130
Wght : weight ,
130
131
},
131
132
Subnet : constants .PrimaryNetworkID ,
@@ -146,16 +147,14 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
146
147
require .NoError (err )
147
148
})
148
149
149
- betaValidatorStartTime := time .Now ().Add (e2e .DefaultValidatorStartTimeDiff )
150
- betaValidatorEndTime := betaValidatorStartTime .Add (validationPeriod )
151
- tests .Outf ("beta node validation period starting at: %v\n " , betaValidatorStartTime )
150
+ betaValidatorEndTime := time .Now ().Add (targetValidationPeriod )
151
+ tests .Outf ("beta node validation period ending at: %v\n " , betaValidatorEndTime )
152
152
153
153
ginkgo .By ("adding beta node as a validator" , func () {
154
154
_ , err := pWallet .IssueAddPermissionlessValidatorTx (
155
155
& txs.SubnetValidator {
156
156
Validator : txs.Validator {
157
157
NodeID : betaNodeID ,
158
- Start : uint64 (betaValidatorStartTime .Unix ()),
159
158
End : uint64 (betaValidatorEndTime .Unix ()),
160
159
Wght : weight ,
161
160
},
@@ -181,16 +180,15 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
181
180
supplyAtDelegatorsStart , _ , err := pvmClient .GetCurrentSupply (e2e .DefaultContext (), constants .PrimaryNetworkID )
182
181
require .NoError (err )
183
182
184
- gammaDelegatorStartTime := time .Now ().Add (e2e . DefaultValidatorStartTimeDiff )
185
- tests .Outf ("gamma delegation period starting at: %v\n " , gammaDelegatorStartTime )
183
+ gammaDelegatorEndTime := time .Now ().Add (targetDelegationPeriod )
184
+ tests .Outf ("gamma delegation period ending at: %v\n " , gammaDelegatorEndTime )
186
185
187
186
ginkgo .By ("adding gamma as delegator to the alpha node" , func () {
188
187
_ , err := pWallet .IssueAddPermissionlessDelegatorTx (
189
188
& txs.SubnetValidator {
190
189
Validator : txs.Validator {
191
190
NodeID : alphaNodeID ,
192
- Start : uint64 (gammaDelegatorStartTime .Unix ()),
193
- End : uint64 (gammaDelegatorStartTime .Add (delegationPeriod ).Unix ()),
191
+ End : uint64 (gammaDelegatorEndTime .Unix ()),
194
192
Wght : weight ,
195
193
},
196
194
Subnet : constants .PrimaryNetworkID ,
@@ -205,16 +203,15 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
205
203
require .NoError (err )
206
204
})
207
205
208
- deltaDelegatorStartTime := time .Now ().Add (e2e . DefaultValidatorStartTimeDiff )
209
- tests .Outf ("delta delegation period starting at: %v\n " , deltaDelegatorStartTime )
206
+ deltaDelegatorEndTime := time .Now ().Add (targetDelegationPeriod )
207
+ tests .Outf ("delta delegation period ending at: %v\n " , deltaDelegatorEndTime )
210
208
211
209
ginkgo .By ("adding delta as delegator to the beta node" , func () {
212
210
_ , err := pWallet .IssueAddPermissionlessDelegatorTx (
213
211
& txs.SubnetValidator {
214
212
Validator : txs.Validator {
215
213
NodeID : betaNodeID ,
216
- Start : uint64 (deltaDelegatorStartTime .Unix ()),
217
- End : uint64 (deltaDelegatorStartTime .Add (delegationPeriod ).Unix ()),
214
+ End : uint64 (deltaDelegatorEndTime .Unix ()),
218
215
Wght : weight ,
219
216
},
220
217
Subnet : constants .PrimaryNetworkID ,
@@ -232,6 +229,14 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
232
229
ginkgo .By ("stopping beta node to prevent it and its delegator from receiving a validation reward" )
233
230
require .NoError (betaNode .Stop ())
234
231
232
+ ginkgo .By ("retrieving staking periods from the chain" )
233
+ data , err := pvmClient .GetCurrentValidators (e2e .DefaultContext (), constants .PlatformChainID , []ids.NodeID {alphaNodeID })
234
+ require .NoError (err )
235
+ require .Len (data , 1 )
236
+ actualAlphaValidationPeriod := time .Duration (data [0 ].EndTime - data [0 ].StartTime ) * time .Second
237
+ delegatorData := data [0 ].Delegators [0 ]
238
+ actualGammaDelegationPeriod := time .Duration (delegatorData .EndTime - delegatorData .StartTime ) * time .Second
239
+
235
240
ginkgo .By ("waiting until all validation periods are over" )
236
241
// The beta validator was the last added and so has the latest end time. The
237
242
// delegation periods are shorter than the validation periods.
@@ -279,8 +284,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
279
284
280
285
ginkgo .By ("determining expected validation and delegation rewards" )
281
286
calculator := reward .NewCalculator (rewardConfig )
282
- expectedValidationReward := calculator .Calculate (validationPeriod , weight , supplyAtValidatorsStart )
283
- potentialDelegationReward := calculator .Calculate (delegationPeriod , weight , supplyAtDelegatorsStart )
287
+ expectedValidationReward := calculator .Calculate (actualAlphaValidationPeriod , weight , supplyAtValidatorsStart )
288
+ potentialDelegationReward := calculator .Calculate (actualGammaDelegationPeriod , weight , supplyAtDelegatorsStart )
284
289
expectedDelegationFee , expectedDelegatorReward := reward .Split (potentialDelegationReward , delegationShare )
285
290
286
291
ginkgo .By ("checking expected rewards against actual rewards" )
0 commit comments