diff --git a/Cargo.toml b/Cargo.toml index e262cd090..1f16f8c53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,11 @@ opt-level = 2 opt-level = 1 lto = "off" +# rgb-lib needs secp256k1 ^0.32.0-beta.2, which is yanked from crates.io. Without a committed +# lockfile a fresh resolve can't select it, so take it from its git tag (tag secp256k1-0.32.0-beta.2) +[patch.crates-io] +secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1", rev = "6e5c556e566d6ca1954daa1d8592efac70e75d06" } + [profile.release] opt-level = 3 lto = true diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 31e519b9f..e1122c4ac 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -1534,7 +1534,7 @@ impl BackgroundProcessor { SCORER_PERSISTENCE_KEY, scorer.encode(), ) { - log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e) + log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e); } } } diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 1731b2198..6deb7192b 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -1596,7 +1596,7 @@ impl Bolt11Invoice { pub fn would_expire(&self, at_time: Duration) -> bool { self.duration_since_epoch() .checked_add(self.expiry_time()) - .unwrap_or_else(|| Duration::new(u64::max_value(), 1_000_000_000 - 1)) + .unwrap_or_else(|| Duration::new(u64::MAX, 1_000_000_000 - 1)) < at_time } diff --git a/lightning-liquidity/src/lsps2/service.rs b/lightning-liquidity/src/lsps2/service.rs index 50b58371a..6d5f18b9e 100644 --- a/lightning-liquidity/src/lsps2/service.rs +++ b/lightning-liquidity/src/lsps2/service.rs @@ -1720,6 +1720,8 @@ where ) -> Option { match peer_state_lock.pending_requests.remove(request_id) { Some(req) => { + // `try_update` is the new name, but is far newer than our MSRV + #[allow(deprecated)] let res = self.total_pending_requests.fetch_update( Ordering::Relaxed, Ordering::Relaxed, diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 37d7a1dba..53b4662ba 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -101,7 +101,7 @@ impl BlindedPaymentPath { { // This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to // be in relation to a specific channel. - let htlc_maximum_msat = u64::max_value(); + let htlc_maximum_msat = u64::MAX; Self::new( &[], payee_node_id, @@ -886,7 +886,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, PaymentForwardNode { node_id: dummy_pk, @@ -904,7 +904,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, ]; let recv_tlvs = UnauthenticatedReceiveTlvs { @@ -961,7 +961,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, PaymentForwardNode { node_id: dummy_pk, @@ -979,7 +979,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, ]; let recv_tlvs = UnauthenticatedReceiveTlvs { @@ -1020,7 +1020,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, PaymentForwardNode { node_id: dummy_pk, @@ -1038,7 +1038,7 @@ mod tests { next_blinding_override: None, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: u64::max_value(), + htlc_maximum_msat: u64::MAX, }, ]; let recv_tlvs = UnauthenticatedReceiveTlvs { diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 5dc46d5a0..709efb4a7 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -21,7 +21,7 @@ use bitcoin::transaction::Transaction; // TODO: Define typed abstraction over feerates to handle their conversions. pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 { - (fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value()) + (fee_sat * 1000 / weight).try_into().unwrap_or(u32::MAX) } pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 { ((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000 diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index bf6e51325..1794c5396 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -7219,7 +7219,7 @@ mod tests { let witness = $sighash_parts.witness_mut($idx).unwrap(); witness.push(ser_sig); if *$weight == WEIGHT_REVOKED_OUTPUT { - witness.push(vec!(1)); + witness.push(vec![1]); } else if *$weight == weight_revoked_offered_htlc($opt_anchors) || *$weight == weight_revoked_received_htlc($opt_anchors) { witness.push(pubkey.clone().serialize().to_vec()); } else if *$weight == weight_received_htlc($opt_anchors) { diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index db46f3be6..1a4ce0eca 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -900,7 +900,7 @@ impl PackageSolvingData { let mut ser_sig = sig.serialize_der().to_vec(); ser_sig.push(EcdsaSighashType::All as u8); bumped_tx.input[i].witness.push(ser_sig); - bumped_tx.input[i].witness.push(vec!(1)); + bumped_tx.input[i].witness.push(vec![1]); bumped_tx.input[i].witness.push(witness_script.clone().into_bytes()); } else { return false; } }, @@ -1546,7 +1546,7 @@ impl PackageTemplate { ) -> u32 where F::Target: FeeEstimator { let feerate_estimate = fee_estimator.bounded_sat_per_1000_weight(conf_target); if self.feerate_previous != 0 { - let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::max_value()); + let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::MAX); match feerate_strategy { FeerateStrategy::RetryPrevious => previous_feerate, FeerateStrategy::HighestOfPreviousOrNew => cmp::max(previous_feerate, feerate_estimate), @@ -1558,7 +1558,7 @@ impl PackageTemplate { // so we choose to bump our previous feerate by 25%, making sure we don't use a // lower feerate or overpay by a large margin by limiting it to 5x the new fee // estimate. - let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::max_value()); + let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::MAX); let mut new_feerate = previous_feerate.saturating_add(previous_feerate / 4); if new_feerate > feerate_estimate * 5 { new_feerate = cmp::max(feerate_estimate * 5, previous_feerate); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 79ab65373..6c9373a87 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5873,9 +5873,9 @@ where dust_exposure_dust_limit_msat = cmp::max(dust_exposure_dust_limit_msat, buffer_dust_limit_success_sat * 1000); } - if htlc_stats.on_holder_tx_dust_exposure_msat as i64 + buffer_dust_limit_timeout_sat as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) { + if htlc_stats.on_holder_tx_dust_exposure_msat as i64 + buffer_dust_limit_timeout_sat as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::MAX) { remaining_msat_below_dust_exposure_limit = Some(cmp::min( - remaining_msat_below_dust_exposure_limit.unwrap_or(u64::max_value()), + remaining_msat_below_dust_exposure_limit.unwrap_or(u64::MAX), max_dust_htlc_exposure_msat.saturating_sub(htlc_stats.on_holder_tx_dust_exposure_msat))); dust_exposure_dust_limit_msat = cmp::max(dust_exposure_dust_limit_msat, buffer_dust_limit_timeout_sat * 1000); } @@ -7407,7 +7407,7 @@ where // 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 = core::usize::MAX; + let mut pending_idx = usize::MAX; let mut htlc_value_msat = 0; for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() { if htlc.htlc_id == htlc_id_arg { @@ -7444,7 +7444,7 @@ where break; } } - if pending_idx == core::usize::MAX { + if pending_idx == usize::MAX { return UpdateFulfillFetch::DuplicateClaim {}; } @@ -7648,7 +7648,7 @@ where // 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 = core::usize::MAX; + let mut pending_idx = usize::MAX; for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() { if htlc.htlc_id == htlc_id_arg { match htlc.state { @@ -7664,7 +7664,7 @@ where pending_idx = idx; } } - if pending_idx == core::usize::MAX { + if pending_idx == usize::MAX { return Err(ChannelError::Ignore(format!("Unable to find a pending HTLC which matched the given HTLC ID ({})", htlc_id_arg))); } @@ -10353,7 +10353,7 @@ where let normal_feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee); let mut proposed_max_feerate = - if self.funding.is_outbound() { normal_feerate } else { u32::max_value() }; + if self.funding.is_outbound() { normal_feerate } else { u32::MAX }; // The spec requires that (when the channel does not have anchors) we only send absolute // channel fees no greater than the absolute channel fee on the current commitment diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 6a9a2cc32..1ff820b76 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6428,7 +6428,7 @@ where } } - if funding_transaction.output.len() > u16::max_value() as usize { + if funding_transaction.output.len() > u16::MAX as usize { result = result.and(Err(APIError::APIMisuseError { err: "Transaction had more than 2^16 outputs, which is not supported".to_owned() })); diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index bbd8522f7..045b9fe98 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -4350,10 +4350,7 @@ impl QueryChannelRange { /// /// Overflow returns `0xffffffff`, otherwise returns `first_blocknum + number_of_blocks`. pub fn end_blocknum(&self) -> u32 { - match self.first_blocknum.checked_add(self.number_of_blocks) { - Some(block) => block, - None => u32::max_value(), - } + self.first_blocknum.checked_add(self.number_of_blocks).unwrap_or(u32::MAX) } } diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index e50ecfeb9..7e5029678 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -3264,7 +3264,7 @@ mod tests { // Note that we represent the test vector payloads 2 and 5 through RawOnionHopData::data // with raw hex instead of our in-memory enums, as the payloads contains custom types, and // we have no way of representing that with our enums. - let payloads = vec!( + let payloads = vec![ RawOnionHopData::new(msgs::OutboundOnionPayload::Forward { short_channel_id: 1, amt_to_forward: 15000, @@ -3319,7 +3319,7 @@ mod tests { RawOnionHopData { data: >::from_hex("fd011002022710040203e8082224a33562c54507a9334e79f0dc4f17d407e6d7c61f0e2f3d0d38599502f617042710fd012de02a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a").unwrap(), }, - ); + ]; // Verify that the serialized OnionHopDataFormat::NonFinalNode tlv payloads matches the test vectors let mut w = VecWriter(Vec::new()); diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 3a4fd4ff9..fa4014ab0 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -2194,7 +2194,7 @@ impl OutboundPayments { continue 'path_check; } let dest_hop_idx = if path.blinded_tail.is_some() && path.blinded_tail.as_ref().unwrap().hops.len() > 1 { - usize::max_value() } else { path.hops.len() - 1 }; + usize::MAX } else { path.hops.len() - 1 }; for (idx, hop) in path.hops.iter().enumerate() { if idx != dest_hop_idx && hop.pubkey == our_node_id { path_errs.push(Err(APIError::InvalidRoute{err: "Path went through us but wasn't a simple rebalance loop to us".to_owned()})); diff --git a/lightning/src/ln/peer_channel_encryptor.rs b/lightning/src/ln/peer_channel_encryptor.rs index fbf8193e2..17880d41d 100644 --- a/lightning/src/ln/peer_channel_encryptor.rs +++ b/lightning/src/ln/peer_channel_encryptor.rs @@ -33,7 +33,7 @@ use core::ops::Deref; /// Maximum Lightning message data length according to /// [BOLT-8](https://github.com/lightning/bolts/blob/v1.0/08-transport.md#lightning-message-specification) /// and [BOLT-1](https://github.com/lightning/bolts/blob/master/01-messaging.md#lightning-message-format): -pub const LN_MAX_MSG_LEN: usize = ::core::u16::MAX as usize; // Must be equal to 65535 +pub const LN_MAX_MSG_LEN: usize = u16::MAX as usize; // Must be equal to 65535 /// The (rough) size buffer to pre-allocate when encoding a message. Messages should reliably be /// smaller than this size by at least 32 bytes or so. @@ -1052,7 +1052,7 @@ mod tests { #[test] fn max_msg_len_limit_value() { assert_eq!(LN_MAX_MSG_LEN, 65535); - assert_eq!(LN_MAX_MSG_LEN, ::core::u16::MAX as usize); + assert_eq!(LN_MAX_MSG_LEN, u16::MAX as usize); } #[test] diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 8ae548b3b..1dc486045 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -3607,8 +3607,7 @@ where // be absurd. We ensure this by checking that at least 100 (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 = - ::core::u16::MAX as u32 / (SocketAddress::MAX_LEN as u32 + 1) / 2; + const HALF_MESSAGE_IS_ADDRS: u32 = u16::MAX as u32 / (SocketAddress::MAX_LEN as u32 + 1) / 2; #[allow(dead_code)] // ...by failing to compile if the number of addresses that would be half of a message is // smaller than 100: diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index f063ac080..41903269d 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -862,7 +862,7 @@ where msg: GossipTimestampFilter { chain_hash: self.network_graph.chain_hash, first_timestamp: gossip_start_time as u32, // 2106 issue! - timestamp_range: u32::max_value(), + timestamp_range: u32::MAX, }, }); Ok(()) @@ -1198,8 +1198,8 @@ impl Readable for ChannelInfo { announcement_received_time, (default_value, 0) ), - node_one_counter: u32::max_value(), - node_two_counter: u32::max_value(), + node_one_counter: u32::MAX, + node_two_counter: u32::MAX, contract_id: _init_tlv_based_struct_field!(contract_id, option), }) } @@ -1361,7 +1361,7 @@ impl EffectiveCapacity { EffectiveCapacity::AdvertisedMaxHTLC { amount_msat } => *amount_msat, EffectiveCapacity::Total { capacity_msat, .. } => *capacity_msat, EffectiveCapacity::HintMaxHTLC { amount_msat } => *amount_msat, - EffectiveCapacity::Infinite => u64::max_value(), + EffectiveCapacity::Infinite => u64::MAX, EffectiveCapacity::Unknown => UNKNOWN_CHANNEL_CAPACITY_MSAT, } } @@ -1641,7 +1641,7 @@ impl Readable for NodeInfo { Ok(NodeInfo { announcement_info: announcement_info_wrap.map(|w| w.0), channels, - node_counter: u32::max_value(), + node_counter: u32::MAX, }) } } @@ -1698,7 +1698,7 @@ where let nodes_count: u64 = Readable::read(reader)?; // There shouldn't be anywhere near `u32::MAX` nodes, and we need some headroom to insert // new nodes during sync, so reject any graphs claiming more than `u32::MAX / 2` nodes. - if nodes_count > u32::max_value() as u64 / 2 { + if nodes_count > u32::MAX as u64 / 2 { return Err(DecodeError::InvalidValue); } let mut nodes = IndexedMap::with_capacity(NODE_COUNT_ESTIMATE); @@ -1814,7 +1814,7 @@ where let nodes = self.nodes.read().unwrap(); let removed_node_counters = self.removed_node_counters.lock().unwrap(); let next_counter = self.next_node_counter.load(Ordering::Acquire); - assert!(next_counter < (u32::max_value() as usize) / 2); + assert!(next_counter < (u32::MAX as usize) / 2); let mut used_node_counters = vec![0u8; next_counter / 8 + 1]; for counter in removed_node_counters.iter() { @@ -2047,8 +2047,8 @@ where capacity_sats, announcement_message: None, announcement_received_time: timestamp, - node_one_counter: u32::max_value(), - node_two_counter: u32::max_value(), + node_one_counter: u32::MAX, + node_two_counter: u32::MAX, contract_id: None, }; @@ -2240,8 +2240,8 @@ where None }, announcement_received_time, - node_one_counter: u32::max_value(), - node_two_counter: u32::max_value(), + node_one_counter: u32::MAX, + node_two_counter: u32::MAX, contract_id: msg.contract_id, }; @@ -2373,7 +2373,7 @@ where pub fn remove_stale_channels_and_tracking_with_time(&self, current_time_unix: u64) { let mut channels = self.channels.write().unwrap(); // Time out if we haven't received an update in at least 14 days. - if current_time_unix > u32::max_value() as u64 { + if current_time_unix > u32::MAX as u64 { return; } // Remove by 2106 if current_time_unix < STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS { @@ -3877,7 +3877,7 @@ pub(crate) mod tests { (msg.first_timestamp as u64) < expected_timestamp - 60 * 60 * 24 * 7 * 2 + 10 ); - assert_eq!(msg.timestamp_range, u32::max_value()); + assert_eq!(msg.timestamp_range, u32::MAX); }, _ => panic!("Expected MessageSendEvent::SendChannelRangeQuery"), }; diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 6334de04a..5679e7162 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -677,7 +677,7 @@ impl Readable for Route { let path_count: u64 = Readable::read(reader)?; if path_count == 0 { return Err(DecodeError::InvalidValue); } let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize); - let mut min_final_cltv_expiry_delta = u32::max_value(); + let mut min_final_cltv_expiry_delta = u32::MAX; for _ in 0..path_count { let hop_count: u8 = Readable::read(reader)?; let mut hops: Vec = Vec::with_capacity(hop_count as usize); @@ -2015,7 +2015,7 @@ fn max_htlc_from_capacity(capacity: EffectiveCapacity, max_channel_saturation_po let saturation_shift: u32 = max_channel_saturation_power_of_half as u32; match capacity { EffectiveCapacity::ExactLiquidity { liquidity_msat } => liquidity_msat, - EffectiveCapacity::Infinite => u64::max_value(), + EffectiveCapacity::Infinite => u64::MAX, EffectiveCapacity::Unknown => EffectiveCapacity::Unknown.as_msat(), EffectiveCapacity::AdvertisedMaxHTLC { amount_msat } => amount_msat.checked_shr(saturation_shift).unwrap_or(0), @@ -2133,7 +2133,7 @@ impl<'a> PaymentPath<'a> { } fn get_path_penalty_msat(&self) -> u64 { - self.hops.first().map(|h| h.0.path_penalty_msat).unwrap_or(u64::max_value()) + self.hops.first().map(|h| h.0.path_penalty_msat).unwrap_or(u64::MAX) } fn get_total_fee_paid_msat(&self) -> u64 { @@ -2315,7 +2315,7 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option { #[rustfmt::skip] fn compute_fees_saturating(amount_msat: u64, channel_fees: RoutingFees) -> u64 { amount_msat.checked_mul(channel_fees.proportional_millionths as u64) - .map(|prop| prop / 1_000_000).unwrap_or(u64::max_value()) + .map(|prop| prop / 1_000_000).unwrap_or(u64::MAX) .saturating_add(channel_fees.base_msat as u64) } @@ -2575,7 +2575,7 @@ where L::Target: Logger { |info| info.features().supports_basic_mpp())) } else { false }; - let max_total_routing_fee_msat = route_params.max_total_routing_fee_msat.unwrap_or(u64::max_value()); + let max_total_routing_fee_msat = route_params.max_total_routing_fee_msat.unwrap_or(u64::MAX); let first_hop_count = first_hops.map(|hops| hops.len()).unwrap_or(0); log_trace!(logger, "Searching for a route from payer {} to {} {} MPP and {} first hops {}overriding the network graph of {} nodes and {} channels with a fee limit of {} msat", @@ -2974,11 +2974,11 @@ where L::Target: Logger { *dist_entry = Some(PathBuildingHop { candidate: $candidate.clone(), fee_msat: 0, - next_hops_fee_msat: u64::max_value(), - hop_use_fee_msat: u64::max_value(), - total_fee_msat: u64::max_value(), + next_hops_fee_msat: u64::MAX, + hop_use_fee_msat: u64::MAX, + total_fee_msat: u64::MAX, path_htlc_minimum_msat, - path_penalty_msat: u64::max_value(), + path_penalty_msat: u64::MAX, was_processed: false, is_first_hop_target: false, is_last_hop_target: false, @@ -3286,15 +3286,15 @@ where L::Target: Logger { candidate: CandidateRouteHop::FirstHop(FirstHopCandidate { details: &chans[0], payer_node_id: &our_node_id, - target_node_counter: u32::max_value(), - payer_node_counter: u32::max_value(), + target_node_counter: u32::MAX, + payer_node_counter: u32::MAX, }), fee_msat: 0, - next_hops_fee_msat: u64::max_value(), - hop_use_fee_msat: u64::max_value(), - total_fee_msat: u64::max_value(), - path_htlc_minimum_msat: u64::max_value(), - path_penalty_msat: u64::max_value(), + next_hops_fee_msat: u64::MAX, + hop_use_fee_msat: u64::MAX, + total_fee_msat: u64::MAX, + path_htlc_minimum_msat: u64::MAX, + path_penalty_msat: u64::MAX, was_processed: false, is_first_hop_target: true, is_last_hop_target: false, @@ -3319,11 +3319,11 @@ where L::Target: Logger { *entry = Some(PathBuildingHop { candidate: candidates[0].clone(), fee_msat: 0, - next_hops_fee_msat: u64::max_value(), - hop_use_fee_msat: u64::max_value(), - total_fee_msat: u64::max_value(), - path_htlc_minimum_msat: u64::max_value(), - path_penalty_msat: u64::max_value(), + next_hops_fee_msat: u64::MAX, + hop_use_fee_msat: u64::MAX, + total_fee_msat: u64::MAX, + path_htlc_minimum_msat: u64::MAX, + path_penalty_msat: u64::MAX, was_processed: false, is_first_hop_target: false, is_last_hop_target: true, @@ -3428,7 +3428,7 @@ where L::Target: Logger { // traversing the graph and arrange the path out of what we found. if node_counter == payer_node_counter { let mut new_entry = dist[payer_node_counter as usize].take().unwrap(); - let mut ordered_hops: Vec<(PathBuildingHop, NodeFeatures)> = vec!((new_entry.clone(), default_node_features.clone())); + let mut ordered_hops: Vec<(PathBuildingHop, NodeFeatures)> = vec![(new_entry.clone(), default_node_features.clone())]; 'path_walk: loop { let mut features_set = false; @@ -3526,7 +3526,7 @@ where L::Target: Logger { // we'll probably end up picking the same path again on the next iteration. // Decrease the available liquidity of a hop in the middle of the path. let victim_candidate = &payment_path.hops[(payment_path.hops.len()) / 2].0.candidate; - let exhausted = u64::max_value(); + let exhausted = u64::MAX; log_trace!(logger, "Disabling route candidate {} for future path building iterations to avoid duplicates.", LoggedCandidateHop(victim_candidate)); @@ -3912,7 +3912,7 @@ fn build_route_from_hops_internal( break; } } - u64::max_value() + u64::MAX } } @@ -6611,8 +6611,8 @@ mod tests { cltv_expiry_delta: (5 << 4) | 5, htlc_minimum_msat: 0, htlc_maximum_msat: 99_000, - fee_base_msat: u32::max_value(), - fee_proportional_millionths: u32::max_value(), + fee_base_msat: u32::MAX, + fee_proportional_millionths: u32::MAX, excess_data: Vec::new() }); update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate { @@ -6624,8 +6624,8 @@ mod tests { cltv_expiry_delta: (5 << 4) | 3, htlc_minimum_msat: 0, htlc_maximum_msat: 99_000, - fee_base_msat: u32::max_value(), - fee_proportional_millionths: u32::max_value(), + fee_base_msat: u32::MAX, + fee_proportional_millionths: u32::MAX, excess_data: Vec::new() }); update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate { @@ -7278,7 +7278,7 @@ mod tests { type ScoreParams = (); #[rustfmt::skip] fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&Self::ScoreParams) -> u64 { - if candidate.short_channel_id() == Some(self.short_channel_id) { u64::max_value() } else { 0 } + if candidate.short_channel_id() == Some(self.short_channel_id) { u64::MAX } else { 0 } } } @@ -7296,7 +7296,7 @@ mod tests { type ScoreParams = (); #[rustfmt::skip] fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&Self::ScoreParams) -> u64 { - if candidate.target() == Some(self.node_id) { u64::max_value() } else { 0 } + if candidate.target() == Some(self.node_id) { u64::MAX } else { 0 } } } diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index cf5dbc032..036e3e2a4 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -706,7 +706,7 @@ pub struct ProbabilisticScoringFeeParameters { pub historical_liquidity_penalty_amount_multiplier_msat: u64, /// Manual penalties used for the given nodes. Allows to set a particular penalty for a given - /// node. Note that a manual penalty of `u64::max_value()` means the node would not ever be + /// node. Note that a manual penalty of `u64::MAX` means the node would not ever be /// considered during path finding. /// /// This is not exported to bindings users @@ -731,7 +731,7 @@ pub struct ProbabilisticScoringFeeParameters { /// applicable, are still included in the overall penalty. /// /// If you wish to avoid creating paths with such channels entirely, setting this to a value of - /// `u64::max_value()` will guarantee that. + /// `u64::MAX` will guarantee that. /// /// Default value: 1_0000_0000_000 msat (1 Bitcoin) /// @@ -809,14 +809,14 @@ impl ProbabilisticScoringFeeParameters { /// Marks the node with the given `node_id` as banned, /// i.e it will be avoided during path finding. pub fn add_banned(&mut self, node_id: &NodeId) { - self.manual_node_penalties.insert(*node_id, u64::max_value()); + self.manual_node_penalties.insert(*node_id, u64::MAX); } /// Marks all nodes in the given list as banned, i.e., /// they will be avoided during path finding. pub fn add_banned_from_list(&mut self, node_ids: Vec) { for id in node_ids { - self.manual_node_penalties.insert(id, u64::max_value()); + self.manual_node_penalties.insert(id, u64::MAX); } } @@ -1338,7 +1338,7 @@ fn linear_success_probability( (max_liquidity_msat - min_liquidity_msat).saturating_add(1)); if min_zero_implies_no_successes && min_liquidity_msat == 0 && - denominator < u64::max_value() / MIN_ZERO_IMPLIES_NO_SUCCESSES_PENALTY_ON_64 + denominator < u64::MAX / MIN_ZERO_IMPLIES_NO_SUCCESSES_PENALTY_ON_64 { denominator = denominator * MIN_ZERO_IMPLIES_NO_SUCCESSES_PENALTY_ON_64 / 64 } @@ -1699,7 +1699,7 @@ where EffectiveCapacity::HintMaxHTLC { amount_msat } => { if usage.amount_msat > amount_msat { - return u64::max_value(); + return u64::MAX; } else { return base_penalty_msat; } @@ -1805,7 +1805,7 @@ where } fn probe_successful(&mut self, path: &Path, duration_since_epoch: Duration) { - self.payment_path_failed(path, u64::max_value(), duration_since_epoch) + self.payment_path_failed(path, u64::MAX, duration_since_epoch) } fn time_passed(&mut self, duration_since_epoch: Duration) { @@ -2032,7 +2032,7 @@ mod bucketed_history { #[inline] #[rustfmt::skip] fn amount_to_pos(amount_msat: u64, capacity_msat: u64) -> u16 { - let pos = if amount_msat < u64::max_value() / (POSITION_TICKS as u64) { + let pos = if amount_msat < u64::MAX / (POSITION_TICKS as u64) { (amount_msat * (POSITION_TICKS as u64) / capacity_msat.saturating_add(1)) .try_into().unwrap_or(POSITION_TICKS) } else { @@ -3059,7 +3059,7 @@ mod tests { let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { liquidity_penalty_multiplier_msat: 1_000, - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let decay_params = ProbabilisticScoringDecayParameters { @@ -3088,9 +3088,9 @@ mod tests { assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 0); let usage = ChannelUsage { amount_msat: 50, ..usage }; assert_ne!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 0); - assert_ne!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_ne!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); let usage = ChannelUsage { amount_msat: 61, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); } #[test] @@ -3174,7 +3174,7 @@ mod tests { let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { liquidity_penalty_multiplier_msat: 1_000, - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let mut scorer = ProbabilisticScorer::new(ProbabilisticScoringDecayParameters::default(), &network_graph, &logger); @@ -3203,9 +3203,9 @@ mod tests { let usage = ChannelUsage { amount_msat: 250, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 300); let usage = ChannelUsage { amount_msat: 500, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); let usage = ChannelUsage { amount_msat: 750, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); } #[test] @@ -3354,7 +3354,7 @@ mod tests { let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { liquidity_penalty_multiplier_msat: 1_000, - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let decay_params = ProbabilisticScoringDecayParameters { @@ -3390,7 +3390,7 @@ mod tests { let usage = ChannelUsage { amount_msat: 768, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 1_479); let usage = ChannelUsage { amount_msat: 896, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); // Half decay (i.e., three-quarter life) scorer.time_passed(Duration::from_secs(5)); @@ -3401,7 +3401,7 @@ mod tests { let usage = ChannelUsage { amount_msat: 768, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 921); let usage = ChannelUsage { amount_msat: 896, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); // One decay (i.e., half life) scorer.time_passed(Duration::from_secs(10)); @@ -3412,7 +3412,7 @@ mod tests { let usage = ChannelUsage { amount_msat: 896, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 1_970); let usage = ChannelUsage { amount_msat: 960, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); // Fully decay liquidity lower bound. scorer.time_passed(Duration::from_secs(10 * 8)); @@ -3423,20 +3423,20 @@ mod tests { let usage = ChannelUsage { amount_msat: 1_023, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 2_000); let usage = ChannelUsage { amount_msat: 1_024, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); // Fully decay liquidity upper bound. scorer.time_passed(Duration::from_secs(10 * 9)); let usage = ChannelUsage { amount_msat: 0, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 0); let usage = ChannelUsage { amount_msat: 1_024, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); scorer.time_passed(Duration::from_secs(10 * 10)); let usage = ChannelUsage { amount_msat: 0, ..usage }; assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 0); let usage = ChannelUsage { amount_msat: 1_024, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); } #[test] @@ -3499,7 +3499,7 @@ mod tests { let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { liquidity_penalty_multiplier_msat: 1_000, - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let decay_params = ProbabilisticScoringDecayParameters { @@ -3521,7 +3521,7 @@ mod tests { info, short_channel_id: 42, }); - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); scorer.time_passed(Duration::from_secs(10)); assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), 473); @@ -3544,7 +3544,7 @@ mod tests { let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { liquidity_penalty_multiplier_msat: 1_000, - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let decay_params = ProbabilisticScoringDecayParameters { @@ -3566,7 +3566,7 @@ mod tests { info, short_channel_id: 42, }); - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); if decay_before_reload { scorer.time_passed(Duration::from_secs(10)); @@ -3746,7 +3746,7 @@ mod tests { let network_graph = network_graph(&logger); let source = source_node_id(); let usage = ChannelUsage { - amount_msat: u64::max_value(), + amount_msat: u64::MAX, inflight_htlc_msat: 0, effective_capacity: EffectiveCapacity::Infinite, }; @@ -3771,7 +3771,7 @@ mod tests { let logger = TestLogger::new(); let network_graph = network_graph(&logger); let params = ProbabilisticScoringFeeParameters { - considered_impossible_penalty_msat: u64::max_value(), + considered_impossible_penalty_msat: u64::MAX, ..ProbabilisticScoringFeeParameters::zero_penalty() }; let scorer = ProbabilisticScorer::new(ProbabilisticScoringDecayParameters::default(), &network_graph, &logger); @@ -3789,10 +3789,10 @@ mod tests { info, short_channel_id: 42, }); - assert_ne!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_ne!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); let usage = ChannelUsage { inflight_htlc_msat: 251, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); } #[test] @@ -3823,7 +3823,7 @@ mod tests { assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), base_penalty_msat); let usage = ChannelUsage { amount_msat: 1_001, ..usage }; - assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::max_value()); + assert_eq!(scorer.channel_penalty_msat(&candidate, usage, ¶ms), u64::MAX); } #[test] diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 58eaeccac..c5ebef03b 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -2477,7 +2477,7 @@ impl SignerProvider for KeysManager { // roll over, we may generate duplicate keys for two different channels, which could result // in loss of funds. Because we only support 32-bit+ systems, assert that our `AtomicUsize` // doesn't reach `u32::MAX`. - assert!(child_idx < core::u32::MAX as usize, "2^32 channels opened without restart"); + assert!(child_idx < u32::MAX as usize, "2^32 channels opened without restart"); let mut id = [0; 32]; id[0..4].copy_from_slice(&(child_idx as u32).to_be_bytes()); id[4..8].copy_from_slice(&self.starting_time_nanos.to_be_bytes());