Skip to content

Commit bee532d

Browse files
Add AccruedFees to state.Chain interface (#3371)
1 parent 89f83c2 commit bee532d

File tree

10 files changed

+176
-2
lines changed

10 files changed

+176
-2
lines changed

vms/platformvm/block/executor/proposal_block_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) {
9090
// setup state to validate proposal block transaction
9191
onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes()
9292
onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes()
93+
onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes()
9394

9495
currentStakersIt := iteratormock.NewIterator[*state.Staker](ctrl)
9596
currentStakersIt.EXPECT().Next().Return(true)
@@ -161,6 +162,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) {
161162
onParentAccept := state.NewMockDiff(ctrl)
162163
onParentAccept.EXPECT().GetTimestamp().Return(parentTime).AnyTimes()
163164
onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes()
165+
onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes()
164166
onParentAccept.EXPECT().GetCurrentSupply(constants.PrimaryNetworkID).Return(uint64(1000), nil).AnyTimes()
165167

166168
env.blkManager.(*manager).blkIDToState[parentID] = &blockState{

vms/platformvm/block/executor/standard_block_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestApricotStandardBlockTimeVerification(t *testing.T) {
5959
chainTime := env.clk.Time().Truncate(time.Second)
6060
onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes()
6161
onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes()
62+
onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes()
6263

6364
// wrong height
6465
apricotChildBlk, err := block.NewApricotStandardBlock(
@@ -136,6 +137,7 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) {
136137

137138
onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes()
138139
onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes()
140+
onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes()
139141

140142
txID := ids.GenerateTestID()
141143
utxo := &avax.UTXO{

vms/platformvm/block/executor/verifier_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func TestVerifierVisitProposalBlock(t *testing.T) {
103103
// One call for each of onCommitState and onAbortState.
104104
parentOnAcceptState.EXPECT().GetTimestamp().Return(timestamp).Times(2)
105105
parentOnAcceptState.EXPECT().GetFeeState().Return(gas.State{}).Times(2)
106+
parentOnAcceptState.EXPECT().GetAccruedFees().Return(uint64(0)).Times(2)
106107

107108
backend := &backend{
108109
lastAccepted: parentID,
@@ -334,6 +335,7 @@ func TestVerifierVisitStandardBlock(t *testing.T) {
334335
timestamp := time.Now()
335336
parentState.EXPECT().GetTimestamp().Return(timestamp).Times(1)
336337
parentState.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
338+
parentState.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
337339
parentStatelessBlk.EXPECT().Height().Return(uint64(1)).Times(1)
338340
mempool.EXPECT().Remove(apricotBlk.Txs()).Times(1)
339341

@@ -595,6 +597,7 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) {
595597
s.EXPECT().GetLastAccepted().Return(parentID).Times(3)
596598
s.EXPECT().GetTimestamp().Return(parentTime).Times(3)
597599
s.EXPECT().GetFeeState().Return(gas.State{}).Times(3)
600+
s.EXPECT().GetAccruedFees().Return(uint64(0)).Times(3)
598601

599602
onDecisionState, err := state.NewDiff(parentID, backend)
600603
require.NoError(err)
@@ -692,6 +695,7 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) {
692695
s.EXPECT().GetLastAccepted().Return(parentID).Times(3)
693696
s.EXPECT().GetTimestamp().Return(parentTime).Times(3)
694697
s.EXPECT().GetFeeState().Return(gas.State{}).Times(3)
698+
s.EXPECT().GetAccruedFees().Return(uint64(0)).Times(3)
695699

696700
onDecisionState, err := state.NewDiff(parentID, backend)
697701
require.NoError(err)
@@ -807,6 +811,7 @@ func TestVerifierVisitStandardBlockWithDuplicateInputs(t *testing.T) {
807811
parentStatelessBlk.EXPECT().Height().Return(uint64(1)).Times(1)
808812
parentState.EXPECT().GetTimestamp().Return(timestamp).Times(1)
809813
parentState.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
814+
parentState.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
810815
parentStatelessBlk.EXPECT().Parent().Return(grandParentID).Times(1)
811816

812817
err = verifier.ApricotStandardBlock(blk)

vms/platformvm/state/diff.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ type diff struct {
3535
parentID ids.ID
3636
stateVersions Versions
3737

38-
timestamp time.Time
39-
feeState gas.State
38+
timestamp time.Time
39+
feeState gas.State
40+
accruedFees uint64
4041

4142
// Subnet ID --> supply of native asset of the subnet
4243
currentSupply map[ids.ID]uint64
@@ -77,6 +78,7 @@ func NewDiff(
7778
stateVersions: stateVersions,
7879
timestamp: parentState.GetTimestamp(),
7980
feeState: parentState.GetFeeState(),
81+
accruedFees: parentState.GetAccruedFees(),
8082
subnetOwners: make(map[ids.ID]fx.Owner),
8183
subnetManagers: make(map[ids.ID]chainIDAndAddr),
8284
}, nil
@@ -112,6 +114,14 @@ func (d *diff) SetFeeState(feeState gas.State) {
112114
d.feeState = feeState
113115
}
114116

117+
func (d *diff) GetAccruedFees() uint64 {
118+
return d.accruedFees
119+
}
120+
121+
func (d *diff) SetAccruedFees(accruedFees uint64) {
122+
d.accruedFees = accruedFees
123+
}
124+
115125
func (d *diff) GetCurrentSupply(subnetID ids.ID) (uint64, error) {
116126
supply, ok := d.currentSupply[subnetID]
117127
if ok {
@@ -437,6 +447,7 @@ func (d *diff) DeleteUTXO(utxoID ids.ID) {
437447
func (d *diff) Apply(baseState Chain) error {
438448
baseState.SetTimestamp(d.timestamp)
439449
baseState.SetFeeState(d.feeState)
450+
baseState.SetAccruedFees(d.accruedFees)
440451
for subnetID, supply := range d.currentSupply {
441452
baseState.SetCurrentSupply(subnetID, supply)
442453
}

vms/platformvm/state/diff_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ func TestDiffFeeState(t *testing.T) {
6767
assertChainsEqual(t, state, d)
6868
}
6969

70+
func TestDiffAccruedFees(t *testing.T) {
71+
require := require.New(t)
72+
73+
state := newTestState(t, memdb.New())
74+
75+
d, err := NewDiffOn(state)
76+
require.NoError(err)
77+
78+
initialAccruedFees := state.GetAccruedFees()
79+
newAccruedFees := initialAccruedFees + 1
80+
d.SetAccruedFees(newAccruedFees)
81+
require.Equal(newAccruedFees, d.GetAccruedFees())
82+
require.Equal(initialAccruedFees, state.GetAccruedFees())
83+
84+
require.NoError(d.Apply(state))
85+
assertChainsEqual(t, state, d)
86+
}
87+
7088
func TestDiffCurrentSupply(t *testing.T) {
7189
require := require.New(t)
7290

@@ -101,6 +119,7 @@ func TestDiffCurrentValidator(t *testing.T) {
101119
// Called in NewDiffOn
102120
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
103121
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
122+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
104123

105124
d, err := NewDiffOn(state)
106125
require.NoError(err)
@@ -135,6 +154,7 @@ func TestDiffPendingValidator(t *testing.T) {
135154
// Called in NewDiffOn
136155
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
137156
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
157+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
138158

139159
d, err := NewDiffOn(state)
140160
require.NoError(err)
@@ -175,6 +195,7 @@ func TestDiffCurrentDelegator(t *testing.T) {
175195
// Called in NewDiffOn
176196
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
177197
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
198+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
178199

179200
d, err := NewDiffOn(state)
180201
require.NoError(err)
@@ -221,6 +242,7 @@ func TestDiffPendingDelegator(t *testing.T) {
221242
// Called in NewDiffOn
222243
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
223244
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
245+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
224246

225247
d, err := NewDiffOn(state)
226248
require.NoError(err)
@@ -361,6 +383,7 @@ func TestDiffTx(t *testing.T) {
361383
// Called in NewDiffOn
362384
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
363385
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
386+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
364387

365388
d, err := NewDiffOn(state)
366389
require.NoError(err)
@@ -458,6 +481,7 @@ func TestDiffUTXO(t *testing.T) {
458481
// Called in NewDiffOn
459482
state.EXPECT().GetTimestamp().Return(time.Now()).Times(1)
460483
state.EXPECT().GetFeeState().Return(gas.State{}).Times(1)
484+
state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1)
461485

462486
d, err := NewDiffOn(state)
463487
require.NoError(err)
@@ -518,6 +542,7 @@ func assertChainsEqual(t *testing.T, expected, actual Chain) {
518542

519543
require.Equal(expected.GetTimestamp(), actual.GetTimestamp())
520544
require.Equal(expected.GetFeeState(), actual.GetFeeState())
545+
require.Equal(expected.GetAccruedFees(), actual.GetAccruedFees())
521546

522547
expectedCurrentSupply, err := expected.GetCurrentSupply(constants.PrimaryNetworkID)
523548
require.NoError(err)

vms/platformvm/state/mock_chain.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vms/platformvm/state/mock_diff.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vms/platformvm/state/mock_state.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)