Skip to content
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

Refactor async signing test utils to toggle specific method availability #3115

Merged

Conversation

alecchendev
Copy link
Contributor

@alecchendev alecchendev commented Jun 11, 2024

Another pre-requisite PR to help shrink async signing diffs. To test async signing, we want be able to control whether our test channel signer returns a valid signature versus no signature. Previously we just had a catch-all flag that would toggle the signer being available/not across all signing methods. In upcoming PRs we'll want to test individual methods becoming available at different times (e.g. we made multiple requests to a remote signer, and got responses back in various orders). This PR refactors our existing tests and test utils to implement this.

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 40 lines in your changes missing coverage. Please review.

Project coverage is 89.79%. Comparing base (07f3380) to head (7e2789e).

Current head 7e2789e differs from pull request most recent head 3785375

Please upload reports for the commit 3785375 to get more accurate results.

Files Patch % Lines
lightning/src/util/test_channel_signer.rs 30.43% 32 Missing ⚠️
lightning/src/ln/functional_test_utils.rs 0.00% 6 Missing ⚠️
lightning/src/util/test_utils.rs 50.00% 0 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3115      +/-   ##
==========================================
- Coverage   89.91%   89.79%   -0.12%     
==========================================
  Files         121      119       -2     
  Lines       99172    97915    -1257     
  Branches    99172    97915    -1257     
==========================================
- Hits        89167    87922    -1245     
- Misses       7405     7428      +23     
+ Partials     2600     2565      -35     

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

lightning/src/ln/functional_test_utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/async_signer_tests.rs Outdated Show resolved Hide resolved
lightning/src/ln/async_signer_tests.rs Outdated Show resolved Hide resolved
lightning/src/ln/async_signer_tests.rs Outdated Show resolved Hide resolved
lightning/src/util/test_channel_signer.rs Outdated Show resolved Hide resolved
@alecchendev alecchendev force-pushed the 2024-06-specific-async-sign branch 2 times, most recently from ff75d8f to 3785375 Compare June 15, 2024 00:49
Copy link
Contributor Author

@alecchendev alecchendev left a comment

Choose a reason for hiding this comment

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

Notes for myself to fix soon

lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/functional_test_utils.rs Outdated Show resolved Hide resolved
Comment on lines 1219 to 1220
/// Holds a list of signer ops to disable for the next signer created by this interface.
pub disable_next_signer_ops: Mutex<HashSet<SignerOp>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove next here since it just applies until you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moving to separate PR

lightning/src/util/test_channel_signer.rs Show resolved Hide resolved
lightning/src/ln/mod.rs Outdated Show resolved Hide resolved
@alecchendev
Copy link
Contributor Author

accidentally included previous commits, rebased to fix it. also have some nits/cleanups + a build issue i'll fix soon

@alecchendev
Copy link
Contributor Author

alecchendev commented Jun 17, 2024

squashed immediately since the changes were getting unreadable. Previously i included a change here to change how we disable a signer upon derive_channel_signer for channels that haven't be created yet, but I decided to move that to a separate PR, so this one is more focused. The other big change is instead of using a mask, I thought it was simpler to just use an enum for the signer ops

@alecchendev alecchendev force-pushed the 2024-06-specific-async-sign branch 4 times, most recently from 4d96e0c to 574bd6e Compare June 17, 2024 22:57
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Seems fine to me. We can always tweak test utils later anyway.

SignChannelAnnouncementWithFundingKey,
}

impl fmt::Display for SignerOp {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: why bother? Debug should be fine?

pub available: Arc<Mutex<bool>>,
/// Set of signer operations that are disabled. If an operation is disabled,
/// the signer will return `Err` when the corresponding method is called.
pub disabled_signer_ops: Arc<Mutex<HashSet<SignerOp>>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really specific to this PR, but we could move this into EnforcementState so that we get a common disable set across ChannelMonitor and ChannelManager for free.

@@ -375,6 +375,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
check_closed_broadcast(&nodes[1], 1, true);
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) }, false, &[nodes[0].node.get_our_node_id()], 100_000);
} else {
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderCommitment);
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderHtlcTransaction);
Copy link
Collaborator

Choose a reason for hiding this comment

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

For convenience we'll probably want some wrapper methods that set/clear everything, no matter the internal representation.

@TheBlueMatt
Copy link
Collaborator

Its just test code, there's no reason to hold this up on another reviewer.

@TheBlueMatt TheBlueMatt merged commit c39ff87 into lightningdevkit:main Jun 18, 2024
14 of 16 checks passed
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.

None yet

3 participants