Skip to content

Commit d2000da

Browse files
committed
staticaddr: fast-flag
1 parent c9e2467 commit d2000da

28 files changed

+1494
-1354
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
843843
quote, err := s.Server.GetLoopInQuote(
844844
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
845845
request.RouteHints, request.Initiator, request.NumDeposits,
846+
request.Fast,
846847
)
847848
if err != nil {
848849
return nil, err

cmd/loop/staticaddr.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ var staticAddressLoopInCommand = cli.Command{
485485
"is change it is sent back to the static " +
486486
"address.",
487487
},
488+
cli.BoolFlag{
489+
Name: "fast",
490+
Usage: "expedited publishing of the change output if " +
491+
"the swap creates one. This results in a " +
492+
"higher swap fee.",
493+
},
488494
lastHopFlag,
489495
labelFlag,
490496
routeHintsFlag,
@@ -573,7 +579,8 @@ func staticAddressLoopIn(ctx *cli.Context) error {
573579
depositOutpoints = ctx.StringSlice("utxo")
574580

575581
case selectedAmount > 0:
576-
// If only an amount is selected we will trigger coin selection.
582+
// If only an amount is selected, we will trigger coin
583+
// selection.
577584

578585
default:
579586
return fmt.Errorf("unknown quote request")
@@ -594,6 +601,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
594601
Private: ctx.Bool(privateFlag.Name),
595602
DepositOutpoints: depositOutpoints,
596603
AutoSelectDeposits: autoSelectDepositsForQuote,
604+
Fast: ctx.Bool("fast"),
597605
}
598606
quote, err := client.GetLoopInQuote(ctxb, quoteReq)
599607
if err != nil {
@@ -623,6 +631,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
623631
RouteHints: hints,
624632
Private: ctx.Bool("private"),
625633
PaymentTimeoutSeconds: paymentTimeoutSeconds,
634+
Fast: ctx.Bool("fast"),
626635
}
627636

628637
resp, err := client.StaticAddressLoopIn(ctxb, req)

interface.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ type StaticAddressLoopInRequest struct {
343343
// the user did not select an amount, the amount of the selected
344344
// deposits is used.
345345
SelectedAmount btcutil.Amount
346+
347+
// Fast indicates whether the user requested a fast static loop-in. If
348+
// set, the flag is passed to the server which may alter its behavior
349+
// (for example, publish sooner) and is stored in the database.
350+
Fast bool
346351
}
347352

348353
// LoopInTerms are the server terms on which it executes loop in swaps.
@@ -405,6 +410,12 @@ type LoopInQuoteRequest struct {
405410
// per-input service fee. This is to cover for the increased on-chain
406411
// fee the server has to pay when the sweeping transaction is broadcast.
407412
NumDeposits uint32
413+
414+
// Fast indicates whether the user requested a fast static loop-in
415+
// publication on-chain. This is helpful if swap change needs to get
416+
// confirmed fast. This comes at a higher swap cost since the server has
417+
// to pay more on-chain fees.
418+
Fast bool
408419
}
409420

410421
// LoopInQuote contains estimates for the fees making up the total swap cost

loopd/swapclient_server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
10251025
Private: req.Private,
10261026
Initiator: defaultLoopdInitiator,
10271027
NumDeposits: uint32(numDeposits),
1028+
Fast: req.Fast,
10281029
})
10291030
if err != nil {
10301031
return nil, err
@@ -2052,6 +2053,7 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
20522053
Private: in.Private,
20532054
RouteHints: routeHints,
20542055
PaymentTimeoutSeconds: in.PaymentTimeoutSeconds,
2056+
Fast: in.GetFast(),
20552057
}
20562058

20572059
if in.LastHop != nil {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Drop 'fast' flag from static_address_swaps
2+
ALTER TABLE static_address_swaps DROP COLUMN fast;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add 'fast' flag to static_address_swaps, default false
2+
ALTER TABLE static_address_swaps ADD COLUMN fast BOOLEAN NOT NULL DEFAULT false;

loopdb/sqlc/models.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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ INSERT INTO static_address_swaps (
99
selected_amount,
1010
htlc_tx_fee_rate_sat_kw,
1111
htlc_timeout_sweep_tx_id,
12-
htlc_timeout_sweep_address
12+
htlc_timeout_sweep_address,
13+
fast
1314
) VALUES (
1415
$1,
1516
$2,
@@ -20,7 +21,8 @@ INSERT INTO static_address_swaps (
2021
$7,
2122
$8,
2223
$9,
23-
$10
24+
$10,
25+
$11
2426
);
2527

2628
-- name: UpdateStaticAddressLoopIn :exec

loopdb/sqlc/static_address_loopin.sql.go

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

loopin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
130130
// channels is an LND side black box feature. Advanced users will quote
131131
// directly anyway and there they have the option to add specific route
132132
// hints.
133+
numDeposits := uint32(0)
134+
fast := false
133135
quote, err := cfg.server.GetLoopInQuote(
134136
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
135-
request.RouteHints, request.Initiator, 0,
137+
request.RouteHints, request.Initiator, numDeposits, fast,
136138
)
137139
if err != nil {
138140
return nil, wrapGrpcError("loop in terms", err)

0 commit comments

Comments
 (0)