use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
use lightning::ln::script::ShutdownScript;
use lightning::ln::functional_test_utils::*;
+use lightning::offers::invoice::UnsignedBolt12Invoice;
+use lightning::offers::invoice_request::UnsignedInvoiceRequest;
use lightning::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
use lightning::util::errors::APIError;
use lightning::util::logger::Logger;
use bitcoin::secp256k1::{Message, PublicKey, SecretKey, Scalar, Secp256k1};
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
+use bitcoin::secp256k1::schnorr;
use std::mem;
use std::cmp::{self, Ordering};
// Background feerate which is <= the minimum Normal feerate.
match conf_target {
ConfirmationTarget::HighPriority => MAX_FEE,
- ConfirmationTarget::Background => 253,
+ ConfirmationTarget::Background|ConfirmationTarget::MempoolMinimum => 253,
ConfirmationTarget::Normal => cmp::min(self.ret_val.load(atomic::Ordering::Acquire), MAX_FEE),
}
}
impl Router for FuzzRouter {
fn find_route(
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
- _inflight_htlcs: &InFlightHtlcs
+ _inflight_htlcs: InFlightHtlcs
) -> Result<Route, msgs::LightningError> {
Err(msgs::LightningError {
err: String::from("Not implemented"),
unreachable!()
}
+ fn sign_bolt12_invoice_request(
+ &self, _invoice_request: &UnsignedInvoiceRequest
+ ) -> Result<schnorr::Signature, ()> {
+ unreachable!()
+ }
+
+ fn sign_bolt12_invoice(
+ &self, _invoice: &UnsignedBolt12Invoice,
+ ) -> Result<schnorr::Signature, ()> {
+ unreachable!()
+ }
+
fn sign_gossip_message(&self, msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<Signature, ()> {
let msg_hash = Message::from_slice(&Sha256dHash::hash(&msg.encode()[..])[..]).map_err(|_| ())?;
let secp_ctx = Secp256k1::signing_only();
}
#[inline]
-fn check_api_err(api_err: APIError) {
+fn check_api_err(api_err: APIError, sendable_bounds_violated: bool) {
match api_err {
APIError::APIMisuseError { .. } => panic!("We can't misuse the API"),
APIError::FeeRateTooHigh { .. } => panic!("We can't send too much fee?"),
// is probably just stale and you should add new messages here.
match err.as_str() {
"Peer for first hop currently disconnected" => {},
- _ if err.starts_with("Cannot push more than their max accepted HTLCs ") => {},
- _ if err.starts_with("Cannot send value that would put us over the max HTLC value in flight our peer will accept ") => {},
- _ if err.starts_with("Cannot send value that would put our balance under counterparty-announced channel reserve value") => {},
- _ if err.starts_with("Cannot send value that would put counterparty balance under holder-announced channel reserve value") => {},
- _ if err.starts_with("Cannot send value that would overdraw remaining funds.") => {},
- _ if err.starts_with("Cannot send value that would not leave enough to pay for fees.") => {},
- _ if err.starts_with("Cannot send value that would put our exposure to dust HTLCs at") => {},
+ _ if err.starts_with("Cannot send less than our next-HTLC minimum - ") => {},
+ _ if err.starts_with("Cannot send more than our next-HTLC maximum - ") => {},
_ => panic!("{}", err),
}
+ assert!(sendable_bounds_violated);
},
APIError::MonitorUpdateInProgress => {
// We can (obviously) temp-fail a monitor update
}
}
#[inline]
-fn check_payment_err(send_err: PaymentSendFailure) {
+fn check_payment_err(send_err: PaymentSendFailure, sendable_bounds_violated: bool) {
match send_err {
- PaymentSendFailure::ParameterError(api_err) => check_api_err(api_err),
+ PaymentSendFailure::ParameterError(api_err) => check_api_err(api_err, sendable_bounds_violated),
PaymentSendFailure::PathParameterError(per_path_results) => {
- for res in per_path_results { if let Err(api_err) = res { check_api_err(api_err); } }
+ for res in per_path_results { if let Err(api_err) = res { check_api_err(api_err, sendable_bounds_violated); } }
},
PaymentSendFailure::AllFailedResendSafe(per_path_results) => {
- for api_err in per_path_results { check_api_err(api_err); }
+ for api_err in per_path_results { check_api_err(api_err, sendable_bounds_violated); }
},
PaymentSendFailure::PartialFailure { results, .. } => {
- for res in results { if let Err(api_err) = res { check_api_err(api_err); } }
+ for res in results { if let Err(api_err) = res { check_api_err(api_err, sendable_bounds_violated); } }
},
PaymentSendFailure::DuplicatePayment => panic!(),
}
let mut payment_id = [0; 32];
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
*payment_idx += 1;
+ let (min_value_sendable, max_value_sendable) = source.list_usable_channels()
+ .iter().find(|chan| chan.short_channel_id == Some(dest_chan_id))
+ .map(|chan|
+ (chan.next_outbound_htlc_minimum_msat, chan.next_outbound_htlc_limit_msat))
+ .unwrap_or((0, 0));
if let Err(err) = source.send_payment_with_route(&Route {
paths: vec![Path { hops: vec![RouteHop {
pubkey: dest.get_our_node_id(),
}], blinded_tail: None }],
payment_params: None,
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
- check_payment_err(err);
+ check_payment_err(err, amt > max_value_sendable || amt < min_value_sendable);
false
- } else { true }
+ } else {
+ // Note that while the max is a strict upper-bound, we can occasionally send substantially
+ // below the minimum, with some gap which is unusable immediately below the minimum. Thus,
+ // we don't check against min_value_sendable here.
+ assert!(amt <= max_value_sendable);
+ true
+ }
}
#[inline]
fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8, payment_idx: &mut u64) -> bool {
let mut payment_id = [0; 32];
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
*payment_idx += 1;
+ let (min_value_sendable, max_value_sendable) = source.list_usable_channels()
+ .iter().find(|chan| chan.short_channel_id == Some(middle_chan_id))
+ .map(|chan|
+ (chan.next_outbound_htlc_minimum_msat, chan.next_outbound_htlc_limit_msat))
+ .unwrap_or((0, 0));
+ let first_hop_fee = 50_000;
if let Err(err) = source.send_payment_with_route(&Route {
paths: vec![Path { hops: vec![RouteHop {
pubkey: middle.get_our_node_id(),
node_features: middle.node_features(),
short_channel_id: middle_chan_id,
channel_features: middle.channel_features(),
- fee_msat: 50000,
+ fee_msat: first_hop_fee,
cltv_expiry_delta: 100,
},RouteHop {
pubkey: dest.get_our_node_id(),
}], blinded_tail: None }],
payment_params: None,
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
- check_payment_err(err);
+ let sent_amt = amt + first_hop_fee;
+ check_payment_err(err, sent_amt < min_value_sendable || sent_amt > max_value_sendable);
false
- } else { true }
+ } else {
+ // Note that while the max is a strict upper-bound, we can occasionally send substantially
+ // below the minimum, with some gap which is unusable immediately below the minimum. Thus,
+ // we don't check against min_value_sendable here.
+ assert!(amt + first_hop_fee <= max_value_sendable);
+ true
+ }
}
#[inline]
config.channel_config.forwarding_fee_proportional_millionths = 0;
config.channel_handshake_config.announced_channel = true;
let network = Network::Bitcoin;
+ let best_block_timestamp = genesis_block(network).header.time;
let params = ChainParameters {
network,
best_block: BestBlock::from_network(network),
};
- (ChannelManager::new($fee_estimator.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params),
+ (ChannelManager::new($fee_estimator.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params, best_block_timestamp),
monitor, keys_manager)
} }
}