Skip to content

Commit 3715410

Browse files
authored
Merge pull request #3249 from TheBlueMatt/2024-08-feature-cleanup-1
bitcoin 0.32 upgrade followups
2 parents bad5e32 + 8049f99 commit 3715410

File tree

15 files changed

+83
-87
lines changed

15 files changed

+83
-87
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ opt-level = 3
4141
lto = true
4242
panic = "abort"
4343

44-
[patch.crates-io.possiblyrandom]
45-
path = "possiblyrandom"
46-
4744
[workspace.lints.rust.unexpected_cfgs]
4845
level = "forbid"
4946
# When adding a new cfg attribute, ensure that it is added to this list.
@@ -58,6 +55,7 @@ check-cfg = [
5855
"cfg(debug_assertions)",
5956
"cfg(c_bindings)",
6057
"cfg(ldk_bench)",
58+
"cfg(ldk_test_vectors)",
6159
"cfg(taproot)",
6260
"cfg(async_signing)",
6361
"cfg(require_route_graph_test)",

ci/ci-tests.sh

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,83 +32,79 @@ cargo test --verbose --color always
3232
cargo check --verbose --color always
3333

3434
echo -e "\n\nBuilding and testing Block Sync Clients with features"
35-
pushd lightning-block-sync
36-
cargo test --verbose --color always --features rest-client
37-
cargo check --verbose --color always --features rest-client
38-
cargo test --verbose --color always --features rpc-client
39-
cargo check --verbose --color always --features rpc-client
40-
cargo test --verbose --color always --features rpc-client,rest-client
41-
cargo check --verbose --color always --features rpc-client,rest-client
42-
cargo test --verbose --color always --features rpc-client,rest-client,tokio
43-
cargo check --verbose --color always --features rpc-client,rest-client,tokio
44-
popd
35+
36+
cargo test -p lightning-block-sync --verbose --color always --features rest-client
37+
cargo check -p lightning-block-sync --verbose --color always --features rest-client
38+
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
39+
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
40+
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
41+
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
42+
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
43+
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
4544

4645
if [[ "$HOST_PLATFORM" != *windows* ]]; then
47-
pushd lightning-transaction-sync
4846
echo -e "\n\nChecking Transaction Sync Clients with features."
49-
cargo check --verbose --color always --features esplora-blocking
50-
cargo check --verbose --color always --features esplora-async
51-
cargo check --verbose --color always --features esplora-async-https
52-
cargo check --verbose --color always --features electrum
47+
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
48+
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
49+
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
50+
cargo check -p lightning-transaction-sync --verbose --color always --features electrum
5351

5452
if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
5553
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
56-
cargo check --tests
54+
cargo check -p lightning-transaction-sync --tests
5755
else
5856
echo -e "\n\nTesting Transaction Sync Clients with features."
59-
cargo test --verbose --color always --features esplora-blocking
60-
cargo test --verbose --color always --features esplora-async
61-
cargo test --verbose --color always --features esplora-async-https
62-
cargo test --verbose --color always --features electrum
57+
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
58+
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
59+
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
60+
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
6361
fi
64-
popd
6562
fi
6663

6764
echo -e "\n\nTest futures builds"
68-
pushd lightning-background-processor
69-
cargo test --verbose --color always --features futures
70-
popd
65+
cargo test -p lightning-background-processor --verbose --color always --features futures
66+
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features
7167

7268
echo -e "\n\nTest Custom Message Macros"
73-
pushd lightning-custom-message
74-
cargo test --verbose --color always
69+
cargo test -p lightning-custom-message --verbose --color always
7570
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
76-
popd
7771

7872
echo -e "\n\nTest backtrace-debug builds"
79-
pushd lightning
80-
cargo test --verbose --color always --features backtrace
81-
popd
73+
cargo test -p lightning --verbose --color always --features backtrace
8274

8375
echo -e "\n\nBuilding with all Log-Limiting features"
84-
pushd lightning
85-
grep '^max_level_' Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
86-
RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check --verbose --color always --features "$FEATURE"
76+
grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
77+
RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE"
8778
done
88-
popd
8979

90-
echo -e "\n\nTesting no-std flags in various combinations"
91-
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
92-
cargo test -p $DIR --verbose --color always --no-default-features --features no-std
93-
# check if there is a conflict between no-std and the default std feature
94-
cargo test -p $DIR --verbose --color always --features no-std
80+
echo -e "\n\nTesting no-std builds"
81+
for DIR in lightning-invoice lightning-rapid-gossip-sync; do
82+
cargo test -p $DIR --verbose --color always --no-default-features
9583
done
9684

97-
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
85+
cargo test -p lightning --verbose --color always --no-default-features --features no-std
86+
# check if there is a conflict between no-std and the default std feature
87+
cargo test -p lightning --verbose --color always --features no-std
88+
89+
echo -e "\n\nTesting c_bindings builds"
90+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
91+
92+
for DIR in lightning-invoice lightning-rapid-gossip-sync; do
9893
# check if there is a conflict between no-std and the c_bindings cfg
99-
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
94+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
10095
done
101-
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
10296

97+
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
98+
# disable tests in `c_bindings` so we skip doctests entirely here.
99+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
100+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std
101+
102+
echo -e "\n\nTesting other crate-specific builds"
103103
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
104-
pushd lightning
105-
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
106-
popd
104+
RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose --color always --no-default-features --features=std
107105
# This one only works for lightning-invoice
108-
pushd lightning-invoice
109106
# check that compile with no-std and serde works in lightning-invoice
110-
cargo test --verbose --color always --no-default-features --features no-std --features serde
111-
popd
107+
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde
112108

113109
echo -e "\n\nTesting no-std build on a downstream no-std crate"
114110
# check no-std compatibility across dependencies

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1515

1616
[features]
1717
futures = [ ]
18-
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
19-
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
18+
std = []
2019

2120
default = ["std"]
2221

lightning-invoice/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ all-features = true
1515
rustdoc-args = ["--cfg", "docsrs"]
1616

1717
[features]
18-
default = ["std"]
19-
no-std = []
20-
std = ["bech32/std"]
18+
std = []
2119

2220
[dependencies]
2321
bech32 = { version = "0.9.1", default-features = false }

lightning-invoice/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
//!
2323
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
2424
25-
#[cfg(not(any(feature = "std", feature = "no-std")))]
26-
compile_error!("at least one of the `std` or `no-std` features must be enabled");
27-
2825
extern crate bech32;
2926
extern crate lightning_types;
3027
extern crate alloc;

lightning-rapid-gossip-sync/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.
1111

1212
[features]
1313
default = ["std"]
14-
no-std = ["lightning/no-std"]
15-
std = ["lightning/std"]
14+
std = []
1615

1716
[dependencies]
1817
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }

lightning-rapid-gossip-sync/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ where
143143
///
144144
/// `sync_path`: Path to the file where the gossip update data is located
145145
///
146-
#[cfg(all(feature = "std", not(feature = "no-std")))]
146+
#[cfg(feature = "std")]
147147
pub fn sync_network_graph_with_file_path(
148148
&self, sync_path: &str,
149149
) -> Result<u32, GraphSyncError> {
@@ -191,7 +191,7 @@ where
191191
}
192192
}
193193

194-
#[cfg(all(feature = "std", not(feature = "no-std")))]
194+
#[cfg(feature = "std")]
195195
#[cfg(test)]
196196
mod tests {
197197
use std::fs;

lightning/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ max_level_trace = []
2828
# Allow signing of local transactions that may have been revoked or will be revoked, for functional testing (e.g. justice tx handling).
2929
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
3030
unsafe_revoked_tx_signing = []
31-
# Override signing to not include randomness when generating signatures for test vectors.
32-
_test_vectors = []
3331

34-
no-std = ["hashbrown", "possiblyrandom", "lightning-invoice/no-std", "libm"]
35-
std = ["lightning-invoice/std", "bech32/std"]
32+
no-std = ["hashbrown", "possiblyrandom", "libm"]
33+
std = []
3634

3735
# Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases
3836
grind_signatures = []
@@ -47,7 +45,7 @@ bech32 = { version = "0.9.1", default-features = false }
4745
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
4846

4947
hashbrown = { version = "0.13", optional = true, default-features = false }
50-
possiblyrandom = { version = "0.2", optional = true, default-features = false }
48+
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
5149
regex = { version = "1.5.6", optional = true }
5250
backtrace = { version = "0.3", optional = true }
5351

lightning/src/crypto/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
7575
break sig;
7676
}
7777
};
78-
#[cfg(all(not(feature = "grind_signatures"), not(feature = "_test_vectors")))]
78+
#[cfg(all(not(feature = "grind_signatures"), not(ldk_test_vectors)))]
7979
let sig = ctx.sign_ecdsa_with_noncedata(msg, sk, &entropy_source.get_secure_random_bytes());
80-
#[cfg(all(not(feature = "grind_signatures"), feature = "_test_vectors"))]
80+
#[cfg(all(not(feature = "grind_signatures"), ldk_test_vectors))]
8181
let sig = sign(ctx, msg, sk);
8282
sig
8383
}

lightning/src/ln/bolt11_payment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ mod tests {
188188

189189
let secp_ctx = Secp256k1::new();
190190
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
191+
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
191192
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
192193
.description("test".into())
193194
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
194195
.payment_secret(payment_secret)
195-
.current_timestamp()
196+
.duration_since_epoch(time)
196197
.min_final_cltv_expiry_delta(144)
197198
.amount_milli_satoshis(50_000)
198199
.payment_metadata(payment_metadata.clone())

lightning/src/ln/channel.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9659,8 +9659,9 @@ mod tests {
96599659
}
96609660
}
96619661

9662-
#[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
9662+
#[cfg(ldk_test_vectors)]
96639663
fn public_from_secret_hex(secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
9664+
assert!(cfg!(not(feature = "grind_signatures")));
96649665
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
96659666
}
96669667

@@ -10237,9 +10238,11 @@ mod tests {
1023710238
assert_eq!(decoded_chan.context.holding_cell_htlc_updates, holding_cell_htlc_updates);
1023810239
}
1023910240

10240-
#[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
10241+
#[cfg(ldk_test_vectors)]
1024110242
#[test]
1024210243
fn outbound_commitment_test() {
10244+
assert!(cfg!(not(feature = "grind_signatures")));
10245+
1024310246
use bitcoin::sighash;
1024410247
use bitcoin::consensus::encode::serialize;
1024510248
use bitcoin::sighash::EcdsaSighashType;

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ impl core::hash::Hash for HTLCSource {
532532
}
533533
}
534534
impl HTLCSource {
535-
#[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
536-
#[cfg(test)]
535+
#[cfg(all(ldk_test_vectors, test))]
537536
pub fn dummy() -> Self {
537+
assert!(cfg!(not(feature = "grind_signatures")));
538538
HTLCSource::OutboundRoute {
539539
path: Path { hops: Vec::new(), blinded_tail: None },
540540
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),

lightning/src/ln/monitor_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ fn test_anchors_monitor_fixes_counterparty_payment_script_on_reload() {
29902990
do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(true);
29912991
}
29922992

2993-
#[cfg(not(feature = "_test_vectors"))]
2993+
#[cfg(not(ldk_test_vectors))]
29942994
fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterparty_commitment: bool) {
29952995
// Tests that our monitor claims will always use fresh random signatures (ensuring a unique
29962996
// 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
30893089
}
30903090
}
30913091

3092-
#[cfg(not(feature = "_test_vectors"))]
3092+
#[cfg(not(ldk_test_vectors))]
30933093
#[test]
30943094
fn test_monitor_claims_with_random_signatures() {
30953095
do_test_monitor_claims_with_random_signatures(false, false);

lightning/src/util/ser.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
6666
}
6767
}
6868

69+
// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
6970
/// Wrap buffering support for implementations of Read.
7071
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
7172
/// every read, implementing [`BufRead`].
@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
9293
impl<'a, R: Read> Read for BufReader<'a, R> {
9394
#[inline]
9495
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
95-
let input = self.fill_buf()?;
96-
let count = cmp::min(input.len(), output.len());
97-
output[..count].copy_from_slice(&input[..count]);
98-
self.consume(count);
99-
Ok(count)
96+
if output.is_empty() { return Ok(0); }
97+
let mut offset = 0;
98+
if !self.is_consumed {
99+
output[0] = self.buf[0];
100+
self.is_consumed = true;
101+
offset = 1;
102+
}
103+
self.inner.read(&mut output[offset..]).map(|len| len + offset)
100104
}
101105
}
102106

103107
impl<'a, R: Read> BufRead for BufReader<'a, R> {
104108
#[inline]
105109
fn fill_buf(&mut self) -> io::Result<&[u8]> {
110+
debug_assert!(false, "rust-bitcoin doesn't actually use this");
106111
if self.is_consumed {
107112
let count = self.inner.read(&mut self.buf[..])?;
108113
debug_assert!(count <= 1, "read gave us a garbage length");
@@ -111,11 +116,16 @@ impl<'a, R: Read> BufRead for BufReader<'a, R> {
111116
self.is_consumed = count == 0;
112117
}
113118

114-
Ok(&self.buf[..])
119+
if self.is_consumed {
120+
Ok(&[])
121+
} else {
122+
Ok(&self.buf[..])
123+
}
115124
}
116125

117126
#[inline]
118127
fn consume(&mut self, amount: usize) {
128+
debug_assert!(false, "rust-bitcoin doesn't actually use this");
119129
if amount >= 1 {
120130
debug_assert_eq!(amount, 1, "Can only consume one byte");
121131
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");

no-std-check/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = ["lightning/no-std", "lightning-invoice/no-std", "lightning-rapid-gossip-sync/no-std"]
7+
default = ["lightning/no-std"]
88

99
[dependencies]
1010
lightning = { path = "../lightning", default-features = false }
@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
1515
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
1616
# even if lightning is built with no-std.
1717
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }
18-
19-
[patch.crates-io]
20-
possiblyrandom = { path = "../possiblyrandom" }

0 commit comments

Comments
 (0)