prepareDestinationLineageBalances pre-creates destination shadow and aggregate balances for all providers. This is called BEFORE acquiring locks to avoid nested lock acquisition deadlocks. Parameters: - ctx context.Context: The context for the operation. - mappings []model.LineageMapping: The sourc
(ctx context.Context, mappings []model.LineageMapping, destinationBalance *model.Balance)
| 476 | // - map[string]*destinationLineageInfo: Map of provider to destination lineage balances. |
| 477 | // - error: An error if any balance could not be created. |
| 478 | func (l *LedgerForge) prepareDestinationLineageBalances(ctx context.Context, mappings []model.LineageMapping, destinationBalance *model.Balance) (map[string]*destinationLineageInfo, error) { |
| 479 | result := make(map[string]*destinationLineageInfo, len(mappings)) |
| 480 | |
| 481 | for _, mapping := range mappings { |
| 482 | shadowBalance, aggBalance, err := l.getOrCreateDestinationLineageBalances(ctx, mapping.Provider, destinationBalance) |
| 483 | if err != nil { |
| 484 | return nil, fmt.Errorf("failed to prepare destination lineage for provider %s: %w", mapping.Provider, err) |
| 485 | } |
| 486 | result[mapping.Provider] = &destinationLineageInfo{ |
| 487 | shadowBalance: shadowBalance, |
| 488 | aggregateBalance: aggBalance, |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | return result, nil |
| 493 | } |
| 494 | |
| 495 | // acquireLineageLocks acquires distributed locks for multiple shadow balances using MultiLocker. |
| 496 | // MultiLocker handles sorting (prevents deadlock) and deduplication automatically. |
no test coverage detected