Skip to content

Commit a8e95b1

Browse files
committed
export "unsafe" feature
Allows unsafe access in dev code, such as functional tests outside our crate
1 parent d735a24 commit a8e95b1

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

lightning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ max_level_error = []
1818
max_level_warn = []
1919
max_level_info = []
2020
max_level_debug = []
21+
unsafe = []
2122

2223
[dependencies]
2324
bitcoin = "0.23"

lightning/src/chain/keysinterface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub trait ChannelKeys : Send+Clone {
238238
/// transactions which will be broadcasted later, after the channel has moved on to a newer
239239
/// state. Thus, needs its own method as sign_local_commitment may enforce that we only ever
240240
/// get called once.
241-
#[cfg(test)]
241+
#[cfg(any(test,feature = "unsafe"))]
242242
fn unsafe_sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
243243

244244
/// Create a signature for each HTLC transaction spending a local commitment transaction.
@@ -498,7 +498,7 @@ impl ChannelKeys for InMemoryChannelKeys {
498498
Ok(local_commitment_tx.get_local_sig(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
499499
}
500500

501-
#[cfg(test)]
501+
#[cfg(any(test,feature = "unsafe"))]
502502
fn unsafe_sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
503503
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
504504
let remote_channel_pubkeys = &self.accepted_channel_data.as_ref().expect("must accept before signing").remote_channel_pubkeys;

lightning/src/ln/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
18401840
/// Unsafe test-only version of get_latest_local_commitment_txn used by our test framework
18411841
/// to bypass LocalCommitmentTransaction state update lockdown after signature and generate
18421842
/// revoked commitment transaction.
1843-
#[cfg(test)]
1843+
#[cfg(any(test,feature = "unsafe"))]
18441844
pub fn unsafe_get_latest_local_commitment_txn<L: Deref>(&mut self, logger: &L) -> Vec<Transaction> where L::Target: Logger {
18451845
log_trace!(logger, "Getting signed copy of latest local commitment transaction!");
18461846
if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_copy_local_tx(&self.funding_redeemscript) {

lightning/src/ln/onchaintx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
930930
}
931931
}
932932

933-
#[cfg(test)]
933+
#[cfg(any(test, feature="unsafe"))]
934934
pub(super) fn get_fully_signed_copy_local_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
935935
if let Some(ref mut local_commitment) = self.local_commitment {
936936
let local_commitment = local_commitment.clone();
@@ -970,7 +970,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
970970
htlc_tx
971971
}
972972

973-
#[cfg(test)]
973+
#[cfg(any(test,feature = "unsafe"))]
974974
pub(super) fn unsafe_get_fully_signed_htlc_tx(&mut self, outp: &::bitcoin::OutPoint, preimage: &Option<PaymentPreimage>) -> Option<Transaction> {
975975
let latest_had_sigs = self.local_htlc_sigs.is_some();
976976
let prev_had_sigs = self.prev_local_htlc_sigs.is_some();

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl ChannelKeys for EnforcingChannelKeys {
8484
Ok(self.inner.sign_local_commitment(local_commitment_tx, secp_ctx).unwrap())
8585
}
8686

87-
#[cfg(test)]
87+
#[cfg(any(test,feature = "unsafe"))]
8888
fn unsafe_sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
8989
Ok(self.inner.unsafe_sign_local_commitment(local_commitment_tx, secp_ctx).unwrap())
9090
}

0 commit comments

Comments
 (0)