CommitInflightTransaction commits an inflight transaction by validating and updating its amount, and finalizing the commitment. It starts a tracing span, fetches and validates the inflight transaction, updates the amount, and finalizes the commitment. Parameters: - ctx context.Context: The context
(ctx context.Context, transactionID string, amount *big.Int)
| 176 | // - *model.Transaction: A pointer to the committed Transaction model. |
| 177 | // - error: An error if the transaction could not be committed. |
| 178 | func (l *LedgerForge) CommitInflightTransaction(ctx context.Context, transactionID string, amount *big.Int) (*model.Transaction, error) { |
| 179 | ctx, span := tracer.Start(ctx, "CommitInflightTransaction") |
| 180 | defer span.End() |
| 181 | |
| 182 | lockKey := fmt.Sprintf("inflight-commit:%s", transactionID) |
| 183 | locker := redlock.NewLocker(l.redis, lockKey, model.GenerateUUIDWithSuffix("loc")) |
| 184 | |
| 185 | err := locker.Lock(ctx, l.Config().Transaction.LockDuration) |
| 186 | if err != nil { |
| 187 | span.RecordError(err) |
| 188 | return nil, fmt.Errorf("failed to acquire lock for inflight commit: %w", err) |
| 189 | } |
| 190 | defer l.releaseSingleLock(ctx, locker) |
| 191 | |
| 192 | transaction, err := l.fetchAndValidateInflightTransaction(ctx, transactionID) |
| 193 | if err != nil { |
| 194 | span.RecordError(err) |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | if err := l.validateAndUpdateAmount(ctx, transaction, amount); err != nil { |
| 199 | span.RecordError(err) |
| 200 | return nil, err |
| 201 | } |
| 202 | |
| 203 | span.AddEvent("Inflight transaction committed", trace.WithAttributes(attribute.String("transaction.id", transaction.TransactionID))) |
| 204 | metrics.InflightCommitTotal.Add(ctx, 1) |
| 205 | |
| 206 | committedTxn, err := l.finalizeCommitment(ctx, transaction, false) |
| 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | |
| 211 | if err := l.queueShadowWork(ctx, transactionID, model.LineageTypeShadowCommit); err != nil { |
| 212 | logrus.WithError(err).WithField("transaction_id", transactionID).Error("failed to queue shadow commit") |
| 213 | } |
| 214 | |
| 215 | return committedTxn, nil |
| 216 | } |
| 217 | |
| 218 | func (l *LedgerForge) CommitInflightTransactionWithQueue(ctx context.Context, transactionID string, amount *big.Int) (*model.Transaction, error) { |
| 219 | ctx, span := tracer.Start(ctx, "CommitInflightTransactionWithQueue") |