Skip to content

Commit c07c1cb

Browse files
committed
Consistently check "no-std" in outbound_payment
The majority of the module checks against feature "no-std" to determine whether or not SystemTime is available. However, the expiration checks use feature "std". This leads to inconsistent behavior when both features are set. Use only "no-std" for consistency.
1 parent be33a96 commit c07c1cb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl Retry {
319319
}
320320
}
321321

322-
#[cfg(feature = "std")]
322+
#[cfg(not(feature = "no-std"))]
323323
pub(super) fn has_expired(route_params: &RouteParameters) -> bool {
324324
if let Some(expiry_time) = route_params.payment_params.expiry_time {
325325
if let Ok(elapsed) = std::time::SystemTime::UNIX_EPOCH.elapsed() {
@@ -894,7 +894,7 @@ impl OutboundPayments {
894894
IH: Fn() -> InFlightHtlcs,
895895
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
896896
{
897-
#[cfg(feature = "std")] {
897+
#[cfg(not(feature = "no-std"))] {
898898
if has_expired(&route_params) {
899899
log_error!(logger, "Payment with id {} and hash {} had expired before we started paying",
900900
payment_id, payment_hash);
@@ -951,7 +951,7 @@ impl OutboundPayments {
951951
IH: Fn() -> InFlightHtlcs,
952952
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
953953
{
954-
#[cfg(feature = "std")] {
954+
#[cfg(not(feature = "no-std"))] {
955955
if has_expired(&route_params) {
956956
log_error!(logger, "Payment params expired on retry, abandoning payment {}", &payment_id);
957957
self.abandon_payment(payment_id, PaymentFailureReason::PaymentExpired, pending_events);
@@ -1830,7 +1830,7 @@ mod tests {
18301830
use crate::ln::features::{ChannelFeatures, NodeFeatures};
18311831
use crate::ln::msgs::{ErrorAction, LightningError};
18321832
use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, Retry, RetryableSendFailure, StaleExpiration};
1833-
#[cfg(feature = "std")]
1833+
#[cfg(not(feature = "no-std"))]
18341834
use crate::offers::invoice::DEFAULT_RELATIVE_EXPIRY;
18351835
use crate::offers::offer::OfferBuilder;
18361836
use crate::offers::test_utils::*;
@@ -1865,12 +1865,12 @@ mod tests {
18651865
}
18661866

18671867
#[test]
1868-
#[cfg(feature = "std")]
1868+
#[cfg(not(feature = "no-std"))]
18691869
fn fails_paying_after_expiration() {
18701870
do_fails_paying_after_expiration(false);
18711871
do_fails_paying_after_expiration(true);
18721872
}
1873-
#[cfg(feature = "std")]
1873+
#[cfg(not(feature = "no-std"))]
18741874
fn do_fails_paying_after_expiration(on_retry: bool) {
18751875
let outbound_payments = OutboundPayments::new();
18761876
let logger = test_utils::TestLogger::new();
@@ -2160,7 +2160,7 @@ mod tests {
21602160
assert!(pending_events.lock().unwrap().is_empty());
21612161
}
21622162

2163-
#[cfg(feature = "std")]
2163+
#[cfg(not(feature = "no-std"))]
21642164
#[test]
21652165
fn fails_sending_payment_for_expired_bolt12_invoice() {
21662166
let logger = test_utils::TestLogger::new();

0 commit comments

Comments
 (0)