Skip to content

Commit bbb8fac

Browse files
committed
Fix (and test) the c_bindings build flag
Rather than only building with the `c_bindings` flag in certain crates, we go ahead and test all crates with the flag in CI here.
1 parent d2532dc commit bbb8fac

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

ci/ci-tests.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ popd
100100

101101
echo -e "\n\nTesting no-std flags in various combinations"
102102
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
103-
pushd $DIR
104-
cargo test --verbose --color always --no-default-features --features no-std
103+
cargo test -p $DIR --verbose --color always --no-default-features --features no-std
105104
# check if there is a conflict between no-std and the default std feature
106-
cargo test --verbose --color always --features no-std
105+
cargo test -p $DIR --verbose --color always --features no-std
106+
done
107+
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
107108
# check if there is a conflict between no-std and the c_bindings cfg
108-
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
109-
popd
109+
RUSTFLAGS="--cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
110110
done
111+
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always
112+
111113
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
112114
pushd lightning
113115
cargo test --verbose --color always --no-default-features --features=std,_test_vectors

lightning-background-processor/src/lib.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ mod tests {
864864
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
865865
use lightning::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
866866
use lightning::routing::router::{DefaultRouter, Path, RouteHop};
867-
use lightning::routing::scoring::{ChannelUsage, ScoreUpdate, ScoreLookUp};
867+
use lightning::routing::scoring::{ChannelUsage, ScoreUpdate, ScoreLookUp, LockableScore};
868868
use lightning::util::config::UserConfig;
869869
use lightning::util::ser::Writeable;
870870
use lightning::util::test_utils;
@@ -894,6 +894,11 @@ mod tests {
894894
fn disconnect_socket(&mut self) {}
895895
}
896896

897+
#[cfg(c_bindings)]
898+
type LockingWrapper<T> = lightning::routing::scoring::MultiThreadedLockableScore<T>;
899+
#[cfg(not(c_bindings))]
900+
type LockingWrapper<T> = Mutex<T>;
901+
897902
type ChannelManager =
898903
channelmanager::ChannelManager<
899904
Arc<ChainMonitor>,
@@ -905,7 +910,7 @@ mod tests {
905910
Arc<DefaultRouter<
906911
Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
907912
Arc<test_utils::TestLogger>,
908-
Arc<Mutex<TestScorer>>,
913+
Arc<LockingWrapper<TestScorer>>,
909914
(),
910915
TestScorer>
911916
>,
@@ -927,7 +932,7 @@ mod tests {
927932
network_graph: Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
928933
logger: Arc<test_utils::TestLogger>,
929934
best_block: BestBlock,
930-
scorer: Arc<Mutex<TestScorer>>,
935+
scorer: Arc<LockingWrapper<TestScorer>>,
931936
}
932937

933938
impl Node {
@@ -1148,6 +1153,9 @@ mod tests {
11481153
}
11491154
}
11501155

1156+
#[cfg(c_bindings)]
1157+
impl lightning::routing::scoring::Score for TestScorer {}
1158+
11511159
impl Drop for TestScorer {
11521160
fn drop(&mut self) {
11531161
if std::thread::panicking() {
@@ -1179,7 +1187,7 @@ mod tests {
11791187
let logger = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
11801188
let genesis_block = genesis_block(network);
11811189
let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
1182-
let scorer = Arc::new(Mutex::new(TestScorer::new()));
1190+
let scorer = Arc::new(LockingWrapper::new(TestScorer::new()));
11831191
let seed = [i as u8; 32];
11841192
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone(), Default::default()));
11851193
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Bitcoin));
@@ -1689,7 +1697,7 @@ mod tests {
16891697
maybe_announced_channel: true,
16901698
}], blinded_tail: None };
16911699

1692-
$nodes[0].scorer.lock().unwrap().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
1700+
$nodes[0].scorer.write_lock().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
16931701
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {
16941702
payment_id: None,
16951703
payment_hash: PaymentHash([42; 32]),
@@ -1706,7 +1714,7 @@ mod tests {
17061714

17071715
// Ensure we'll score payments that were explicitly failed back by the destination as
17081716
// ProbeSuccess.
1709-
$nodes[0].scorer.lock().unwrap().expect(TestResult::ProbeSuccess { path: path.clone() });
1717+
$nodes[0].scorer.write_lock().expect(TestResult::ProbeSuccess { path: path.clone() });
17101718
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {
17111719
payment_id: None,
17121720
payment_hash: PaymentHash([42; 32]),
@@ -1721,7 +1729,7 @@ mod tests {
17211729
_ => panic!("Unexpected event"),
17221730
}
17231731

1724-
$nodes[0].scorer.lock().unwrap().expect(TestResult::PaymentSuccess { path: path.clone() });
1732+
$nodes[0].scorer.write_lock().expect(TestResult::PaymentSuccess { path: path.clone() });
17251733
$nodes[0].node.push_pending_event(Event::PaymentPathSuccessful {
17261734
payment_id: PaymentId([42; 32]),
17271735
payment_hash: None,
@@ -1733,7 +1741,7 @@ mod tests {
17331741
_ => panic!("Unexpected event"),
17341742
}
17351743

1736-
$nodes[0].scorer.lock().unwrap().expect(TestResult::ProbeSuccess { path: path.clone() });
1744+
$nodes[0].scorer.write_lock().expect(TestResult::ProbeSuccess { path: path.clone() });
17371745
$nodes[0].node.push_pending_event(Event::ProbeSuccessful {
17381746
payment_id: PaymentId([42; 32]),
17391747
payment_hash: PaymentHash([42; 32]),
@@ -1745,7 +1753,7 @@ mod tests {
17451753
_ => panic!("Unexpected event"),
17461754
}
17471755

1748-
$nodes[0].scorer.lock().unwrap().expect(TestResult::ProbeFailure { path: path.clone() });
1756+
$nodes[0].scorer.write_lock().expect(TestResult::ProbeFailure { path: path.clone() });
17491757
$nodes[0].node.push_pending_event(Event::ProbeFailed {
17501758
payment_id: PaymentId([42; 32]),
17511759
payment_hash: PaymentHash([42; 32]),

0 commit comments

Comments
 (0)