Skip to content

Commit b2c155f

Browse files
committed
Introduce DynSigner, a dynamically dispatched signer
DynSigner provides an abstraction for specifying an external signer for functional tests.
1 parent 50af46d commit b2c155f

File tree

6 files changed

+432
-26
lines changed

6 files changed

+432
-26
lines changed

lightning/src/sign/ecdsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
8484
/// only ever get called once.
8585
///
8686
/// This method is *not* async as it is intended only for testing purposes.
87-
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
87+
#[cfg(any(test, feature = "_test_utils", feature = "unsafe_revoked_tx_signing"))]
8888
fn unsafe_sign_holder_commitment(
8989
&self, channel_parameters: &ChannelTransactionParameters,
9090
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,

lightning/src/sign/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use bitcoin::hashes::{Hash, HashEngine};
3131
use bitcoin::secp256k1::ecdh::SharedSecret;
3232
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
3333
use bitcoin::secp256k1::schnorr;
34-
#[cfg(taproot)]
3534
use bitcoin::secp256k1::All;
3635
use bitcoin::secp256k1::{Keypair, PublicKey, Scalar, Secp256k1, SecretKey, Signing};
3736
use bitcoin::{secp256k1, Psbt, Sequence, Txid, WPubkeyHash, Witness};
@@ -704,6 +703,13 @@ impl HTLCDescriptor {
704703
}
705704
}
706705

706+
/// Extension trait for [`ChannelSigner`] providing access to additional channel-specific
707+
/// details. In particular, this is useful for functional tests.
708+
pub trait ChannelSignerExt: ChannelSigner {
709+
/// Returns the commitment seed for the channel.
710+
fn commitment_seed(&self) -> [u8; 32];
711+
}
712+
707713
/// A trait to handle Lightning channel key material without concretizing the channel type or
708714
/// the signature mechanism.
709715
///
@@ -898,10 +904,10 @@ pub trait OutputSpender {
898904
/// Returns `Err(())` if the output value is greater than the input value minus required fee,
899905
/// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
900906
/// does not match the one we can spend.
901-
fn spend_spendable_outputs<C: Signing>(
907+
fn spend_spendable_outputs(
902908
&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>,
903909
change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32,
904-
locktime: Option<LockTime>, secp_ctx: &Secp256k1<C>,
910+
locktime: Option<LockTime>, secp_ctx: &Secp256k1<All>,
905911
) -> Result<Transaction, ()>;
906912
}
907913

@@ -1227,6 +1233,12 @@ impl EntropySource for InMemorySigner {
12271233
}
12281234
}
12291235

1236+
impl ChannelSignerExt for InMemorySigner {
1237+
fn commitment_seed(&self) -> [u8; 32] {
1238+
self.commitment_seed
1239+
}
1240+
}
1241+
12301242
impl ChannelSigner for InMemorySigner {
12311243
fn get_per_commitment_point(
12321244
&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -1351,7 +1363,7 @@ impl EcdsaChannelSigner for InMemorySigner {
13511363
))
13521364
}
13531365

1354-
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
1366+
#[cfg(any(test, feature = "_test_utils", feature = "unsafe_revoked_tx_signing"))]
13551367
fn unsafe_sign_holder_commitment(
13561368
&self, channel_parameters: &ChannelTransactionParameters,
13571369
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -2044,10 +2056,10 @@ impl OutputSpender for KeysManager {
20442056
///
20452057
/// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
20462058
/// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2047-
fn spend_spendable_outputs<C: Signing>(
2059+
fn spend_spendable_outputs(
20482060
&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>,
20492061
change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32,
2050-
locktime: Option<LockTime>, secp_ctx: &Secp256k1<C>,
2062+
locktime: Option<LockTime>, secp_ctx: &Secp256k1<All>,
20512063
) -> Result<Transaction, ()> {
20522064
let (mut psbt, expected_max_weight) =
20532065
SpendableOutputDescriptor::create_spendable_outputs_psbt(
@@ -2194,10 +2206,10 @@ impl NodeSigner for PhantomKeysManager {
21942206
impl OutputSpender for PhantomKeysManager {
21952207
/// See [`OutputSpender::spend_spendable_outputs`] and [`KeysManager::spend_spendable_outputs`]
21962208
/// for documentation on this method.
2197-
fn spend_spendable_outputs<C: Signing>(
2209+
fn spend_spendable_outputs(
21982210
&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>,
21992211
change_destination_script: ScriptBuf, feerate_sat_per_1000_weight: u32,
2200-
locktime: Option<LockTime>, secp_ctx: &Secp256k1<C>,
2212+
locktime: Option<LockTime>, secp_ctx: &Secp256k1<All>,
22012213
) -> Result<Transaction, ()> {
22022214
self.inner.spend_spendable_outputs(
22032215
descriptors,

0 commit comments

Comments
 (0)