paymentsdb: fix SettleAttempt and FailAttempt to use caller-provided timestamps
The SQL backend introduced in this PR was ignoring the SettleTime and FailTime fields provided in HTLCSettleInfo and HTLCFailInfo, instead always recording time.Now() as the resolution timestamp. The KV backend correctly serializes and deserializes these fields. The timestamps are set by the caller using a mockable clock (p.router.cfg.Clock.Now() in payment_lifecycle.go), so ignoring them means the stored timestamp reflects when the DB write happened rather than when the event occurred, breaking deterministic testing. This commit also extends the test assertions in assertPaymentInfo to verify that SettleTime and FailTime are correctly stored and retrieved by the SQL backend, and updates the relevant call sites to pass explicit timestamps so regressions are caught.
This commit is contained in:
2 files changed
+79
-58
No files matched your search
@@ -1629,7 +1629,7 @@ func (s *SQLStore) SettleAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
|
||||
err = db.SettleAttempt(ctx, sqlc.SettleAttemptParams{
|
||||
AttemptIndex: int64(attemptID),
|
||||
ResolutionTime: time.Now(),
|
||||
ResolutionTime: settleInfo.SettleTime.UTC(),
|
||||
ResolutionType: int32(HTLCAttemptResolutionSettled),
|
||||
SettlePreimage: settleInfo.Preimage[:],
|
||||
})
|
||||
@@ -1716,7 +1716,7 @@ func (s *SQLStore) FailAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
|
||||
err = db.FailAttempt(ctx, sqlc.FailAttemptParams{
|
||||
AttemptIndex: int64(attemptID),
|
||||
ResolutionTime: time.Now(),
|
||||
ResolutionTime: failInfo.FailTime.UTC(),
|
||||
ResolutionType: int32(HTLCAttemptResolutionFailed),
|
||||
FailureSourceIndex: sqldb.SQLInt32(
|
||||
failInfo.FailureSourceIndex,
|
||||
|
||||
Reference in new issue
Block a user