Skip to content

Commit 4cb0f59

Browse files
committed
looprpc: expose static autoloop output
Extend the public rpc surface for static autoloop integration without turning the planner on yet. SuggestSwaps responses can now carry static-address loop-in requests and the new planner reason for missing static candidates is mapped over rpc.
1 parent bfa7f66 commit 4cb0f59

7 files changed

Lines changed: 199 additions & 109 deletions

File tree

liquidity/liquidity.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ type Suggestions struct {
933933
// InSwaps is the set of loop in swaps that we suggest executing.
934934
InSwaps []loop.LoopInRequest
935935

936+
// StaticInSwaps is the set of static-address loop-ins that we suggest
937+
// executing.
938+
StaticInSwaps []loop.StaticAddressLoopInRequest
939+
936940
// DisqualifiedChans maps the set of channels that we do not recommend
937941
// swaps on to the reason that we did not recommend a swap.
938942
DisqualifiedChans map[lnwire.ShortChannelID]Reason

liquidity/reasons.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ const (
7373
// ReasonCustomChannelData indicates that the channel is not standard
7474
// and should not be used for swaps.
7575
ReasonCustomChannelData
76+
77+
// ReasonStaticLoopInNoCandidate indicates that static loop-in
78+
// autoloop was selected, but no full-deposit static candidate was
79+
// available for the target peer.
80+
ReasonStaticLoopInNoCandidate
7681
)
7782

7883
// String returns a string representation of a reason.
@@ -123,6 +128,9 @@ func (r Reason) String() string {
123128
case ReasonLoopInUnreachable:
124129
return "loop in unreachable"
125130

131+
case ReasonStaticLoopInNoCandidate:
132+
return "no static loop-in candidate"
133+
126134
default:
127135
return "unknown"
128136
}

loopd/swapclient_server.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,10 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
14261426
LoopIn: make(
14271427
[]*looprpc.LoopInRequest, len(suggestions.InSwaps),
14281428
),
1429+
StaticLoopIn: make(
1430+
[]*looprpc.StaticAddressLoopInRequest,
1431+
len(suggestions.StaticInSwaps),
1432+
),
14291433
}
14301434

14311435
for i, swap := range suggestions.OutSwaps {
@@ -1456,6 +1460,24 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
14561460
resp.LoopIn[i] = loopIn
14571461
}
14581462

1463+
for i, swap := range suggestions.StaticInSwaps {
1464+
request := &looprpc.StaticAddressLoopInRequest{
1465+
Outpoints: swap.DepositOutpoints,
1466+
MaxSwapFeeSatoshis: int64(swap.MaxSwapFee),
1467+
Label: swap.Label,
1468+
Initiator: swap.Initiator,
1469+
PaymentTimeoutSeconds: swap.PaymentTimeoutSeconds,
1470+
Amount: int64(swap.SelectedAmount),
1471+
Fast: swap.Fast,
1472+
}
1473+
1474+
if swap.LastHop != nil {
1475+
request.LastHop = swap.LastHop[:]
1476+
}
1477+
1478+
resp.StaticLoopIn[i] = request
1479+
}
1480+
14591481
for id, reason := range suggestions.DisqualifiedChans {
14601482
autoloopReason, err := rpcAutoloopReason(reason)
14611483
if err != nil {
@@ -2416,6 +2438,10 @@ func rpcAutoloopReason(reason liquidity.Reason) (looprpc.AutoReason, error) {
24162438
case liquidity.ReasonFeePPMInsufficient:
24172439
return looprpc.AutoReason_AUTO_REASON_SWAP_FEE, nil
24182440

2441+
case liquidity.ReasonStaticLoopInNoCandidate:
2442+
return looprpc.AutoReason_AUTO_REASON_STATIC_LOOP_IN_NO_CANDIDATE,
2443+
nil
2444+
24192445
default:
24202446
return 0, fmt.Errorf("unknown autoloop reason: %v", reason)
24212447
}

loopd/swapclient_server_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/lightninglabs/loop"
1616
"github.com/lightninglabs/loop/fsm"
1717
"github.com/lightninglabs/loop/labels"
18+
"github.com/lightninglabs/loop/liquidity"
1819
"github.com/lightninglabs/loop/loopdb"
1920
"github.com/lightninglabs/loop/looprpc"
2021
"github.com/lightninglabs/loop/staticaddr/address"
@@ -279,6 +280,20 @@ func TestStaticAddressLoopInRejectsReservedLabel(t *testing.T) {
279280
require.ErrorContains(t, err, labels.ErrReservedPrefix.Error())
280281
}
281282

283+
// TestRPCAutoloopReasonStaticLoopInNoCandidate verifies that the new planner
284+
// reason is exposed over rpc.
285+
func TestRPCAutoloopReasonStaticLoopInNoCandidate(t *testing.T) {
286+
reason, err := rpcAutoloopReason(
287+
liquidity.ReasonStaticLoopInNoCandidate,
288+
)
289+
require.NoError(t, err)
290+
require.Equal(
291+
t,
292+
looprpc.AutoReason_AUTO_REASON_STATIC_LOOP_IN_NO_CANDIDATE,
293+
reason,
294+
)
295+
}
296+
282297
// TestSwapClientServerStopDaemon ensures that calling StopDaemon triggers the
283298
// daemon shutdown.
284299
func TestSwapClientServerStopDaemon(t *testing.T) {

0 commit comments

Comments
 (0)