-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
multi: route blinding for hodl invoices #9034
base: master
Are you sure you want to change the base?
Changes from all commits
2056c9e
bbafece
9d3b6ea
2783dd7
f7f76e0
1ed22a3
2d8ad57
0ce1aad
6dcfab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/btcsuite/btcd/btcutil" | ||
"github.com/lightningnetwork/lnd/chainreg" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" | ||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" | ||
"github.com/lightningnetwork/lnd/lntest" | ||
"github.com/lightningnetwork/lnd/lntest/node" | ||
|
@@ -607,7 +608,7 @@ func setupFourHopNetwork(ht *lntest.HarnessTest, | |
// testBlindedRouteInvoices tests lnd's ability to create a blinded payment path | ||
// which it then inserts into an invoice, sending to an invoice with a blinded | ||
// path and forward payments in a blinded route and finally, receiving the | ||
// payment. | ||
// payment. It also tests that blinded paths work for hodl invoices. | ||
func testBlindedRouteInvoices(ht *lntest.HarnessTest) { | ||
ctx, testCase := newBlindedForwardTest(ht) | ||
defer testCase.cleanup() | ||
|
@@ -662,6 +663,56 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) { | |
|
||
// Now let Alice pay the invoice. | ||
ht.CompletePaymentRequests(ht.Alice, []string{invoice.PaymentRequest}) | ||
|
||
// We'll also test the invoice flow for HODL invoices. | ||
preimage, err := lntypes.MakePreimage(testCase.preimage[:]) | ||
require.NoError(ht, err) | ||
hash := preimage.Hash() | ||
|
||
// Register the HODL invoice on Dave's node. | ||
minNumRealHops = 2 | ||
numHops = 2 | ||
hodlResp := testCase.dave.RPC.AddHoldInvoice( | ||
&invoicesrpc.AddHoldInvoiceRequest{ | ||
Memo: "test", | ||
Hash: hash[:], | ||
ValueMsat: 10_000_000, | ||
IsBlinded: true, | ||
BlindedPathConfig: &lnrpc.BlindedPathConfig{ | ||
MinNumRealHops: &minNumRealHops, | ||
NumHops: &numHops, | ||
}, | ||
}, | ||
) | ||
|
||
Comment on lines
+673
to
+687
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Extract repeated code into a helper function to avoid duplication The code block from lines 673-687 duplicates the logic for creating a HODL invoice with blinded path configuration. Extracting this into a helper function enhances maintainability. Consider adding a helper function: func addBlindedHoldInvoice(dave *node.HarnessNode, preimage lntypes.Preimage) *invoicesrpc.AddHoldInvoiceResp {
var (
minNumRealHops uint32 = 2
numHops uint32 = 2
)
hash := preimage.Hash()
return dave.RPC.AddHoldInvoice(
&invoicesrpc.AddHoldInvoiceRequest{
Memo: "test",
Hash: hash[:],
ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
},
},
)
} Then replace lines 673-687 with: hodlResp := addBlindedHoldInvoice(testCase.dave, preimage) |
||
// Subscribe to HOLD invoice stream on Dave's side. | ||
invStream := testCase.dave.RPC.SubscribeSingleInvoice(hash[:]) | ||
|
||
// Assert that the invoice is open. | ||
ht.AssertInvoiceState(invStream, lnrpc.Invoice_OPEN) | ||
|
||
// From Alice, we will now attempt to settle the invoice. | ||
sendReq := &routerrpc.SendPaymentRequest{ | ||
PaymentRequest: hodlResp.PaymentRequest, | ||
TimeoutSeconds: 60, | ||
FeeLimitSat: 1000000, | ||
} | ||
payStream := ht.Alice.RPC.SendPayment(sendReq) | ||
|
||
// From Alice's side, the payment should now be in-flight. | ||
ht.AssertPaymentStatusFromStream( | ||
payStream, lnrpc.Payment_IN_FLIGHT, | ||
) | ||
|
||
// From Dave's side, the invoice should be in the accepted state. | ||
ht.AssertInvoiceState(invStream, lnrpc.Invoice_ACCEPTED) | ||
|
||
// Now, let Dave settle the invoice. | ||
testCase.dave.RPC.SettleInvoice(preimage[:]) | ||
ht.AssertInvoiceState(invStream, lnrpc.Invoice_SETTLED) | ||
|
||
// And that Alice has received the preimage. | ||
ht.AssertPaymentStatus(ht.Alice, preimage, lnrpc.Payment_SUCCEEDED) | ||
} | ||
|
||
// testReceiverBlindedError tests handling of errors from the receiving node in | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve grammar and clarity in the new feature description.
The sentence structure in this new feature description can be improved for better clarity and grammatical correctness.
Consider applying the following changes:
This change removes the redundant "to" and improves the overall readability of the sentence.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
🪛 Markdownlint