@@ -169,7 +169,7 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier,
169
169
// account changes at UTXO level without needing to worry about multiple spenders of the same account in the same slot,
170
170
// we only care about the initial account output to be consumed and the final account output to be created.
171
171
// output side
172
- createdAccounts , consumedAccounts , destroyedAccounts , err := l .processCreatedAndConsumedAccountOutputs (stateDiff , accountDiffs )
172
+ createdAccountOutputs , consumedAccountOutputs , createdAccounts , destroyedAccounts , err := l .processCreatedAndConsumedAccountOutputs (stateDiff , accountDiffs )
173
173
if err != nil {
174
174
return iotago.Identifier {}, iotago.Identifier {}, iotago.Identifier {}, nil , nil , nil , ierrors .Wrapf (err , "failed to process outputs consumed and created in slot %d" , slot )
175
175
}
@@ -181,7 +181,8 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier,
181
181
182
182
return nil
183
183
})
184
- l .prepareAccountDiffs (accountDiffs , slot , consumedAccounts , createdAccounts )
184
+
185
+ l .prepareAccountDiffs (accountDiffs , slot , consumedAccountOutputs , createdAccountOutputs )
185
186
186
187
// Commit the changes
187
188
// Update the UTXO ledger
@@ -206,15 +207,17 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier,
206
207
}
207
208
208
209
// Update the mana manager's cache
209
- if err = l .manaManager .ApplyDiff (slot , destroyedAccounts , createdAccounts , accountDiffs ); err != nil {
210
+ if err = l .manaManager .ApplyDiff (slot , destroyedAccounts , createdAccountOutputs , accountDiffs ); err != nil {
210
211
return iotago.Identifier {}, iotago.Identifier {}, iotago.Identifier {}, nil , nil , nil , ierrors .Wrapf (err , "failed to apply diff to mana manager for slot %d" , slot )
211
212
}
212
213
213
214
// Created account event need to be triggered only after the AccountLedger and UTXO ledger are updated,
214
215
// so that components (like Scheduler) that listen to the event can access the consistent account state.
215
- for accountID := range createdAccounts {
216
+ _ = createdAccounts . ForEach ( func ( accountID iotago. AccountID ) error {
216
217
l .events .AccountCreated .Trigger (accountID )
217
- }
218
+
219
+ return nil
220
+ })
218
221
219
222
// Mark each transaction as committed so the mempool can evict it
220
223
stateDiff .ExecutedTransactions ().ForEach (func (_ iotago.TransactionID , tx mempool.TransactionMetadata ) bool {
@@ -509,9 +512,10 @@ func (l *Ledger) prepareAccountDiffs(accountDiffs map[iotago.AccountID]*model.Ac
509
512
}
510
513
}
511
514
512
- func (l * Ledger ) processCreatedAndConsumedAccountOutputs (stateDiff mempool.StateDiff , accountDiffs map [iotago.AccountID ]* model.AccountDiff ) (createdAccounts map [iotago.AccountID ]* utxoledger.Output , consumedAccounts map [iotago.AccountID ]* utxoledger.Output , destroyedAccounts ds.Set [iotago.AccountID ], err error ) {
513
- createdAccounts = make (map [iotago.AccountID ]* utxoledger.Output )
514
- consumedAccounts = make (map [iotago.AccountID ]* utxoledger.Output )
515
+ func (l * Ledger ) processCreatedAndConsumedAccountOutputs (stateDiff mempool.StateDiff , accountDiffs map [iotago.AccountID ]* model.AccountDiff ) (createdAccountOutputs map [iotago.AccountID ]* utxoledger.Output , consumedAccountOutputs map [iotago.AccountID ]* utxoledger.Output , createdAccounts ds.Set [iotago.AccountID ], destroyedAccounts ds.Set [iotago.AccountID ], err error ) {
516
+ createdAccountOutputs = make (map [iotago.AccountID ]* utxoledger.Output )
517
+ consumedAccountOutputs = make (map [iotago.AccountID ]* utxoledger.Output )
518
+ createdAccounts = ds .NewSet [iotago.AccountID ]()
515
519
destroyedAccounts = ds .NewSet [iotago.AccountID ]()
516
520
517
521
newAccountDelegation := make (map [iotago.ChainID ]* iotago.DelegationOutput )
@@ -536,9 +540,10 @@ func (l *Ledger) processCreatedAndConsumedAccountOutputs(stateDiff mempool.State
536
540
accountID := createdAccount .AccountID
537
541
if accountID .Empty () {
538
542
accountID = iotago .AccountIDFromOutputID (createdOutput .OutputID ())
543
+ createdAccounts .Add (accountID )
539
544
}
540
545
541
- createdAccounts [accountID ] = createdOutput
546
+ createdAccountOutputs [accountID ] = createdOutput
542
547
case iotago .OutputDelegation :
543
548
delegationOutput , _ := createdOutput .Output ().(* iotago.DelegationOutput )
544
549
delegationID := delegationOutput .DelegationID
@@ -554,15 +559,16 @@ func (l *Ledger) processCreatedAndConsumedAccountOutputs(stateDiff mempool.State
554
559
// if a basic output is sent to an implicit account creation address, we need to create the account
555
560
if createdOutput .Output ().UnlockConditionSet ().Address ().Address .Type () == iotago .AddressImplicitAccountCreation {
556
561
accountID := iotago .AccountIDFromOutputID (createdOutput .OutputID ())
557
- createdAccounts [accountID ] = createdOutput
562
+ createdAccounts .Add (accountID )
563
+ createdAccountOutputs [accountID ] = createdOutput
558
564
}
559
565
}
560
566
561
567
return true
562
568
})
563
569
564
570
if err != nil {
565
- return nil , nil , nil , ierrors .Wrap (err , "error while processing created states" )
571
+ return nil , nil , nil , nil , ierrors .Wrap (err , "error while processing created states" )
566
572
}
567
573
568
574
// input side
@@ -585,10 +591,10 @@ func (l *Ledger) processCreatedAndConsumedAccountOutputs(stateDiff mempool.State
585
591
if consumedAccount .FeatureSet ().BlockIssuer () == nil && consumedAccount .FeatureSet ().Staking () == nil {
586
592
return true
587
593
}
588
- consumedAccounts [accountID ] = spentOutput
594
+ consumedAccountOutputs [accountID ] = spentOutput
589
595
590
596
// if we have consumed accounts that are not created in the same slot, we need to track them as destroyed
591
- if _ , exists := createdAccounts [accountID ]; ! exists {
597
+ if _ , exists := createdAccountOutputs [accountID ]; ! exists {
592
598
destroyedAccounts .Add (accountID )
593
599
}
594
600
@@ -606,7 +612,7 @@ func (l *Ledger) processCreatedAndConsumedAccountOutputs(stateDiff mempool.State
606
612
// if a basic output (implicit account) is consumed, get the accountID as hash of the output ID.
607
613
if spentOutput .Output ().UnlockConditionSet ().Address ().Address .Type () == iotago .AddressImplicitAccountCreation {
608
614
accountID := iotago .AccountIDFromOutputID (spentOutput .OutputID ())
609
- consumedAccounts [accountID ] = spentOutput
615
+ consumedAccountOutputs [accountID ] = spentOutput
610
616
}
611
617
}
612
618
@@ -620,10 +626,10 @@ func (l *Ledger) processCreatedAndConsumedAccountOutputs(stateDiff mempool.State
620
626
}
621
627
622
628
if err != nil {
623
- return nil , nil , nil , ierrors .Wrap (err , "error while processing created states" )
629
+ return nil , nil , nil , nil , ierrors .Wrap (err , "error while processing created states" )
624
630
}
625
631
626
- return createdAccounts , consumedAccounts , destroyedAccounts , nil
632
+ return createdAccountOutputs , consumedAccountOutputs , createdAccounts , destroyedAccounts , nil
627
633
}
628
634
629
635
func (l * Ledger ) processStateDiffTransactions (stateDiff mempool.StateDiff ) (spents utxoledger.Spents , outputs utxoledger.Outputs , accountDiffs map [iotago.AccountID ]* model.AccountDiff , err error ) {
0 commit comments