@@ -120,6 +120,11 @@ type Engine struct {
120
120
// what we want to achieve is that when the balanceSnapshotFrequency net param is restored we don't use it to reschedule the nextBalancesSnapshot
121
121
// but rather just set the frequency. On post restore we release the active restore flag.
122
122
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
123
128
}
124
129
125
130
// New instantiates a new collateral engine.
@@ -145,6 +150,23 @@ func New(log *logging.Logger, conf Config, ts TimeService, broker Broker) *Engin
145
150
}
146
151
}
147
152
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
+
148
170
func (e * Engine ) BeginBlock () {
149
171
t := e .timeService .GetTimeNow ()
150
172
if e .nextBalancesSnapshot .IsZero () || ! e .nextBalancesSnapshot .After (t ) {
@@ -342,6 +364,20 @@ func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error {
342
364
e .enabledAssets [asset .ID ] = asset
343
365
// update state
344
366
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 ) {
345
381
// then creat a new infrastructure fee account for the asset
346
382
// these are fee related account only
347
383
infraFeeID := e .accountID (noMarket , systemOwner , asset .ID , types .AccountTypeFeesInfrastructure )
@@ -463,11 +499,6 @@ func (e *Engine) EnableAsset(ctx context.Context, asset types.Asset) error {
463
499
e .addAccountToHashableSlice (pendingFeeReferrerRewardAcc )
464
500
e .broker .Send (events .NewAccountEvent (ctx , * pendingFeeReferrerRewardAcc ))
465
501
}
466
-
467
- e .log .Info ("new asset added successfully" ,
468
- logging .AssetID (asset .ID ),
469
- )
470
- return nil
471
502
}
472
503
473
504
func (e * Engine ) PropagateAssetUpdate (ctx context.Context , asset types.Asset ) error {
0 commit comments