Skip to content

Commit 92c1f8c

Browse files
authored
Merge pull request #600 from GeorgeTsagk/add-initiators
Add initiators
2 parents a9f1826 + e9bc1dc commit 92c1f8c

17 files changed

+590
-448
lines changed

client.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
397397
}
398398

399399
// Calculate htlc expiry height.
400-
terms, err := s.Server.GetLoopOutTerms(globalCtx)
400+
terms, err := s.Server.GetLoopOutTerms(globalCtx, request.Initiator)
401401
if err != nil {
402402
return nil, err
403403
}
@@ -456,7 +456,7 @@ func (s *Client) getExpiry(height int32, terms *LoopOutTerms,
456456
func (s *Client) LoopOutQuote(ctx context.Context,
457457
request *LoopOutQuoteRequest) (*LoopOutQuote, error) {
458458

459-
terms, err := s.Server.GetLoopOutTerms(ctx)
459+
terms, err := s.Server.GetLoopOutTerms(ctx, request.Initiator)
460460
if err != nil {
461461
return nil, err
462462
}
@@ -477,6 +477,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
477477

478478
quote, err := s.Server.GetLoopOutQuote(
479479
ctx, request.Amount, expiry, request.SwapPublicationDeadline,
480+
request.Initiator,
480481
)
481482
if err != nil {
482483
return nil, err
@@ -528,10 +529,10 @@ func (s *Client) getLoopOutSweepFee(ctx context.Context, confTarget int32) (
528529
}
529530

530531
// LoopOutTerms returns the terms on which the server executes swaps.
531-
func (s *Client) LoopOutTerms(ctx context.Context) (
532+
func (s *Client) LoopOutTerms(ctx context.Context, initiator string) (
532533
*LoopOutTerms, error) {
533534

534-
return s.Server.GetLoopOutTerms(ctx)
535+
return s.Server.GetLoopOutTerms(ctx, initiator)
535536
}
536537

537538
// waitForInitialized for swaps to be resumed and executor ready.
@@ -601,7 +602,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
601602
request *LoopInQuoteRequest) (*LoopInQuote, error) {
602603

603604
// Retrieve current server terms to calculate swap fee.
604-
terms, err := s.Server.GetLoopInTerms(ctx)
605+
terms, err := s.Server.GetLoopInTerms(ctx, request.Initiator)
605606
if err != nil {
606607
return nil, err
607608
}
@@ -641,7 +642,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
641642

642643
quote, err := s.Server.GetLoopInQuote(
643644
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
644-
request.RouteHints,
645+
request.RouteHints, request.Initiator,
645646
)
646647
if err != nil {
647648
return nil, err
@@ -721,10 +722,10 @@ func (s *Client) estimateFee(ctx context.Context, amt btcutil.Amount,
721722
}
722723

723724
// LoopInTerms returns the terms on which the server executes swaps.
724-
func (s *Client) LoopInTerms(ctx context.Context) (
725+
func (s *Client) LoopInTerms(ctx context.Context, initiator string) (
725726
*LoopInTerms, error) {
726727

727-
return s.Server.GetLoopInTerms(ctx)
728+
return s.Server.GetLoopInTerms(ctx, initiator)
728729
}
729730

730731
// wrapGrpcError wraps the non-nil error provided with a message providing

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ require (
3333
github.com/stretchr/testify v1.8.1
3434
github.com/urfave/cli v1.22.9
3535
golang.org/x/net v0.8.0
36-
google.golang.org/grpc v1.45.0
37-
google.golang.org/protobuf v1.27.1
36+
google.golang.org/grpc v1.53.0
37+
google.golang.org/protobuf v1.28.1
3838
gopkg.in/macaroon-bakery.v2 v2.0.1
3939
gopkg.in/macaroon.v2 v2.1.0
4040
modernc.org/sqlite v1.20.3
@@ -203,4 +203,6 @@ require (
203203
// with https://github.com/grpc/grpc-go/pull/4474.
204204
replace google.golang.org/grpc => google.golang.org/grpc v1.39.0
205205

206+
replace github.com/lightninglabs/loop/swapserverrpc => ./swapserverrpc
207+
206208
go 1.18

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,6 @@ github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI
940940
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
941941
github.com/lightninglabs/lndclient v0.16.0-10 h1:cMBJNfssBQtpgYIu23QLP/qw0ijiT5SBZffnXz8zjJk=
942942
github.com/lightninglabs/lndclient v0.16.0-10/go.mod h1:mqY0znSNa+M40HZowwKfno29RyZnmxoqo++BlYP82EY=
943-
github.com/lightninglabs/loop/swapserverrpc v1.0.4 h1:cEX+mt7xmQlEbmuQ52vOBT7l+a471v94ofdJbB6MmXs=
944-
github.com/lightninglabs/loop/swapserverrpc v1.0.4/go.mod h1:imy1/sqnb70EEyBKMo4pHwwLBPW8uYahWZ8s+1Xcq1o=
945943
github.com/lightninglabs/neutrino v0.15.0 h1:yr3uz36fLAq8hyM0TRUVlef1TRNoWAqpmmNlVtKUDtI=
946944
github.com/lightninglabs/neutrino v0.15.0/go.mod h1:pmjwElN/091TErtSE9Vd5W4hpxoG2/+xlb+HoPm9Gug=
947945
github.com/lightninglabs/neutrino/cache v1.1.1 h1:TllWOSlkABhpgbWJfzsrdUaDH2fBy/54VSIB4vVqV8M=
@@ -1996,8 +1994,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
19961994
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
19971995
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
19981996
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
1999-
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
20001997
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
1998+
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
1999+
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
20012000
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
20022001
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
20032002
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

interface.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ type LoopOutQuoteRequest struct {
129129
// available routes and off-chain fee estimates. To apply these maximum
130130
// values properly, the server needs to be queried for its required
131131
// final cltv delta values for the off-chain payments.
132+
133+
// Initiator is an optional string that identifies what software
134+
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
135+
// appended to the user agent string.
136+
Initiator string
132137
}
133138

134139
// LoopOutTerms are the server terms on which it executes swaps.
@@ -267,6 +272,11 @@ type LoopInQuoteRequest struct {
267272
// private. In which case, loop will generate hophints to assist with
268273
// probing and payment.
269274
Private bool
275+
276+
// Initiator is an optional string that identifies what software
277+
// initiated the swap (loop CLI, autolooper, LiT UI and so on) and is
278+
// appended to the user agent string.
279+
Initiator string
270280
}
271281

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

liquidity/autoloop_testcontext_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func newAutoloopTestCtx(t *testing.T, parameters Parameters,
135135

136136
cfg := &Config{
137137
AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker),
138-
Restrictions: func(_ context.Context, swapType swap.Type) (*Restrictions,
138+
Restrictions: func(_ context.Context, swapType swap.Type, initiator string) (*Restrictions,
139139
error) {
140140

141141
if swapType == swap.TypeOut {

liquidity/liquidity.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ type Config struct {
178178

179179
// Restrictions returns the restrictions that the server applies to
180180
// swaps.
181-
Restrictions func(ctx context.Context, swapType swap.Type) (
182-
*Restrictions, error)
181+
Restrictions func(ctx context.Context, swapType swap.Type,
182+
initiator string) (*Restrictions, error)
183183

184184
// Lnd provides us with access to lnd's rpc servers.
185185
Lnd *lndclient.LndServices
@@ -212,10 +212,12 @@ type Config struct {
212212
request *loop.LoopInRequest) (*loop.LoopInSwapInfo, error)
213213

214214
// LoopInTerms returns the terms for a loop in swap.
215-
LoopInTerms func(ctx context.Context) (*loop.LoopInTerms, error)
215+
LoopInTerms func(ctx context.Context,
216+
initiator string) (*loop.LoopInTerms, error)
216217

217218
// LoopOutTerms returns the terms for a loop out swap.
218-
LoopOutTerms func(ctx context.Context) (*loop.LoopOutTerms, error)
219+
LoopOutTerms func(ctx context.Context,
220+
initiator string) (*loop.LoopOutTerms, error)
219221

220222
// Clock allows easy mocking of time in unit tests.
221223
Clock clock.Clock
@@ -355,7 +357,9 @@ func (m *Manager) SetParameters(ctx context.Context,
355357
func (m *Manager) setParameters(ctx context.Context,
356358
params Parameters) error {
357359

358-
restrictions, err := m.cfg.Restrictions(ctx, swap.TypeOut)
360+
restrictions, err := m.cfg.Restrictions(
361+
ctx, swap.TypeOut, getInitiator(m.params),
362+
)
359363
if err != nil {
360364
return err
361365
}
@@ -566,7 +570,9 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
566570
return nil
567571
}
568572

569-
restrictions, err := m.cfg.Restrictions(ctx, swap.TypeOut)
573+
restrictions, err := m.cfg.Restrictions(
574+
ctx, swap.TypeOut, getInitiator(m.params),
575+
)
570576
if err != nil {
571577
return err
572578
}
@@ -999,7 +1005,9 @@ func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
9991005
func (m *Manager) getSwapRestrictions(ctx context.Context, swapType swap.Type) (
10001006
*Restrictions, error) {
10011007

1002-
restrictions, err := m.cfg.Restrictions(ctx, swapType)
1008+
restrictions, err := m.cfg.Restrictions(
1009+
ctx, swapType, getInitiator(m.params),
1010+
)
10031011
if err != nil {
10041012
return nil, err
10051013
}
@@ -1487,6 +1495,14 @@ func (m *Manager) checkSummaryInflight(
14871495
return allowedSwaps, nil
14881496
}
14891497

1498+
func getInitiator(params Parameters) string {
1499+
if params.EasyAutoloop {
1500+
return "easy-autoloop"
1501+
}
1502+
1503+
return "autoloop"
1504+
}
1505+
14901506
// isAutoloopLabel is a helper function that returns a flag indicating whether
14911507
// the provided label corresponds to an autoloop swap.
14921508
func isAutoloopLabel(label string) bool {

liquidity/liquidity_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func newTestConfig() (*Config, *test.LndMockServices) {
147147
)
148148

149149
return &Config{
150-
Restrictions: func(_ context.Context, _ swap.Type) (*Restrictions,
150+
Restrictions: func(_ context.Context, _ swap.Type, initiator string) (*Restrictions,
151151
error) {
152152

153153
return testRestrictions, nil
@@ -1318,7 +1318,8 @@ type mockServer struct {
13181318
}
13191319

13201320
// Restrictions mocks a call to the server to get swap size restrictions.
1321-
func (m *mockServer) Restrictions(ctx context.Context, swapType swap.Type) (
1321+
func (m *mockServer) Restrictions(ctx context.Context, swapType swap.Type,
1322+
initiator string) (
13221323
*Restrictions, error) {
13231324

13241325
args := m.Called(ctx, swapType)

liquidity/loopin_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
9090
Amount: amount,
9191
LastHop: &pubkey,
9292
HtlcConfTarget: params.HtlcConfTarget,
93+
Initiator: getInitiator(params),
9394
})
9495
if err != nil {
9596
// If the server fails our quote, we're not reachable right
@@ -113,7 +114,7 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
113114
MaxMinerFee: quote.MinerFee,
114115
HtlcConfTarget: params.HtlcConfTarget,
115116
LastHop: &pubkey,
116-
Initiator: autoloopSwapInitiator,
117+
Initiator: getInitiator(params),
117118
}
118119

119120
if params.Autoloop {

liquidity/loopin_builder_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestLoopinBuildSwap(t *testing.T) {
113113
Amount: swapAmt,
114114
LastHop: &peer1,
115115
HtlcConfTarget: htlcConfTarget,
116+
Initiator: autoloopSwapInitiator,
116117
}
117118

118119
errPrecondition = status.Error(codes.FailedPrecondition, "failed")

liquidity/loopout_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
101101
Amount: amount,
102102
SweepConfTarget: params.SweepConfTarget,
103103
SwapPublicationDeadline: b.cfg.Clock.Now(),
104+
Initiator: getInitiator(params),
104105
},
105106
)
106107
if err != nil {
@@ -144,7 +145,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
144145
MaxSwapFee: quote.SwapFee,
145146
MaxPrepayAmount: quote.PrepayAmount,
146147
SweepConfTarget: params.SweepConfTarget,
147-
Initiator: autoloopSwapInitiator,
148+
Initiator: getInitiator(params),
148149
}
149150

150151
if params.Autoloop {

0 commit comments

Comments
 (0)