MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / persistQueuedTransactionBatch

Method persistQueuedTransactionBatch

transaction.go:949–977  ·  view source on GitHub ↗

persistQueuedTransactionBatch acquires the balance-set lock, prepares the batch in memory, commits the final state atomically, and dispatches post-commit side effects.

(ctx context.Context, transactions []*model.Transaction)

Source from the content-addressed store, hash-verified

947// persistQueuedTransactionBatch acquires the balance-set lock, prepares the batch in memory,
948// commits the final state atomically, and dispatches post-commit side effects.
949func (l *LedgerForge) persistQueuedTransactionBatch(ctx context.Context, transactions []*model.Transaction) error {
950 ctx, span := tracer.Start(ctx, "RecordQueuedTransactionBatch")
951 defer span.End()
952
953 if err := validateQueuedBatchCurrencies(transactions); err != nil {
954 return err
955 }
956
957 if len(transactions) == 0 {
958 return nil
959 }
960
961 currency := transactions[0].Currency
962
963 balanceIDs := collectQueuedCoalescingBalanceIDs(transactions)
964 locker, err := l.acquireBalanceSetLock(ctx, balanceIDs)
965 if err != nil {
966 hotpairs.RecordContention(ctx, l.hotPairs, transactions[0].Source, transactions[0].Destination, currency, err)
967 return fmt.Errorf("failed to acquire batch lock: %w", err)
968 }
969
970 result, err := l.persistQueuedTransactionBatchLocked(ctx, span, locker, balanceIDs, transactions)
971 if err != nil {
972 return err
973 }
974
975 l.runQueuedBatchPostCommitWork(ctx, span, result)
976 return nil
977}
978
979// validateQueuedBatchCurrencies ensures that every transaction in a coalesced batch uses the
980// same currency before any lock or balance work begins.

Callers 1

Tested by

no test coverage detected