Skip to content

Commit 61d505f

Browse files
committed
staticaddr/loopin: persist risk decisions
1 parent 8128304 commit 61d505f

16 files changed

Lines changed: 730 additions & 103 deletions

loopd/daemon.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,30 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
555555
}
556556
}
557557

558+
// Static address loop-in store setup is needed by the notification
559+
// manager so confirmation-risk decisions are durable before fan-out.
560+
staticAddressLoopInStore := loopin.NewSqlStore(
561+
loopdb.NewTypedStore[loopin.Querier](baseDb),
562+
clock.NewDefaultClock(), d.lnd.ChainParams,
563+
)
564+
558565
// Start the notification manager.
559566
notificationCfg := &notifications.Config{
560567
Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn),
561568
CurrentToken: swapClient.L402Store.CurrentToken,
569+
PersistStaticLoopInRiskDecision: func(ctx context.Context,
570+
swapHash lntypes.Hash, accepted bool) error {
571+
572+
decision := loopin.ConfirmationRiskDecisionRejected
573+
if accepted {
574+
decision = loopin.ConfirmationRiskDecisionAccepted
575+
}
576+
577+
return staticAddressLoopInStore.
578+
RecordStaticAddressRiskDecision(
579+
ctx, swapHash, decision,
580+
)
581+
},
562582
}
563583
notificationManager := notifications.NewManager(notificationCfg)
564584

@@ -642,12 +662,6 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
642662
}
643663
openChannelManager = openchannel.NewManager(openChannelCfg)
644664

645-
// Static address loop-in manager setup.
646-
staticAddressLoopInStore := loopin.NewSqlStore(
647-
loopdb.NewTypedStore[loopin.Querier](baseDb),
648-
clock.NewDefaultClock(), d.lnd.ChainParams,
649-
)
650-
651665
// Run the deposit swap hash migration.
652666
err = loopin.MigrateDepositSwapHash(
653667
d.mainCtx, swapDb, depositStore, staticAddressLoopInStore,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Drop confirmation-risk decision fields from static address loop-ins.
2+
ALTER TABLE static_address_swaps DROP COLUMN confirmation_risk_decision;
3+
ALTER TABLE static_address_swaps DROP COLUMN confirmation_risk_decision_time;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- confirmation_risk_decision records the server's confirmation-risk decision
2+
-- for a static address loop-in. The empty string means no decision has been
3+
-- received yet.
4+
ALTER TABLE static_address_swaps ADD COLUMN confirmation_risk_decision TEXT NOT NULL DEFAULT '';
5+
6+
-- confirmation_risk_decision_time records when loopd received and persisted
7+
-- the server's decision, so payment deadlines can be reconstructed after
8+
-- restart.
9+
ALTER TABLE static_address_swaps ADD COLUMN confirmation_risk_decision_time TIMESTAMP;

loopdb/sqlc/models.go

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/queries/static_address_loopin.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ SET
3333
WHERE
3434
swap_hash = $1;
3535

36+
-- name: RecordStaticAddressRiskDecision :exec
37+
UPDATE static_address_swaps
38+
SET
39+
confirmation_risk_decision = $2,
40+
confirmation_risk_decision_time = $3
41+
WHERE
42+
swap_hash = $1;
43+
3644
-- name: InsertStaticAddressMetaUpdate :exec
3745
INSERT INTO static_address_swap_updates (
3846
swap_hash,
@@ -150,4 +158,3 @@ WHERE
150158

151159

152160

153-

loopdb/sqlc/static_address_loopin.sql.go

Lines changed: 90 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)