commitShadowTransactions commits all inflight shadow transactions for a parent transaction. It attempts to commit all shadows and returns an error if any fail (for outbox retry). Already-committed shadows return "already committed" error which is treated as success. Parameters: - ctx context.Contex
(ctx context.Context, parentTransactionID string, amount *big.Int)
| 1225 | // Returns: |
| 1226 | // - error: An error if any shadow transaction failed to commit (excluding already-committed). |
| 1227 | func (l *LedgerForge) commitShadowTransactions(ctx context.Context, parentTransactionID string, amount *big.Int) error { |
| 1228 | ctx, span := tracer.Start(ctx, "CommitShadowTransactions") |
| 1229 | defer span.End() |
| 1230 | |
| 1231 | shadowTxns, err := l.datasource.GetTransactionsByShadowFor(ctx, parentTransactionID) |
| 1232 | if err != nil { |
| 1233 | return fmt.Errorf("failed to get shadow transactions: %w", err) |
| 1234 | } |
| 1235 | |
| 1236 | var failedShadows []string |
| 1237 | for _, shadow := range shadowTxns { |
| 1238 | _, err := l.CommitInflightTransaction(ctx, shadow.TransactionID, shadow.PreciseAmount) |
| 1239 | if err != nil { |
| 1240 | if strings.Contains(err.Error(), "already committed") || |
| 1241 | strings.Contains(err.Error(), "not in inflight status") { |
| 1242 | span.AddEvent("Shadow transaction already processed, skipping", trace.WithAttributes( |
| 1243 | attribute.String("shadow.id", shadow.TransactionID), |
| 1244 | )) |
| 1245 | continue |
| 1246 | } |
| 1247 | logrus.Errorf("failed to commit shadow transaction %s: %v", shadow.TransactionID, err) |
| 1248 | failedShadows = append(failedShadows, shadow.TransactionID) |
| 1249 | continue |
| 1250 | } |
| 1251 | span.AddEvent("Shadow transaction committed", trace.WithAttributes( |
| 1252 | attribute.String("shadow.id", shadow.TransactionID), |
| 1253 | attribute.String("parent.id", parentTransactionID), |
| 1254 | )) |
| 1255 | } |
| 1256 | |
| 1257 | if len(failedShadows) > 0 { |
| 1258 | return fmt.Errorf("failed to commit %d shadow transactions: %v", len(failedShadows), failedShadows) |
| 1259 | } |
| 1260 | |
| 1261 | return nil |
| 1262 | } |
| 1263 | |
| 1264 | // voidShadowTransactions voids all inflight shadow transactions for a parent transaction. |
| 1265 | // It attempts to void all shadows and returns an error if any fail (for outbox retry). |
no test coverage detected