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

allow functional tests to be used externally with a dynamic signer factory #3016

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

devrandom
Copy link
Member

@devrandom devrandom commented Apr 24, 2024

  • dynamic signer factory
  • DynSigner
  • apply xtest macros
  • PoC external usage

mut-global/src/lib.rs Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 90.32258% with 48 lines in your changes are missing coverage. Please review.

Project coverage is 89.83%. Comparing base (0e22b12) to head (445e611).
Report is 24 commits behind head on main.

Files Patch % Lines
lightning/src/util/dyn_signer.rs 88.82% 18 Missing and 1 partial ⚠️
lightning/src/util/test_channel_signer.rs 7.14% 13 Missing ⚠️
ext-test-macro/src/lib.rs 68.00% 8 Missing ⚠️
lightning/src/util/test_utils.rs 84.21% 3 Missing ⚠️
lightning/src/events/mod.rs 50.00% 2 Missing ⚠️
lightning/src/ln/onion_utils.rs 66.66% 2 Missing ⚠️
lightning/src/util/mut_global.rs 96.66% 1 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3016      +/-   ##
==========================================
+ Coverage   89.15%   89.83%   +0.68%     
==========================================
  Files         118      121       +3     
  Lines       97678   102001    +4323     
  Branches    97678   102001    +4323     
==========================================
+ Hits        87080    91637    +4557     
+ Misses       8357     8166     -191     
+ Partials     2241     2198      -43     

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

@@ -0,0 +1,14 @@
[package]
name = "ext-test-macro"
Copy link
Contributor

@tnull tnull Apr 24, 2024

Choose a reason for hiding this comment

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

I wonder if we should call this more generally ldk-macros? Currently, we use bdk-macros to provide a dual blocking/async interface in lightning-transaction-sync. However, the bdk-macros crate is basically going away with BDK 1.0, so we might want to include the corresponding functionality here?

(cc @TheBlueMatt)

@@ -727,6 +725,32 @@ impl HTLCDescriptor {
/// A trait to handle Lightning channel key material without concretizing the channel type or
/// the signature mechanism.
pub trait ChannelSigner {
/// Returns the commitment seed for the channel.
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe create a separate trait for these

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, sgtm, some kind of extension trait should do.

self.commitment_seed
}

fn counterparty_pubkeys(&self) -> Option<&ChannelPublicKeys> {
Copy link
Member Author

Choose a reason for hiding this comment

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

move to trait

@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from 9d4e233 to f341a0c Compare April 25, 2024 09:02
htlc: &HTLCOutputInCommitment,
secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()> {
EcdsaChannelSigner::sign_justice_revoked_htlc(&*self.inner, justice_tx, input, amount, per_commitment_key, htlc, secp_ctx)
Copy link
Member Author

Choose a reason for hiding this comment

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

name clashes are inconvenient, result in this need to disambiguate, and can't use delegate! macro

@devrandom devrandom force-pushed the 2024-04-ext-test branch 6 times, most recently from 87aadef to 4efd374 Compare April 26, 2024 08:19
@devrandom devrandom marked this pull request as ready for review April 26, 2024 08:20
let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
chanmon_cfgs[1].keys_manager.backing = make_dyn_keys_interface(&seed_1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised these tests pass? The point is to have the same cross_node_seed across the nodes.

@@ -1981,9 +1978,6 @@ where
/// required to access the channel with the `counterparty_node_id`.
///
/// See `ChannelManager` struct-level documentation for lock order requirements.
#[cfg(not(test))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I'd prefer to keep these kinds of things if possible. They're kinda verbose and dumb but I don't really want internal things leaking and someone starting to rely on them being usable across the crate.

@@ -727,6 +725,32 @@ impl HTLCDescriptor {
/// A trait to handle Lightning channel key material without concretizing the channel type or
/// the signature mechanism.
pub trait ChannelSigner {
/// Returns the commitment seed for the channel.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, sgtm, some kind of extension trait should do.

Comment on lines +18 to +21
pub mod dyn_signer;

#[cfg(feature = "std")]
pub mod mut_global;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these need to be visible outside of test builds?

Comment on lines +53 to +54
delegate = "0.12.0"
ext-test-macro = { path = "../ext-test-macro" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar here, can we make these only a part of _test_utils builds only?

}

impl NodeSigner for DynKeysInterface {
delegate! {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly not convinced this actually saves enough typing to be worth it, but whatever.


#[cfg(not(taproot))]
/// A super-trait for all the traits that a dyn signer backing implements
pub trait DynSignerTrait: EcdsaChannelSigner + Send + Sync {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this all because we need Writeable for the channelsigner? I think we can remove the Writeable bound entirely now! We started ignoring the bytes read in OnchainTx in 0.0.113, and according to our release notes LDK objects written by 0.0.119 are no longer expected to be readable in 113 anyway, so we can just wholesale remove the Writeable bound and move on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

4 participants