-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add LND Integration Tests in CI #509
Conversation
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.
Cool, thank you for looking into this! Already looks pretty good!
run: docker compose -f docker-compose-lnd.yml up -d | ||
|
||
- name: Set permissions for data_lnd folder | ||
run: sudo chmod -R 755 ./data_lnd/ |
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.
Curious to learn why we need this? Doesn't LND set the correct permissions already?
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.
In PR 4622, LND added automatic file creation. However, it sets the file permissions to 0700, which prevents the test code from reading the files. As a result, it's necessary to explicitly modify the permissions for the test code to access them.
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.
I see, makes sense. Mind adding that context as a comment here?
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.
Yes, I added a comment to provide that context.
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.
I ran the test locally and passed. Although I had to change the permissions for data_lnd
directory. Maybe those could be set in the docker-compose-lnd.yml
instead of only CI?
b785427
to
9b21153
Compare
Sets up a local environment for LND integration testing in CI Closes 505
9b21153
to
2abfdcf
Compare
I think it's better for the user or CI to set the permissions, as modifying file permissions automatically via Docker can be invasive and might require sudo. Now, the user or CI specifies the directory for LND files, allowing them to decide where the files will be stored and handle permission modifications as needed. |
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.
Already looks pretty good, just some minor comments.
tests/integration_tests_lnd.rs
Outdated
let cert = cert_bytes.as_hex().to_string(); | ||
let macaroon = mac_bytes.as_hex().to_string(); | ||
|
||
let client = connect(cert, macaroon, socket).await?; |
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.
Given this is test code, can we just expect
here and drop the Result
from the return type?
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.
Yes, I removed the Result
and added the expect
with indications of where they failed.
tests/integration_tests_lnd.rs
Outdated
use ldk_node::{Builder, Event}; | ||
|
||
use lnd_grpc_rust::lnrpc::{ | ||
invoice::InvoiceState::Settled, GetInfoRequest, GetInfoResponse, Invoice, ListInvoiceRequest, |
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.
Can we prefix all these imports with Lnd
to make it easier to parse which type comes from 'which side'? I.e., make all of these Invoice as LndInvoice
, etc.
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.
Yes, I updated the imports and prefixed them with Lnd
run: docker compose -f docker-compose-lnd.yml up -d | ||
|
||
- name: Set permissions for data_lnd folder | ||
run: sudo chmod -R 755 ./data_lnd/ |
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.
I see, makes sense. Mind adding that context as a comment here?
tests/integration_tests_lnd.rs
Outdated
tokio::time::sleep(Duration::from_secs(1)).await; | ||
|
||
// Send a payment to LDK | ||
let mut rng = thread_rng(); |
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.
I think we don't need this to be random at all, no? Let's just make up a fixed string here?
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.
Ok, I removed the RNG
and replaced it with a fixed string.
tests/integration_tests_lnd.rs
Outdated
assert_eq!(lnd_listed_invoices.first().unwrap().state, Settled as i32); | ||
|
||
// Sleep to process payment in LND | ||
tokio::time::sleep(Duration::from_secs(1)).await; |
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.
Such sleeps tend to be or get flaky in CI. Rather than just sleeping a fixed amount here, any chance we can poll repeatedly in smaller intervals until we see the payment processed, or reach a max number of tries?
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.
Yes, I replaced the sleep with a retry mechanism (max 25 attempts) since my tests showed variance up to 20. This avoids CI flakiness. I also improved error checking to verify if the invoice was actually paid.
dd4bb77
to
6f1017c
Compare
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.
Thanks for addressing the feedback, one comment.
tests/integration_tests_lnd.rs
Outdated
// This retries the payment multiple times to account for that delay. | ||
let max_retries = 25; | ||
|
||
for attempt in 1..=max_retries { |
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.
Thanks for adding this retry logic, but it's a bit weird to have it be part of pay_invoice
, given that we're waiting on the previous operation to complete essentially. Rather than just always retrying here, can we instead retry checking the incoming payment settled at the callsite, and then move on to pay_invoice
when we're positive it should succeed?
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.
Yes, after reviewing the process, I realized the payment is registered as paid but not immediately available for routing. To address this, I added a check to ensure the payment can be routed through the channel. Since it takes around 0.6 to 1.1 seconds for this to happen, I added 7 retries with 200ms intervals, totaling a maximum wait time of 1.4 seconds to ensure the balance is available for routing.
env: | ||
LND_DATA_DIR: ${{ env.LND_DATA_DIR }} | ||
|
||
# In PR 4622 (https://github.com/lightningnetwork/lnd/pull/4622), |
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.
nit: Thanks for adding comment, but let's move it down into the item this is meant for.
6f1017c
to
51fe0a3
Compare
Adds tests to: - Open a payment channel with LND. - Request and pay an invoice, verifying receipt. - Generate an invoice for LND to pay, verifying receipt. Uses lnd_grpc_rust for gRPC communication. Closes lightningdevkit#505
Configures CI to run LND tests using the Docker Compose environment. Closes lightningdevkit#505
51fe0a3
to
7d592bb
Compare
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.
LGTM, thank you!
This PR introduces integration tests for LND, mirroring the existing CLN tests. Here's what was done:
Dockerized LND Node: Set up a Docker container to run an LND node in CI, configured to work with LDK-Node.
Rust Library Choice: Used lnd-grpc-rust instead of tonic_lnd, as it’s more up-to-date and compatible with recent LND versions.
Test Implementation:
CI Workflow: Added a workflow to the CI pipeline to run the LND tests.
close #505