Skip to content

Commit a08b444

Browse files
authored
Merge pull request #9643 from vegaprotocol/feature/9542
feat: ensure all per asset accounts exists after a migration
2 parents f9dd11b + 959d1d0 commit a08b444

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
- [9460](https://github.com/vegaprotocol/vega/issues/9460) - Add APIs for volume discount program.
129129
- [9628](https://github.com/vegaprotocol/vega/issues/9628) - Upgrade `CometBFT`.
130130
- [9577](https://github.com/vegaprotocol/vega/issues/9577) - Feature test coverage for distribution strategy
131+
- [9542](https://github.com/vegaprotocol/vega/issues/9542) - Ensure all per asset accounts exist after migration
131132

132133
### 🐛 Fixes
133134

core/collateral/engine.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ type Engine struct {
120120
// what we want to achieve is that when the balanceSnapshotFrequency net param is restored we don't use it to reschedule the nextBalancesSnapshot
121121
// but rather just set the frequency. On post restore we release the active restore flag.
122122
activeRestore bool
123+
124+
// set to false when started
125+
// we'll use it only once after an upgrade
126+
// to make sure asset are being created
127+
ensuredAssetAccounts bool
123128
}
124129

125130
// New instantiates a new collateral engine.
@@ -145,6 +150,23 @@ func New(log *logging.Logger, conf Config, ts TimeService, broker Broker) *Engin
145150
}
146151
}
147152

153+
func (e *Engine) OnTick(ctx context.Context, _ time.Time) {
154+
// FIXME(jeremy): to be removed after the migration from
155+
// 72.x to 73, this will ensure all per assets accounts are being
156+
// created after the restart
157+
if !e.ensuredAssetAccounts {
158+
// we don't want to do that again
159+
e.ensuredAssetAccounts = true
160+
161+
assets := maps.Keys(e.enabledAssets)
162+
sort.Strings(assets)
163+
for _, assetId := range assets {
164+
asset := e.enabledAssets[assetId]
165+
e.ensureAllAssetAccounts(ctx, asset)
166+
}
167+
}
168+
}
169+
148170
func (e *Engine) BeginBlock() {
149171
t := e.timeService.GetTimeNow()
150172
if e.nextBalancesSnapshot.IsZero() || !e.nextBalancesSnapshot.After(t) {
@@ -342,6 +364,20 @@ func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error {
342364
e.enabledAssets[asset.ID] = asset
343365
// update state
344366
e.state.enableAsset(asset)
367+
368+
e.ensureAllAssetAccounts(ctx, asset)
369+
370+
e.log.Info("new asset added successfully",
371+
logging.AssetID(asset.ID),
372+
)
373+
return nil
374+
}
375+
376+
// ensureAllAssetAccounts will try to get all asset specific accounts
377+
// and if they do not exists will create them and send an event
378+
// this is useful when doing a migration so we can create all asset
379+
// account for already enabled assets.
380+
func (e *Engine) ensureAllAssetAccounts(ctx context.Context, asset types.Asset) {
345381
// then creat a new infrastructure fee account for the asset
346382
// these are fee related account only
347383
infraFeeID := e.accountID(noMarket, systemOwner, asset.ID, types.AccountTypeFeesInfrastructure)
@@ -463,11 +499,6 @@ func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error {
463499
e.addAccountToHashableSlice(pendingFeeReferrerRewardAcc)
464500
e.broker.Send(events.NewAccountEvent(ctx, *pendingFeeReferrerRewardAcc))
465501
}
466-
467-
e.log.Info("new asset added successfully",
468-
logging.AssetID(asset.ID),
469-
)
470-
return nil
471502
}
472503

473504
func (e *Engine) PropagateAssetUpdate(ctx context.Context, asset types.Asset) error {

core/protocol/all_services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func (svcs *allServices) registerTimeServiceCallbacks() {
432432
svcs.timeService.NotifyOnTick(
433433
svcs.epochService.OnTick,
434434
svcs.builtinOracle.OnTick,
435+
svcs.collateral.OnTick,
435436

436437
svcs.netParams.OnTick,
437438
svcs.erc20MultiSigTopology.OnTick,

0 commit comments

Comments
 (0)