Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
quote, err := s.Server.GetLoopInQuote(
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
request.RouteHints, request.Initiator, request.NumDeposits,
request.Fast,
)
if err != nil {
return nil, err
Expand Down
29 changes: 27 additions & 2 deletions cmd/loop/staticaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ var staticAddressLoopInCommand = cli.Command{
"is change it is sent back to the static " +
"address.",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep previous flag as well? So it is possible to set it via --amount. Some people may prefer this, e.g. in scripts where each argument is on a separate line. Positional argument is good for manual use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I re-added the flag.

cli.BoolFlag{
Name: "fast",
Usage: "Usage: complete the swap faster by paying a " +
"higher fee, so the change output is " +
"available sooner",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to rephrase it to make the purpose clearer:

Usage: "complete the swap faster by paying a higher fee, so the change output is available sooner",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this description

lastHopFlag,
labelFlag,
routeHintsFlag,
Expand All @@ -500,6 +506,23 @@ func staticAddressLoopIn(ctx *cli.Context) error {
return cli.ShowCommandHelp(ctx, "in")
}

var selectedAmount int64
switch {
case ctx.NArg() == 1:
amt, err := parseAmt(ctx.Args().Get(0))
if err != nil {
return err
}
selectedAmount = int64(amt)

case ctx.NArg() > 1:
return fmt.Errorf("only a single positional argument is " +
"allowed")

default:
selectedAmount = ctx.Int64("amount")
}

client, cleanup, err := getClient(ctx)
if err != nil {
return err
Expand All @@ -510,7 +533,6 @@ func staticAddressLoopIn(ctx *cli.Context) error {
ctxb = context.Background()
isAllSelected = ctx.IsSet("all")
isUtxoSelected = ctx.IsSet("utxo")
selectedAmount = ctx.Int64("amount")
autoSelectDepositsForQuote bool
label = ctx.String("static-loop-in")
hints []*swapserverrpc.RouteHint
Expand Down Expand Up @@ -573,7 +595,8 @@ func staticAddressLoopIn(ctx *cli.Context) error {
depositOutpoints = ctx.StringSlice("utxo")

case selectedAmount > 0:
// If only an amount is selected we will trigger coin selection.
// If only an amount is selected, we will trigger coin
// selection.

default:
return fmt.Errorf("unknown quote request")
Expand All @@ -594,6 +617,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
Private: ctx.Bool(privateFlag.Name),
DepositOutpoints: depositOutpoints,
AutoSelectDeposits: autoSelectDepositsForQuote,
Fast: ctx.Bool("fast"),
}
quote, err := client.GetLoopInQuote(ctxb, quoteReq)
if err != nil {
Expand Down Expand Up @@ -623,6 +647,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
RouteHints: hints,
Private: ctx.Bool("private"),
PaymentTimeoutSeconds: paymentTimeoutSeconds,
Fast: ctx.Bool("fast"),
}

resp, err := client.StaticAddressLoopIn(ctxb, req)
Expand Down
11 changes: 11 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ type StaticAddressLoopInRequest struct {
// the user did not select an amount, the amount of the selected
// deposits is used.
SelectedAmount btcutil.Amount

// Fast indicates whether the user requested a fast static loop-in. If
// set, the flag is passed to the server which may alter its behavior
// (for example, publish sooner) and is stored in the database.
Fast bool
}

// LoopInTerms are the server terms on which it executes loop in swaps.
Expand Down Expand Up @@ -405,6 +410,12 @@ type LoopInQuoteRequest struct {
// per-input service fee. This is to cover for the increased on-chain
// fee the server has to pay when the sweeping transaction is broadcast.
NumDeposits uint32

// Fast indicates whether the user requested a fast static loop-in
// publication on-chain. This is helpful if swap change needs to get
// confirmed fast. This comes at a higher swap cost since the server has
// to pay more on-chain fees.
Fast bool
}

// LoopInQuote contains estimates for the fees making up the total swap cost
Expand Down
10 changes: 10 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,14 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
return nil, err
}

// The fast flag is only available for static loop in quote requests.
if req.Fast {
if !autoSelectDeposits && len(req.DepositOutpoints) == 0 {
return nil, fmt.Errorf("fast flag is only " +
"available for static address requests")
}
}

// If deposits should be automatically selected, we do so and count the
// number of deposits to quote for.
numDeposits := 0
Expand Down Expand Up @@ -1025,6 +1033,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
Private: req.Private,
Initiator: defaultLoopdInitiator,
NumDeposits: uint32(numDeposits),
Fast: req.Fast,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to check here that if req.Fast is set, we make sure that the swap is static. Otherwise fail. Just as a sanity check measure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a sanity check.

})
if err != nil {
return nil, err
Expand Down Expand Up @@ -2052,6 +2061,7 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
Private: in.Private,
RouteHints: routeHints,
PaymentTimeoutSeconds: in.PaymentTimeoutSeconds,
Fast: in.Fast,
}

if in.LastHop != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Drop 'fast' flag from static_address_swaps
ALTER TABLE static_address_swaps DROP COLUMN fast;
2 changes: 2 additions & 0 deletions loopdb/sqlc/migrations/000020_static_address_fast_flag.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add 'fast' flag to static_address_swaps, default false
ALTER TABLE static_address_swaps ADD COLUMN fast BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions loopdb/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions loopdb/sqlc/queries/static_address_loopin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ INSERT INTO static_address_swaps (
selected_amount,
htlc_tx_fee_rate_sat_kw,
htlc_timeout_sweep_tx_id,
htlc_timeout_sweep_address
htlc_timeout_sweep_address,
fast
) VALUES (
$1,
$2,
Expand All @@ -20,7 +21,8 @@ INSERT INTO static_address_swaps (
$7,
$8,
$9,
$10
$10,
$11
);

-- name: UpdateStaticAddressLoopIn :exec
Expand Down
16 changes: 12 additions & 4 deletions loopdb/sqlc/static_address_loopin.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion loopin.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
// channels is an LND side black box feature. Advanced users will quote
// directly anyway and there they have the option to add specific route
// hints.
numDeposits := uint32(0)
fast := false
quote, err := cfg.server.GetLoopInQuote(
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
request.RouteHints, request.Initiator, 0,
request.RouteHints, request.Initiator, numDeposits, fast,
)
if err != nil {
return nil, wrapGrpcError("loop in terms", err)
Expand Down
Loading