Skip to content

Commit b775a25

Browse files
committed
add cltv limit buffer for incoming invoices
1 parent c248a14 commit b775a25

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

wallets/server/wrap.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const INCOMING_EXPIRATION_BUFFER_MSECS = 120_000 // the buffer enforce for the i
1010
const MAX_OUTGOING_CLTV_DELTA = 1000 // the maximum cltv delta we'll allow for the outgoing invoice
1111
export const MIN_SETTLEMENT_CLTV_DELTA = 80 // the minimum blocks we'll leave for settling the incoming invoice
1212
const FEE_ESTIMATE_TIMEOUT_SECS = 5 // the timeout for the fee estimate request
13+
// the buffer in case we underestimated the cltv delta with our probe
14+
// also ln-service enforces a 3 block buffer ontop of the final hop's cltv delta
15+
// preventing outgoing cltv limits that may be exact from being sent
16+
const CLTV_DELTA_BUFFER = 10
1317

1418
/*
1519
The wrapInvoice function is used to wrap an outgoing invoice with the necessary parameters for an incoming hold invoice.
@@ -165,8 +169,9 @@ async function wrapBolt11Params ({ msats, bolt11, maxRoutingFeeMsats, hideInvoic
165169
*/
166170
wrapped.cltv_delta = toPositiveNumber(
167171
toPositiveNumber(timeLockDelay) + toPositiveNumber(inv.cltv_delta) -
168-
toPositiveNumber(blockHeight) + MIN_SETTLEMENT_CLTV_DELTA)
169-
console.log('routingFeeMsat', routingFeeMsat, 'timeLockDelay', timeLockDelay, 'blockHeight', blockHeight)
172+
toPositiveNumber(blockHeight) + MIN_SETTLEMENT_CLTV_DELTA + CLTV_DELTA_BUFFER)
173+
console.log('routingFeeMsat', routingFeeMsat, 'wrapped cltv_delta', wrapped.cltv_delta,
174+
'timeLockDelay', timeLockDelay, 'inv.cltv_delta', inv.cltv_delta, 'blockHeight', blockHeight)
170175

171176
// validate the cltv delta
172177
if (wrapped.cltv_delta > MAX_OUTGOING_CLTV_DELTA) {

0 commit comments

Comments
 (0)