Skip to content

Commit 45e88b3

Browse files
committed
Use core types in no_std builds
In no_std builds, replace std with core types where available
1 parent 452a550 commit 45e88b3

27 files changed

+120
-44
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ use utils::test_persister::TestPersister;
5656
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
5757
use bitcoin::secp256k1::Secp256k1;
5858

59-
use std::mem;
60-
use std::cmp::Ordering;
59+
#[cfg(not(feature = "no_std"))]
60+
use std::{cmp::Ordering, mem, sync::atomic};
61+
#[cfg(feature = "no_std")]
62+
use core::{cmp::Ordering, mem, sync::atomic};
6163
#[cfg(not(feature = "no_std"))]
6264
use std::collections::{HashSet, hash_map, HashMap};
6365
#[cfg(feature = "no_std")]
6466
use hashbrown::{HashMap, HashSet, hash_map};
6567
use std::sync::{Arc,Mutex};
66-
use std::sync::atomic;
6768
use std::io::Cursor;
6869

6970
struct FuzzEstimator {}

fuzz/src/full_stack.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ use utils::test_persister::TestPersister;
4848
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
4949
use bitcoin::secp256k1::Secp256k1;
5050

51-
use std::cell::RefCell;
51+
#[cfg(not(feature = "no_std"))]
52+
use std::{cell::RefCell, cmp, sync::atomic::{AtomicU64, AtomicUsize, Ordering}};
53+
#[cfg(feature = "no_std")]
54+
use core::{cell::RefCell, cmp, sync::atomic::{AtomicU64, AtomicUsize, Ordering}};
5255
#[cfg(not(feature = "no_std"))]
5356
use std::collections::{HashMap, hash_map};
5457
#[cfg(feature = "no_std")]
5558
use hashbrown::{HashMap, hash_map};
56-
use std::cmp;
5759
use std::sync::Arc;
58-
use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
5960

6061
#[inline]
6162
pub fn slice_to_be16(v: &[u8]) -> u16 {

fuzz/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ pub mod router;
2121

2222
pub mod msg_targets;
2323

24+
#[cfg(feature = "no_std")] extern crate core;
2425
#[cfg(feature = "no_std")] extern crate hashbrown;

fuzz/src/router.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ use std::collections::HashSet;
3131
#[cfg(feature = "no_std")]
3232
use hashbrown::HashSet;
3333
use std::sync::Arc;
34+
#[cfg(not(feature = "no_std"))]
3435
use std::sync::atomic::{AtomicUsize, Ordering};
36+
#[cfg(feature = "no_std")]
37+
use core::sync::atomic::{AtomicUsize, Ordering};
3538

3639
#[inline]
3740
pub fn slice_to_be16(v: &[u8]) -> u16 {

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ use util::events::Event;
5555
use std::collections::{HashMap, HashSet, hash_map};
5656
#[cfg(feature = "no_std")]
5757
use hashbrown::{HashMap, HashSet, hash_map};
58-
use std::{cmp, mem};
58+
#[cfg(not(feature = "no_std"))]
59+
use std::{cmp, mem, ops::Deref};
60+
#[cfg(feature = "no_std")]
61+
use core::{cmp, mem, ops::Deref};
5962
use std::io::Error;
60-
use std::ops::Deref;
6163
use std::sync::Mutex;
6264

6365
/// An update generated by the underlying Channel itself which contains some new information the

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ use ln::msgs::UnsignedChannelAnnouncement;
4040
use std::collections::HashSet;
4141
#[cfg(feature = "no_std")]
4242
use hashbrown::HashSet;
43+
#[cfg(not(feature = "no_std"))]
4344
use std::sync::atomic::{AtomicUsize, Ordering};
45+
#[cfg(feature = "no_std")]
46+
use core::sync::atomic::{AtomicUsize, Ordering};
4447
use std::io::Error;
4548
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};
4649

lightning/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern crate bitcoin;
3434
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
3535
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;
3636

37+
#[cfg(feature = "no_std")] extern crate core;
3738
#[cfg(feature = "no_std")] extern crate hashbrown;
3839

3940
#[macro_use]

lightning/src/ln/chan_utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ use bitcoin::secp256k1::{Secp256k1, Signature, Message};
3131
use bitcoin::secp256k1::Error as SecpError;
3232
use bitcoin::secp256k1;
3333

34-
use std::cmp;
34+
#[cfg(not(feature = "no_std"))]
35+
use std::{cmp, ops::Deref};
36+
#[cfg(feature = "no_std")]
37+
use core::{cmp, ops::Deref};
3538
use ln::chan_utils;
3639
use util::transaction_utils::sort_outputs;
3740
use ln::channel::INITIAL_COMMITMENT_NUMBER;
3841
use std::io::Read;
39-
use std::ops::Deref;
4042
use chain;
4143

4244
const HTLC_OUTPUT_IN_COMMITMENT_SIZE: usize = 1 + 8 + 4 + 32 + 5;

lightning/src/ln/channel.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ use util::logger::Logger;
3838
use util::errors::APIError;
3939
use util::config::{UserConfig,ChannelConfig};
4040

41-
use std;
42-
use std::{cmp,mem,fmt};
43-
use std::ops::Deref;
41+
#[cfg(not(feature = "no_std"))]
42+
use std::{cmp, mem, fmt, ops::Deref};
43+
#[cfg(feature = "no_std")]
44+
use core::{cmp, mem, fmt, ops::Deref};
4445
#[cfg(any(test, feature = "fuzztarget"))]
4546
use std::sync::Mutex;
4647
use bitcoin::hashes::hex::ToHex;

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,32 @@ use util::chacha20::{ChaCha20, ChaChaReader};
5555
use util::logger::Logger;
5656
use util::errors::APIError;
5757

58-
use std::{cmp, mem};
58+
#[cfg(not(feature = "no_std"))]
59+
use std::{
60+
cmp,
61+
mem,
62+
marker::{Sync, Send},
63+
ops::Deref,
64+
sync::atomic::{AtomicUsize, Ordering},
65+
time::Duration,
66+
};
67+
#[cfg(feature = "no_std")]
68+
use core::{
69+
cmp,
70+
mem,
71+
marker::{Sync, Send},
72+
ops::Deref,
73+
sync::atomic::{AtomicUsize, Ordering},
74+
time::Duration,
75+
};
5976
#[cfg(not(feature = "no_std"))]
6077
use std::collections::{HashMap, hash_map, HashSet};
6178
#[cfg(feature = "no_std")]
6279
use hashbrown::{HashMap, HashSet, hash_map};
6380
use std::io::{Cursor, Read};
6481
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
65-
use std::sync::atomic::{AtomicUsize, Ordering};
66-
use std::time::Duration;
6782
#[cfg(any(test, feature = "allow_wallclock_use"))]
6883
use std::time::Instant;
69-
use std::marker::{Sync, Send};
70-
use std::ops::Deref;
7184
use bitcoin::hashes::hex::ToHex;
7285

7386
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
@@ -4309,7 +4322,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
43094322
mod tests {
43104323
use ln::channelmanager::PersistenceNotifier;
43114324
use std::sync::Arc;
4325+
#[cfg(not(feature = "no_std"))]
43124326
use std::sync::atomic::{AtomicBool, Ordering};
4327+
#[cfg(feature = "no_std")]
4328+
use core::sync::atomic::{AtomicBool, Ordering};
43134329
use std::thread;
43144330
use std::time::Duration;
43154331

0 commit comments

Comments
 (0)