Skip to content

Commit 41d8d4d

Browse files
authored
Merge pull request #1008 from lightning-signer/2021-07-sync-no-std
Dummy sync implementation for no_std
2 parents ef4bfdc + 2e8f4fe commit 41d8d4d

18 files changed

+163
-33
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ jobs:
9090
if: "matrix.build-no-std && !matrix.coverage"
9191
run: |
9292
cd lightning
93-
cargo test --verbose --color always --features hashbrown
93+
cargo test --verbose --color always --no-default-features --features no_std
94+
# check if there is a conflict between no_std and the default std feature
95+
cargo test --verbose --color always --features no_std
9496
cd ..
9597
- name: Test on no_std bullds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
9698
if: "matrix.build-no-std && matrix.coverage"
9799
run: |
98100
cd lightning
99-
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features hashbrown
101+
RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no_std
100102
cd ..
101103
- name: Test on Rust ${{ matrix.toolchain }}
102104
if: "! matrix.build-net-tokio"

lightning/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ max_level_debug = []
2525
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
2626
unsafe_revoked_tx_signing = []
2727
unstable = []
28+
2829
no_std = ["hashbrown"]
30+
std = []
31+
32+
default = ["std"]
2933

3034
[dependencies]
3135
bitcoin = "0.26"

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use util::events;
3838
use util::events::EventHandler;
3939

4040
use prelude::*;
41-
use std::sync::RwLock;
41+
use sync::RwLock;
4242
use core::ops::Deref;
4343

4444
/// An implementation of [`chain::Watch`] for monitoring channels.

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use prelude::*;
5555
use core::{cmp, mem};
5656
use std::io::Error;
5757
use core::ops::Deref;
58-
use std::sync::Mutex;
58+
use sync::Mutex;
5959

6060
/// An update generated by the underlying Channel itself which contains some new information the
6161
/// ChannelMonitor should be made aware of.
@@ -2843,7 +2843,7 @@ mod tests {
28432843
use util::test_utils::{TestLogger, TestBroadcaster, TestFeeEstimator};
28442844
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
28452845
use bitcoin::secp256k1::Secp256k1;
2846-
use std::sync::{Arc, Mutex};
2846+
use sync::{Arc, Mutex};
28472847
use chain::keysinterface::InMemorySigner;
28482848
use prelude::*;
28492849

lightning/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ mod prelude {
5353
#[cfg(feature = "hashbrown")]
5454
pub use self::hashbrown::{HashMap, HashSet, hash_map};
5555
}
56+
57+
#[cfg(feature = "std")]
58+
mod sync {
59+
pub use ::std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard};
60+
}
61+
62+
#[cfg(not(feature = "std"))]
63+
mod sync;

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use ln::functional_test_utils::*;
4141
use util::test_utils;
4242

4343
use prelude::*;
44-
use std::sync::{Arc, Mutex};
44+
use sync::{Arc, Mutex};
4545

4646
// If persister_fail is true, we have the persister return a PermanentFailure
4747
// instead of the higher-level ChainMonitor.

lightning/src/ln/channel.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ use util::scid_utils::scid_from_parts;
4444
use prelude::*;
4545
use core::{cmp,mem,fmt};
4646
use core::ops::Deref;
47-
#[cfg(any(test, feature = "fuzztarget"))]
48-
use std::sync::Mutex;
47+
#[cfg(any(test, feature = "fuzztarget", debug_assertions))]
48+
use sync::Mutex;
4949
use bitcoin::hashes::hex::ToHex;
5050
use bitcoin::blockdata::opcodes::all::OP_PUSHBYTES_0;
5151

@@ -374,10 +374,10 @@ pub(super) struct Channel<Signer: Sign> {
374374

375375
#[cfg(debug_assertions)]
376376
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
377-
holder_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>,
377+
holder_max_commitment_tx_output: Mutex<(u64, u64)>,
378378
#[cfg(debug_assertions)]
379379
/// Max to_local and to_remote outputs in a remote-generated commitment transaction
380-
counterparty_max_commitment_tx_output: ::std::sync::Mutex<(u64, u64)>,
380+
counterparty_max_commitment_tx_output: Mutex<(u64, u64)>,
381381

382382
last_sent_closing_fee: Option<(u32, u64, Signature)>, // (feerate, fee, holder_sig)
383383

@@ -595,9 +595,9 @@ impl<Signer: Sign> Channel<Signer> {
595595
monitor_pending_failures: Vec::new(),
596596

597597
#[cfg(debug_assertions)]
598-
holder_max_commitment_tx_output: ::std::sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
598+
holder_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
599599
#[cfg(debug_assertions)]
600-
counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
600+
counterparty_max_commitment_tx_output: Mutex::new((channel_value_satoshis * 1000 - push_msat, push_msat)),
601601

602602
last_sent_closing_fee: None,
603603

@@ -836,9 +836,9 @@ impl<Signer: Sign> Channel<Signer> {
836836
monitor_pending_failures: Vec::new(),
837837

838838
#[cfg(debug_assertions)]
839-
holder_max_commitment_tx_output: ::std::sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
839+
holder_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
840840
#[cfg(debug_assertions)]
841-
counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
841+
counterparty_max_commitment_tx_output: Mutex::new((msg.push_msat, msg.funding_satoshis * 1000 - msg.push_msat)),
842842

843843
last_sent_closing_fee: None,
844844

@@ -4943,9 +4943,9 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
49434943
feerate_per_kw,
49444944

49454945
#[cfg(debug_assertions)]
4946-
holder_max_commitment_tx_output: ::std::sync::Mutex::new((0, 0)),
4946+
holder_max_commitment_tx_output: Mutex::new((0, 0)),
49474947
#[cfg(debug_assertions)]
4948-
counterparty_max_commitment_tx_output: ::std::sync::Mutex::new((0, 0)),
4948+
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
49494949

49504950
last_sent_closing_fee,
49514951

@@ -5023,7 +5023,7 @@ mod tests {
50235023
use bitcoin::hashes::sha256::Hash as Sha256;
50245024
use bitcoin::hashes::Hash;
50255025
use bitcoin::hash_types::{Txid, WPubkeyHash};
5026-
use std::sync::Arc;
5026+
use sync::Arc;
50275027
use prelude::*;
50285028

50295029
struct TestFeeEstimator {

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use prelude::*;
6464
use core::{cmp, mem};
6565
use core::cell::RefCell;
6666
use std::io::{Cursor, Read};
67-
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
67+
use sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
6868
use core::sync::atomic::{AtomicUsize, Ordering};
6969
use core::time::Duration;
7070
#[cfg(any(test, feature = "allow_wallclock_use"))]
@@ -4951,14 +4951,15 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
49514951
#[cfg(test)]
49524952
mod tests {
49534953
use ln::channelmanager::PersistenceNotifier;
4954-
use std::sync::Arc;
4954+
use sync::Arc;
49554955
use core::sync::atomic::{AtomicBool, Ordering};
49564956
use std::thread;
49574957
use core::time::Duration;
49584958
use ln::functional_test_utils::*;
49594959
use ln::features::InitFeatures;
49604960
use ln::msgs::ChannelMessageHandler;
49614961

4962+
#[cfg(feature = "std")]
49624963
#[test]
49634964
fn test_wait_timeout() {
49644965
let persistence_notifier = Arc::new(PersistenceNotifier::new());
@@ -5094,7 +5095,7 @@ pub mod bench {
50945095
use bitcoin::hashes::sha256::Hash as Sha256;
50955096
use bitcoin::{Block, BlockHeader, Transaction, TxOut};
50965097

5097-
use std::sync::{Arc, Mutex};
5098+
use sync::{Arc, Mutex};
50985099

50995100
use test::Bencher;
51005101

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use bitcoin::secp256k1::key::PublicKey;
4242
use prelude::*;
4343
use core::cell::RefCell;
4444
use std::rc::Rc;
45-
use std::sync::{Arc, Mutex};
45+
use sync::{Arc, Mutex};
4646
use core::mem;
4747

4848
pub const CHAN_CONFIRM_DEPTH: u32 = 10;

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use regex;
5353
use prelude::*;
5454
use alloc::collections::BTreeSet;
5555
use core::default::Default;
56-
use std::sync::{Arc, Mutex};
56+
use sync::{Arc, Mutex};
5757

5858
use ln::functional_test_utils::*;
5959
use ln::chan_utils::CommitmentTransaction;

0 commit comments

Comments
 (0)