Skip to content

Commit c7e198e

Browse files
authored
Merge pull request #926 from GeneFerneau/core
Use core replacements for std members
2 parents b6de281 + ec3739b commit c7e198e

32 files changed

+108
-110
lines changed

lightning/src/chain/chainmonitor.rs

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

4040
use std::collections::{HashMap, hash_map};
4141
use std::sync::RwLock;
42-
use std::ops::Deref;
42+
use core::ops::Deref;
4343

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

lightning/src/chain/channelmonitor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ use util::byte_utils;
5252
use util::events::Event;
5353

5454
use std::collections::{HashMap, HashSet};
55-
use std::{cmp, mem};
55+
use core::{cmp, mem};
5656
use std::io::Error;
57-
use std::ops::Deref;
57+
use core::ops::Deref;
5858
use std::sync::Mutex;
5959

6060
/// An update generated by the underlying Channel itself which contains some new information the
@@ -85,7 +85,7 @@ pub struct ChannelMonitorUpdate {
8585
/// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
8686
/// with the update providing said payment preimage. No other update types are allowed after
8787
/// force-close.
88-
pub const CLOSED_CHANNEL_UPDATE_ID: u64 = std::u64::MAX;
88+
pub const CLOSED_CHANNEL_UPDATE_ID: u64 = core::u64::MAX;
8989

9090
impl Writeable for ChannelMonitorUpdate {
9191
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
@@ -101,7 +101,7 @@ impl Readable for ChannelMonitorUpdate {
101101
fn read<R: ::std::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
102102
let update_id: u64 = Readable::read(r)?;
103103
let len: u64 = Readable::read(r)?;
104-
let mut updates = Vec::with_capacity(cmp::min(len as usize, MAX_ALLOC_SIZE / ::std::mem::size_of::<ChannelMonitorUpdateStep>()));
104+
let mut updates = Vec::with_capacity(cmp::min(len as usize, MAX_ALLOC_SIZE / ::core::mem::size_of::<ChannelMonitorUpdateStep>()));
105105
for _ in 0..len {
106106
updates.push(Readable::read(r)?);
107107
}
@@ -1932,7 +1932,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19321932

19331933
for &(ref htlc, _, _) in holder_tx.htlc_outputs.iter() {
19341934
if let Some(transaction_output_index) = htlc.transaction_output_index {
1935-
claim_requests.push(ClaimRequest { absolute_timelock: ::std::u32::MAX, aggregable: false, outpoint: BitcoinOutPoint { txid: holder_tx.txid, vout: transaction_output_index as u32 },
1935+
claim_requests.push(ClaimRequest { absolute_timelock: ::core::u32::MAX, aggregable: false, outpoint: BitcoinOutPoint { txid: holder_tx.txid, vout: transaction_output_index as u32 },
19361936
witness_data: InputMaterial::HolderHTLC {
19371937
preimage: if !htlc.offered {
19381938
if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
@@ -2594,7 +2594,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25942594
fn is_paying_spendable_output<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) where L::Target: Logger {
25952595
let mut spendable_output = None;
25962596
for (i, outp) in tx.output.iter().enumerate() { // There is max one spendable output for any channel tx, including ones generated by us
2597-
if i > ::std::u16::MAX as usize {
2597+
if i > ::core::u16::MAX as usize {
25982598
// While it is possible that an output exists on chain which is greater than the
25992599
// 2^16th output in a given transaction, this is only possible if the output is not
26002600
// in a lightning transaction and was instead placed there by some third party who

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelP
3838
use ln::msgs::UnsignedChannelAnnouncement;
3939

4040
use std::collections::HashSet;
41-
use std::sync::atomic::{AtomicUsize, Ordering};
41+
use core::sync::atomic::{AtomicUsize, Ordering};
4242
use std::io::Error;
4343
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};
4444

@@ -857,7 +857,7 @@ impl KeysManager {
857857
/// onchain output detection for which a corresponding delayed_payment_key must be derived.
858858
pub fn derive_channel_keys(&self, channel_value_satoshis: u64, params: &[u8; 32]) -> InMemorySigner {
859859
let chan_id = byte_utils::slice_to_be64(&params[0..8]);
860-
assert!(chan_id <= std::u32::MAX as u64); // Otherwise the params field wasn't created by us
860+
assert!(chan_id <= core::u32::MAX as u64); // Otherwise the params field wasn't created by us
861861
let mut unique_start = Sha256::engine();
862862
unique_start.input(params);
863863
unique_start.input(&self.seed);
@@ -1039,7 +1039,7 @@ impl KeysInterface for KeysManager {
10391039

10401040
fn get_channel_signer(&self, _inbound: bool, channel_value_satoshis: u64) -> Self::Signer {
10411041
let child_ix = self.channel_child_index.fetch_add(1, Ordering::AcqRel);
1042-
assert!(child_ix <= std::u32::MAX as usize);
1042+
assert!(child_ix <= core::u32::MAX as usize);
10431043
let mut id = [0; 32];
10441044
id[0..8].copy_from_slice(&byte_utils::be64_to_array(child_ix as u64));
10451045
id[8..16].copy_from_slice(&byte_utils::be64_to_array(self.starting_time_nanos as u64));

lightning/src/chain/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub struct WatchedOutput {
246246
pub script_pubkey: Script,
247247
}
248248

249-
impl<T: Listen> Listen for std::ops::Deref<Target = T> {
249+
impl<T: Listen> Listen for core::ops::Deref<Target = T> {
250250
fn block_connected(&self, block: &Block, height: u32) {
251251
(**self).block_connected(block, height);
252252
}
@@ -256,7 +256,7 @@ impl<T: Listen> Listen for std::ops::Deref<Target = T> {
256256
}
257257
}
258258

259-
impl<T: std::ops::Deref, U: std::ops::Deref> Listen for (T, U)
259+
impl<T: core::ops::Deref, U: core::ops::Deref> Listen for (T, U)
260260
where
261261
T::Target: Listen,
262262
U::Target: Listen,

lightning/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))] extern crate test;
3333

3434
extern crate bitcoin;
35+
extern crate core;
3536
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
3637
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;
3738

lightning/src/ln/chan_utils.rs

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

34-
use std::cmp;
34+
use core::cmp;
3535
use ln::chan_utils;
3636
use util::transaction_utils::sort_outputs;
3737
use ln::channel::INITIAL_COMMITMENT_NUMBER;
3838
use std::io::Read;
39-
use std::ops::Deref;
39+
use core::ops::Deref;
4040
use chain;
4141

4242
// Maximum size of a serialized HTLCOutputInCommitment

lightning/src/ln/channel.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ use util::errors::APIError;
3939
use util::config::{UserConfig,ChannelConfig};
4040
use util::scid_utils::scid_from_parts;
4141

42-
use std;
43-
use std::{cmp,mem,fmt};
44-
use std::ops::Deref;
42+
use core::{cmp,mem,fmt};
43+
use core::ops::Deref;
4544
#[cfg(any(test, feature = "fuzztarget"))]
4645
use std::sync::Mutex;
4746
use bitcoin::hashes::hex::ToHex;
@@ -1220,7 +1219,7 @@ impl<Signer: Sign> Channel<Signer> {
12201219
// on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
12211220
// these, but for now we just have to treat them as normal.
12221221

1223-
let mut pending_idx = std::usize::MAX;
1222+
let mut pending_idx = core::usize::MAX;
12241223
for (idx, htlc) in self.pending_inbound_htlcs.iter().enumerate() {
12251224
if htlc.htlc_id == htlc_id_arg {
12261225
assert_eq!(htlc.payment_hash, payment_hash_calc);
@@ -1243,7 +1242,7 @@ impl<Signer: Sign> Channel<Signer> {
12431242
break;
12441243
}
12451244
}
1246-
if pending_idx == std::usize::MAX {
1245+
if pending_idx == core::usize::MAX {
12471246
return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
12481247
}
12491248

@@ -1342,7 +1341,7 @@ impl<Signer: Sign> Channel<Signer> {
13421341
// on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
13431342
// these, but for now we just have to treat them as normal.
13441343

1345-
let mut pending_idx = std::usize::MAX;
1344+
let mut pending_idx = core::usize::MAX;
13461345
for (idx, htlc) in self.pending_inbound_htlcs.iter().enumerate() {
13471346
if htlc.htlc_id == htlc_id_arg {
13481347
match htlc.state {
@@ -1359,7 +1358,7 @@ impl<Signer: Sign> Channel<Signer> {
13591358
pending_idx = idx;
13601359
}
13611360
}
1362-
if pending_idx == std::usize::MAX {
1361+
if pending_idx == core::usize::MAX {
13631362
return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
13641363
}
13651364

@@ -4410,8 +4409,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44104409

44114410
let mut key_data = VecWriter(Vec::new());
44124411
self.holder_signer.write(&mut key_data)?;
4413-
assert!(key_data.0.len() < std::usize::MAX);
4414-
assert!(key_data.0.len() < std::u32::MAX as usize);
4412+
assert!(key_data.0.len() < core::usize::MAX);
4413+
assert!(key_data.0.len() < core::u32::MAX as usize);
44154414
(key_data.0.len() as u32).write(writer)?;
44164415
writer.write_all(&key_data.0[..])?;
44174416

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ use util::chacha20::{ChaCha20, ChaChaReader};
6161
use util::logger::Logger;
6262
use util::errors::APIError;
6363

64-
use std::{cmp, mem};
64+
use core::{cmp, mem};
6565
use std::collections::{HashMap, hash_map, HashSet};
6666
use std::io::{Cursor, Read};
6767
use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
68-
use std::sync::atomic::{AtomicUsize, Ordering};
69-
use std::time::Duration;
68+
use core::sync::atomic::{AtomicUsize, Ordering};
69+
use core::time::Duration;
7070
#[cfg(any(test, feature = "allow_wallclock_use"))]
7171
use std::time::Instant;
72-
use std::ops::Deref;
72+
use core::ops::Deref;
7373
use bitcoin::hashes::hex::ToHex;
7474

7575
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
@@ -1781,7 +1781,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
17811781
// be absurd. We ensure this by checking that at least 500 (our stated public contract on when
17821782
// broadcast_node_announcement panics) of the maximum-length addresses would fit in a 64KB
17831783
// message...
1784-
const HALF_MESSAGE_IS_ADDRS: u32 = ::std::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
1784+
const HALF_MESSAGE_IS_ADDRS: u32 = ::core::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
17851785
#[deny(const_err)]
17861786
#[allow(dead_code)]
17871787
// ...by failing to compile if the number of addresses that would be half of a message is
@@ -4817,9 +4817,9 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
48174817
mod tests {
48184818
use ln::channelmanager::PersistenceNotifier;
48194819
use std::sync::Arc;
4820-
use std::sync::atomic::{AtomicBool, Ordering};
4820+
use core::sync::atomic::{AtomicBool, Ordering};
48214821
use std::thread;
4822-
use std::time::Duration;
4822+
use core::time::Duration;
48234823

48244824
#[test]
48254825
fn test_wait_timeout() {

lightning/src/ln/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
//! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
2323
//! [messages]: crate::ln::msgs
2424
25-
use std::{cmp, fmt};
26-
use std::marker::PhantomData;
25+
use core::{cmp, fmt};
26+
use core::marker::PhantomData;
2727

2828
use bitcoin::bech32;
2929
use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5, WriteBase32};

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ use bitcoin::hash_types::BlockHash;
3939

4040
use bitcoin::secp256k1::key::PublicKey;
4141

42-
use std::cell::RefCell;
42+
use core::cell::RefCell;
4343
use std::rc::Rc;
4444
use std::sync::Mutex;
45-
use std::mem;
45+
use core::mem;
4646
use std::collections::HashMap;
4747

4848
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
@@ -557,7 +557,7 @@ pub fn create_chan_between_nodes_with_value_confirm_second<'a, 'b, 'c>(node_recv
557557
}
558558

559559
pub fn create_chan_between_nodes_with_value_confirm<'a, 'b, 'c, 'd>(node_a: &'a Node<'b, 'c, 'd>, node_b: &'a Node<'b, 'c, 'd>, tx: &Transaction) -> ((msgs::FundingLocked, msgs::AnnouncementSignatures), [u8; 32]) {
560-
let conf_height = std::cmp::max(node_a.best_block_info().1 + 1, node_b.best_block_info().1 + 1);
560+
let conf_height = core::cmp::max(node_a.best_block_info().1 + 1, node_b.best_block_info().1 + 1);
561561
create_chan_between_nodes_with_value_confirm_first(node_a, node_b, tx, conf_height);
562562
confirm_transaction_at(node_a, tx, conf_height);
563563
connect_blocks(node_a, CHAN_CONFIRM_DEPTH - 1);

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use bitcoin::secp256k1::key::{PublicKey,SecretKey};
5151
use regex;
5252

5353
use std::collections::{BTreeSet, HashMap, HashSet};
54-
use std::default::Default;
54+
use core::default::Default;
5555
use std::sync::Mutex;
5656

5757
use ln::functional_test_utils::*;

lightning/src/ln/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use bitcoin::hash_types::{Txid, BlockHash};
3232

3333
use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
3434

35-
use std::{cmp, fmt};
36-
use std::fmt::Debug;
35+
use core::{cmp, fmt};
36+
use core::fmt::Debug;
3737
use std::io::Read;
3838

3939
use util::events::MessageSendEventsProvider;

lightning/src/ln/onchaintx.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use util::ser::{Readable, ReadableArgs, Writer, Writeable, VecWriter};
3333
use util::byte_utils;
3434

3535
use std::collections::HashMap;
36-
use std::cmp;
37-
use std::ops::Deref;
38-
use std::mem::replace;
36+
use core::cmp;
37+
use core::ops::Deref;
38+
use core::mem::replace;
3939

4040
const MAX_ALLOC_SIZE: usize = 64*1024;
4141

@@ -220,7 +220,7 @@ impl Readable for Option<Vec<Option<(usize, Signature)>>> {
220220
0u8 => Ok(None),
221221
1u8 => {
222222
let vlen: u64 = Readable::read(reader)?;
223-
let mut ret = Vec::with_capacity(cmp::min(vlen as usize, MAX_ALLOC_SIZE / ::std::mem::size_of::<Option<(usize, Signature)>>()));
223+
let mut ret = Vec::with_capacity(cmp::min(vlen as usize, MAX_ALLOC_SIZE / ::core::mem::size_of::<Option<(usize, Signature)>>()));
224224
for _ in 0..vlen {
225225
ret.push(match Readable::read(reader)? {
226226
0u8 => None,
@@ -320,8 +320,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
320320

321321
let mut key_data = VecWriter(Vec::new());
322322
self.signer.write(&mut key_data)?;
323-
assert!(key_data.0.len() < std::usize::MAX);
324-
assert!(key_data.0.len() < std::u32::MAX as usize);
323+
assert!(key_data.0.len() < core::usize::MAX);
324+
assert!(key_data.0.len() < core::u32::MAX as usize);
325325
(key_data.0.len() as u32).write(writer)?;
326326
writer.write_all(&key_data.0[..])?;
327327

@@ -711,7 +711,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
711711
log_trace!(logger, "Updating claims view at height {} with {} matched transactions and {} claim requests", height, txn_matched.len(), claimable_outpoints.len());
712712
let mut new_claims = Vec::new();
713713
let mut aggregated_claim = HashMap::new();
714-
let mut aggregated_soonest = ::std::u32::MAX;
714+
let mut aggregated_soonest = ::core::u32::MAX;
715715

716716
// Try to aggregate outputs if their timelock expiration isn't imminent (absolute_timelock
717717
// <= CLTV_SHARED_CLAIM_BUFFER) and they don't require an immediate nLockTime (aggregable).

lightning/src/ln/onion_route_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use bitcoin::hashes::Hash;
3232
use bitcoin::secp256k1::Secp256k1;
3333
use bitcoin::secp256k1::key::SecretKey;
3434

35-
use std::default::Default;
35+
use core::default::Default;
3636
use std::io;
3737

3838
use ln::functional_test_utils::*;

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
2828
use bitcoin::secp256k1;
2929

3030
use std::io::Cursor;
31-
use std::ops::Deref;
31+
use core::ops::Deref;
3232

3333
pub(super) struct OnionKeys {
3434
#[cfg(test)]

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bitcoin::hashes::hex::ToHex;
2525
/// Maximum Lightning message data length according to
2626
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
2727
/// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
28-
pub const LN_MAX_MSG_LEN: usize = ::std::u16::MAX as usize; // Must be equal to 65535
28+
pub const LN_MAX_MSG_LEN: usize = ::core::u16::MAX as usize; // Must be equal to 65535
2929

3030
// Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
3131
const NOISE_CK: [u8; 32] = [0x26, 0x40, 0xf5, 0x2e, 0xeb, 0xcd, 0x9e, 0x88, 0x29, 0x58, 0x95, 0x1c, 0x79, 0x42, 0x50, 0xee, 0xdb, 0x28, 0x00, 0x2c, 0x05, 0xd7, 0xdc, 0x2e, 0xa0, 0xf1, 0x95, 0x40, 0x60, 0x42, 0xca, 0xf1];
@@ -715,7 +715,7 @@ mod tests {
715715
#[test]
716716
fn max_msg_len_limit_value() {
717717
assert_eq!(LN_MAX_MSG_LEN, 65535);
718-
assert_eq!(LN_MAX_MSG_LEN, ::std::u16::MAX as usize);
718+
assert_eq!(LN_MAX_MSG_LEN, ::core::u16::MAX as usize);
719719
}
720720

721721
#[test]

lightning/src/ln/peer_handler.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ use routing::network_graph::NetGraphMsgHandler;
3232

3333
use std::collections::{HashMap,hash_map,HashSet,LinkedList};
3434
use std::sync::{Arc, Mutex};
35-
use std::sync::atomic::{AtomicUsize, Ordering};
36-
use std::{cmp, error, hash, fmt, mem};
37-
use std::ops::Deref;
35+
use core::sync::atomic::{AtomicUsize, Ordering};
36+
use core::{cmp, hash, fmt, mem};
37+
use core::ops::Deref;
38+
use std::error;
3839

3940
use bitcoin::hashes::sha256::Hash as Sha256;
4041
use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
@@ -1420,9 +1421,8 @@ mod tests {
14201421
use bitcoin::secp256k1::Secp256k1;
14211422
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
14221423

1423-
use std;
14241424
use std::sync::{Arc, Mutex};
1425-
use std::sync::atomic::Ordering;
1425+
use core::sync::atomic::Ordering;
14261426

14271427
#[derive(Clone)]
14281428
struct FileDescriptor {
@@ -1435,8 +1435,8 @@ mod tests {
14351435
}
14361436
}
14371437
impl Eq for FileDescriptor { }
1438-
impl std::hash::Hash for FileDescriptor {
1439-
fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
1438+
impl core::hash::Hash for FileDescriptor {
1439+
fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {
14401440
self.fd.hash(hasher)
14411441
}
14421442
}

0 commit comments

Comments
 (0)