Skip to content

Commit ac2a2ae

Browse files
committed
all quote changes
1 parent 0245989 commit ac2a2ae

File tree

10 files changed

+50
-9
lines changed

10 files changed

+50
-9
lines changed

client.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
692692

693693
quote, err := s.Server.GetLoopInQuote(
694694
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
695-
request.RouteHints, request.Initiator,
695+
request.RouteHints, request.Initiator, request.NumDeposits,
696696
)
697697
if err != nil {
698698
return nil, err
@@ -709,6 +709,15 @@ func (s *Client) LoopInQuote(ctx context.Context,
709709
}, nil
710710
}
711711

712+
// We don't calculate the on-chain fee if the loop in is funded by
713+
// static address deposits.
714+
if request.NumDeposits > 0 {
715+
return &LoopInQuote{
716+
SwapFee: swapFee,
717+
MinerFee: 0,
718+
}, nil
719+
}
720+
712721
// Get estimate for miner fee. If estimating the miner fee for the
713722
// requested amount is not possible because lnd's wallet cannot
714723
// construct a sample TX, we just return zero instead of failing the

interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ type LoopInQuoteRequest struct {
288288
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
289289
// appended to the user agent string.
290290
Initiator string
291+
292+
NumDeposits uint32
291293
}
292294

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

loopd/swapclient_server.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
749749
log.Infof("Loop in quote request received")
750750

751751
htlcConfTarget, err := validateLoopInRequest(
752-
req.ConfTarget, req.ExternalHtlc,
752+
req.ConfTarget, req.ExternalHtlc, req.NumDeposits,
753753
)
754754
if err != nil {
755755
return nil, err
@@ -785,6 +785,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
785785
RouteHints: routeHints,
786786
Private: req.Private,
787787
Initiator: defaultLoopdInitiator,
788+
NumDeposits: req.NumDeposits,
788789
})
789790
if err != nil {
790791
return nil, err
@@ -881,7 +882,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
881882
log.Infof("Loop in request received")
882883

883884
htlcConfTarget, err := validateLoopInRequest(
884-
in.HtlcConfTarget, in.ExternalHtlc,
885+
in.HtlcConfTarget, in.ExternalHtlc, 0,
885886
)
886887
if err != nil {
887888
return nil, err
@@ -1674,7 +1675,9 @@ func validateConfTarget(target, defaultTarget int32) (int32, error) {
16741675

16751676
// validateLoopInRequest fails if the mutually exclusive conf target and
16761677
// external parameters are both set.
1677-
func validateLoopInRequest(htlcConfTarget int32, external bool) (int32, error) {
1678+
func validateLoopInRequest(htlcConfTarget int32, external bool,
1679+
numDeposits uint32) (int32, error) {
1680+
16781681
// If the htlc is going to be externally set, the htlcConfTarget should
16791682
// not be set, because it has no relevance when the htlc is external.
16801683
if external && htlcConfTarget != 0 {
@@ -1688,6 +1691,12 @@ func validateLoopInRequest(htlcConfTarget int32, external bool) (int32, error) {
16881691
return 0, nil
16891692
}
16901693

1694+
// If the loop in uses static address deposits, we do not need to set a
1695+
// confirmation target since the HTLC won't be published by the client.
1696+
if numDeposits > 0 {
1697+
return 0, nil
1698+
}
1699+
16911700
return validateConfTarget(htlcConfTarget, loop.DefaultHtlcConfTarget)
16921701
}
16931702

loopd/swapclient_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func TestValidateLoopInRequest(t *testing.T) {
193193
t.Run(test.name, func(t *testing.T) {
194194
external := test.external
195195
conf, err := validateLoopInRequest(
196-
test.confTarget, external,
196+
test.confTarget, external, 0,
197197
)
198198

199199
if test.expectErr {

loopin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
128128
// hints.
129129
quote, err := cfg.server.GetLoopInQuote(
130130
globalCtx, request.Amount, cfg.lnd.NodePubkey, request.LastHop,
131-
request.RouteHints, request.Initiator,
131+
request.RouteHints, request.Initiator, 0,
132132
)
133133
if err != nil {
134134
return nil, wrapGrpcError("loop in terms", err)

looprpc/client.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ message QuoteRequest {
760760
probing and payment.
761761
*/
762762
bool private = 7;
763+
764+
uint32 num_deposits = 8;
763765
}
764766

765767
message InQuoteResponse {

looprpc/client.swagger.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@
254254
"in": "query",
255255
"required": false,
256256
"type": "boolean"
257+
},
258+
{
259+
"name": "num_deposits",
260+
"in": "query",
261+
"required": false,
262+
"type": "integer",
263+
"format": "int64"
257264
}
258265
],
259266
"tags": [
@@ -404,6 +411,13 @@
404411
"in": "query",
405412
"required": false,
406413
"type": "boolean"
414+
},
415+
{
416+
"name": "num_deposits",
417+
"in": "query",
418+
"required": false,
419+
"type": "integer",
420+
"format": "int64"
407421
}
408422
],
409423
"tags": [

server_mock_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func (s *serverMock) GetLoopInTerms(ctx context.Context, initiator string) (
225225
}
226226

227227
func (s *serverMock) GetLoopInQuote(context.Context, btcutil.Amount,
228-
route.Vertex, *route.Vertex, [][]zpay32.HopHint, string) (*LoopInQuote, error) {
228+
route.Vertex, *route.Vertex, [][]zpay32.HopHint, string,
229+
uint32) (*LoopInQuote, error) {
229230

230231
return &LoopInQuote{
231232
SwapFee: testSwapFee,

swap_server_client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type swapServerClient interface {
8282
GetLoopInQuote(ctx context.Context, amt btcutil.Amount,
8383
pubKey route.Vertex, lastHop *route.Vertex,
8484
routeHints [][]zpay32.HopHint,
85-
initiator string) (*LoopInQuote, error)
85+
initiator string, numDeposits uint32) (*LoopInQuote, error)
8686

8787
Probe(ctx context.Context, amt btcutil.Amount, target route.Vertex,
8888
lastHop *route.Vertex, routeHints [][]zpay32.HopHint) error
@@ -268,7 +268,8 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context,
268268

269269
func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
270270
amt btcutil.Amount, pubKey route.Vertex, lastHop *route.Vertex,
271-
routeHints [][]zpay32.HopHint, initiator string) (*LoopInQuote, error) {
271+
routeHints [][]zpay32.HopHint, initiator string,
272+
numDeposits uint32) (*LoopInQuote, error) {
272273

273274
err := s.Probe(ctx, amt, pubKey, lastHop, routeHints)
274275
if err != nil && status.Code(err) != codes.Unavailable {
@@ -283,6 +284,7 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
283284
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
284285
Pubkey: pubKey[:],
285286
UserAgent: UserAgent(initiator),
287+
NumDeposits: numDeposits,
286288
}
287289

288290
if lastHop != nil {

swapserverrpc/server.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ message ServerLoopInQuoteRequest {
284284
// loopd/v0.10.0-beta/commit=3b635821
285285
// litd/v0.2.0-alpha/commit=326d754
286286
string user_agent = 6;
287+
288+
uint32 num_deposits = 7;
287289
}
288290

289291
message ServerLoopInQuoteResponse {

0 commit comments

Comments
 (0)