Skip to content

Commit 54a98ee

Browse files
author
Elias Rohrer
committed
Move and rename CTLV delta limit.
1 parent 922d8e1 commit 54a98ee

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

lightning-invoice/src/payment.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ use bitcoin_hashes::sha256::Hash as Sha256;
140140

141141
use crate::prelude::*;
142142
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
143-
use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure, MAX_TOTAL_CLTV_EXPIRY_DELTA};
143+
use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
144144
use lightning::ln::msgs::LightningError;
145145
use lightning::routing::scoring::{LockableScore, Score};
146-
use lightning::routing::router::{Payee, Route, RouteParameters};
146+
use lightning::routing::router::{Payee, Route, RouteParameters, DEFAULT_MAX_TOTAL_CLTV_DELTA};
147147
use lightning::util::events::{Event, EventHandler};
148148
use lightning::util::logger::Logger;
149149
use crate::sync::Mutex;
@@ -306,7 +306,7 @@ where
306306
payee,
307307
final_value_msat: invoice.amount_milli_satoshis().or(amount_msats).unwrap(),
308308
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
309-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
309+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
310310
};
311311

312312
let send_payment = |route: &Route| {
@@ -335,7 +335,7 @@ where
335335
payee: Payee::for_keysend(pubkey),
336336
final_value_msat: amount_msats,
337337
final_cltv_expiry_delta,
338-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
338+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
339339
};
340340

341341
let send_payment = |route: &Route| {
@@ -1275,7 +1275,7 @@ mod tests {
12751275
payee,
12761276
final_value_msat,
12771277
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
1278-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
1278+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
12791279
}
12801280
}
12811281
}

lightning-invoice/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ mod test {
194194
use core::time::Duration;
195195
use {Currency, Description, InvoiceDescription};
196196
use lightning::ln::PaymentHash;
197-
use lightning::ln::channelmanager::{MIN_FINAL_CLTV_EXPIRY,MAX_TOTAL_CLTV_EXPIRY_DELTA};
197+
use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY;
198198
use lightning::ln::functional_test_utils::*;
199199
use lightning::ln::features::InitFeatures;
200200
use lightning::ln::msgs::ChannelMessageHandler;
201-
use lightning::routing::router::{Payee, RouteParameters, find_route};
201+
use lightning::routing::router::{Payee, RouteParameters, find_route, DEFAULT_MAX_TOTAL_CLTV_DELTA};
202202
use lightning::util::events::MessageSendEventsProvider;
203203
use lightning::util::test_utils;
204204
use utils::create_invoice_from_channelmanager_and_duration_since_epoch;
@@ -224,7 +224,7 @@ mod test {
224224
payee,
225225
final_value_msat: invoice.amount_milli_satoshis().unwrap(),
226226
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
227-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
227+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
228228
};
229229
let first_hops = nodes[0].node.list_usable_channels();
230230
let network_graph = node_cfgs[0].network_graph;

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use chain::transaction::{OutPoint, TransactionData};
4545
use ln::{PaymentHash, PaymentPreimage, PaymentSecret};
4646
use ln::channel::{Channel, ChannelError, ChannelUpdateStatus, UpdateFulfillCommitFetch};
4747
use ln::features::{InitFeatures, NodeFeatures};
48-
use routing::router::{Payee, Route, RouteHop, RoutePath, RouteParameters};
48+
use routing::router::{Payee, Route, RouteHop, RoutePath, RouteParameters, DEFAULT_MAX_TOTAL_CLTV_DELTA};
4949
use ln::msgs;
5050
use ln::msgs::NetAddress;
5151
use ln::onion_utils;
@@ -1119,9 +1119,6 @@ pub(super) const CLTV_FAR_FAR_AWAY: u32 = 6 * 24 * 7; //TODO?
11191119
// a payment was being routed, so we add an extra block to be safe.
11201120
pub const MIN_FINAL_CLTV_EXPIRY: u32 = HTLC_FAIL_BACK_BUFFER + 3;
11211121

1122-
/// Maximum total CTLV difference we allow for a full payment path
1123-
pub const MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = 1000;
1124-
11251122
// Check that our CLTV_EXPIRY is at least CLTV_CLAIM_BUFFER + ANTI_REORG_DELAY + LATENCY_GRACE_PERIOD_BLOCKS,
11261123
// ie that if the next-hop peer fails the HTLC within
11271124
// LATENCY_GRACE_PERIOD_BLOCKS then we'll still have CLTV_CLAIM_BUFFER left to timeout it onchain,
@@ -2654,7 +2651,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
26542651
payee: payee.clone(),
26552652
final_value_msat: pending_amt_unsent,
26562653
final_cltv_expiry_delta: max_unsent_cltv_delta,
2657-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
2654+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
26582655
})
26592656
} else { None }
26602657
} else { None },
@@ -3601,7 +3598,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
36013598
payee: payee_data,
36023599
final_value_msat: path_last_hop.fee_msat,
36033600
final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta,
3604-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
3601+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
36053602
})
36063603
} else { None };
36073604
let mut pending_events = self.pending_events.lock().unwrap();
@@ -3687,7 +3684,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
36873684
payee: payee_data.clone(),
36883685
final_value_msat: path_last_hop.fee_msat,
36893686
final_cltv_expiry_delta: path_last_hop.cltv_expiry_delta,
3690-
max_total_cltv_expiry_delta: MAX_TOTAL_CLTV_EXPIRY_DELTA,
3687+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_DELTA,
36913688
})
36923689
} else { None };
36933690
log_trace!(self.logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));

lightning/src/routing/router.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ impl_writeable_tlv_based!(RouteParameters, {
177177
(6, max_total_cltv_expiry_delta, required),
178178
});
179179

180+
/// Maximum total CTLV difference we allow for a full payment path
181+
pub const DEFAULT_MAX_TOTAL_CLTV_DELTA: u32 = 1000;
182+
183+
180184
/// The recipient of a payment.
181185
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
182186
pub struct Payee {

0 commit comments

Comments
 (0)