Skip to content

Commit

Permalink
Merge pull request fedimint#6309 from m1sterc001guy/min_cltv
Browse files Browse the repository at this point in the history
fix: LNv1 add min_cltv_delta to timelock constant
  • Loading branch information
elsirion authored Nov 8, 2024
2 parents d224592 + 82ddc2e commit 1d956fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion devimint/src/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::util::{
poll, poll_with_timeout, ClnLightningCli, GatewayClnExtension, ProcessHandle, ProcessManager,
};
use crate::vars::utf8;
use crate::version_constants::VERSION_0_4_0_ALPHA;
use crate::version_constants::{VERSION_0_4_0_ALPHA, VERSION_0_5_0_ALPHA};
use crate::{cmd, poll_eq, Gatewayd};

#[derive(Clone)]
Expand Down Expand Up @@ -776,12 +776,21 @@ impl Lnd {
bitcoin::hashes::HashEngine::input(&mut engine, &preimage);
bitcoin::hashes::sha256::Hash::from_engine(engine)
};
// TODO(support:v0.5): LNv1 cannot pay HOLD invoices with a CLTV expiry greater
// than 500 before v0.5
let fedimint_cli_version = crate::util::FedimintCli::version_or_default().await;
let cltv_expiry = if fedimint_cli_version >= *VERSION_0_5_0_ALPHA {
650
} else {
100
};
let hold_request = self
.invoices_client_lock()
.await?
.add_hold_invoice(tonic_lnd::invoicesrpc::AddHoldInvoiceRequest {
value_msat: amount as i64,
hash: hash.to_byte_array().to_vec(),
cltv_expiry,
..Default::default()
})
.await?
Expand Down
7 changes: 6 additions & 1 deletion modules/fedimint-ln-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,12 @@ impl LightningClientModule {
.fetch_consensus_block_count()
.await?
.ok_or(format_err!("Cannot get consensus block count"))?;
let absolute_timelock = consensus_count + OUTGOING_LN_CONTRACT_TIMELOCK - 1;

// Add the timelock to the current block count and the invoice's
// `min_cltv_delta`
let min_final_cltv = invoice.min_final_cltv_expiry_delta();
let absolute_timelock =
consensus_count + min_final_cltv + OUTGOING_LN_CONTRACT_TIMELOCK - 1;

// Compute amount to lock in the outgoing contract
let invoice_amount = Amount::from_msats(
Expand Down

0 comments on commit 1d956fd

Please sign in to comment.