Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,9 +41,6 @@ opt-level = 3
lto = true
panic = "abort"

[patch.crates-io.possiblyrandom]
path = "possiblyrandom"

[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
Expand All@@ -58,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)",
Expand Down
92 changes: 44 additions & 48 deletions ci/ci-tests.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,83 +32,79 @@ cargo test --verbose --color always
cargo check --verbose --color always

echo -e "\n\nBuilding and testing Block Sync Clients with features"
pushd lightning-block-sync
cargo test --verbose --color always --features rest-client
cargo check --verbose --color always --features rest-client
cargo test --verbose --color always --features rpc-client
cargo check --verbose --color always --features rpc-client
cargo test --verbose --color always --features rpc-client,rest-client
cargo check --verbose --color always --features rpc-client,rest-client
cargo test --verbose --color always --features rpc-client,rest-client,tokio
cargo check --verbose --color always --features rpc-client,rest-client,tokio
popd

cargo test -p lightning-block-sync --verbose --color always --features rest-client
cargo check -p lightning-block-sync --verbose --color always --features rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client
cargo test -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio
cargo check -p lightning-block-sync --verbose --color always --features rpc-client,rest-client,tokio

if [[ "$HOST_PLATFORM" != *windows* ]]; then
pushd lightning-transaction-sync
echo -e "\n\nChecking Transaction Sync Clients with features."
cargo check --verbose --color always --features esplora-blocking
cargo check --verbose --color always --features esplora-async
cargo check --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features electrum
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo check -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo check -p lightning-transaction-sync --verbose --color always --features electrum

if [ -z "$CI_ENV" ] && [[ -z "$BITCOIND_EXE" || -z "$ELECTRS_EXE" ]]; then
echo -e "\n\nSkipping testing Transaction Sync Clients due to BITCOIND_EXE or ELECTRS_EXE being unset."
cargo check --tests
cargo check -p lightning-transaction-sync --tests
else
echo -e "\n\nTesting Transaction Sync Clients with features."
cargo test --verbose --color always --features esplora-blocking
cargo test --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-blocking
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async
cargo test -p lightning-transaction-sync --verbose --color always --features esplora-async-https
cargo test -p lightning-transaction-sync --verbose --color always --features electrum
fi
popd
fi

echo -e "\n\nTest futures builds"
pushd lightning-background-processor
cargo test --verbose --color always --features futures
popd
cargo test -p lightning-background-processor --verbose --color always --features futures
cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features

echo -e "\n\nTest Custom Message Macros"
pushd lightning-custom-message
cargo test --verbose --color always
cargo test -p lightning-custom-message --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\nTest backtrace-debug builds"
pushd lightning
cargo test --verbose --color always --features backtrace
popd
cargo test -p lightning --verbose --color always --features backtrace

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

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

for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
cargo test -p lightning --verbose --color always --no-default-features --features no-std
# check if there is a conflict between no-std and the default std feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
cargo test --verbose --color always --no-default-features --features=std,_test_vectors
popd
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
pushd lightning-invoice
# check that compile with no-std and serde works in lightning-invoice
cargo test --verbose --color always --no-default-features --features no-std --features serde
popd
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde

echo -e "\n\nTesting no-std build on a downstream no-std crate"
# check no-std compatibility across dependencies
Expand Down
3 changes: 1 addition & 2 deletions lightning-background-processor/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
std = []

default = ["std"]

Expand Down
4 changes: 1 addition & 3 deletions lightning-invoice/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = []
std = ["bech32/std"]
Comment thread
tnull marked this conversation as resolved.
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions lightning-invoice/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,9 +22,6 @@
//!
//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

extern crate bech32;
extern crate lightning_types;
extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions lightning-rapid-gossip-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@ Utility to process gossip routing data from Rapid Gossip Sync Server.

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["lightning/std"]
std = []

[dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lightning-rapid-gossip-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ where
///
/// `sync_path`: Path to the file where the gossip update data is located
///
#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
pub fn sync_network_graph_with_file_path(
&self, sync_path: &str,
) -> Result<u32, GraphSyncError> {
Expand DownExpand Up@@ -191,7 +191,7 @@ where
}
}

#[cfg(all(feature = "std", not(feature = "no-std")))]
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions lightning/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,11 +28,9 @@ 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", "lightning-invoice/no-std", "libm"]
std = ["lightning-invoice/std", "bech32/std"]
no-std = ["hashbrown", "possiblyrandom", "libm"]
std = []

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

hashbrown = { version = "0.13", optional = true, default-features = false }
possiblyrandom = { version = "0.2", optional = true, default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false }
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/crypto/utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
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
}
3 changes: 2 additions & 1 deletion lightning/src/ln/bolt11_payment.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,11 +188,12 @@ mod tests {

let secp_ctx = Secp256k1::new();
let node_secret = nodes[1].keys_manager.backing.get_node_secret_key();
let time = std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("test".into())
.payment_hash(Sha256::from_slice(&payment_hash.0).unwrap())
.payment_secret(payment_secret)
.current_timestamp()
.duration_since_epoch(time)
.min_final_cltv_expiry_delta(144)
.amount_milli_satoshis(50_000)
.payment_metadata(payment_metadata.clone())
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
assert!(cfg!(not(feature = "grind_signatures")));
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex(hex).unwrap()[..]).unwrap())
}

Expand DownExpand Up@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand DownExpand Up@@ -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);
Expand Down
22 changes: 16 additions & 6 deletions lightning/src/util/ser.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,6 +66,7 @@ impl<W: Write> Writer for W {
}
}

// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
/// Wrap buffering support for implementations of Read.
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
/// every read, implementing [`BufRead`].
Expand All@@ -92,17 +93,21 @@ impl<'a, R: Read> BufReader<'a, R> {
impl<'a, R: Read> Read for BufReader<'a, R> {
#[inline]
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
let input = self.fill_buf()?;
let count = cmp::min(input.len(), output.len());
output[..count].copy_from_slice(&input[..count]);
self.consume(count);
Ok(count)
if output.is_empty() { return Ok(0); }
Comment thread
tnull marked this conversation as resolved.
let mut offset = 0;
if !self.is_consumed {
output[0] = self.buf[0];
self.is_consumed = true;
offset = 1;
}
self.inner.read(&mut output[offset..]).map(|len| len + offset)
}
}

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

Ok(&self.buf[..])
if self.is_consumed {
Ok(&[])
} else {
Ok(&self.buf[..])
}
}

#[inline]
fn consume(&mut self, amount: usize) {
debug_assert!(false, "rust-bitcoin doesn't actually use this");
if amount >= 1 {
debug_assert_eq!(amount, 1, "Can only consume one byte");
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
Expand Down
5 changes: 1 addition & 4 deletions no-std-check/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

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

[dependencies]
lightning = { path = "../lightning", default-features = false }
Expand All@@ -15,6 +15,3 @@ lightning-background-processor = { path = "../lightning-background-processor", f
# Obviously lightning-transaction-sync doesn't support no-std, but it should build
# even if lightning is built with no-std.
lightning-transaction-sync = { path = "../lightning-transaction-sync", optional = true }

[patch.crates-io]
possiblyrandom = { path = "../possiblyrandom" }