Skip to content

Commit

Permalink
fix: Ensure the vesting stats events are generated after the computation
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTrinque committed May 13, 2024
1 parent 63f94d6 commit 6fde061
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 103 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### 🐛 Fixes

- [](https://github.com/vegaprotocol/vega/issues/xxx)
- [11066](https://github.com/vegaprotocol/vega/issues/11066) - Ensure vesting statistics match vesting accounts numbers.


## 0.76.1
Expand Down
2 changes: 1 addition & 1 deletion core/collateral/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestGetAllVestingQuantumBalance(t *testing.T) {
)

balance = eng.GetAllVestingQuantumBalance(party)
assert.Equal(t, balance.String(), "103.17")
assert.Equal(t, balance.String(), "103.1666666666666667")
}

func testClearFeeAccounts(t *testing.T) {
Expand Down
11 changes: 7 additions & 4 deletions core/vesting/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func (e *Engine) OnRewardVestingMinimumTransferUpdate(_ context.Context, minimum

func (e *Engine) OnEpochEvent(ctx context.Context, epoch types.Epoch) {
if epoch.Action == proto.EpochAction_EPOCH_ACTION_END {
e.broadcastRewardBonusMultipliers(ctx, epoch.Seq)
e.moveLocked()
e.distributeVested(ctx)
e.clearState()
e.broadcastVestingStatsUpdate(ctx, epoch.Seq)
e.broadcastSummary(ctx, epoch.Seq)
e.clearState()
}
}

Expand Down Expand Up @@ -328,7 +328,6 @@ func (e *Engine) makeTransfer(
return transfer
}

// just remove party entries once they are not needed anymore.
func (e *Engine) clearState() {
for party, v := range e.state {
if len(v.Locked) == 0 && len(v.Vesting) == 0 {
Expand All @@ -344,6 +343,10 @@ func (e *Engine) broadcastSummary(ctx context.Context, seq uint64) {
}

for p, pRewards := range e.state {
if len(pRewards.Vesting) == 0 && len(pRewards.Locked) == 0 {
continue
}

pSummary := &eventspb.PartyVestingSummary{
Party: p,
PartyLockedBalances: []*eventspb.PartyLockedBalance{},
Expand Down Expand Up @@ -395,7 +398,7 @@ func (e *Engine) broadcastSummary(ctx context.Context, seq uint64) {
e.broker.Send(events.NewVestingBalancesSummaryEvent(ctx, evt))
}

func (e *Engine) broadcastRewardBonusMultipliers(ctx context.Context, seq uint64) {
func (e *Engine) broadcastVestingStatsUpdate(ctx context.Context, seq uint64) {
evt := &eventspb.VestingStatsUpdated{
AtEpoch: seq,
Stats: make([]*eventspb.PartyVestingStats, 0, len(e.state)),
Expand Down
Loading

0 comments on commit 6fde061

Please sign in to comment.