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

Method CommitInflightTransaction

inflight_transaction.go:178–216  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

176// - *model.Transaction: A pointer to the committed Transaction model.
177// - error: An error if the transaction could not be committed.
178func (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
218func (l *LedgerForge) CommitInflightTransactionWithQueue(ctx context.Context, transactionID string, amount *big.Int) (*model.Transaction, error) {
219 ctx, span := tracer.Start(ctx, "CommitInflightTransactionWithQueue")

Calls 10

LockMethod · 0.95
ConfigMethod · 0.95
releaseSingleLockMethod · 0.95
finalizeCommitmentMethod · 0.95
queueShadowWorkMethod · 0.95
GenerateUUIDWithSuffixFunction · 0.92
StartMethod · 0.45
ErrorMethod · 0.45