diff --git a/lightning/src/ln/bolt11_payment.rs b/lightning/src/ln/bolt11_payment.rs index 653c714b6e0..57ddce069a6 100644 --- a/lightning/src/ln/bolt11_payment.rs +++ b/lightning/src/ln/bolt11_payment.rs @@ -93,7 +93,6 @@ mod tests { use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; use lightning_invoice::{Currency, InvoiceBuilder}; use std::time::SystemTime; - use bech32::ToBase32; use crate::sign::{NodeSigner, Recipient}; #[test] @@ -180,8 +179,6 @@ mod tests { let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(None, 7200, None).unwrap(); - let secp_ctx = Secp256k1::new(); - let node_secret = nodes[1].keys_manager.backing.get_node_secret_key(); let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); let invoice = InvoiceBuilder::new(Currency::Bitcoin) .description("test".into()) @@ -192,7 +189,7 @@ mod tests { .amount_milli_satoshis(50_000) .payment_metadata(payment_metadata.clone()) .build_raw().unwrap(); - let sig = nodes[1].keys_manager.backing.sign_invoice(invoice.hrp.to_string().as_bytes(), &invoice.data.to_base32(), Recipient::Node).unwrap(); + let sig = nodes[1].keys_manager.backing.sign_invoice(&invoice, Recipient::Node).unwrap(); let invoice = invoice.sign::<_, ()>(|_| Ok(sig)).unwrap(); let invoice = Bolt11Invoice::from_signed(invoice).unwrap(); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 4c4b2d3251d..553ac7f56be 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -31,7 +31,7 @@ use crate::util::errors::APIError; use crate::util::logger::Logger; use crate::util::scid_utils; use crate::util::test_channel_signer::TestChannelSigner; -#[cfg(test)] +#[cfg(any(test, feature = "_test_utils"))] use crate::util::test_channel_signer::SignerOp; use crate::util::test_utils; use crate::util::test_utils::{TestChainMonitor, TestScorer, TestKeysInterface}; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 52a89ad9365..28aa2ab607f 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -95,8 +95,8 @@ fn test_channel_resumption_fail_post_funding() { assert_eq!(nodes[0].node.get_and_clear_pending_msg_events(), Vec::new()); } -#[test] -fn test_insane_channel_opens() { +#[xtest(feature = "_test_utils")] +pub fn test_insane_channel_opens() { // Stand up a network of 2 nodes use crate::ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS; let mut cfg = UserConfig::default(); diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 947ec4a1304..1ae243b725f 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -2251,8 +2251,8 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Reset our RNG counters to mirror the RNG output from when this test was written. - nodes[0].keys_manager.backing.inner.entropy_source.set_counter(0x1_0000_0004); - nodes[1].keys_manager.backing.inner.entropy_source.set_counter(0x1_0000_0004); + nodes[0].keys_manager.backing.inner.set_counter(0x1_0000_0004); + nodes[1].keys_manager.backing.inner.set_counter(0x1_0000_0004); // Open a channel, lock in an HTLC, and immediately broadcast the commitment transaction. This // ensures that the HTLC timeout package is held until we reach its expiration height. diff --git a/lightning/src/util/dyn_signer.rs b/lightning/src/util/dyn_signer.rs index 97b41430af3..1313b83d1c9 100644 --- a/lightning/src/util/dyn_signer.rs +++ b/lightning/src/util/dyn_signer.rs @@ -21,7 +21,7 @@ use crate::sign::taproot::TaprootChannelSigner; use crate::sign::ChannelSigner; use crate::sign::InMemorySigner; use crate::sign::{ - ecdsa::WriteableEcdsaChannelSigner, KeyMaterial, NodeSigner, Recipient, SignerProvider, + KeyMaterial, NodeSigner, Recipient, SignerProvider, SpendableOutputDescriptor, }; use crate::sign::{EntropySource, HTLCDescriptor, OutputSpender, PhantomKeysManager}; @@ -29,9 +29,9 @@ use crate::util::ser::{Readable, ReadableArgs}; use crate::util::ser::{Writeable, Writer}; #[cfg(any(test, feature = "_test_utils"))] use crate::util::test_utils::OnlyReadsKeysInterface; +use lightning_invoice::RawBolt11Invoice; use bitcoin; use bitcoin::absolute::LockTime; -use bitcoin::bech32::u5; use bitcoin::secp256k1::All; use bitcoin::{secp256k1, ScriptBuf, Transaction, TxOut}; #[cfg(taproot)] @@ -72,8 +72,6 @@ impl DynSigner { } } -impl WriteableEcdsaChannelSigner for DynSigner {} - #[cfg(taproot)] #[allow(unused_variables)] impl TaprootChannelSigner for DynSigner { @@ -265,11 +263,11 @@ impl ChannelSigner for DynSigner { &self, idx: u64, secp_ctx: &Secp256k1, - ) -> PublicKey; + ) -> Result; fn counterparty_pubkeys(&self) -> Option<&ChannelPublicKeys>; fn funding_outpoint(&self) -> Option<&OutPoint>; fn get_channel_parameters(&self) -> Option<&ChannelTransactionParameters>; - fn release_commitment_secret(&self, idx: u64) -> [u8; 32]; + fn release_commitment_secret(&self, idx: u64) -> Result<[u8; 32], ()>; fn validate_holder_commitment( &self, @@ -333,12 +331,7 @@ impl NodeSigner for DynKeysInterface { fn sign_gossip_message(&self, msg: UnsignedGossipMessage) -> Result; fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result; - fn sign_invoice( - &self, - hrp_bytes: &[u8], - invoice_data: &[u5], - recipient: Recipient, - ) -> Result; + fn sign_invoice(&self, invoice: &RawBolt11Invoice, recipient: Recipient) -> Result; fn sign_bolt12_invoice( &self, invoice: &crate::offers::invoice::UnsignedBolt12Invoice @@ -398,6 +391,10 @@ impl OutputSpender for DynKeysInterface { pub trait DynKeysInterfaceTrait: NodeSigner + OutputSpender + SignerProvider + EntropySource + Send + Sync { + #[cfg(test)] + fn set_counter(&self, _count: u64) { + } + } #[cfg(taproot)] @@ -431,12 +428,7 @@ impl NodeSigner for DynPhantomKeysInterface { fn sign_gossip_message(&self, msg: UnsignedGossipMessage) -> Result; fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result; - fn sign_invoice( - &self, - hrp_bytes: &[u8], - invoice_data: &[u5], - recipient: Recipient, - ) -> Result; + fn sign_invoice(&self, invoice: &RawBolt11Invoice, recipient: Recipient) -> Result; fn sign_bolt12_invoice( &self, invoice: &crate::offers::invoice::UnsignedBolt12Invoice @@ -498,7 +490,12 @@ impl OutputSpender for DynPhantomKeysInterface { } } -impl DynKeysInterfaceTrait for DynPhantomKeysInterface {} +impl DynKeysInterfaceTrait for DynPhantomKeysInterface { + #[cfg(test)] + fn set_counter(&self, count: u64) { + self.inner.inner.entropy_source.set_counter(count); + } +} impl ReadableArgs<&DynKeysInterface> for DynSigner { fn read(_reader: &mut R, _params: &DynKeysInterface) -> Result { diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index 6b1ba0f9b01..0cfa2781ba6 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -149,12 +149,12 @@ impl TestChannelSigner { self.state.lock().unwrap() } - #[cfg(test)] + #[cfg(any(test, feature = "_test_utils"))] pub fn enable_op(&self, signer_op: SignerOp) { self.get_enforcement_state().disabled_signer_ops.remove(&signer_op); } - #[cfg(test)] + #[cfg(any(test, feature = "_test_utils"))] pub fn disable_op(&self, signer_op: SignerOp) { self.get_enforcement_state().disabled_signer_ops.insert(signer_op); }