run: |
sudo apt-get -y install shellcheck
shellcheck ci/ci-tests.sh
+ - name: Set RUSTFLAGS to deny warnings
+ if: "matrix.toolchain == '1.63.0'"
+ run: echo "RUSTFLAGS=-D warnings" >> "$GITHUB_ENV"
- name: Run CI script
shell: bash # Default on Winblows is powershell
run: CI_MINIMIZE_DISK_USAGE=1 ./ci/ci-tests.sh
pass
elif feature == "electrum":
pass
+ elif feature == "time":
+ pass
elif feature == "_test_utils":
pass
elif feature == "_test_vectors":
DOWNLOAD_ELECTRS_AND_BITCOIND
- RUSTFLAGS="--cfg no_download" cargo test --verbose --color always --features esplora-blocking
- RUSTFLAGS="--cfg no_download" cargo check --verbose --color always --features esplora-blocking
- RUSTFLAGS="--cfg no_download" cargo test --verbose --color always --features esplora-async
- RUSTFLAGS="--cfg no_download" cargo check --verbose --color always --features esplora-async
- RUSTFLAGS="--cfg no_download" cargo test --verbose --color always --features esplora-async-https
- RUSTFLAGS="--cfg no_download" cargo check --verbose --color always --features esplora-async-https
- RUSTFLAGS="--cfg no_download" cargo test --verbose --color always --features electrum
- RUSTFLAGS="--cfg no_download" cargo check --verbose --color always --features electrum
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo test --verbose --color always --features esplora-blocking
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo check --verbose --color always --features esplora-blocking
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo test --verbose --color always --features esplora-async
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo check --verbose --color always --features esplora-async
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo test --verbose --color always --features esplora-async-https
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo check --verbose --color always --features esplora-async-https
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo test --verbose --color always --features electrum
+ RUSTFLAGS="$RUSTFLAGS --cfg no_download" cargo check --verbose --color always --features electrum
popd
fi
echo -e "\n\nBuilding with all Log-Limiting features"
pushd lightning
grep '^max_level_' Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
- cargo check --verbose --color always --features "$FEATURE"
+ RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check --verbose --color always --features "$FEATURE"
done
popd
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
- RUSTFLAGS="--cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
+ RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
done
-RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always
+RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
pushd lightning
fi
echo -e "\n\nTest cfg-flag builds"
-RUSTFLAGS="$RUSTFLAGS --cfg=taproot" cargo test --verbose --color always -p lightning
-RUSTFLAGS="$RUSTFLAGS --cfg=async_signing" cargo test --verbose --color always -p lightning
+RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
+RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
use lightning::sign::{EntropySource, NodeSigner, SignerProvider};
use lightning::events::{Event, PathFailure};
#[cfg(feature = "std")]
-use lightning::events::{EventHandler, EventsProvider};
+use lightning::events::EventHandler;
+#[cfg(any(feature = "std", feature = "futures"))]
+use lightning::events::EventsProvider;
+
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::msgs::OnionMessageHandler;
use lightning::ln::peer_handler::APeerManager;
where
PM::Target: APeerManager + Send + Sync,
{
- use lightning::events::EventsProvider;
-
let events = core::cell::RefCell::new(Vec::new());
peer_manager.onion_message_handler().process_pending_events(&|e| events.borrow_mut().push(e));
/// The REST `getutxos` endpoint retuns a whole pile of data we don't care about and one bit we do
/// - whether the `hit bitmap` field had any entries. Thus we condense the result down into only
/// that.
+#[cfg(feature = "rest-client")]
pub(crate) struct GetUtxosResponse {
pub(crate) hit_bitmap_nonempty: bool
}
+#[cfg(feature = "rest-client")]
impl TryInto<GetUtxosResponse> for JsonResponse {
type Error = std::io::Error;
mod ser;
mod tb;
+#[allow(unused_imports)]
mod prelude {
#[cfg(feature = "hashbrown")]
extern crate hashbrown;
use crate::prelude::*;
-/// Sync compat for std/no_std
-#[cfg(not(feature = "std"))]
-mod sync;
-
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
#[allow(missing_docs)]
use lightning::routing::router::RouteHintHop;
use secp256k1::Secp256k1;
use secp256k1::{SecretKey, PublicKey};
- use std::time::{UNIX_EPOCH, Duration};
+ use std::time::Duration;
let secp_ctx = Secp256k1::new();
assert_eq!(invoice.currency(), Currency::BitcoinTestnet);
#[cfg(feature = "std")]
assert_eq!(
- invoice.timestamp().duration_since(UNIX_EPOCH).unwrap().as_secs(),
+ invoice.timestamp().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(),
1234567
);
assert_eq!(invoice.payee_pub_key(), Some(&public_key));
use super::*;
use crate::{InvoiceBuilder, Currency};
use bitcoin::hashes::sha256::Hash as Sha256;
- use lightning::events::Event;
- use lightning::ln::channelmanager::{Retry, PaymentId};
- use lightning::ln::msgs::ChannelMessageHandler;
use lightning::ln::PaymentSecret;
- use lightning::ln::functional_test_utils::*;
use lightning::routing::router::Payee;
use secp256k1::{SecretKey, PublicKey, Secp256k1};
- use std::time::{SystemTime, Duration};
+ use core::time::Duration;
+ #[cfg(feature = "std")]
+ use std::time::SystemTime;
fn duration_since_epoch() -> Duration {
#[cfg(feature = "std")]
#[test]
#[cfg(feature = "std")]
fn payment_metadata_end_to_end() {
+ use lightning::events::Event;
+ use lightning::ln::channelmanager::{Retry, PaymentId};
+ use lightning::ln::msgs::ChannelMessageHandler;
+ use lightning::ln::functional_test_utils::*;
// Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all
// the way out through the `PaymentClaimable` event.
let chanmon_cfgs = create_chanmon_cfgs(2);
+++ /dev/null
-use core::cell::{RefCell, RefMut};
-use core::ops::{Deref, DerefMut};
-
-pub type LockResult<Guard> = Result<Guard, ()>;
-
-pub struct Mutex<T: ?Sized> {
- inner: RefCell<T>
-}
-
-#[must_use = "if unused the Mutex will immediately unlock"]
-pub struct MutexGuard<'a, T: ?Sized + 'a> {
- lock: RefMut<'a, T>,
-}
-
-impl<T: ?Sized> Deref for MutexGuard<'_, T> {
- type Target = T;
-
- fn deref(&self) -> &T {
- &self.lock.deref()
- }
-}
-
-impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
- fn deref_mut(&mut self) -> &mut T {
- self.lock.deref_mut()
- }
-}
-
-impl<T> Mutex<T> {
- pub fn new(inner: T) -> Mutex<T> {
- Mutex { inner: RefCell::new(inner) }
- }
-
- pub fn lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
- Ok(MutexGuard { lock: self.inner.borrow_mut() })
- }
-}
#[cfg(test)]
mod test {
- use core::cell::RefCell;
use core::time::Duration;
use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError};
use bitcoin::hashes::{Hash, sha256};
use bitcoin::hashes::sha256::Hash as Sha256;
use lightning::sign::PhantomKeysManager;
- use lightning::events::{MessageSendEvent, MessageSendEventsProvider, Event, EventsProvider};
- use lightning::ln::{PaymentPreimage, PaymentHash};
+ use lightning::events::{MessageSendEvent, MessageSendEventsProvider};
+ use lightning::ln::PaymentHash;
+ #[cfg(feature = "std")]
+ use lightning::ln::PaymentPreimage;
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::ChannelMessageHandler;
#[cfg(feature = "std")]
fn do_test_multi_node_receive(user_generated_pmt_hash: bool) {
+ use lightning::events::{Event, EventsProvider};
+ use core::cell::RefCell;
+
let mut chanmon_cfgs = create_chanmon_cfgs(3);
let seed_1 = [42u8; 32];
let seed_2 = [43u8; 32];
use lightning::util::persist::read_channel_monitors;
use std::fs;
use std::str::FromStr;
- #[cfg(target_os = "windows")]
- use {
- lightning::get_event_msg,
- lightning::ln::msgs::ChannelMessageHandler,
- };
impl Drop for FilesystemStore {
fn drop(&mut self) {
rustdoc-args = ["--cfg", "docsrs"]
[features]
-default = []
+default = ["time"]
+time = []
esplora-async = ["async-interface", "esplora-client/async", "futures"]
esplora-async-https = ["esplora-async", "esplora-client/async-https-rustls"]
esplora-blocking = ["esplora-client/blocking"]
#[cfg(not(feature = "async-interface"))]
use esplora_client::blocking::BlockingClient;
-use std::time::Instant;
use std::collections::HashSet;
use core::ops::Deref;
let mut sync_state = self.sync_state.lock().await;
log_trace!(self.logger, "Starting transaction sync.");
- let start_time = Instant::now();
+ #[cfg(feature = "time")]
+ let start_time = std::time::Instant::now();
let mut num_confirmed = 0;
let mut num_unconfirmed = 0;
sync_state.pending_sync = false;
}
}
+ #[cfg(feature = "time")]
log_debug!(self.logger, "Finished transaction sync at tip {} in {}ms: {} confirmed, {} unconfirmed.",
tip_hash, start_time.elapsed().as_millis(), num_confirmed, num_unconfirmed);
+ #[cfg(not(feature = "time"))]
+ log_debug!(self.logger, "Finished transaction sync at tip {}: {} confirmed, {} unconfirmed.",
+ tip_hash, num_confirmed, num_unconfirmed);
Ok(())
}
use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
#[cfg(any(feature = "_test_utils", test))]
use crate::ln::features::Bolt11InvoiceFeatures;
-use crate::routing::gossip::NetworkGraph;
-use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
-use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
+use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundOnionErr, NextPacketDetails};
use crate::ln::msgs;
use crate::ln::onion_utils;
use crate::offers::parse::Bolt12SemanticError;
use crate::offers::refund::{Refund, RefundBuilder};
use crate::onion_message::{Destination, MessageRouter, OffersMessage, OffersMessageHandler, PendingOnionMessage, new_pending_onion_message};
-use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider};
+use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
use crate::util::wakers::{Future, Notifier};
use crate::util::ser::{BigSize, FixedLengthReader, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter};
use crate::util::logger::{Level, Logger, WithContext};
use crate::util::errors::APIError;
+#[cfg(not(c_bindings))]
+use {
+ crate::routing::router::DefaultRouter,
+ crate::routing::gossip::NetworkGraph,
+ crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
+ crate::sign::KeysManager,
+};
use alloc::collections::{btree_map, BTreeMap};
use crate::ln::functional_test_utils::*;
use crate::routing::gossip::NodeId;
#[cfg(feature = "std")]
-use {
- crate::util::time::tests::SinceEpoch,
- std::time::{SystemTime, Instant, Duration}
-};
+use std::time::{SystemTime, Instant, Duration};
+#[cfg(not(feature = "no-std"))]
+use crate::util::time::tests::SinceEpoch;
#[test]
fn mpp_failure() {
use bitcoin::blockdata::constants::ChainHash;
use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey};
-use crate::sign::{KeysManager, NodeSigner, Recipient};
+use crate::sign::{NodeSigner, Recipient};
use crate::events::{EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
use crate::ln::ChannelId;
use crate::ln::features::{InitFeatures, NodeFeatures};
#[cfg(not(c_bindings))]
use crate::onion_message::{SimpleArcOnionMessenger, SimpleRefOnionMessenger};
use crate::onion_message::{CustomOnionMessageHandler, OffersMessage, OffersMessageHandler, OnionMessageContents, PendingOnionMessage};
-use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, NodeAlias};
+use crate::routing::gossip::{NodeId, NodeAlias};
use crate::util::atomic_counter::AtomicCounter;
use crate::util::logger::{Logger, WithContext};
use crate::util::string::PrintableString;
use crate::prelude::*;
use crate::io;
use alloc::collections::VecDeque;
-use crate::sync::{Arc, Mutex, MutexGuard, FairRwLock};
+use crate::sync::{Mutex, MutexGuard, FairRwLock};
use core::sync::atomic::{AtomicBool, AtomicU32, AtomicI32, Ordering};
use core::{cmp, hash, fmt, mem};
use core::ops::Deref;
use core::convert::Infallible;
-#[cfg(feature = "std")] use std::error;
+#[cfg(feature = "std")]
+use std::error;
+#[cfg(not(c_bindings))]
+use {
+ crate::routing::gossip::{NetworkGraph, P2PGossipSync},
+ crate::sign::KeysManager,
+ crate::sync::Arc,
+};
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
use crate::sign::EntropySource;
use crate::chain::transaction::OutPoint;
use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider};
-use crate::ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, Retry, RecipientOnionFields};
+use crate::ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, RecipientOnionFields};
use crate::ln::msgs;
use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ErrorAction};
-use crate::routing::router::{RouteParameters, PaymentParameters};
use crate::util::test_channel_signer::TestChannelSigner;
use crate::util::test_utils;
use crate::util::errors::APIError;
use crate::util::ser::{Writeable, ReadableArgs};
use crate::util::config::UserConfig;
-use crate::util::string::UntrustedString;
use bitcoin::hash_types::BlockHash;
#[cfg(feature = "std")]
fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, not_stale: bool) {
+ use crate::routing::router::{RouteParameters, PaymentParameters};
+ use crate::ln::channelmanager::Retry;
+ use crate::util::string::UntrustedString;
// When we get a data_loss_protect proving we're behind, we immediately panic as the
// chain::Watch API requirements have been violated (e.g. the user restored from a backup). The
// panic message informs the user they should force-close without broadcasting, which is tested
use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs};
use crate::blinded_path::utils;
use crate::events::{Event, EventHandler, EventsProvider};
-use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient};
+use crate::sign::{EntropySource, NodeSigner, Recipient};
#[cfg(not(c_bindings))]
use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager};
use crate::ln::features::{InitFeatures, NodeFeatures};
use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
use crate::ln::onion_utils;
-use crate::ln::peer_handler::IgnoringMessageHandler;
use crate::routing::gossip::{NetworkGraph, NodeId};
pub use super::packet::OnionMessageContents;
use super::packet::ParsedOnionMessageContents;
use core::fmt;
use core::ops::Deref;
use crate::io;
-use crate::sync::{Arc, Mutex};
+use crate::sync::Mutex;
use crate::prelude::*;
+#[cfg(not(c_bindings))]
+use {
+ crate::sign::KeysManager,
+ crate::ln::peer_handler::IgnoringMessageHandler,
+ crate::sync::Arc,
+};
+
pub(super) const MAX_TIMER_TICKS: usize = 2;
/// A sender, receiver and forwarder of [`OnionMessage`]s.
///
/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
/// enqueued for sending.
-pub type PendingOnionMessage<T: OnionMessageContents> = (T, Destination, Option<BlindedPath>);
+pub type PendingOnionMessage<T> = (T, Destination, Option<BlindedPath>);
pub(crate) fn new_pending_onion_message<T: OnionMessageContents>(
contents: T, destination: Destination, reply_path: Option<BlindedPath>
use crate::offers::invoice::Bolt12Invoice;
use crate::offers::parse::Bolt12ParseError;
use crate::onion_message::OnionMessageContents;
-use crate::onion_message::messenger::PendingOnionMessage;
use crate::util::logger::Logger;
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
+#[cfg(not(c_bindings))]
+use crate::onion_message::messenger::PendingOnionMessage;
use crate::prelude::*;
use crate::prelude::*;
use core::{cmp, fmt};
-use core::cell::{RefCell, RefMut, Ref};
use core::convert::TryInto;
use core::ops::{Deref, DerefMut};
use core::time::Duration;
use crate::io::{self, Read};
-use crate::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
+use crate::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
+#[cfg(not(c_bindings))]
+use {
+ core::cell::{RefCell, RefMut, Ref},
+ crate::sync::{Mutex, MutexGuard},
+};
/// We define Score ever-so-slightly differently based on whether we are being built for C bindings
/// or not. For users, `LockableScore` must somehow be writeable to disk. For Rust users, this is
Ok(MutexGuard { lock: self.inner.borrow_mut() })
}
- pub fn try_lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
- Ok(MutexGuard { lock: self.inner.borrow_mut() })
- }
-
pub fn into_inner(self) -> LockResult<T> {
Ok(self.inner.into_inner())
}
}
#[inline]
+#[allow(unused_variables)]
pub fn sign_with_aux_rand<C: Signing, ES: Deref>(
ctx: &Secp256k1<C>, msg: &Message, sk: &SecretKey, entropy_source: &ES
) -> Signature where ES::Target: EntropySource {