acquireLineageLocks acquires distributed locks for multiple shadow balances using MultiLocker. MultiLocker handles sorting (prevents deadlock) and deduplication automatically. This is used for both credit and debit lineage processing to prevent race conditions. Parameters: - ctx context.Context: Th
(ctx context.Context, balanceIDs []string)
| 504 | // - *redlock.MultiLocker: The acquired multi-lock. |
| 505 | // - error: An error if the locks could not be acquired. |
| 506 | func (l *LedgerForge) acquireLineageLocks(ctx context.Context, balanceIDs []string) (*redlock.MultiLocker, error) { |
| 507 | // Prefix all keys to avoid collision with main transaction locks |
| 508 | lockKeys := make([]string, 0, len(balanceIDs)) |
| 509 | for _, id := range balanceIDs { |
| 510 | lockKeys = append(lockKeys, fmt.Sprintf("lineage:%s", id)) |
| 511 | } |
| 512 | |
| 513 | // MultiLocker handles deduplication and sorts keys lexicographically |
| 514 | locker := redlock.NewMultiLocker(l.redis, lockKeys, model.GenerateUUIDWithSuffix("loc")) |
| 515 | |
| 516 | err := locker.Lock(ctx, l.Config().Transaction.LockDuration) |
| 517 | if err != nil { |
| 518 | return nil, fmt.Errorf("failed to acquire lineage locks: %w", err) |
| 519 | } |
| 520 | |
| 521 | return locker, nil |
| 522 | } |
| 523 | |
| 524 | // getSourceAggregateBalance retrieves or creates the aggregate balance for the source identity. |
| 525 | // |
no test coverage detected