Skip to content

Use core replacements for std members #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
12 changes: 6 additions & 6 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
Expand All @@ -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)?);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lightning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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()));
}

Expand Down Expand Up @@ -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[..])?;

Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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[..])?;

Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/peer_channel_encryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down
Loading