Skip to content

Add a simple test of upgrading from LDK 0.1 and correct in_flight_monitor_updates on upgrade #3584

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

Merged
merged 5 commits into from
May 21, 2025

Conversation

TheBlueMatt
Copy link
Collaborator

One major hole in our test coverage historically has been tests
covering upgrades or downgrades across LDK versions. Luckily, these
aren't particularly hard to write as cargo lets us depend on
previous versions of the lightning crate directly, which we can
use in tests.

Here we add a simple initial test of upgrading from LDK 0.1 while
there's a pending payment to be claimed.

@TheBlueMatt TheBlueMatt added this to the 0.2 milestone Feb 2, 2025
@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch from 708a5cc to a237be2 Compare February 2, 2025 19:42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have this live in a dedicated tests crate or in the integration tests (tests) folder? This would also allow us to keep our testing script untouched, IIUC?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, yea, we definitely could. I'm kinda on the fence. On the one hand, you're right, we'd be able to do cargo -p lightning which is really nice, on the other hand we wouldn't run the upgrade tests with cargo test, which kinda sucks (and means yet more cases of things passing trivially but failing in CI). Do you have a strong opinion here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wouldn't run the upgrade tests with cargo test, which kinda sucks (and means yet more cases of things passing trivially but failing in CI).

Huh, but integration tests are run via cargo test, just after normal unit tests are run?

Do you have a strong opinion here?

Yeah, kinda tbh, I'd prefer to not interweave yet another layer of complexity into CI & dependency scripts. I agree we should see that tests are always run in CI and easy to run locally, but would prefer to have them live separately from the code and unit tests.

Note we could either have integration tests live as lightning/tests, or, especially if we think that we'd want to add more cross-crate tests there over time, could add them as a new member crate to the workspace at /lightning-tests. While the former is a bit more focused on lightning, the latter would open the door for moving some of the tests in lightning-background-processor there, which currently acts as the defacto place for integration tests as it's the only place in the dependency tree that allows for accessing all the necessary objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, but integration tests are run via cargo test, just after normal unit tests are run?
Note we could either have integration tests live as lightning/tests

I don't see a way to add a separate dependency to the normal rust integration test files. We'd have to do it as a proper crate with a proper Cargo.toml, which I assume wouldn't get run like integration tests would.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's true. Then IMO it might be preferable to just add a lightning-tests crate to the workspace? Yes, it wouldn't get run by cargo test, but by the ci-tests.sh, which we already need to run anyways to cover all feature variants, etc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chatted a bit more offline. To me the question is whether most devs run cargo test as their usual workflow or run ci-tests.sh. Indeed, devs need to run ci-tests.sh to hit "everything" but most things get hit with cargo test normally. With upgrade/downgrade tests, I fear that they're going to be as likely to fail as most other tests, if not more, so making devs (especially new devs who tend to hit this often) wait for a CI cycle before they find the bug is gonna be pretty annoying.

the latter would open the door for moving some of the tests in lightning-background-processor there, which currently acts as the defacto place for integration tests as it's the only place in the dependency tree that allows for accessing all the necessary objects.

That's a fair point, and I did go ahead and create a new crate for this reason. For now I left it in the workspace until we resolve the above question.

@valentinewallace
Copy link
Contributor

LGTM after @tnull's feedback is resolved (and it looks like this need rebase). Nice to have this testing infra!

@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch from a237be2 to 44e1a54 Compare March 4, 2025 19:16
@TheBlueMatt
Copy link
Collaborator Author

TheBlueMatt commented Mar 4, 2025

Rebased. I pinged @tnull offline but dunno when/if he'll respond, there's also no rush.

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 87.25490% with 13 lines in your changes missing coverage. Please review.

Project coverage is 90.99%. Comparing base (df68774) to head (f9fb216).
Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/util/test_channel_signer.rs 76.47% 11 Missing and 1 partial ⚠️
lightning/src/ln/channelmanager.rs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3584      +/-   ##
==========================================
+ Coverage   89.22%   90.99%   +1.77%     
==========================================
  Files         155      157       +2     
  Lines      118973   134041   +15068     
  Branches   118973   134041   +15068     
==========================================
+ Hits       106154   121975   +15821     
+ Misses      10239     9675     -564     
+ Partials     2580     2391     -189     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch from 44e1a54 to b099963 Compare March 4, 2025 20:57
@wpaulino
Copy link
Contributor

wpaulino commented Mar 5, 2025

CI is still sad

@wpaulino
Copy link
Contributor

error: package ID specification `lightning-test` did not match any packages

	Did you mean `lightning-tests`?

@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch from 8c96d90 to f9fb216 Compare March 11, 2025 19:21
@wpaulino
Copy link
Contributor

cargo doc -p lightning-tests --document-private-items seems to cause issues, we don't really need docs there anyway

In e8854f9 we changed the type of
`ChannelManager::in_flight_monitor_updates`, writing a legacy
version and reading the new version as a new TLV field. Sadly, we
spuriously marked the new TLV as `required`, breaking upgrade from
0.1.

Here we fix the oversight by simply marking it `option`al.
The code was a bit too long to begin with, and rustfmt made a total
mess of it, so instead we should be building with more intermediate
variables.
The signer we use in tests tracks the state of the channel and
refuses to sign when the channel attempts an invalid state
transition. In the next commit, however, we'll add an upgrade test
which will fail these checks as the the state won't get copied from
previous versions of LDK to this version.

Thus, here, we add the ability to disable all state-based checks
in the signer.
@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch 2 times, most recently from 171401f to c3f8144 Compare May 16, 2025 14:39
@TheBlueMatt
Copy link
Collaborator Author

Ooookayyyyyy. We discussed offline and it seems many folks who work on LDK do use cargo test -p lightning so moved the tests into a non-workspace crate entirely. Note that clippy is failing but that'll be fixed by #3782. Also went ahead and rebased and squashed since its been so long since this was put up.

@TheBlueMatt TheBlueMatt requested review from tnull and removed request for tnull May 16, 2025 14:40
@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz May 18, 2025 00:02
@TheBlueMatt TheBlueMatt requested review from wpaulino and removed request for jkczyz May 19, 2025 17:55
wpaulino
wpaulino previously approved these changes May 19, 2025
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, two questions.

lightning-types = { version = "0.3.0", path = "../lightning-types", features = ["_test_utils"] }
lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false }
lightning-macros = { version = "0.2", path = "../lightning-macros" }
lightning = { version = "0.2", path = "../lightning", features = ["_test_utils"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be using the +git version numbers, which also might help remembering to bump them post-release?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't even need the version tag, removed them.

One major hole in our test coverage historically has been tests
covering upgrades or downgrades across LDK versions. Luckily, these
aren't particularly hard to write as cargo lets us depend on
previous versions of the `lightning` crate directly, which we can
use in tests.

Here we add a simple initial test of upgrading from LDK 0.1 while
there's a pending payment to be claimed.
Running `cargo test -p crate` for each crate in the workspace
results in re-building the `lightning` crate for each workspace
crate, which can be quite slow. This adds nontrivial time to our
total CI runs.

Here, instead, we just run `cargo test` and let it build the whole
workspace crate list in one go. This does result in combined
features which may leave some issues with `cargo test -p crate`
undetected, but there's not a ton of harm to that.
@TheBlueMatt TheBlueMatt force-pushed the 2025-02-upgrade-tests branch from c3f8144 to 86c661a Compare May 21, 2025 15:39
@TheBlueMatt
Copy link
Collaborator Author

Squash pushed a quick Cargo.toml simplification:

$ git diff-tree -U1 c3f8144222 86c661a5e6
diff --git a/lightning-tests/Cargo.toml b/lightning-tests/Cargo.toml
index 01ad635580..75c68e03f5 100644
--- a/lightning-tests/Cargo.toml
+++ b/lightning-tests/Cargo.toml
@@ -12,6 +12,6 @@ edition = "2021"
 [dependencies]
-lightning-types = { version = "0.3.0", path = "../lightning-types", features = ["_test_utils"] }
-lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false }
-lightning-macros = { version = "0.2", path = "../lightning-macros" }
-lightning = { version = "0.2", path = "../lightning", features = ["_test_utils"] }
+lightning-types = { path = "../lightning-types", features = ["_test_utils"] }
+lightning-invoice = { path = "../lightning-invoice", default-features = false }
+lightning-macros = { path = "../lightning-macros" }
+lightning = { path = "../lightning", features = ["_test_utils"] }
 lightning_0_1 = { package = "lightning", version = "0.1.1", features = ["_test_utils"] }

@TheBlueMatt
Copy link
Collaborator Author

@tnull already said "LGTM" and the one remaining question was addressed, landing since i want to base more PRs on this.

@TheBlueMatt TheBlueMatt merged commit 02b5564 into lightningdevkit:main May 21, 2025
27 of 28 checks passed
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge ACK

@TheBlueMatt
Copy link
Collaborator Author

Partially backported in #3794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants