Skip to content

Commit 1aa1963

Browse files
authored
Merge pull request #11280 from vegaprotocol/11279
fix: handle properly multiple transfers (potentially recurring vs gov…
2 parents cff38ea + c18cdea commit 1aa1963

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
### 🐛 Fixes
1919

2020
- [11066](https://github.com/vegaprotocol/vega/issues/11066) - Ensure vesting statistics match vesting accounts numbers.
21+
- [11279](https://github.com/vegaprotocol/vega/issues/11279) - Handle properly the case of multiple transfers for the same game id.
2122

2223

2324
## 0.76.1

core/banking/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ type Engine struct {
210210

211211
metricUpdateFrequency time.Duration
212212
nextMetricUpdate time.Time
213+
214+
// transient cache used to market a dispatch strategy as checked for eligibility for this round so we don't check again.
215+
dispatchRequiredCache map[string]bool
213216
}
214217

215218
type withdrawalRef struct {
@@ -275,6 +278,7 @@ func New(log *logging.Logger,
275278
pendingPerAssetAndPartyFeeDiscountUpdates: map[string]map[string]*num.Uint{},
276279
primaryBridgeView: primaryBridgeView,
277280
secondaryBridgeView: secondaryBridgeView,
281+
dispatchRequiredCache: map[string]bool{},
278282
}
279283
}
280284

@@ -347,6 +351,7 @@ func (e *Engine) OnEpoch(ctx context.Context, ep types.Epoch) {
347351
e.distributeRecurringGovernanceTransfers(ctx)
348352
e.applyPendingFeeDiscountsUpdates(ctx)
349353
e.sendTeamsStats(ctx, ep.Seq)
354+
e.dispatchRequiredCache = map[string]bool{}
350355
// as the metrics are going to be published here, we want to progress the next update.
351356
e.nextMetricUpdate = e.timeService.GetTimeNow().Add(e.metricUpdateFrequency)
352357
default:

core/banking/recurring_transfers.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func (e *Engine) ensureNoRecurringTransferDuplicates(
185185
// NB2: for validator ranking this will always return true as it is assumed that for the network to resume there must always be
186186
// a validator with non zero ranking.
187187
func (e *Engine) dispatchRequired(ctx context.Context, ds *vegapb.DispatchStrategy) bool {
188+
required, ok := e.dispatchRequiredCache[e.hashDispatchStrategy(ds)]
189+
if ok {
190+
return required
191+
}
192+
defer func() { e.dispatchRequiredCache[e.hashDispatchStrategy(ds)] = required }()
188193
switch ds.Metric {
189194
case vegapb.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_PAID,
190195
vegapb.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_RECEIVED,
@@ -210,17 +215,21 @@ func (e *Engine) dispatchRequired(ctx context.Context, ds *vegapb.DispatchStrate
210215
break
211216
}
212217
}
213-
return hasNonZeroMetric || (hasEligibleParties && ds.DistributionStrategy == vegapb.DistributionStrategy_DISTRIBUTION_STRATEGY_RANK)
218+
required = hasNonZeroMetric || (hasEligibleParties && ds.DistributionStrategy == vegapb.DistributionStrategy_DISTRIBUTION_STRATEGY_RANK)
219+
return required
214220
} else {
215221
tcs, pcs := e.marketActivityTracker.CalculateMetricForTeams(ctx, ds)
216222
gs := events.NewTeamGameScoresEvent(ctx, int64(e.currentEpoch), e.hashDispatchStrategy(ds), e.timeService.GetTimeNow(), tcs, pcs)
217223
e.broker.Send(gs)
218-
return len(tcs) > 0
224+
required = len(tcs) > 0
225+
return required
219226
}
220227
case vegapb.DispatchMetric_DISPATCH_METRIC_VALIDATOR_RANKING:
221-
return true
228+
required = true
229+
return required
222230
}
223-
return false
231+
required = false
232+
return required
224233
}
225234

226235
func (e *Engine) distributeRecurringTransfers(ctx context.Context, newEpoch uint64) {

0 commit comments

Comments
 (0)