From d639da9d234e4ae6423fc012a6498140396665a3 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 20 Mar 2024 19:14:40 +0000 Subject: [PATCH 1/9] Fix new warnings causing CI build failures on rustc beta --- lightning-rapid-gossip-sync/src/processing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning-rapid-gossip-sync/src/processing.rs b/lightning-rapid-gossip-sync/src/processing.rs index 9023b9ba38c..b3fae0ffd8b 100644 --- a/lightning-rapid-gossip-sync/src/processing.rs +++ b/lightning-rapid-gossip-sync/src/processing.rs @@ -19,7 +19,7 @@ use crate::{GraphSyncError, RapidGossipSync}; #[cfg(all(feature = "std", not(test)))] use std::time::{SystemTime, UNIX_EPOCH}; -#[cfg(not(feature = "std"))] +#[cfg(all(not(feature = "std"), not(test)))] use alloc::{vec::Vec, borrow::ToOwned}; /// The purpose of this prefix is to identify the serialization format, should other rapid gossip From fb3a86f498f971dc01fdd58b166031793ff1bc1a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 20 Mar 2024 20:40:41 +0000 Subject: [PATCH 2/9] Debug more information when we fail to find a lock call symbol --- lightning/src/sync/debug_sync.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightning/src/sync/debug_sync.rs b/lightning/src/sync/debug_sync.rs index 2b75e095380..5968a79ee4d 100644 --- a/lightning/src/sync/debug_sync.rs +++ b/lightning/src/sync/debug_sync.rs @@ -103,7 +103,9 @@ fn locate_call_symbol(backtrace: &Backtrace) -> (String, Option) { } } } - let symbol = symbol_after_latest_debug_sync.expect("Couldn't find lock call symbol"); + let symbol = symbol_after_latest_debug_sync.unwrap_or_else(|| { + panic!("Couldn't find lock call symbol in trace {:?}", backtrace); + }); (format!("{}:{}", symbol.filename().unwrap().display(), symbol.lineno().unwrap()), symbol.colno()) } From cd327089a8c719844b776601e9ccd0728777ac28 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 15:18:22 +0000 Subject: [PATCH 3/9] Allow(unused_imports) on prelude imports New rustc now warns on duplicate imports when one of the imports is from a wildcard import or the default prelude. Thus, because we often don't actually use the imports from our prelude (as they exist to duplicate the `std` default prelude), we have to mark most of our `crate::prelude` imports with `#[allow(unused_imports)]`, which we do here. --- lightning/src/blinded_path/message.rs | 4 +++- lightning/src/blinded_path/payment.rs | 4 +++- lightning/src/blinded_path/utils.rs | 2 ++ lightning/src/chain/channelmonitor.rs | 4 ++++ lightning/src/chain/mod.rs | 1 + lightning/src/chain/package.rs | 4 +++- lightning/src/events/mod.rs | 4 +++- lightning/src/ln/chan_utils.rs | 8 ++++++-- lightning/src/ln/features.rs | 5 ++++- lightning/src/ln/mod.rs | 2 ++ lightning/src/ln/msgs.rs | 6 +++++- lightning/src/ln/onion_payment.rs | 2 ++ lightning/src/ln/onion_utils.rs | 8 ++++++-- lightning/src/ln/peer_handler.rs | 6 +++++- lightning/src/offers/invoice.rs | 3 ++- lightning/src/offers/invoice_error.rs | 1 + lightning/src/offers/invoice_request.rs | 1 + lightning/src/offers/merkle.rs | 1 + lightning/src/offers/offer.rs | 1 + lightning/src/offers/parse.rs | 2 ++ lightning/src/offers/payer.rs | 1 + lightning/src/offers/refund.rs | 1 + lightning/src/routing/test_utils.rs | 1 + lightning/src/sign/ecdsa.rs | 2 ++ lightning/src/util/base32.rs | 2 +- lightning/src/util/invoice.rs | 2 ++ lightning/src/util/message_signing.rs | 1 + lightning/src/util/ser_macros.rs | 4 +++- lightning/src/util/test_channel_signer.rs | 2 ++ lightning/src/util/transaction_utils.rs | 2 ++ lightning/src/util/wakers.rs | 1 + 31 files changed, 74 insertions(+), 14 deletions(-) diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 3a5541fa146..bdcbd7726f7 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -1,12 +1,14 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey}; +#[allow(unused_imports)] +use crate::prelude::*; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::blinded_path::utils; use crate::io; use crate::io::Cursor; use crate::ln::onion_utils; use crate::onion_message::packet::ControlTlvs; -use crate::prelude::*; use crate::sign::{NodeSigner, Recipient}; use crate::crypto::streams::ChaChaPolyReadAdapter; use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Writeable, Writer}; diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 6467af56888..c77e4e33e5a 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -12,9 +12,11 @@ use crate::ln::channelmanager::CounterpartyForwardingInfo; use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs::DecodeError; use crate::offers::invoice::BlindedPayInfo; -use crate::prelude::*; use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer}; +#[allow(unused_imports)] +use crate::prelude::*; + use core::convert::TryFrom; /// An intermediate node, its outbound channel, and relay parameters. diff --git a/lightning/src/blinded_path/utils.rs b/lightning/src/blinded_path/utils.rs index d4894a86aa1..7e43f314536 100644 --- a/lightning/src/blinded_path/utils.rs +++ b/lightning/src/blinded_path/utils.rs @@ -23,6 +23,8 @@ use crate::crypto::streams::ChaChaPolyWriteAdapter; use crate::util::ser::{Readable, Writeable}; use crate::io; + +#[allow(unused_imports)] use crate::prelude::*; // TODO: DRY with onion_utils::construct_onion_keys_callback diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 4352076e94d..b878640d46d 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -53,7 +53,9 @@ use crate::util::byte_utils; use crate::events::{ClosureReason, Event, EventHandler}; use crate::events::bump_transaction::{AnchorDescriptor, BumpTransactionEvent}; +#[allow(unused_imports)] use crate::prelude::*; + use core::{cmp, mem}; use crate::io::{self, Error}; use core::convert::TryInto; @@ -4765,6 +4767,8 @@ mod tests { use crate::sync::{Arc, Mutex}; use crate::io; use crate::ln::features::ChannelTypeFeatures; + + #[allow(unused_imports)] use crate::prelude::*; use std::str::FromStr; diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 356520b5cba..e22ccca986a 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -21,6 +21,7 @@ use crate::ln::ChannelId; use crate::sign::ecdsa::WriteableEcdsaChannelSigner; use crate::chain::transaction::{OutPoint, TransactionData}; +#[allow(unused_imports)] use crate::prelude::*; pub mod chaininterface; diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index e304b16ef3e..8c833707eed 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -35,12 +35,14 @@ use crate::util::logger::Logger; use crate::util::ser::{Readable, Writer, Writeable, RequiredWrapper}; use crate::io; -use crate::prelude::*; use core::cmp; use core::convert::TryInto; use core::mem; use core::ops::Deref; +#[allow(unused_imports)] +use crate::prelude::*; + use super::chaininterface::LowerBoundedFeeEstimator; const MAX_ALLOC_SIZE: usize = 64*1024; diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index b43f2f9370d..f6e7f716487 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -38,11 +38,13 @@ use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::PublicKey; use crate::io; -use crate::prelude::*; use core::time::Duration; use core::ops::Deref; use crate::sync::Arc; +#[allow(unused_imports)] +use crate::prelude::*; + /// Some information provided on receipt of payment depends on whether the payment received is a /// spontaneous payment or a "conventional" lightning payment that's paying an invoice. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 18c4d83406c..c002dfaea25 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -37,7 +37,6 @@ use bitcoin::{secp256k1, Sequence, Witness}; use bitcoin::PublicKey as BitcoinPublicKey; use crate::io; -use crate::prelude::*; use core::cmp; use crate::ln::chan_utils; use crate::util::transaction_utils::sort_outputs; @@ -48,6 +47,9 @@ use crate::ln::features::ChannelTypeFeatures; use crate::crypto::utils::{sign, sign_with_aux_rand}; use super::channel_keys::{DelayedPaymentBasepoint, DelayedPaymentKey, HtlcKey, HtlcBasepoint, RevocationKey, RevocationBasepoint}; +#[allow(unused_imports)] +use crate::prelude::*; + /// Maximum number of one-way in-flight HTLC (protocol-level value). pub const MAX_HTLCS: u16 = 483; /// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, non-anchor variant. @@ -1812,7 +1814,6 @@ pub fn get_commitment_transaction_number_obscure_factor( mod tests { use super::{CounterpartyCommitmentSecrets, ChannelPublicKeys}; use crate::chain; - use crate::prelude::*; use crate::ln::chan_utils::{get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript, CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment}; use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1}; use crate::util::test_utils; @@ -1825,6 +1826,9 @@ mod tests { use bitcoin::PublicKey as BitcoinPublicKey; use crate::ln::features::ChannelTypeFeatures; + #[allow(unused_imports)] + use crate::prelude::*; + struct TestCommitmentTxBuilder { commitment_number: u64, holder_funding_pubkey: PublicKey, diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 04ce90445f9..ff91654a3f7 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -78,8 +78,10 @@ //! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md //! [messages]: crate::ln::msgs -use crate::{io, io_extras}; +#[allow(unused_imports)] use crate::prelude::*; + +use crate::{io, io_extras}; use core::{cmp, fmt}; use core::borrow::Borrow; use core::hash::{Hash, Hasher}; @@ -91,6 +93,7 @@ use crate::ln::msgs::DecodeError; use crate::util::ser::{Readable, WithoutLength, Writeable, Writer}; mod sealed { + #[allow(unused_imports)] use crate::prelude::*; use crate::ln::features::Features; diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index 25b32c4c79d..26a384dffd4 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -126,7 +126,9 @@ impl From for PaymentHash { #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)] pub struct PaymentSecret(pub [u8; 32]); +#[allow(unused_imports)] use crate::prelude::*; + use bitcoin::bech32; use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5}; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 19fbbae3166..9424d341de2 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -38,7 +38,9 @@ use crate::ln::onion_utils; use crate::onion_message; use crate::sign::{NodeSigner, Recipient}; +#[allow(unused_imports)] use crate::prelude::*; + #[cfg(feature = "std")] use core::convert::TryFrom; use core::fmt; @@ -1673,11 +1675,13 @@ pub struct FinalOnionHopData { mod fuzzy_internal_msgs { use bitcoin::secp256k1::PublicKey; use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay}; - use crate::prelude::*; use crate::ln::{PaymentPreimage, PaymentSecret}; use crate::ln::features::BlindedHopFeatures; use super::{FinalOnionHopData, TrampolineOnionPacket}; + #[allow(unused_imports)] + use crate::prelude::*; + // These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize // them from untrusted input): diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index a5560e28020..aa8ee0ce9be 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -20,7 +20,9 @@ use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING}; use crate::sign::{NodeSigner, Recipient}; use crate::util::logger::Logger; +#[allow(unused_imports)] use crate::prelude::*; + use core::ops::Deref; /// Invalid inbound onion payment. diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index a946dae6779..2cbc2895c0b 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -30,10 +30,12 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey}; use crate::io::{Cursor, Read}; -use crate::prelude::*; use core::convert::{AsMut, TryInto}; use core::ops::Deref; +#[allow(unused_imports)] +use crate::prelude::*; + pub(crate) struct OnionKeys { #[cfg(test)] pub(crate) shared_secret: SharedSecret, @@ -1240,10 +1242,12 @@ mod tests { use crate::ln::features::{ChannelFeatures, NodeFeatures}; use crate::ln::msgs; use crate::ln::PaymentHash; - use crate::prelude::*; use crate::routing::router::{Path, Route, RouteHop}; use crate::util::ser::{VecWriter, Writeable, Writer}; + #[allow(unused_imports)] + use crate::prelude::*; + use bitcoin::hashes::hex::FromHex; use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::{PublicKey, SecretKey}; diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index cfa32a009fe..e76da792adc 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -36,7 +36,9 @@ use crate::util::atomic_counter::AtomicCounter; use crate::util::logger::{Level, Logger, WithContext}; use crate::util::string::PrintableString; +#[allow(unused_imports)] use crate::prelude::*; + use crate::io; use alloc::collections::VecDeque; use crate::sync::{Mutex, MutexGuard, FairRwLock}; @@ -2648,11 +2650,13 @@ mod tests { use bitcoin::blockdata::constants::ChainHash; use bitcoin::secp256k1::{PublicKey, SecretKey}; - use crate::prelude::*; use crate::sync::{Arc, Mutex}; use core::convert::Infallible; use core::sync::atomic::{AtomicBool, Ordering}; + #[allow(unused_imports)] + use crate::prelude::*; + #[derive(Clone)] struct FileDescriptor { fd: u16, diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index fc837102348..9b54927048a 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1,4 +1,4 @@ -// This file is Copyright its original authors, visible in version control + // This file is Copyright its original authors, visible in version control // history. // // This file is licensed under the Apache License, Version 2.0 //! +#[allow(unused)] use crate::prelude::*; use crate::util::base32; use bitcoin::hashes::{sha256d, Hash}; diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index dce160a7c5e..312fe7d9f98 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -1112,8 +1112,10 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable { #[cfg(test)] mod tests { - use crate::io::{self, Cursor}; + #[allow(unused_imports)] use crate::prelude::*; + + use crate::io::{self, Cursor}; use crate::ln::msgs::DecodeError; use crate::util::ser::{Writeable, HighZeroBytesDroppedBigSize, VecWriter}; use bitcoin::hashes::hex::FromHex; diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index bfa3e32c91f..43ac9ff87e9 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -14,7 +14,9 @@ use crate::ln::{msgs, PaymentPreimage}; use crate::sign::{InMemorySigner, ChannelSigner}; use crate::sign::ecdsa::{EcdsaChannelSigner, WriteableEcdsaChannelSigner}; +#[allow(unused_imports)] use crate::prelude::*; + use core::cmp; use crate::sync::{Mutex, Arc}; #[cfg(test)] use crate::sync::MutexGuard; diff --git a/lightning/src/util/transaction_utils.rs b/lightning/src/util/transaction_utils.rs index 12b504a69ef..8b0ef3da013 100644 --- a/lightning/src/util/transaction_utils.rs +++ b/lightning/src/util/transaction_utils.rs @@ -14,7 +14,9 @@ use bitcoin::consensus::encode::VarInt; use crate::ln::msgs::MAX_VALUE_MSAT; +#[allow(unused_imports)] use crate::prelude::*; + use crate::io_extras::sink; use core::cmp::Ordering; diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index b2c9d21b998..6c0de2bfa85 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -17,6 +17,7 @@ use alloc::sync::Arc; use core::mem; use crate::sync::Mutex; +#[allow(unused_imports)] use crate::prelude::*; #[cfg(feature = "std")] From 061d396b074a8d8b2f7d83c316b158749e6dcdb5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 14:22:52 +0000 Subject: [PATCH 4/9] Add more `std` prelude items to `crate::prelude` New rustc beta now warns on duplicate imports when one of the imports is from a wildcard import or the default prelude. Thus, for simplicity, we need to make our `crate::prelude` mostly identical to the `std` one, allowing us to always simply use the `crate::prelude` and let it decide if we need to import anything. --- lightning/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 1adf3786b76..29fe76b49ad 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -170,6 +170,9 @@ mod prelude { pub use alloc::borrow::ToOwned; pub use alloc::string::ToString; + pub use core::convert::{TryFrom, TryInto}; + pub use core::marker::Sized; + pub(crate) use crate::util::hash_tables::*; } From ae0d825d89ca0ac2489737d1b413e778650b093c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 14:27:05 +0000 Subject: [PATCH 5/9] Use `crate::prelude::*` rather than specific imports New rustc beta now warns on duplicate imports when one of the imports is from a wildcard import or the default prelude. Thus, to avoid this here we prefer to always use `crate::prelude::*` and let it decide if we actually need to import anything. --- lightning-invoice/src/de.rs | 1 + lightning-invoice/src/utils.rs | 1 + lightning/src/blinded_path/payment.rs | 2 -- lightning/src/chain/chaininterface.rs | 3 ++- lightning/src/chain/channelmonitor.rs | 1 - lightning/src/chain/package.rs | 1 - lightning/src/crypto/chacha20.rs | 6 ++---- lightning/src/crypto/poly1305.rs | 4 ++-- lightning/src/lib.rs | 5 ++++- lightning/src/ln/channel.rs | 1 - lightning/src/ln/functional_tests.rs | 3 --- lightning/src/ln/inbound_payment.rs | 5 +++-- lightning/src/ln/msgs.rs | 3 --- lightning/src/ln/onion_route_tests.rs | 1 - lightning/src/ln/onion_utils.rs | 1 - lightning/src/ln/peer_handler.rs | 1 - lightning/src/ln/priv_short_conf_tests.rs | 1 - lightning/src/ln/reload_tests.rs | 1 - lightning/src/ln/script.rs | 10 +++++++--- lightning/src/ln/shutdown_tests.rs | 6 +----- lightning/src/ln/wire.rs | 1 - lightning/src/offers/invoice.rs | 5 +++-- lightning/src/offers/invoice_request.rs | 2 -- lightning/src/offers/merkle.rs | 1 - lightning/src/offers/offer.rs | 2 -- lightning/src/offers/parse.rs | 2 -- lightning/src/offers/refund.rs | 5 +++-- lightning/src/offers/signer.rs | 1 - lightning/src/offers/test_utils.rs | 5 ++++- lightning/src/onion_message/offers.rs | 1 - lightning/src/routing/gossip.rs | 1 - lightning/src/routing/router.rs | 11 +++-------- lightning/src/routing/scoring.rs | 1 - lightning/src/routing/utxo.rs | 1 - lightning/src/sign/mod.rs | 1 - lightning/src/util/errors.rs | 4 +++- lightning/src/util/indexed_map.rs | 2 -- lightning/src/util/persist.rs | 3 --- lightning/src/util/scid_utils.rs | 2 +- lightning/src/util/ser.rs | 4 +--- lightning/src/util/string.rs | 4 +++- lightning/src/util/test_utils.rs | 3 --- lightning/src/util/transaction_utils.rs | 4 ++-- lightning/src/util/wakers.rs | 2 +- 44 files changed, 47 insertions(+), 78 deletions(-) diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index 9284999b188..56e5c53ba1f 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -1,5 +1,6 @@ #[cfg(feature = "std")] use std::error; +#[cfg(not(feature = "std"))] use core::convert::TryFrom; use core::fmt; use core::fmt::{Display, Formatter}; diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index d45a4e8e646..1d6b9210afd 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -19,6 +19,7 @@ use secp256k1::PublicKey; use alloc::collections::{btree_map, BTreeMap}; use core::ops::Deref; use core::time::Duration; +#[cfg(not(feature = "std"))] use core::iter::Iterator; /// Utility to create an invoice that can be paid to one of multiple nodes, or a "phantom invoice." diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index c77e4e33e5a..3d56020a626 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -17,8 +17,6 @@ use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer} #[allow(unused_imports)] use crate::prelude::*; -use core::convert::TryFrom; - /// An intermediate node, its outbound channel, and relay parameters. #[derive(Clone, Debug)] pub struct ForwardNode { diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 1f42dc2fe42..2bf6d6130e1 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -14,7 +14,8 @@ //! disconnections, transaction broadcasting, and feerate information requests. use core::{cmp, ops::Deref}; -use core::convert::TryInto; + +use crate::prelude::*; use bitcoin::blockdata::transaction::Transaction; diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index b878640d46d..c2d3a43b1f4 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -58,7 +58,6 @@ use crate::prelude::*; use core::{cmp, mem}; use crate::io::{self, Error}; -use core::convert::TryInto; use core::ops::Deref; use crate::sync::{Mutex, LockTestExt}; diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index 8c833707eed..3023be604d3 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -36,7 +36,6 @@ use crate::util::ser::{Readable, Writer, Writeable, RequiredWrapper}; use crate::io; use core::cmp; -use core::convert::TryInto; use core::mem; use core::ops::Deref; diff --git a/lightning/src/crypto/chacha20.rs b/lightning/src/crypto/chacha20.rs index d6fd3a7dee0..0c51d4562fe 100644 --- a/lightning/src/crypto/chacha20.rs +++ b/lightning/src/crypto/chacha20.rs @@ -12,7 +12,6 @@ #[cfg(not(fuzzing))] mod real_chacha { use core::cmp; - use core::convert::TryInto; #[derive(Clone, Copy, PartialEq, Eq)] #[allow(non_camel_case_types)] @@ -335,11 +334,10 @@ pub use self::fuzzy_chacha::ChaCha20; #[cfg(test)] mod test { - use alloc::vec; - use alloc::vec::{Vec}; - use core::convert::TryInto; use core::iter::repeat; + use crate::prelude::*; + use super::ChaCha20; #[test] diff --git a/lightning/src/crypto/poly1305.rs b/lightning/src/crypto/poly1305.rs index a1b9fbac516..59320021005 100644 --- a/lightning/src/crypto/poly1305.rs +++ b/lightning/src/crypto/poly1305.rs @@ -8,7 +8,8 @@ // https://github.com/floodyberry/poly1305-donna use core::cmp::min; -use core::convert::TryInto; + +use crate::prelude::*; #[derive(Clone, Copy)] pub struct Poly1305 { @@ -206,7 +207,6 @@ impl Poly1305 { #[cfg(test)] mod test { use core::iter::repeat; - use alloc::vec::Vec; use super::Poly1305; diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 29fe76b49ad..3b5a4ebfbf1 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -165,12 +165,15 @@ mod io_extras { } mod prelude { + #![allow(unused_imports)] + pub use alloc::{vec, vec::Vec, string::String, collections::VecDeque, boxed::Box}; pub use alloc::borrow::ToOwned; pub use alloc::string::ToString; - pub use core::convert::{TryFrom, TryInto}; + pub use core::convert::{AsMut, AsRef, TryFrom, TryInto}; + pub use core::default::Default; pub use core::marker::Sized; pub(crate) use crate::util::hash_tables::*; diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index ed8c861d7bb..2698abee2d7 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -50,7 +50,6 @@ use crate::util::scid_utils::scid_from_parts; use crate::io; use crate::prelude::*; use core::{cmp,mem,fmt}; -use core::convert::TryInto; use core::ops::Deref; #[cfg(any(test, fuzzing, debug_assertions))] use crate::sync::Mutex; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index eee9ef49b60..5ea3e6372c0 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -49,12 +49,9 @@ use bitcoin::OutPoint as BitcoinOutPoint; use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::{PublicKey,SecretKey}; -use regex; - use crate::io; use crate::prelude::*; use alloc::collections::BTreeSet; -use core::default::Default; use core::iter::repeat; use bitcoin::hashes::Hash; use crate::sync::{Arc, Mutex, RwLock}; diff --git a/lightning/src/ln/inbound_payment.rs b/lightning/src/ln/inbound_payment.rs index eeae514fdf3..f27d8aab119 100644 --- a/lightning/src/ln/inbound_payment.rs +++ b/lightning/src/ln/inbound_payment.rs @@ -9,7 +9,6 @@ //! Utilities to generate inbound payment information in service of invoice creation. -use alloc::string::ToString; use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::cmp::fixed_time_eq; use bitcoin::hashes::hmac::{Hmac, HmacEngine}; @@ -23,7 +22,9 @@ use crate::crypto::utils::hkdf_extract_expand_5x; use crate::util::errors::APIError; use crate::util::logger::Logger; -use core::convert::{TryFrom, TryInto}; +#[allow(unused_imports)] +use crate::prelude::*; + use core::ops::Deref; pub(crate) const IV_LEN: usize = 16; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 9424d341de2..8040d8c4209 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -41,8 +41,6 @@ use crate::sign::{NodeSigner, Recipient}; #[allow(unused_imports)] use crate::prelude::*; -#[cfg(feature = "std")] -use core::convert::TryFrom; use core::fmt; use core::fmt::Debug; use core::ops::Deref; @@ -3167,7 +3165,6 @@ impl_writeable_msg!(GossipTimestampFilter, { #[cfg(test)] mod tests { - use std::convert::TryFrom; use bitcoin::{Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut}; use hex::DisplayHex; use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 80c588e2562..aeb175bc626 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -39,7 +39,6 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; use crate::io; use crate::prelude::*; -use core::default::Default; use bitcoin::hashes::hex::FromHex; use crate::ln::functional_test_utils::*; diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 2cbc2895c0b..f2b5c69e9e6 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -30,7 +30,6 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey}; use crate::io::{Cursor, Read}; -use core::convert::{AsMut, TryInto}; use core::ops::Deref; #[allow(unused_imports)] diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index e76da792adc..0322de6428e 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -40,7 +40,6 @@ use crate::util::string::PrintableString; use crate::prelude::*; use crate::io; -use alloc::collections::VecDeque; use crate::sync::{Mutex, MutexGuard, FairRwLock}; use core::sync::atomic::{AtomicBool, AtomicU32, AtomicI32, Ordering}; use core::{cmp, hash, fmt, mem}; diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 3d799df8d73..6fd8623d317 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -26,7 +26,6 @@ use crate::util::ser::Writeable; use crate::util::test_utils; use crate::prelude::*; -use core::default::Default; use crate::ln::functional_test_utils::*; diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs index fa216bc15f4..8b25f7701be 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -27,7 +27,6 @@ use crate::util::config::UserConfig; use bitcoin::hash_types::BlockHash; use crate::prelude::*; -use core::default::Default; use crate::sync::Mutex; use crate::ln::functional_test_utils::*; diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index dc733dd25a1..1909eb0c5f7 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -12,9 +12,11 @@ use crate::ln::features::InitFeatures; use crate::ln::msgs::DecodeError; use crate::util::ser::{Readable, Writeable, Writer}; -use core::convert::TryFrom; use crate::io; +#[allow(unused_imports)] +use crate::prelude::*; + /// A script pubkey for shutting down a channel as defined by [BOLT #2]. /// /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md @@ -167,13 +169,15 @@ impl core::fmt::Display for ShutdownScript{ #[cfg(test)] mod shutdown_script_tests { use super::ShutdownScript; + + use bitcoin::address::{WitnessProgram, WitnessVersion}; use bitcoin::blockdata::opcodes; use bitcoin::blockdata::script::{Builder, ScriptBuf}; use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::{PublicKey, SecretKey}; + use crate::ln::features::InitFeatures; - use core::convert::TryFrom; - use bitcoin::address::{WitnessProgram, WitnessVersion}; + use crate::prelude::*; fn pubkey() -> bitcoin::key::PublicKey { let secp_ctx = Secp256k1::signing_only(); diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index c6d0cc58b9b..7f004948ffe 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -25,6 +25,7 @@ use crate::util::test_utils::OnGetShutdownScriptpubkey; use crate::util::errors::APIError; use crate::util::config::UserConfig; use crate::util::string::UntrustedString; +use crate::prelude::*; use bitcoin::{Transaction, TxOut}; use bitcoin::blockdata::locktime::absolute::LockTime; @@ -33,11 +34,6 @@ use bitcoin::blockdata::opcodes; use bitcoin::network::constants::Network; use bitcoin::address::{WitnessProgram, WitnessVersion}; -use regex; - -use core::default::Default; -use std::convert::TryFrom; - use crate::ln::functional_test_utils::*; #[test] diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index 5087df33b83..dc4eecde630 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -617,7 +617,6 @@ impl Encode for msgs::GossipTimestampFilter { mod tests { use super::*; use crate::prelude::*; - use core::convert::TryInto; use crate::ln::peer_handler::IgnoringMessageHandler; // Big-endian wire encoding of Pong message (type = 19, byteslen = 2). diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 9b54927048a..f2fb387942d 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -110,7 +110,6 @@ use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self}; use bitcoin::secp256k1::schnorr::Signature; use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion}; use bitcoin::key::TweakedPublicKey; -use core::convert::{AsRef, TryFrom}; use core::time::Duration; use crate::io; use crate::blinded_path::BlindedPath; @@ -1453,8 +1452,9 @@ mod tests { use bitcoin::secp256k1::{Message, Secp256k1, XOnlyPublicKey, self}; use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion}; use bitcoin::key::TweakedPublicKey; - use core::convert::TryFrom; + use core::time::Duration; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::sign::KeyMaterial; use crate::ln::features::{Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures}; @@ -1463,6 +1463,7 @@ mod tests { use crate::offers::invoice_request::InvoiceRequestTlvStreamRef; use crate::offers::merkle::{SignError, SignatureTlvStreamRef, TaggedHash, self}; use crate::offers::offer::{Amount, OfferTlvStreamRef, Quantity}; + use crate::prelude::*; #[cfg(not(c_bindings))] use { crate::offers::offer::OfferBuilder, diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 60df1fe4753..5e3ed40ac08 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -61,7 +61,6 @@ use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self}; use bitcoin::secp256k1::schnorr::Signature; -use core::convert::{AsRef, TryFrom}; use core::ops::Deref; use crate::sign::EntropySource; use crate::io; @@ -1104,7 +1103,6 @@ mod tests { use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::{KeyPair, Secp256k1, SecretKey, self}; - use core::convert::TryFrom; use core::num::NonZeroU64; #[cfg(feature = "std")] use core::time::Duration; diff --git a/lightning/src/offers/merkle.rs b/lightning/src/offers/merkle.rs index 8151631e6ef..da3fab58996 100644 --- a/lightning/src/offers/merkle.rs +++ b/lightning/src/offers/merkle.rs @@ -12,7 +12,6 @@ use bitcoin::hashes::{Hash, HashEngine, sha256}; use bitcoin::secp256k1::{Message, PublicKey, Secp256k1, self}; use bitcoin::secp256k1::schnorr::Signature; -use core::convert::AsRef; use crate::io; use crate::util::ser::{BigSize, Readable, Writeable, Writer}; diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index f9cc07b3117..7f48be23e00 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -79,7 +79,6 @@ use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self}; -use core::convert::TryFrom; use core::hash::{Hash, Hasher}; use core::num::NonZeroU64; use core::ops::Deref; @@ -1067,7 +1066,6 @@ mod tests { use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::Secp256k1; - use core::convert::TryFrom; use core::num::NonZeroU64; use core::time::Duration; use crate::blinded_path::{BlindedHop, BlindedPath}; diff --git a/lightning/src/offers/parse.rs b/lightning/src/offers/parse.rs index 00c48d9eae7..72c4c380d52 100644 --- a/lightning/src/offers/parse.rs +++ b/lightning/src/offers/parse.rs @@ -11,7 +11,6 @@ use bitcoin::bech32; use bitcoin::secp256k1; -use core::convert::TryFrom; use crate::io; use crate::ln::msgs::DecodeError; use crate::util::ser::SeekReadable; @@ -28,7 +27,6 @@ pub use sealed::Bech32Encode; mod sealed { use bitcoin::bech32; use bitcoin::bech32::{FromBase32, ToBase32}; - use core::convert::TryFrom; use core::fmt; use super::Bolt12ParseError; diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index 8e6c029f159..73b48521ae6 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -84,7 +84,6 @@ use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::{PublicKey, Secp256k1, self}; -use core::convert::TryFrom; use core::hash::{Hash, Hasher}; use core::ops::Deref; use core::str::FromStr; @@ -895,8 +894,9 @@ mod tests { use bitcoin::blockdata::constants::ChainHash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::{KeyPair, Secp256k1, SecretKey}; - use core::convert::TryFrom; + use core::time::Duration; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::sign::KeyMaterial; use crate::ln::channelmanager::PaymentId; @@ -910,6 +910,7 @@ mod tests { use crate::offers::test_utils::*; use crate::util::ser::{BigSize, Writeable}; use crate::util::string::PrintableString; + use crate::prelude::*; trait ToBytes { fn to_bytes(&self) -> Vec; diff --git a/lightning/src/offers/signer.rs b/lightning/src/offers/signer.rs index e0abd82767f..c5a96cbf184 100644 --- a/lightning/src/offers/signer.rs +++ b/lightning/src/offers/signer.rs @@ -14,7 +14,6 @@ use bitcoin::hashes::cmp::fixed_time_eq; use bitcoin::hashes::hmac::{Hmac, HmacEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey, self}; -use core::convert::TryFrom; use core::fmt; use crate::ln::channelmanager::PaymentId; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce}; diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 29bed53d83f..b4329803016 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -11,7 +11,7 @@ use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey}; use bitcoin::secp256k1::schnorr::Signature; -use core::convert::AsRef; + use core::time::Duration; use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::sign::EntropySource; @@ -20,6 +20,9 @@ use crate::ln::features::BlindedHopFeatures; use crate::offers::invoice::BlindedPayInfo; use crate::offers::merkle::TaggedHash; +#[allow(unused_imports)] +use crate::prelude::*; + pub(crate) fn fail_sign>(_message: &T) -> Result { Err(()) } diff --git a/lightning/src/onion_message/offers.rs b/lightning/src/onion_message/offers.rs index 6672b5dfcdd..faf539f8682 100644 --- a/lightning/src/onion_message/offers.rs +++ b/lightning/src/onion_message/offers.rs @@ -9,7 +9,6 @@ //! Message handling for BOLT 12 Offers. -use core::convert::TryFrom; use core::fmt; use crate::io::{self, Read}; use crate::ln::msgs::DecodeError; diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 045772486ba..42bf20a78a5 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -38,7 +38,6 @@ use crate::io; use crate::io_extras::{copy, sink}; use crate::prelude::*; use core::{cmp, fmt}; -use core::convert::TryFrom; use crate::sync::{RwLock, RwLockReadGuard, LockTestExt}; #[cfg(feature = "std")] use core::sync::atomic::{AtomicUsize, Ordering}; diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 8d37182266b..e8276712ee8 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -3259,8 +3259,6 @@ mod tests { use crate::prelude::*; use crate::sync::Arc; - use core::convert::TryInto; - fn get_channel_details(short_channel_id: Option, node_id: PublicKey, features: InitFeatures, outbound_capacity_msat: u64) -> channelmanager::ChannelDetails { channelmanager::ChannelDetails { @@ -8344,17 +8342,14 @@ pub(crate) mod bench_utils { use std::time::Duration; use bitcoin::hashes::Hash; - use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; + use bitcoin::secp256k1::SecretKey; use crate::chain::transaction::OutPoint; use crate::routing::scoring::ScoreUpdate; - use crate::sign::{EntropySource, KeysManager}; + use crate::sign::KeysManager; use crate::ln::ChannelId; - use crate::ln::channelmanager::{self, ChannelCounterparty, ChannelDetails}; - use crate::ln::features::Bolt11InvoiceFeatures; - use crate::routing::gossip::NetworkGraph; + use crate::ln::channelmanager::{self, ChannelCounterparty}; use crate::util::config::UserConfig; - use crate::util::ser::ReadableArgs; use crate::util::test_utils::TestLogger; /// Tries to open a network graph file, or panics with a URL to fetch it. diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index bb043164a0e..4850479b899 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -64,7 +64,6 @@ use crate::util::logger::Logger; use crate::prelude::*; use core::{cmp, fmt}; -use core::convert::TryInto; use core::ops::{Deref, DerefMut}; use core::time::Duration; use crate::io::{self, Read}; diff --git a/lightning/src/routing/utxo.rs b/lightning/src/routing/utxo.rs index ada90345ee6..e775e2628f6 100644 --- a/lightning/src/routing/utxo.rs +++ b/lightning/src/routing/utxo.rs @@ -563,7 +563,6 @@ mod tests { use super::*; use crate::routing::gossip::tests::*; use crate::util::test_utils::{TestChainSource, TestLogger}; - use crate::ln::msgs; use bitcoin::secp256k1::{Secp256k1, SecretKey}; diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index a7237493be7..c959b115cf0 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -53,7 +53,6 @@ use crate::offers::invoice::UnsignedBolt12Invoice; use crate::offers::invoice_request::UnsignedInvoiceRequest; use crate::prelude::*; -use core::convert::TryInto; use core::ops::Deref; use core::sync::atomic::{AtomicUsize, Ordering}; #[cfg(taproot)] diff --git a/lightning/src/util/errors.rs b/lightning/src/util/errors.rs index 4ffde9a72d2..735ce044f81 100644 --- a/lightning/src/util/errors.rs +++ b/lightning/src/util/errors.rs @@ -11,7 +11,9 @@ use crate::ln::script::ShutdownScript; -use alloc::string::String; +#[allow(unused_imports)] +use crate::prelude::*; + use core::fmt; /// Indicates an error on the client's part (usually some variant of attempting to use too-low or diff --git a/lightning/src/util/indexed_map.rs b/lightning/src/util/indexed_map.rs index d4c20f72215..4f694bd2b6e 100644 --- a/lightning/src/util/indexed_map.rs +++ b/lightning/src/util/indexed_map.rs @@ -1,10 +1,8 @@ //! This module has a map which can be iterated in a deterministic order. See the [`IndexedMap`]. use crate::prelude::*; -use alloc::vec::Vec; use alloc::slice::Iter; use core::hash::Hash; -use core::cmp::Ord; use core::ops::{Bound, RangeBounds}; /// A map which can be iterated in a deterministic order. diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs index a7b4bda6f31..6fd0048daf7 100644 --- a/lightning/src/util/persist.rs +++ b/lightning/src/util/persist.rs @@ -11,13 +11,11 @@ //! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager use core::cmp; -use core::convert::{TryFrom, TryInto}; use core::ops::Deref; use core::str::FromStr; use bitcoin::{BlockHash, Txid}; use crate::{io, log_error}; -use crate::alloc::string::ToString; use crate::prelude::*; use crate::chain; @@ -837,7 +835,6 @@ impl From for UpdateName { #[cfg(test)] mod tests { use super::*; - use crate::chain::chainmonitor::Persist; use crate::chain::ChannelMonitorUpdateStatus; use crate::events::{ClosureReason, MessageSendEventsProvider}; use crate::ln::functional_test_utils::*; diff --git a/lightning/src/util/scid_utils.rs b/lightning/src/util/scid_utils.rs index 38be0eb88fc..c9485b60b70 100644 --- a/lightning/src/util/scid_utils.rs +++ b/lightning/src/util/scid_utils.rs @@ -76,8 +76,8 @@ pub(crate) mod fake_scid { use crate::sign::EntropySource; use crate::crypto::chacha20::ChaCha20; use crate::util::scid_utils; + use crate::prelude::*; - use core::convert::TryInto; use core::ops::Deref; const TEST_SEGWIT_ACTIVATION_HEIGHT: u32 = 1; diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 7ff6b248cfb..f88d9f36a72 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -19,7 +19,6 @@ use crate::io_extras::{copy, sink}; use core::hash::Hash; use crate::sync::{Mutex, RwLock}; use core::cmp; -use core::convert::TryFrom; use core::ops::Deref; use alloc::collections::BTreeMap; @@ -35,7 +34,6 @@ use bitcoin::{consensus, Witness}; use bitcoin::consensus::Encodable; use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::hash_types::{Txid, BlockHash}; -use core::marker::Sized; use core::time::Duration; use crate::chain::ClaimId; use crate::ln::msgs::DecodeError; @@ -1494,10 +1492,10 @@ impl Readable for ClaimId { #[cfg(test)] mod tests { - use core::convert::TryFrom; use bitcoin::hashes::hex::FromHex; use bitcoin::secp256k1::ecdsa; use crate::util::ser::{Readable, Hostname, Writeable}; + use crate::prelude::*; #[test] fn hostname_conversion() { diff --git a/lightning/src/util/string.rs b/lightning/src/util/string.rs index 6949c936e00..ab12486a0d8 100644 --- a/lightning/src/util/string.rs +++ b/lightning/src/util/string.rs @@ -9,12 +9,14 @@ //! Utilities for strings. -use alloc::string::String; use core::fmt; use crate::io::{self, Read}; use crate::ln::msgs; use crate::util::ser::{Writeable, Writer, Readable}; +#[allow(unused_imports)] +use crate::prelude::*; + /// Struct to `Display` fields in a safe way using `PrintableString` #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] pub struct UntrustedString(pub String); diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 15cc07466d6..ee09119b9e6 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -59,9 +59,6 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature}; use bitcoin::secp256k1::schnorr; -#[cfg(any(test, feature = "_test_utils"))] -use regex; - use crate::io; use crate::prelude::*; use core::cell::RefCell; diff --git a/lightning/src/util/transaction_utils.rs b/lightning/src/util/transaction_utils.rs index 8b0ef3da013..59b7be6073c 100644 --- a/lightning/src/util/transaction_utils.rs +++ b/lightning/src/util/transaction_utils.rs @@ -74,8 +74,8 @@ mod tests { use super::*; use bitcoin::blockdata::locktime::absolute::LockTime; - use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn, OutPoint}; - use bitcoin::blockdata::script::{ScriptBuf, Builder}; + use bitcoin::blockdata::transaction::{TxIn, OutPoint}; + use bitcoin::blockdata::script::Builder; use bitcoin::hash_types::{PubkeyHash, Txid}; use bitcoin::hashes::Hash; use bitcoin::hashes::hex::FromHex; diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index 6c0de2bfa85..c95b3dbef3d 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -306,7 +306,7 @@ mod tests { use super::*; use core::sync::atomic::{AtomicBool, Ordering}; use core::future::Future as FutureTrait; - use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; + use core::task::{RawWaker, RawWakerVTable}; #[test] fn notifier_pre_notified_future() { From d9b9854e87b81e43bcd33ae7bc059cf40af5b5e1 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 15:44:45 +0000 Subject: [PATCH 6/9] Drop now-unused methods on `Time` We no longer use `Time` during scoring, which makes several of its methods now useless. We remove those here. --- lightning/src/util/time.rs | 55 +++----------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/lightning/src/util/time.rs b/lightning/src/util/time.rs index a6e6f4d1fda..bedeab1d489 100644 --- a/lightning/src/util/time.rs +++ b/lightning/src/util/time.rs @@ -16,16 +16,8 @@ pub trait Time: Copy + Sub where Self: Sized { /// Returns an instance corresponding to the current moment. fn now() -> Self; - /// Returns the amount of time elapsed since `self` was created. - fn elapsed(&self) -> Duration; - /// Returns the amount of time passed between `earlier` and `self`. fn duration_since(&self, earlier: Self) -> Duration; - - /// Returns the amount of time passed since the beginning of [`Time`]. - /// - /// Used during (de-)serialization. - fn duration_since_epoch() -> Duration; } /// A state in which time has no meaning. @@ -40,14 +32,6 @@ impl Time for Eternity { fn duration_since(&self, _earlier: Self) -> Duration { Duration::from_secs(0) } - - fn duration_since_epoch() -> Duration { - Duration::from_secs(0) - } - - fn elapsed(&self) -> Duration { - Duration::from_secs(0) - } } impl Sub for Eternity { @@ -82,15 +66,6 @@ impl Time for MonotonicTime { let now = Self::now(); if now.0 > earlier.0 { now.0 - earlier.0 } else { Duration::from_secs(0) } } - - fn duration_since_epoch() -> Duration { - use std::time::SystemTime; - SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap() - } - - fn elapsed(&self) -> Duration { - Self::now().0 - self.0 - } } #[cfg(feature = "std")] @@ -127,20 +102,12 @@ pub mod tests { impl Time for SinceEpoch { fn now() -> Self { - Self(Self::duration_since_epoch()) + Self(Self::ELAPSED.with(|elapsed| elapsed.get())) } fn duration_since(&self, earlier: Self) -> Duration { self.0 - earlier.0 } - - fn duration_since_epoch() -> Duration { - Self::ELAPSED.with(|elapsed| elapsed.get()) - } - - fn elapsed(&self) -> Duration { - Self::duration_since_epoch() - self.0 - } } impl Sub for SinceEpoch { @@ -154,36 +121,20 @@ pub mod tests { #[test] fn time_passes_when_advanced() { let now = SinceEpoch::now(); - assert_eq!(now.elapsed(), Duration::from_secs(0)); SinceEpoch::advance(Duration::from_secs(1)); SinceEpoch::advance(Duration::from_secs(1)); - let elapsed = now.elapsed(); let later = SinceEpoch::now(); - assert_eq!(elapsed, Duration::from_secs(2)); - assert_eq!(later - elapsed, now); + assert_eq!(now.0 + Duration::from_secs(2), later.0); } #[test] fn time_never_passes_in_an_eternity() { let now = Eternity::now(); - let elapsed = now.elapsed(); let later = Eternity::now(); - assert_eq!(now.elapsed(), Duration::from_secs(0)); - assert_eq!(later - elapsed, now); - } - - #[test] - #[cfg(feature = "std")] - fn monotonic_time_subtracts() { - let now = super::MonotonicTime::now(); - assert!(now.elapsed() < Duration::from_secs(10)); - - let ten_years = Duration::from_secs(10 * 365 * 24 * 60 * 60); - let past = now - ten_years; - assert!(past.elapsed() >= ten_years); + assert_eq!(later, now); } } From d1d7d8787e0931af972c50a0895e11ae0215c1a7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 15:46:31 +0000 Subject: [PATCH 7/9] Mark several test_utils which are only used in test as `cfg(test)` --- lightning/src/util/test_utils.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index ee09119b9e6..305dc40a0a2 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -13,6 +13,7 @@ use crate::chain; use crate::chain::WatchedOutput; use crate::chain::chaininterface; use crate::chain::chaininterface::ConfirmationTarget; +#[cfg(test)] use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW; use crate::chain::chainmonitor; use crate::chain::chainmonitor::{MonitorUpdateId, UpdateOrigin}; @@ -25,6 +26,7 @@ use crate::events; use crate::events::bump_transaction::{WalletSource, Utxo}; use crate::ln::ChannelId; use crate::ln::channelmanager::{ChannelDetails, self}; +#[cfg(test)] use crate::ln::chan_utils::CommitmentTransaction; use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use crate::ln::{msgs, wire}; @@ -396,12 +398,14 @@ impl<'a> chain::Watch for TestChainMonitor<'a> { } } +#[cfg(test)] struct JusticeTxData { justice_tx: Transaction, value: u64, commitment_number: u64, } +#[cfg(test)] pub(crate) struct WatchtowerPersister { persister: TestPersister, /// Upon a new commitment_signed, we'll get a @@ -415,6 +419,7 @@ pub(crate) struct WatchtowerPersister { destination_script: ScriptBuf, } +#[cfg(test)] impl WatchtowerPersister { #[cfg(test)] pub(crate) fn new(destination_script: ScriptBuf) -> Self { @@ -445,6 +450,7 @@ impl WatchtowerPersister { } } +#[cfg(test)] impl chainmonitor::Persist for WatchtowerPersister { fn persist_new_channel(&self, funding_txo: OutPoint, data: &channelmonitor::ChannelMonitor, id: MonitorUpdateId From ef2e739295be14b09d2cb6f7b2d6d7b089d2eea4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 15:48:54 +0000 Subject: [PATCH 8/9] Remove a handful of redundant imports ... that newer rustc now warns about. --- lightning-block-sync/src/init.rs | 2 -- lightning-invoice/tests/ser_de.rs | 3 --- lightning-net-tokio/src/lib.rs | 1 - lightning-persister/src/fs_store.rs | 1 - 4 files changed, 7 deletions(-) diff --git a/lightning-block-sync/src/init.rs b/lightning-block-sync/src/init.rs index 8cb0ff70a2e..ba93d12f5bc 100644 --- a/lightning-block-sync/src/init.rs +++ b/lightning-block-sync/src/init.rs @@ -252,8 +252,6 @@ mod tests { use crate::test_utils::{Blockchain, MockChainListener}; use super::*; - use bitcoin::network::constants::Network; - #[tokio::test] async fn sync_from_same_chain() { let chain = Blockchain::default().with_height(4); diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index 92bc87bef63..e5e311fe669 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -8,9 +8,6 @@ use bitcoin::address::WitnessVersion; use bitcoin::{PubkeyHash, ScriptHash}; use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; -use lightning::ln::PaymentSecret; -use lightning::routing::gossip::RoutingFees; -use lightning::routing::router::{RouteHint, RouteHintHop}; use lightning_invoice::*; use secp256k1::PublicKey; use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index be41a240124..41691d9a079 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -556,7 +556,6 @@ mod tests { use lightning::ln::features::*; use lightning::ln::msgs::*; use lightning::ln::peer_handler::{MessageHandler, PeerManager}; - use lightning::ln::features::NodeFeatures; use lightning::routing::gossip::NodeId; use lightning::events::*; use lightning::util::test_utils::TestNodeSigner; diff --git a/lightning-persister/src/fs_store.rs b/lightning-persister/src/fs_store.rs index 350b1cdd195..364a3ee706f 100644 --- a/lightning-persister/src/fs_store.rs +++ b/lightning-persister/src/fs_store.rs @@ -379,7 +379,6 @@ mod tests { use lightning::ln::functional_test_utils::*; use lightning::util::test_utils; use lightning::util::persist::read_channel_monitors; - use std::fs; use std::str::FromStr; impl Drop for FilesystemStore { From 2f734f97550014e5424e55523ed46d76b94b737d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 21 Mar 2024 15:53:00 +0000 Subject: [PATCH 9/9] Fix unused warning for un-accessed enum variant field in net-tokio --- lightning-net-tokio/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 41691d9a079..71d63ecadcf 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -208,7 +208,12 @@ impl Connection { break Disconnect::CloseConnection; } }, - SelectorOutput::B(_) => {}, + SelectorOutput::B(some) => { + // The mpsc Receiver should only return `None` if the write side has been + // dropped, but that shouldn't be possible since its referenced by the Self in + // `us`. + debug_assert!(some.is_some()); + }, SelectorOutput::C(res) => { if res.is_err() { break Disconnect::PeerDisconnected; } match reader.try_read(&mut buf) {