From: Matt Corallo Date: Sat, 17 Aug 2024 21:06:52 +0000 (+0000) Subject: Drop the `_test_vectors` feature in favor of a `cfg` flag X-Git-Tag: v0.0.124-beta~5^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=3fe4ef9640d83309488ef15bc9577c406a36856e;p=rust-lightning Drop the `_test_vectors` feature in favor of a `cfg` flag This exists just for tests, so there's no reason for it to be publicly visible. --- diff --git a/Cargo.toml b/Cargo.toml index d1e2f0e05..ae5d1bc8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ check-cfg = [ "cfg(debug_assertions)", "cfg(c_bindings)", "cfg(ldk_bench)", + "cfg(ldk_test_vectors)", "cfg(taproot)", "cfg(async_signing)", "cfg(require_route_graph_test)", diff --git a/ci/ci-tests.sh b/ci/ci-tests.sh index d6c8f0517..22d0783a9 100755 --- a/ci/ci-tests.sh +++ b/ci/ci-tests.sh @@ -101,7 +101,7 @@ RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --colo echo -e "\n\nTesting other crate-specific builds" # Note that outbound_commitment_test only runs in this mode because of hardcoded signature values -cargo test -p lightning --verbose --color always --no-default-features --features=std,_test_vectors +RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose --color always --no-default-features --features=std # This one only works for lightning-invoice # check that compile with no-std and serde works in lightning-invoice cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index d642b6fbd..b8ebfdca2 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -28,8 +28,6 @@ max_level_trace = [] # Allow signing of local transactions that may have been revoked or will be revoked, for functional testing (e.g. justice tx handling). # This is unsafe to use in production because it may result in the counterparty publishing taking our funds. unsafe_revoked_tx_signing = [] -# Override signing to not include randomness when generating signatures for test vectors. -_test_vectors = [] no-std = ["hashbrown", "possiblyrandom", "libm"] std = ["lightning-invoice/std", "bech32/std"] diff --git a/lightning/src/crypto/utils.rs b/lightning/src/crypto/utils.rs index 98963c7c2..aab406157 100644 --- a/lightning/src/crypto/utils.rs +++ b/lightning/src/crypto/utils.rs @@ -75,9 +75,9 @@ pub fn sign_with_aux_rand( break sig; } }; - #[cfg(all(not(feature = "grind_signatures"), not(feature = "_test_vectors")))] + #[cfg(all(not(feature = "grind_signatures"), not(ldk_test_vectors)))] let sig = ctx.sign_ecdsa_with_noncedata(msg, sk, &entropy_source.get_secure_random_bytes()); - #[cfg(all(not(feature = "grind_signatures"), feature = "_test_vectors"))] + #[cfg(all(not(feature = "grind_signatures"), ldk_test_vectors))] let sig = sign(ctx, msg, sk); sig } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 907a50587..226fb5082 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -9659,8 +9659,9 @@ mod tests { } } - #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))] + #[cfg(ldk_test_vectors)] fn public_from_secret_hex(secp_ctx: &Secp256k1, hex: &str) -> PublicKey { + assert!(cfg!(not(feature = "grind_signatures"))); PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&>::from_hex(hex).unwrap()[..]).unwrap()) } @@ -10237,9 +10238,11 @@ mod tests { assert_eq!(decoded_chan.context.holding_cell_htlc_updates, holding_cell_htlc_updates); } - #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))] + #[cfg(ldk_test_vectors)] #[test] fn outbound_commitment_test() { + assert!(cfg!(not(feature = "grind_signatures"))); + use bitcoin::sighash; use bitcoin::consensus::encode::serialize; use bitcoin::sighash::EcdsaSighashType; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index b0bf76111..2684bb0f3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -532,9 +532,9 @@ impl core::hash::Hash for HTLCSource { } } impl HTLCSource { - #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))] - #[cfg(test)] + #[cfg(all(ldk_test_vectors, test))] pub fn dummy() -> Self { + assert!(cfg!(not(feature = "grind_signatures"))); HTLCSource::OutboundRoute { path: Path { hops: Vec::new(), blinded_tail: None }, session_priv: SecretKey::from_slice(&[1; 32]).unwrap(), diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 16f3b4926..3fbcef344 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -2990,7 +2990,7 @@ fn test_anchors_monitor_fixes_counterparty_payment_script_on_reload() { do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(true); } -#[cfg(not(feature = "_test_vectors"))] +#[cfg(not(ldk_test_vectors))] fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterparty_commitment: bool) { // Tests that our monitor claims will always use fresh random signatures (ensuring a unique // wtxid) to prevent certain classes of transaction replacement at the bitcoin P2P layer. @@ -3089,7 +3089,7 @@ fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterp } } -#[cfg(not(feature = "_test_vectors"))] +#[cfg(not(ldk_test_vectors))] #[test] fn test_monitor_claims_with_random_signatures() { do_test_monitor_claims_with_random_signatures(false, false);