Skip to content

Update litcli for multi-rfq send #1125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: tapd-main-branch
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GO_VERSION = 1.23.9
# installed before running the integration tests which include backward
# compatibility tests. The list of versions must be in sync with any version
# used in the backwardCompat map in itest/litd_test_list_on_test.go.
LITD_COMPAT_VERSIONS = v0.14.1-alpha
LITD_COMPAT_VERSIONS = v0.14.1-alpha v0.15.0-alpha

LOOP_COMMIT := $(shell cat go.mod | \
grep $(LOOP_PKG) | \
Expand Down
99 changes: 52 additions & 47 deletions cmd/litcli/ln.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"time"

"github.com/lightninglabs/taproot-assets/rfq"
"github.com/lightninglabs/taproot-assets/rfqmath"
"github.com/lightninglabs/taproot-assets/rpcutils"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
"github.com/lightningnetwork/lnd/cmd/commands"
"github.com/lightningnetwork/lnd/lnrpc"
Expand Down Expand Up @@ -210,9 +210,8 @@ var (
rfqPeerPubKeyFlag = cli.StringFlag{
Name: "rfq_peer_pubkey",
Usage: "(optional) the public key of the peer to ask for a " +
"quote when converting from assets to sats; must be " +
"set if there are multiple channels with the same " +
"asset ID present",
"quote when converting from assets to sats; if left " +
"unset then rfq peers will be picked automatically",
}

allowOverpayFlag = cli.BoolFlag{
Expand All @@ -237,74 +236,80 @@ type resultStreamWrapper struct {
//
// NOTE: This method is part of the PaymentResultStream interface.
func (w *resultStreamWrapper) Recv() (*lnrpc.Payment, error) {
resp, err := w.stream.Recv()
if err != nil {
return nil, err
}

res := resp.Result
switch r := res.(type) {
// The very first response might be an accepted sell order, which we
// just print out.
case *tchrpc.SendPaymentResponse_AcceptedSellOrder:
quote := r.AcceptedSellOrder
// printQuote unmarshals and prints an accepted quote.
printQuote := func(quote *rfqrpc.PeerAcceptedSellQuote) error {
rpcRate := quote.BidAssetRate
rate, err := rpcutils.UnmarshalRfqFixedPoint(rpcRate)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal fixed "+
"point: %w", err)
return fmt.Errorf("unable to unmarshal fixed point: %w",
err)
}

amountMsat := lnwire.MilliSatoshi(w.amountMsat)
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, *rate)
numUnits := milliSatsFP.ScaleTo(0).ToUint64()

// If the calculated number of units is 0 then the asset rate
// was not sufficient to represent the value of this payment.
// The purpose of this function is just to print, so let's avoid
// dividing by zero or reporting an invalid msat/unit rate.
if numUnits == 0 {
// We will calculate the minimum amount that can be
// effectively sent with this asset by calculating the
// value of a single asset unit, based on the provided
// asset rate.

// We create the single unit.
unit := rfqmath.FixedPointFromUint64[rfqmath.BigInt](
1, 0,
)

// We derive the minimum amount.
minAmt := rfqmath.UnitsToMilliSatoshi(unit, *rate)

// We return the error to the user.
return nil, fmt.Errorf("smallest payment with asset "+
"rate %v is %v, cannot send %v",
rate.ToUint64(), minAmt, amountMsat)
return nil
}

msatPerUnit := uint64(w.amountMsat) / numUnits

fmt.Printf("Got quote for %v asset units at %v msat/unit from "+
"peer %s with SCID %d\n", numUnits, msatPerUnit,
" peer %s with SCID %d\n", numUnits, msatPerUnit,
quote.Peer, quote.Scid)

resp, err = w.stream.Recv()
return nil
}

// A boolean to indicate whether the first quote was printed via the
// legacy single-rfq response field.
legacyFirstPrint := false

for {
resp, err := w.stream.Recv()
if err != nil {
return nil, err
}

if resp == nil || resp.Result == nil ||
resp.GetPaymentResult() == nil {
res := resp.Result

return nil, errors.New("unexpected nil result")
}
switch r := res.(type) {
case *tchrpc.SendPaymentResponse_AcceptedSellOrder:
err := printQuote(r.AcceptedSellOrder)
if err != nil {
return nil, err
}

return resp.GetPaymentResult(), nil
legacyFirstPrint = true

case *tchrpc.SendPaymentResponse_PaymentResult:
return r.PaymentResult, nil
case *tchrpc.SendPaymentResponse_AcceptedSellOrders:
quotes := r.AcceptedSellOrders.AcceptedSellOrders

default:
return nil, fmt.Errorf("unexpected response type: %T", r)
for _, quote := range quotes {
// If the first item was returned via the legacy
// field then skip printing it again here. This
// skip only applies to the first element.
if legacyFirstPrint {
legacyFirstPrint = false
continue
}

err := printQuote(quote)
if err != nil {
return nil, err
}
}

case *tchrpc.SendPaymentResponse_PaymentResult:
return r.PaymentResult, nil

default:
return nil, fmt.Errorf("unexpected response type: %T",
r)
}
}
}

Expand Down
57 changes: 52 additions & 5 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,35 @@ COPY --from=nodejsbuilder /go/src/github.com/lightninglabs/lightning-terminal /g
# queries required to connect to linked containers succeed.
ENV GODEBUG netdns=cgo

# Allow forcing a specific lnd, taproot-assets, and taprpc version through a
# build argument.
# Allow forcing a specific lnd, taproot-assets, taprpc, and/or loop repo so that
# commits referenced by LND_VERSION, TAPROOT_ASSETS_VERSION, TAPRPC_VERSION, and
# LOOP_VERSION don't have to exist in the default repository. If any of these
# build arguments are not defined, the build continues using the default
# repository for that module. NOTE: If these arguments ARE defined then the
# corresponding `_VERSION` argument MUST also be defined, otherwise the build
# continues using the default repository defined for that module.
ARG LND_REPO
ARG TAPROOT_ASSETS_REPO
ARG TAPRPC_REPO
ARG LOOP_REPO

# Allow forcing a specific lnd, taproot-assets, taprpc, and/or loop version
# through a build argument.
# Please see https://go.dev/ref/mod#version-queries for the types of
# queries that can be used to define a version.
# If any of these build arguments are not defined then build uses the version
# already defined in go.mod and go.sum for that module.
# Note: If the corresponding `_REPO` argument is not defined, `go get` will
# be used along with `go mod tidy`, which sometimes may change the version you
# are trying to use because some other module requires the same requirement
# but of a different version. A trick to overcome this is to also use the
# `_REPO` argument and just put in the default repository for that module and
# that will cause a `go mod edit -replace=` to be used instead which won't have
# this issue.
ARG LND_VERSION
ARG TAPROOT_ASSETS_VERSION
ARG TAPRPC_VERSION
ARG LOOP_VERSION

# Need to restate this since running in a new container from above.
ARG NO_UI
Expand All @@ -46,17 +68,42 @@ RUN apk add --no-cache --update alpine-sdk make \
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
# If a custom lnd version is supplied, force it now.
&& if [ -n "$LND_VERSION" ]; then \
go get -v github.com/lightningnetwork/lnd@$LND_VERSION \
# If a custom lnd repo is supplied, force it now.
if [ -n "$LND_REPO" ]; then \
go mod edit -replace=github.com/lightningnetwork/lnd=$LND_REPO@$LND_VERSION; \
else \
go get -v github.com/lightningnetwork/lnd@$LND_VERSION; \
fi \
&& go mod tidy; \
fi \
# If a custom taproot-assets version is supplied, force it now.
&& if [ -n "$TAPROOT_ASSETS_VERSION" ]; then \
go get -v github.com/lightninglabs/taproot-assets@$TAPROOT_ASSETS_VERSION \
# If a custom taproot-assets repo is supplied, force it now.
if [ -n "$TAPROOT_ASSETS_REPO" ]; then \
go mod edit -replace=github.com/lightninglabs/taproot-assets=$TAPROOT_ASSETS_REPO@$TAPROOT_ASSETS_VERSION; \
else \
go get -v github.com/lightninglabs/taproot-assets@$TAPROOT_ASSETS_VERSION; \
fi \
&& go mod tidy; \
fi \
# If a custom taprpc version is supplied, force it now.
&& if [ -n "$TAPRPC_VERSION" ]; then \
go get -v github.com/lightninglabs/taproot-assets/taprpc@$TAPRPC_VERSION \
# If a custom taprpc repo is supplied, force it now.
if [ -n "$TAPRPC_REPO" ]; then \
go mod edit -replace=github.com/lightninglabs/taproot-assets/taprpc=$TAPRPC_REPO@$TAPRPC_VERSION; \
else \
go get -v github.com/lightninglabs/taproot-assets/taprpc@$TAPRPC_VERSION; \
fi \
&& go mod tidy; \
fi \
# If a custom loop version is supplied, force it now.
&& if [ -n "$LOOP_VERSION" ]; then \
# If a custom loop repo is supplied, force it now.
if [ -n "$LOOP_REPO" ]; then \
go mod edit -replace=github.com/lightninglabs/loop=$LOOP_REPO@$LOOP_VERSION; \
else \
go get -v github.com/lightninglabs/loop@$LOOP_VERSION; \
fi \
&& go mod tidy; \
fi \
&& if [ "$NO_UI" -eq "1" ]; then \
Expand Down
12 changes: 4 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ require (
github.com/lightninglabs/lightning-terminal/litrpc v1.0.2
github.com/lightninglabs/lightning-terminal/perms v1.0.1
github.com/lightninglabs/lndclient v0.19.0-12
github.com/lightninglabs/loop v0.31.2-beta
github.com/lightninglabs/loop v0.31.2-beta.0.20250730111713-3b0f6e84dc14
github.com/lightninglabs/loop/looprpc v1.0.8
github.com/lightninglabs/loop/swapserverrpc v1.0.15
github.com/lightninglabs/pool v0.6.6-beta
github.com/lightninglabs/pool/auctioneerrpc v1.1.3
github.com/lightninglabs/pool/poolrpc v1.0.1
github.com/lightninglabs/taproot-assets v0.6.1
github.com/lightninglabs/taproot-assets/taprpc v1.0.8-0.20250716163904-2ef55ba74036
github.com/lightninglabs/taproot-assets v0.6.1-0.20250729190616-3f323918a96e
github.com/lightninglabs/taproot-assets/taprpc v1.0.10-0.20250729190616-3f323918a96e
github.com/lightningnetwork/lnd v0.19.2-beta
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/fn v1.2.3
github.com/lightningnetwork/lnd/fn v1.2.5
github.com/lightningnetwork/lnd/fn/v2 v2.0.8
github.com/lightningnetwork/lnd/kvdb v1.4.16
github.com/lightningnetwork/lnd/sqldb v1.0.11-0.20250623231731-45c15646c68b
Expand Down Expand Up @@ -247,7 +247,3 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
// it is a replace in the tapd repository, it doesn't get propagated here
// automatically, so we need to add it manually.
replace github.com/golang-migrate/migrate/v4 => github.com/lightninglabs/migrate/v4 v4.18.2-9023d66a-fork-pr-2

// tapd wants v0.19.0-12, but loop can't handle that yet. So we'll just use the
// previous version for now.
replace github.com/lightninglabs/lndclient => github.com/lightninglabs/lndclient v0.19.0-11
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,10 @@ github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.3 h1:NuDp6Z+QNM
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.3/go.mod h1:bDnEKRN1u13NFBuy/C+bFLhxA5bfd3clT25y76QY0AM=
github.com/lightninglabs/lightning-node-connect/mailbox v1.0.1 h1:RWmohykp3n/DTMWY8b18RNTEcLDf+KT/AZHKYdOObkM=
github.com/lightninglabs/lightning-node-connect/mailbox v1.0.1/go.mod h1:NYtNexZE9gO1eOeegTxmIW9fqanl7eZ9cOrE9yewSAk=
github.com/lightninglabs/lndclient v0.19.0-11 h1:/WwowlNff19lb7DXzq3c6L4nRMvwBZjbjLOy1/u4a5Y=
github.com/lightninglabs/lndclient v0.19.0-11/go.mod h1:cicoJY1AwZuRVXGD8Knp50TRT7TGBmw1k37uPQsGQiw=
github.com/lightninglabs/loop v0.31.2-beta h1:lm5t5FqDpSfQCxoz/vTvXpylxSgU+gvJJIbfJiKeyUk=
github.com/lightninglabs/loop v0.31.2-beta/go.mod h1:xnPKuZmLusNERwzz15RZ7mpQ8xuSqqh3g8Qw/PRyiRE=
github.com/lightninglabs/lndclient v0.19.0-12 h1:aSIKfnvnHKiyFWppUGHJG5fn8VoF5WG5Lx958ksLmqs=
github.com/lightninglabs/lndclient v0.19.0-12/go.mod h1:cicoJY1AwZuRVXGD8Knp50TRT7TGBmw1k37uPQsGQiw=
github.com/lightninglabs/loop v0.31.2-beta.0.20250730111713-3b0f6e84dc14 h1:PA/bTHYZ/leIoky3mFgbD4h9FV1lamzS+bw45GLd4l8=
github.com/lightninglabs/loop v0.31.2-beta.0.20250730111713-3b0f6e84dc14/go.mod h1:ukAfrXOf5OqpJORSYLjsyFzOGgIASyC2Qbstsl0ZvWw=
github.com/lightninglabs/loop/looprpc v1.0.8 h1:OFmJNLjem6fLuH1YUO+3G6QA1wmjAd0zyhvdHONOBDs=
github.com/lightninglabs/loop/looprpc v1.0.8/go.mod h1:c7WykKQZ3PspCMVvv2kr9o4l3bgJBEBVv0SOoBOjPOw=
github.com/lightninglabs/loop/swapserverrpc v1.0.15 h1:vEZBF65Lv0T7MPydCRxHSIlEJzHBkZ4I8FtSD6OJK88=
Expand All @@ -1172,10 +1172,10 @@ github.com/lightninglabs/pool/poolrpc v1.0.1 h1:XbNx28TYwEj/PVsnnF9TnveVCMCYfS1v
github.com/lightninglabs/pool/poolrpc v1.0.1/go.mod h1:836icifg/SBnZbiae0v3jeRRzCrT6LWo32SqCS/JiGk=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
github.com/lightninglabs/taproot-assets v0.6.1 h1:98XCk7nvAridyE67uct0NDVpyY1evpIdvPQpeNElskM=
github.com/lightninglabs/taproot-assets v0.6.1/go.mod h1:rF+GwuUVuDVUejAHsUCml4Nru9xnl7A4YZQfR4qLMzY=
github.com/lightninglabs/taproot-assets/taprpc v1.0.8-0.20250716163904-2ef55ba74036 h1:ZUQrEmdZa72RieBKI/NiUQJGAnh6R6Pq6FoXh+VCOJQ=
github.com/lightninglabs/taproot-assets/taprpc v1.0.8-0.20250716163904-2ef55ba74036/go.mod h1:vOM2Ap2wYhEZjiJU7bNNg+e5tDxkvRAuyXwf/KQ4tgo=
github.com/lightninglabs/taproot-assets v0.6.1-0.20250729190616-3f323918a96e h1:wlaM8dTlpCQ0uNj0TBskBDeNTTDessxiXiakYDB4RFo=
github.com/lightninglabs/taproot-assets v0.6.1-0.20250729190616-3f323918a96e/go.mod h1:mIgx0p/GkMZeEjEm91vYQsH41YQBAgJl7TP6JcT+wgs=
github.com/lightninglabs/taproot-assets/taprpc v1.0.10-0.20250729190616-3f323918a96e h1:MnXspinwkd6VhV8G9I+TdSak05UitfYyNBCQhTIIr0g=
github.com/lightninglabs/taproot-assets/taprpc v1.0.10-0.20250729190616-3f323918a96e/go.mod h1:c8gTEcKEUoUPVChgZNwqTL1hss7UWa5FDeObr8WBzQk=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.19.2-beta h1:3SKVrKYFY4IJLlrMf7cDzZcBeT+MxjI9Xy6YpY+EEX4=
Expand All @@ -1184,8 +1184,8 @@ github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
github.com/lightningnetwork/lnd/clock v1.1.1/go.mod h1:mGnAhPyjYZQJmebS7aevElXKTFDuO+uNFFfMXK1W8xQ=
github.com/lightningnetwork/lnd/fn v1.2.3 h1:Q1OrgNSgQynVheBNa16CsKVov1JI5N2AR6G07x9Mles=
github.com/lightningnetwork/lnd/fn v1.2.3/go.mod h1:SyFohpVrARPKH3XVAJZlXdVe+IwMYc4OMAvrDY32kw0=
github.com/lightningnetwork/lnd/fn v1.2.5 h1:pGMz0BDUxrhvOtShD4FIysdVy+ulfFAnFvTKjZO5Pp8=
github.com/lightningnetwork/lnd/fn v1.2.5/go.mod h1:SyFohpVrARPKH3XVAJZlXdVe+IwMYc4OMAvrDY32kw0=
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 h1:r2SLz7gZYQPVc3IZhU82M66guz3Zk2oY+Rlj9QN5S3g=
github.com/lightningnetwork/lnd/fn/v2 v2.0.8/go.mod h1:TOzwrhjB/Azw1V7aa8t21ufcQmdsQOQMDtxVOQWNl8s=
github.com/lightningnetwork/lnd/healthcheck v1.2.6 h1:1sWhqr93GdkWy4+6U7JxBfcyZIE78MhIHTJZfPx7qqI=
Expand Down
Loading