Skip to content

Commit 9e8c663

Browse files
committed
multi: revise rfq.SellOrder fields
This commit removes the `max_asset_amount` and `min_ask` fields from the `SellOrder` type and introduces a new `payment_max_amt` field. The removed fields were not used correctly. The new `payment_max_amt` field allows us to leverage the `MaxInAmount` from the RFQ request wire message.
1 parent eae8f82 commit 9e8c663

File tree

7 files changed

+247
-253
lines changed

7 files changed

+247
-253
lines changed

itest/rfq_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
264264

265265
// Alice sends a sell order to Bob for some amount of the newly minted
266266
// asset.
267-
purchaseAssetAmt := uint64(200)
268267
askAmt := uint64(42000)
269268
sellOrderExpiry := uint64(time.Now().Add(24 * time.Hour).Unix())
270269

@@ -275,9 +274,8 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
275274
AssetId: mintedAssetIdBytes,
276275
},
277276
},
278-
MaxAssetAmount: purchaseAssetAmt,
279-
MinAsk: askAmt,
280-
Expiry: sellOrderExpiry,
277+
PaymentMaxAmt: askAmt,
278+
Expiry: sellOrderExpiry,
281279

282280
// Here we explicitly specify Bob as the destination
283281
// peer for the sell order. This will prompt Alice's

rfq/manager.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,15 @@ type SellOrder struct {
739739
// AssetGroupKey is the public key of the asset group to sell.
740740
AssetGroupKey *btcec.PublicKey
741741

742-
// MaxAssetAmount is the maximum amount of the asset that can be sold as
743-
// part of the order.
744-
MaxAssetAmount uint64
745-
746-
// MinAsk is the minimum ask price that the seller is willing to accept.
747-
MinAsk lnwire.MilliSatoshi
742+
// PaymentMaxAmt is the maximum msat amount that the responding peer
743+
// must agree to pay.
744+
PaymentMaxAmt lnwire.MilliSatoshi
748745

749746
// Expiry is the unix timestamp at which the order expires.
747+
//
748+
// TODO(ffranr): This is the invoice expiry unix timestamp in seconds.
749+
// We should make use of this field to ensure quotes are valid for the
750+
// duration of the invoice.
750751
Expiry uint64
751752

752753
// Peer is the peer that the buy order is intended for. This field is

rfq/negotiator.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,10 @@ func (n *Negotiator) HandleOutgoingSellOrder(order SellOrder) {
489489

490490
if n.cfg.PriceOracle != nil && assetSpecifier.IsSome() {
491491
// Query the price oracle for an asking price.
492-
//
493-
// TODO(ffranr): Add paymentMaxAmt to SellOrder and use
494-
// as arg here.
495492
assetRate, err := n.queryAskFromPriceOracle(
496493
order.Peer, assetSpecifier,
497494
fn.None[uint64](),
498-
fn.None[lnwire.MilliSatoshi](),
495+
fn.Some(order.PaymentMaxAmt),
499496
fn.None[rfqmsg.AssetRate](),
500497
)
501498
if err != nil {
@@ -508,12 +505,9 @@ func (n *Negotiator) HandleOutgoingSellOrder(order SellOrder) {
508505
assetRateHint = fn.Some[rfqmsg.AssetRate](*assetRate)
509506
}
510507

511-
// TODO(ffranr): Add paymentMaxAmt to SellOrder and use as arg
512-
// here.
513508
request, err := rfqmsg.NewSellRequest(
514509
*order.Peer, order.AssetID, order.AssetGroupKey,
515-
lnwire.MilliSatoshi(order.MaxAssetAmount),
516-
assetRateHint,
510+
order.PaymentMaxAmt, assetRateHint,
517511
)
518512
if err != nil {
519513
err := fmt.Errorf("unable to create sell request "+

rpcserver.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,12 +6405,10 @@ func unmarshalAssetSellOrder(
64056405
}
64066406

64076407
return &rfq.SellOrder{
6408-
AssetID: assetId,
6409-
AssetGroupKey: assetGroupKey,
6410-
MaxAssetAmount: req.MaxAssetAmount,
6411-
MinAsk: lnwire.MilliSatoshi(req.MinAsk),
6412-
Expiry: req.Expiry,
6413-
Peer: peer,
6408+
AssetID: assetId,
6409+
AssetGroupKey: assetGroupKey,
6410+
PaymentMaxAmt: lnwire.MilliSatoshi(req.PaymentMaxAmt),
6411+
Peer: peer,
64146412
}, nil
64156413
}
64166414

@@ -6922,11 +6920,36 @@ func (r *rpcServer) SendPayment(req *tchrpc.SendPaymentRequest,
69226920
// set.
69236921
peerPubKey = &assetChan.channelInfo.PubKeyBytes
69246922

6925-
// TODO(guggero): This should actually be the max BTC amount
6926-
// (invoice amount plus fee limit) in milli-satoshi, not the
6927-
// asset amount. Need to change the whole RFQ API to do that
6928-
// though.
6929-
maxAssetAmount := assetChan.assetInfo.LocalBalance
6923+
// paymentMaxAmt is the maximum amount that the counterparty is
6924+
// expected to pay. This is the amount that the invoice is
6925+
// asking for plus the fee limit in milli-satoshis.
6926+
var paymentMaxAmt lnwire.MilliSatoshi
6927+
if invoice.MilliSat == nil {
6928+
amt, err := lnrpc.UnmarshallAmt(pReq.Amt, pReq.AmtMsat)
6929+
if err != nil {
6930+
return fmt.Errorf("error unmarshalling "+
6931+
"amount: %w", err)
6932+
}
6933+
if amt == 0 {
6934+
return errors.New("amount must be specified " +
6935+
"when paying a zero amount invoice")
6936+
}
6937+
6938+
paymentMaxAmt = amt
6939+
} else {
6940+
paymentMaxAmt = *invoice.MilliSat
6941+
}
6942+
6943+
// Calculate the fee limit that should be used for this payment.
6944+
feeLimit, err := lnrpc.UnmarshallAmt(
6945+
pReq.FeeLimitSat, pReq.FeeLimitMsat,
6946+
)
6947+
if err != nil {
6948+
return fmt.Errorf("error unmarshalling fee limit: %w",
6949+
err)
6950+
}
6951+
6952+
paymentMaxAmt += feeLimit
69306953

69316954
expiryTimestamp := invoice.Timestamp.Add(invoice.Expiry())
69326955
resp, err := r.AddAssetSellOrder(
@@ -6936,10 +6959,9 @@ func (r *rpcServer) SendPayment(req *tchrpc.SendPaymentRequest,
69366959
AssetId: assetID[:],
69376960
},
69386961
},
6939-
MaxAssetAmount: maxAssetAmount,
6940-
MinAsk: uint64(*invoice.MilliSat),
6941-
Expiry: uint64(expiryTimestamp.Unix()),
6942-
PeerPubKey: peerPubKey[:],
6962+
PaymentMaxAmt: uint64(paymentMaxAmt),
6963+
Expiry: uint64(expiryTimestamp.Unix()),
6964+
PeerPubKey: peerPubKey[:],
69436965
TimeoutSeconds: uint32(
69446966
rfq.DefaultTimeout.Seconds(),
69456967
),

0 commit comments

Comments
 (0)