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.
This commit is contained in:
Boris Nagaev 2026-04-10 23:58:29 -05:00
parent 7cf0a87c2b
commit e467ac932b
No known key found for this signature in database
8 changed files with 201 additions and 110 deletions

View file

@ -1426,6 +1426,10 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
LoopIn: make(
[]*looprpc.LoopInRequest, len(suggestions.InSwaps),
),
StaticLoopIn: make(
[]*looprpc.StaticAddressLoopInRequest,
len(suggestions.StaticInSwaps),
),
}
for i, swap := range suggestions.OutSwaps {
@ -1456,6 +1460,24 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
resp.LoopIn[i] = loopIn
}
for i, swap := range suggestions.StaticInSwaps {
request := &looprpc.StaticAddressLoopInRequest{
Outpoints: swap.DepositOutpoints,
MaxSwapFeeSatoshis: int64(swap.MaxSwapFee),
Label: swap.Label,
Initiator: swap.Initiator,
PaymentTimeoutSeconds: swap.PaymentTimeoutSeconds,
Amount: int64(swap.SelectedAmount),
Fast: swap.Fast,
}
if swap.LastHop != nil {
request.LastHop = swap.LastHop[:]
}
resp.StaticLoopIn[i] = request
}
for id, reason := range suggestions.DisqualifiedChans {
autoloopReason, err := rpcAutoloopReason(reason)
if err != nil {
@ -2416,6 +2438,10 @@ func rpcAutoloopReason(reason liquidity.Reason) (looprpc.AutoReason, error) {
case liquidity.ReasonFeePPMInsufficient:
return looprpc.AutoReason_AUTO_REASON_SWAP_FEE, nil
case liquidity.ReasonStaticLoopInNoCandidate:
return looprpc.AutoReason_AUTO_REASON_STATIC_LOOP_IN_NO_CANDIDATE,
nil
default:
return 0, fmt.Errorf("unknown autoloop reason: %v", reason)
}

View file

@ -15,6 +15,7 @@ import (
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/labels"
"github.com/lightninglabs/loop/liquidity"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/staticaddr/address"
@ -280,6 +281,20 @@ func TestStaticAddressLoopInRejectsReservedLabel(t *testing.T) {
require.ErrorContains(t, err, labels.ErrReservedPrefix.Error())
}
// TestRPCAutoloopReasonStaticLoopInNoCandidate verifies that the new planner
// reason is exposed over rpc.
func TestRPCAutoloopReasonStaticLoopInNoCandidate(t *testing.T) {
reason, err := rpcAutoloopReason(
liquidity.ReasonStaticLoopInNoCandidate,
)
require.NoError(t, err)
require.Equal(
t,
looprpc.AutoReason_AUTO_REASON_STATIC_LOOP_IN_NO_CANDIDATE,
reason,
)
}
// TestSwapClientServerStopDaemon ensures that calling StopDaemon triggers the
// daemon shutdown.
func TestSwapClientServerStopDaemon(t *testing.T) {