Use core replacements for std members
authorGene Ferneau <gene@ferneau.link>
Sun, 23 May 2021 23:22:46 +0000 (23:22 +0000)
committerGene Ferneau <gene@ferneau.link>
Sun, 23 May 2021 23:48:27 +0000 (23:48 +0000)
In preparation for no_std build support, replace std structs and
functions with core equivalents

32 files changed:
lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs
lightning/src/chain/keysinterface.rs
lightning/src/chain/mod.rs
lightning/src/lib.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/features.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onchaintx.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/peer_channel_encryptor.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/reorg_tests.rs
lightning/src/ln/wire.rs
lightning/src/routing/network_graph.rs
lightning/src/routing/router.rs
lightning/src/util/chacha20.rs
lightning/src/util/enforcing_trait_impls.rs
lightning/src/util/errors.rs
lightning/src/util/events.rs
lightning/src/util/logger.rs
lightning/src/util/macro_logger.rs
lightning/src/util/message_signing.rs
lightning/src/util/poly1305.rs
lightning/src/util/ser.rs
lightning/src/util/test_utils.rs
lightning/src/util/transaction_utils.rs

index f708bfe9b6110e543e1a7d6aad63a34fcd7e08ed..a9b570d523d69d420e7b9bb31c3f638eb7d6df23 100644 (file)
@@ -39,7 +39,7 @@ use util::events::Event;
 
 use std::collections::{HashMap, hash_map};
 use std::sync::RwLock;
-use std::ops::Deref;
+use core::ops::Deref;
 
 /// An implementation of [`chain::Watch`] for monitoring channels.
 ///
index 62cb740e816d94ab517335d88e562a40191126fd..8526ce51722afefa80d14657f095fbcbfdf41ab2 100644 (file)
@@ -52,9 +52,9 @@ use util::byte_utils;
 use util::events::Event;
 
 use std::collections::{HashMap, HashSet};
-use std::{cmp, mem};
+use core::{cmp, mem};
 use std::io::Error;
-use std::ops::Deref;
+use core::ops::Deref;
 use std::sync::Mutex;
 
 /// An update generated by the underlying Channel itself which contains some new information the
@@ -85,7 +85,7 @@ pub struct ChannelMonitorUpdate {
 /// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
 /// with the update providing said payment preimage. No other update types are allowed after
 /// force-close.
-pub const CLOSED_CHANNEL_UPDATE_ID: u64 = std::u64::MAX;
+pub const CLOSED_CHANNEL_UPDATE_ID: u64 = core::u64::MAX;
 
 impl Writeable for ChannelMonitorUpdate {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
@@ -101,7 +101,7 @@ impl Readable for ChannelMonitorUpdate {
        fn read<R: ::std::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
                let update_id: u64 = Readable::read(r)?;
                let len: u64 = Readable::read(r)?;
-               let mut updates = Vec::with_capacity(cmp::min(len as usize, MAX_ALLOC_SIZE / ::std::mem::size_of::<ChannelMonitorUpdateStep>()));
+               let mut updates = Vec::with_capacity(cmp::min(len as usize, MAX_ALLOC_SIZE / ::core::mem::size_of::<ChannelMonitorUpdateStep>()));
                for _ in 0..len {
                        updates.push(Readable::read(r)?);
                }
@@ -1932,7 +1932,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
 
                for &(ref htlc, _, _) in holder_tx.htlc_outputs.iter() {
                        if let Some(transaction_output_index) = htlc.transaction_output_index {
-                               claim_requests.push(ClaimRequest { absolute_timelock: ::std::u32::MAX, aggregable: false, outpoint: BitcoinOutPoint { txid: holder_tx.txid, vout: transaction_output_index as u32 },
+                               claim_requests.push(ClaimRequest { absolute_timelock: ::core::u32::MAX, aggregable: false, outpoint: BitcoinOutPoint { txid: holder_tx.txid, vout: transaction_output_index as u32 },
                                        witness_data: InputMaterial::HolderHTLC {
                                                preimage: if !htlc.offered {
                                                                if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
@@ -2594,7 +2594,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
        fn is_paying_spendable_output<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) where L::Target: Logger {
                let mut spendable_output = None;
                for (i, outp) in tx.output.iter().enumerate() { // There is max one spendable output for any channel tx, including ones generated by us
-                       if i > ::std::u16::MAX as usize {
+                       if i > ::core::u16::MAX as usize {
                                // While it is possible that an output exists on chain which is greater than the
                                // 2^16th output in a given transaction, this is only possible if the output is not
                                // in a lightning transaction and was instead placed there by some third party who
index 249a2f524604b4a64b28d2753abc78e79b369417..114ceec211cd254fb22d14f64ac379960237f59b 100644 (file)
@@ -38,7 +38,7 @@ use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelP
 use ln::msgs::UnsignedChannelAnnouncement;
 
 use std::collections::HashSet;
-use std::sync::atomic::{AtomicUsize, Ordering};
+use core::sync::atomic::{AtomicUsize, Ordering};
 use std::io::Error;
 use ln::msgs::{DecodeError, MAX_VALUE_MSAT};
 
@@ -857,7 +857,7 @@ impl KeysManager {
        /// onchain output detection for which a corresponding delayed_payment_key must be derived.
        pub fn derive_channel_keys(&self, channel_value_satoshis: u64, params: &[u8; 32]) -> InMemorySigner {
                let chan_id = byte_utils::slice_to_be64(&params[0..8]);
-               assert!(chan_id <= std::u32::MAX as u64); // Otherwise the params field wasn't created by us
+               assert!(chan_id <= core::u32::MAX as u64); // Otherwise the params field wasn't created by us
                let mut unique_start = Sha256::engine();
                unique_start.input(params);
                unique_start.input(&self.seed);
@@ -1039,7 +1039,7 @@ impl KeysInterface for KeysManager {
 
        fn get_channel_signer(&self, _inbound: bool, channel_value_satoshis: u64) -> Self::Signer {
                let child_ix = self.channel_child_index.fetch_add(1, Ordering::AcqRel);
-               assert!(child_ix <= std::u32::MAX as usize);
+               assert!(child_ix <= core::u32::MAX as usize);
                let mut id = [0; 32];
                id[0..8].copy_from_slice(&byte_utils::be64_to_array(child_ix as u64));
                id[8..16].copy_from_slice(&byte_utils::be64_to_array(self.starting_time_nanos as u64));
index 2d62016e9ec53e35b771efb5bdce8fde860941fe..42c74da1326750c01f3a0b0670797a3bac8af815 100644 (file)
@@ -246,7 +246,7 @@ pub struct WatchedOutput {
        pub script_pubkey: Script,
 }
 
-impl<T: Listen> Listen for std::ops::Deref<Target = T> {
+impl<T: Listen> Listen for core::ops::Deref<Target = T> {
        fn block_connected(&self, block: &Block, height: u32) {
                (**self).block_connected(block, height);
        }
@@ -256,7 +256,7 @@ impl<T: Listen> Listen for std::ops::Deref<Target = T> {
        }
 }
 
-impl<T: std::ops::Deref, U: std::ops::Deref> Listen for (T, U)
+impl<T: core::ops::Deref, U: core::ops::Deref> Listen for (T, U)
 where
        T::Target: Listen,
        U::Target: Listen,
index 9bf9470458f8310f005788769d781b74055fd835..3c09f386753040320c27199086790b022944df26 100644 (file)
@@ -32,6 +32,7 @@
 #[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))] extern crate test;
 
 extern crate bitcoin;
+extern crate core;
 #[cfg(any(test, feature = "_test_utils"))] extern crate hex;
 #[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;
 
index 4438579657eecc74e6cf1cb9458b339c2db82292..9b44d11964534e9fb968cb6ebc49597225626d8d 100644 (file)
@@ -31,12 +31,12 @@ use bitcoin::secp256k1::{Secp256k1, Signature, Message};
 use bitcoin::secp256k1::Error as SecpError;
 use bitcoin::secp256k1;
 
-use std::cmp;
+use core::cmp;
 use ln::chan_utils;
 use util::transaction_utils::sort_outputs;
 use ln::channel::INITIAL_COMMITMENT_NUMBER;
 use std::io::Read;
-use std::ops::Deref;
+use core::ops::Deref;
 use chain;
 
 // Maximum size of a serialized HTLCOutputInCommitment
index a21375483da1e5982966243e2c7f0b2bcf1d6344..b940b45f7013e976e0c36d9abe1fde4de1c56ec1 100644 (file)
@@ -39,9 +39,8 @@ use util::errors::APIError;
 use util::config::{UserConfig,ChannelConfig};
 use util::scid_utils::scid_from_parts;
 
-use std;
-use std::{cmp,mem,fmt};
-use std::ops::Deref;
+use core::{cmp,mem,fmt};
+use core::ops::Deref;
 #[cfg(any(test, feature = "fuzztarget"))]
 use std::sync::Mutex;
 use bitcoin::hashes::hex::ToHex;
@@ -1220,7 +1219,7 @@ impl<Signer: Sign> Channel<Signer> {
                // on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
                // these, but for now we just have to treat them as normal.
 
-               let mut pending_idx = std::usize::MAX;
+               let mut pending_idx = core::usize::MAX;
                for (idx, htlc) in self.pending_inbound_htlcs.iter().enumerate() {
                        if htlc.htlc_id == htlc_id_arg {
                                assert_eq!(htlc.payment_hash, payment_hash_calc);
@@ -1243,7 +1242,7 @@ impl<Signer: Sign> Channel<Signer> {
                                break;
                        }
                }
-               if pending_idx == std::usize::MAX {
+               if pending_idx == core::usize::MAX {
                        return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
                }
 
@@ -1342,7 +1341,7 @@ impl<Signer: Sign> Channel<Signer> {
                // on-chain ChannelsMonitors during block rescan. Ideally we'd figure out a way to drop
                // these, but for now we just have to treat them as normal.
 
-               let mut pending_idx = std::usize::MAX;
+               let mut pending_idx = core::usize::MAX;
                for (idx, htlc) in self.pending_inbound_htlcs.iter().enumerate() {
                        if htlc.htlc_id == htlc_id_arg {
                                match htlc.state {
@@ -1359,7 +1358,7 @@ impl<Signer: Sign> Channel<Signer> {
                                pending_idx = idx;
                        }
                }
-               if pending_idx == std::usize::MAX {
+               if pending_idx == core::usize::MAX {
                        return Err(ChannelError::Ignore("Unable to find a pending HTLC which matched the given HTLC ID".to_owned()));
                }
 
@@ -4410,8 +4409,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
 
                let mut key_data = VecWriter(Vec::new());
                self.holder_signer.write(&mut key_data)?;
-               assert!(key_data.0.len() < std::usize::MAX);
-               assert!(key_data.0.len() < std::u32::MAX as usize);
+               assert!(key_data.0.len() < core::usize::MAX);
+               assert!(key_data.0.len() < core::u32::MAX as usize);
                (key_data.0.len() as u32).write(writer)?;
                writer.write_all(&key_data.0[..])?;
 
index 52bd8ad1cdbd82fdba046839f3497c49c8a775f2..fe3be2aeca56d9dc089d3385afadd5921b24ebd4 100644 (file)
@@ -61,15 +61,15 @@ use util::chacha20::{ChaCha20, ChaChaReader};
 use util::logger::Logger;
 use util::errors::APIError;
 
-use std::{cmp, mem};
+use core::{cmp, mem};
 use std::collections::{HashMap, hash_map, HashSet};
 use std::io::{Cursor, Read};
 use std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard};
-use std::sync::atomic::{AtomicUsize, Ordering};
-use std::time::Duration;
+use core::sync::atomic::{AtomicUsize, Ordering};
+use core::time::Duration;
 #[cfg(any(test, feature = "allow_wallclock_use"))]
 use std::time::Instant;
-use std::ops::Deref;
+use core::ops::Deref;
 use bitcoin::hashes::hex::ToHex;
 
 // 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
        // be absurd. We ensure this by checking that at least 500 (our stated public contract on when
        // broadcast_node_announcement panics) of the maximum-length addresses would fit in a 64KB
        // message...
-       const HALF_MESSAGE_IS_ADDRS: u32 = ::std::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
+       const HALF_MESSAGE_IS_ADDRS: u32 = ::core::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
        #[deny(const_err)]
        #[allow(dead_code)]
        // ...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>
 mod tests {
        use ln::channelmanager::PersistenceNotifier;
        use std::sync::Arc;
-       use std::sync::atomic::{AtomicBool, Ordering};
+       use core::sync::atomic::{AtomicBool, Ordering};
        use std::thread;
-       use std::time::Duration;
+       use core::time::Duration;
 
        #[test]
        fn test_wait_timeout() {
index 99e5cd0994c9971cdc32383c70650184d024c879..cbe8cedf1dd1c41d958a46b1c3b8a4357e4186cc 100644 (file)
@@ -22,8 +22,8 @@
 //! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
 //! [messages]: crate::ln::msgs
 
-use std::{cmp, fmt};
-use std::marker::PhantomData;
+use core::{cmp, fmt};
+use core::marker::PhantomData;
 
 use bitcoin::bech32;
 use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5, WriteBase32};
index 78fd0644ccb7b1a47123cb77174239fb0c3c32a1..93e898d561fa0c2e305168ab538f6cbd0c704e41 100644 (file)
@@ -39,10 +39,10 @@ use bitcoin::hash_types::BlockHash;
 
 use bitcoin::secp256k1::key::PublicKey;
 
-use std::cell::RefCell;
+use core::cell::RefCell;
 use std::rc::Rc;
 use std::sync::Mutex;
-use std::mem;
+use core::mem;
 use std::collections::HashMap;
 
 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
 }
 
 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]) {
-       let conf_height = std::cmp::max(node_a.best_block_info().1 + 1, node_b.best_block_info().1 + 1);
+       let conf_height = core::cmp::max(node_a.best_block_info().1 + 1, node_b.best_block_info().1 + 1);
        create_chan_between_nodes_with_value_confirm_first(node_a, node_b, tx, conf_height);
        confirm_transaction_at(node_a, tx, conf_height);
        connect_blocks(node_a, CHAN_CONFIRM_DEPTH - 1);
index 17602e272fd4b70cc7dba312ab1c9732e0234c89..9f1769ff513c242f3f3f72c20e9683b53c4be203 100644 (file)
@@ -51,7 +51,7 @@ use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 use regex;
 
 use std::collections::{BTreeSet, HashMap, HashSet};
-use std::default::Default;
+use core::default::Default;
 use std::sync::Mutex;
 
 use ln::functional_test_utils::*;
index 5ae6955dcbfb62c82f18439385ce890b62f04a5d..3c1a549ada269adb56220aa3c021be3b9ec2b202 100644 (file)
@@ -32,8 +32,8 @@ use bitcoin::hash_types::{Txid, BlockHash};
 
 use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
 
-use std::{cmp, fmt};
-use std::fmt::Debug;
+use core::{cmp, fmt};
+use core::fmt::Debug;
 use std::io::Read;
 
 use util::events::MessageSendEventsProvider;
index c7b79bf2f9d668fce59c2da84d670de17ebbc67d..a51f265135f26cfac08a61f06c6743240b013687 100644 (file)
@@ -33,9 +33,9 @@ use util::ser::{Readable, ReadableArgs, Writer, Writeable, VecWriter};
 use util::byte_utils;
 
 use std::collections::HashMap;
-use std::cmp;
-use std::ops::Deref;
-use std::mem::replace;
+use core::cmp;
+use core::ops::Deref;
+use core::mem::replace;
 
 const MAX_ALLOC_SIZE: usize = 64*1024;
 
@@ -220,7 +220,7 @@ impl Readable for Option<Vec<Option<(usize, Signature)>>> {
                        0u8 => Ok(None),
                        1u8 => {
                                let vlen: u64 = Readable::read(reader)?;
-                               let mut ret = Vec::with_capacity(cmp::min(vlen as usize, MAX_ALLOC_SIZE / ::std::mem::size_of::<Option<(usize, Signature)>>()));
+                               let mut ret = Vec::with_capacity(cmp::min(vlen as usize, MAX_ALLOC_SIZE / ::core::mem::size_of::<Option<(usize, Signature)>>()));
                                for _ in 0..vlen {
                                        ret.push(match Readable::read(reader)? {
                                                0u8 => None,
@@ -320,8 +320,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
 
                let mut key_data = VecWriter(Vec::new());
                self.signer.write(&mut key_data)?;
-               assert!(key_data.0.len() < std::usize::MAX);
-               assert!(key_data.0.len() < std::u32::MAX as usize);
+               assert!(key_data.0.len() < core::usize::MAX);
+               assert!(key_data.0.len() < core::u32::MAX as usize);
                (key_data.0.len() as u32).write(writer)?;
                writer.write_all(&key_data.0[..])?;
 
@@ -711,7 +711,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                log_trace!(logger, "Updating claims view at height {} with {} matched transactions and {} claim requests", height, txn_matched.len(), claimable_outpoints.len());
                let mut new_claims = Vec::new();
                let mut aggregated_claim = HashMap::new();
-               let mut aggregated_soonest = ::std::u32::MAX;
+               let mut aggregated_soonest = ::core::u32::MAX;
 
                // Try to aggregate outputs if their timelock expiration isn't imminent (absolute_timelock
                // <= CLTV_SHARED_CLAIM_BUFFER) and they don't require an immediate nLockTime (aggregable).
index 6f178d2136e30be5c9b4e03a6ea6612f3c575191..e3184fc65bb711f824636df7dc020f3342f79a04 100644 (file)
@@ -32,7 +32,7 @@ use bitcoin::hashes::Hash;
 use bitcoin::secp256k1::Secp256k1;
 use bitcoin::secp256k1::key::SecretKey;
 
-use std::default::Default;
+use core::default::Default;
 use std::io;
 
 use ln::functional_test_utils::*;
index 6d9118e21a8e38529e4ab5f93f8109c5b21a1363..07686a214e23c90c3e1166bca19580da55309777 100644 (file)
@@ -28,7 +28,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1;
 
 use std::io::Cursor;
-use std::ops::Deref;
+use core::ops::Deref;
 
 pub(super) struct OnionKeys {
        #[cfg(test)]
index d38d5ae6a166814e1c98afc1e5550fa077a6cb43..dd8619bf275b424263b014d349540ef68456238c 100644 (file)
@@ -25,7 +25,7 @@ use bitcoin::hashes::hex::ToHex;
 /// Maximum Lightning message data length according to
 /// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
 /// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
-pub const LN_MAX_MSG_LEN: usize = ::std::u16::MAX as usize; // Must be equal to 65535
+pub const LN_MAX_MSG_LEN: usize = ::core::u16::MAX as usize; // Must be equal to 65535
 
 // Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
 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 {
        #[test]
        fn max_msg_len_limit_value() {
                assert_eq!(LN_MAX_MSG_LEN, 65535);
-               assert_eq!(LN_MAX_MSG_LEN, ::std::u16::MAX as usize);
+               assert_eq!(LN_MAX_MSG_LEN, ::core::u16::MAX as usize);
        }
 
        #[test]
index f9e79429913dac7815ada3b90a6f7c58a7519bb5..097e9928677bb4a288e8d44820a1fb7df9567e42 100644 (file)
@@ -32,9 +32,10 @@ use routing::network_graph::NetGraphMsgHandler;
 
 use std::collections::{HashMap,hash_map,HashSet,LinkedList};
 use std::sync::{Arc, Mutex};
-use std::sync::atomic::{AtomicUsize, Ordering};
-use std::{cmp, error, hash, fmt, mem};
-use std::ops::Deref;
+use core::sync::atomic::{AtomicUsize, Ordering};
+use core::{cmp, hash, fmt, mem};
+use core::ops::Deref;
+use std::error;
 
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
@@ -1420,9 +1421,8 @@ mod tests {
        use bitcoin::secp256k1::Secp256k1;
        use bitcoin::secp256k1::key::{SecretKey, PublicKey};
 
-       use std;
        use std::sync::{Arc, Mutex};
-       use std::sync::atomic::Ordering;
+       use core::sync::atomic::Ordering;
 
        #[derive(Clone)]
        struct FileDescriptor {
@@ -1435,8 +1435,8 @@ mod tests {
                }
        }
        impl Eq for FileDescriptor { }
-       impl std::hash::Hash for FileDescriptor {
-               fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
+       impl core::hash::Hash for FileDescriptor {
+               fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {
                        self.fd.hash(hasher)
                }
        }
index e5feeb25e4266f29975ec7e8f8020e923b4da52c..6906e724d26daef663e1eb53f794bbfb09b9c145 100644 (file)
@@ -23,7 +23,7 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::hash_types::BlockHash;
 
 use std::collections::HashMap;
-use std::mem;
+use core::mem;
 
 use ln::functional_test_utils::*;
 
index 12e77d07f698f851b0430a638d8595c111fd0595..532ebbf312511da55c6fc1f1c021b4d64d41d1e3 100644 (file)
@@ -105,8 +105,8 @@ impl MessageType {
        }
 }
 
-impl ::std::fmt::Display for MessageType {
-       fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+impl ::core::fmt::Display for MessageType {
+       fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
                write!(f, "{}", self.0)
        }
 }
@@ -396,12 +396,12 @@ mod tests {
 
        #[test]
        fn read_unknown_message() {
-               let buffer = &byte_utils::be16_to_array(::std::u16::MAX);
+               let buffer = &byte_utils::be16_to_array(::core::u16::MAX);
                let mut reader = ::std::io::Cursor::new(buffer);
                let message = read(&mut reader).unwrap();
                match message {
-                       Message::Unknown(MessageType(::std::u16::MAX)) => (),
-                       _ => panic!("Expected message type {}; found: {}", ::std::u16::MAX, message.type_id()),
+                       Message::Unknown(MessageType(::core::u16::MAX)) => (),
+                       _ => panic!("Expected message type {}; found: {}", ::core::u16::MAX, message.type_id()),
                }
        }
 
@@ -411,7 +411,7 @@ mod tests {
                let mut buffer = Vec::new();
                assert!(write(&message, &mut buffer).is_ok());
 
-               let type_length = ::std::mem::size_of::<u16>();
+               let type_length = ::core::mem::size_of::<u16>();
                let (type_bytes, payload_bytes) = buffer.split_at(type_length);
                assert_eq!(byte_utils::slice_to_be16(type_bytes), msgs::Pong::TYPE);
                assert_eq!(payload_bytes, &ENCODED_PONG[type_length..]);
index 765a3430f579c033b31b674ae6071ab94b125330..ee73dc0e88e3c4e5308776b9c1dac0908602bc29 100644 (file)
@@ -32,13 +32,13 @@ use util::logger::Logger;
 use util::events::{MessageSendEvent, MessageSendEventsProvider};
 use util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
 
-use std::{cmp, fmt};
+use core::{cmp, fmt};
 use std::sync::{RwLock, RwLockReadGuard};
-use std::sync::atomic::{AtomicUsize, Ordering};
+use core::sync::atomic::{AtomicUsize, Ordering};
 use std::sync::Mutex;
 use std::collections::BTreeMap;
 use std::collections::btree_map::Entry as BtreeEntry;
-use std::ops::Deref;
+use core::ops::Deref;
 use bitcoin::hashes::hex::ToHex;
 
 /// The maximum number of extra bytes which we do not understand in a gossip message before we will
@@ -423,7 +423,7 @@ where
        fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
                let mut ret = Vec::new();
                let mut pending_events = self.pending_events.lock().unwrap();
-               std::mem::swap(&mut ret, &mut pending_events);
+               core::mem::swap(&mut ret, &mut pending_events);
                ret
        }
 }
index ca7f30e30631a9679938a6a7eec0ebf371adf8a4..ba964d734c670e4cfbbc4d12eca1ea9e71f37491 100644 (file)
@@ -21,9 +21,9 @@ use routing::network_graph::{NetworkGraph, RoutingFees};
 use util::ser::{Writeable, Readable};
 use util::logger::Logger;
 
-use std::cmp;
+use core::cmp;
 use std::collections::{HashMap, BinaryHeap};
-use std::ops::Deref;
+use core::ops::Deref;
 
 /// A hop in a route
 #[derive(Clone, PartialEq)]
@@ -3872,7 +3872,7 @@ mod tests {
 
        pub(super) fn random_init_seed() -> u64 {
                // Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
-               use std::hash::{BuildHasher, Hasher};
+               use core::hash::{BuildHasher, Hasher};
                let seed = std::collections::hash_map::RandomState::new().build_hasher().finish();
                println!("Using seed of {}", seed);
                seed
index c23856b60c8d69fb412e04f2eb3934b8ac29ff35..e8c6e229c1c00129cc22ace046845c1d6b5e5922 100644 (file)
@@ -13,13 +13,13 @@ use std::io;
 
 #[cfg(not(feature = "fuzztarget"))]
 mod real_chacha {
-       use std::cmp;
+       use core::cmp;
        use util::byte_utils::{slice_to_le32, le32_to_array};
 
        #[derive(Clone, Copy, PartialEq, Eq)]
        #[allow(non_camel_case_types)]
        struct u32x4(pub u32, pub u32, pub u32, pub u32);
-       impl ::std::ops::Add for u32x4 {
+       impl ::core::ops::Add for u32x4 {
                type Output = u32x4;
                fn add(self, rhs: u32x4) -> u32x4 {
                        u32x4(self.0.wrapping_add(rhs.0),
@@ -28,7 +28,7 @@ mod real_chacha {
                              self.3.wrapping_add(rhs.3))
                }
        }
-       impl ::std::ops::Sub for u32x4 {
+       impl ::core::ops::Sub for u32x4 {
                type Output = u32x4;
                fn sub(self, rhs: u32x4) -> u32x4 {
                        u32x4(self.0.wrapping_sub(rhs.0),
@@ -37,19 +37,19 @@ mod real_chacha {
                              self.3.wrapping_sub(rhs.3))
                }
        }
-       impl ::std::ops::BitXor for u32x4 {
+       impl ::core::ops::BitXor for u32x4 {
                type Output = u32x4;
                fn bitxor(self, rhs: u32x4) -> u32x4 {
                        u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3)
                }
        }
-       impl ::std::ops::Shr<u32x4> for u32x4 {
+       impl ::core::ops::Shr<u32x4> for u32x4 {
                type Output = u32x4;
                fn shr(self, rhs: u32x4) -> u32x4 {
                        u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3)
                }
        }
-       impl ::std::ops::Shl<u32x4> for u32x4 {
+       impl ::core::ops::Shl<u32x4> for u32x4 {
                type Output = u32x4;
                fn shl(self, rhs: u32x4) -> u32x4 {
                        u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3)
@@ -318,7 +318,7 @@ impl<'a, R: io::Read> io::Read for ChaChaReader<'a, R> {
 
 #[cfg(test)]
 mod test {
-       use std::iter::repeat;
+       use core::iter::repeat;
 
        use super::ChaCha20;
 
index c2908836c8078b311c16c3ae4690fe36ac361ab7..32c17af64dd877efcd8c07a7698e0049bdc739bd 100644 (file)
@@ -11,7 +11,7 @@ use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, HolderCommitment
 use ln::{chan_utils, msgs};
 use chain::keysinterface::{Sign, InMemorySigner, BaseSign};
 
-use std::cmp;
+use core::cmp;
 use std::sync::{Mutex, Arc};
 
 use bitcoin::blockdata::transaction::{Transaction, SigHashType};
index f67621c828ca521f4739d99ec5a54760310cb1a8..b47e134efab29524c220c7781bb2d610d72dbf2e 100644 (file)
@@ -9,7 +9,7 @@
 
 //! Error types live here.
 
-use std::fmt;
+use core::fmt;
 
 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
 /// too-high values)
index 599ed2afa68c0b7d2363904959a6daadb9a72c10..b7b8bf3137b8ea44d6d667842c3b2473b7a8790e 100644 (file)
@@ -23,7 +23,7 @@ use bitcoin::blockdata::script::Script;
 
 use bitcoin::secp256k1::key::PublicKey;
 
-use std::time::Duration;
+use core::time::Duration;
 
 /// An Event which you should probably take some action in response to.
 ///
index 2cf0f13633661a5ae6eed6ed180ddc3978fdaa26..df2b7f704051958a1e8ddc63523108061c8cfb08 100644 (file)
@@ -14,8 +14,8 @@
 //! The second one, client-side by implementing check against Record Level field.
 //! Each module may have its own Logger or share one.
 
-use std::cmp;
-use std::fmt;
+use core::cmp;
+use core::fmt;
 
 static LOG_LEVEL_NAMES: [&'static str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"];
 
index 330d31b683b56d5f8cef7ff1901061005986c083..c4630c638c7568aa5a2d9bbfc6835985a4260866 100644 (file)
@@ -17,11 +17,9 @@ use bitcoin::secp256k1::key::PublicKey;
 use routing::router::Route;
 use ln::chan_utils::HTLCType;
 
-use std;
-
 pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey);
-impl<'a> std::fmt::Display for DebugPubKey<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugPubKey<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                for i in self.0.serialize().iter() {
                        write!(f, "{:02x}", i)?;
                }
@@ -35,8 +33,8 @@ macro_rules! log_pubkey {
 }
 
 pub(crate) struct DebugBytes<'a>(pub &'a [u8]);
-impl<'a> std::fmt::Display for DebugBytes<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugBytes<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                for i in self.0 {
                        write!(f, "{:02x}", i)?;
                }
@@ -50,8 +48,8 @@ macro_rules! log_bytes {
 }
 
 pub(crate) struct DebugFundingChannelId<'a>(pub &'a Txid, pub u16);
-impl<'a> std::fmt::Display for DebugFundingChannelId<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugFundingChannelId<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                for i in (OutPoint { txid: self.0.clone(), index: self.1 }).to_channel_id().iter() {
                        write!(f, "{:02x}", i)?;
                }
@@ -65,8 +63,8 @@ macro_rules! log_funding_channel_id {
 }
 
 pub(crate) struct DebugFundingInfo<'a, T: 'a>(pub &'a (OutPoint, T));
-impl<'a, T> std::fmt::Display for DebugFundingInfo<'a, T> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a, T> core::fmt::Display for DebugFundingInfo<'a, T> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                DebugBytes(&(self.0).0.to_channel_id()[..]).fmt(f)
        }
 }
@@ -77,8 +75,8 @@ macro_rules! log_funding_info {
 }
 
 pub(crate) struct DebugRoute<'a>(pub &'a Route);
-impl<'a> std::fmt::Display for DebugRoute<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugRoute<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                for (idx, p) in self.0.paths.iter().enumerate() {
                        writeln!(f, "path {}:", idx)?;
                        for h in p.iter() {
@@ -95,8 +93,8 @@ macro_rules! log_route {
 }
 
 pub(crate) struct DebugTx<'a>(pub &'a Transaction);
-impl<'a> std::fmt::Display for DebugTx<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugTx<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                if self.0.input.len() >= 1 && self.0.input.iter().any(|i| !i.witness.is_empty()) {
                        if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 &&
                                        (self.0.input[0].sequence >> 8*3) as u8 == 0x80 {
@@ -134,8 +132,8 @@ macro_rules! log_tx {
 }
 
 pub(crate) struct DebugSpendable<'a>(pub &'a SpendableOutputDescriptor);
-impl<'a> std::fmt::Display for DebugSpendable<'a> {
-       fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+impl<'a> core::fmt::Display for DebugSpendable<'a> {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
                match self.0 {
                        &SpendableOutputDescriptor::StaticOutput { ref outpoint, .. } => {
                                write!(f, "StaticOutput {}:{} marked for spending", outpoint.txid, outpoint.index)?;
index b73ba2b4c0c0e108f9d2e0688c48f5379de08936..1ad1ea5ed3571582dc67e8e4187c7d06175b2680 100644 (file)
@@ -82,7 +82,7 @@ pub fn verify(msg: &[u8], sig: &str, pk: PublicKey) -> bool {
 
 #[cfg(test)]
 mod test {
-    use std::str::FromStr;
+    use core::str::FromStr;
     use util::message_signing::{sign, recover_pk, verify};
     use bitcoin::secp256k1::key::ONE_KEY;
     use bitcoin::secp256k1::{PublicKey, Secp256k1};
index d5173f2e27ea28f56cfb3313af3d4599842fa931..c6dbb43dd0d455f3538bcfb5d6edc9af101d6688 100644 (file)
@@ -7,7 +7,7 @@
 // This is a port of Andrew Moons poly1305-donna
 // https://github.com/floodyberry/poly1305-donna
 
-use std::cmp::min;
+use core::cmp::min;
 use util::byte_utils::{slice_to_le32, le32_to_array};
 
 #[derive(Clone, Copy)]
@@ -205,7 +205,7 @@ impl Poly1305 {
 
 #[cfg(test)]
 mod test {
-       use std::iter::repeat;
+       use core::iter::repeat;
 
        use util::poly1305::Poly1305;
 
index c31fcaa1ff6de28eb450f770182414145cda1909..66c89aa83913177bf6b31c9d5abb90c94c022884 100644 (file)
@@ -12,9 +12,9 @@
 
 use std::io::{Read, Write};
 use std::collections::HashMap;
-use std::hash::Hash;
+use core::hash::Hash;
 use std::sync::Mutex;
-use std::cmp;
+use core::cmp;
 
 use bitcoin::secp256k1::Signature;
 use bitcoin::secp256k1::key::{PublicKey, SecretKey};
@@ -25,7 +25,7 @@ use bitcoin::consensus;
 use bitcoin::consensus::Encodable;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hash_types::{Txid, BlockHash};
-use std::marker::Sized;
+use core::marker::Sized;
 use ln::msgs::DecodeError;
 use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
 use util::byte_utils;
index 00c346a80cb8c48c31f6aae7e61f527647df82ba..c167c3412637408ae4008921ee9360dfc9b7f932 100644 (file)
@@ -36,10 +36,10 @@ use bitcoin::secp256k1::recovery::RecoverableSignature;
 
 use regex;
 
-use std::time::Duration;
+use core::time::Duration;
 use std::sync::{Mutex, Arc};
-use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
-use std::{cmp, mem};
+use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
+use core::{cmp, mem};
 use std::collections::{HashMap, HashSet, VecDeque};
 use chain::keysinterface::InMemorySigner;
 
@@ -624,8 +624,8 @@ impl OnRegisterOutput {
        }
 }
 
-impl std::fmt::Debug for OnRegisterOutput {
-       fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+impl core::fmt::Debug for OnRegisterOutput {
+       fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                f.debug_struct("OnRegisterOutput")
                        .field("outpoint", &self.outpoint())
                        .field("script_pubkey", self.script_pubkey())
index 1984b480586a7c1da99254c4cdf9413b9964720f..34d0fb275764a339ce13c9b50bef0eaebda43683 100644 (file)
@@ -14,7 +14,7 @@ use bitcoin::consensus::encode::VarInt;
 
 use ln::msgs::MAX_VALUE_MSAT;
 
-use std::cmp::Ordering;
+use core::cmp::Ordering;
 
 pub fn sort_outputs<T, C : Fn(&T, &T) -> Ordering>(outputs: &mut Vec<(TxOut, T)>, tie_breaker: C) {
        outputs.sort_unstable_by(|a, b| {