Skip to content

Commit 201dbcd

Browse files
committed
Drop the stale final_expiry_too_soon error code
This replaces `final_expiry_too_soon` with `incorrect_or_unknown_payment` as was done in lightning/bolts#608. Note that the rationale for this (that it may expose whether you are the final recipient for the payment or not) does not currently apply to us - we don't apply different final CLTV values to different payments. However, we might in the future, and this will make us slightly more consistent with other nodes.
1 parent 5ced282 commit 201dbcd

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,10 +2042,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
20422042
// Also, ensure that, in the case of an unknown preimage for the received payment hash, our
20432043
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
20442044
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
2045-
if (hop_data.outgoing_cltv_value as u64) <= self.best_block.read().unwrap().height() as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2045+
let current_height: u32 = self.best_block.read().unwrap().height();
2046+
if (hop_data.outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2047+
let mut err_data = Vec::with_capacity(12);
2048+
err_data.extend_from_slice(&amt_msat.to_be_bytes());
2049+
err_data.extend_from_slice(&current_height.to_be_bytes());
20462050
return Err(ReceiveError {
2047-
err_code: 17,
2048-
err_data: Vec::new(),
2051+
err_code: 0x4000 | 15, err_data,
20492052
msg: "The final CLTV expiry is too soon to handle",
20502053
});
20512054
}

lightning/src/ln/onion_route_tests.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ fn test_onion_failure() {
548548
connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
549549
connect_blocks(&nodes[1], height - nodes[1].best_block_info().1);
550550
connect_blocks(&nodes[2], height - nodes[2].best_block_info().1);
551-
}, || {}, true, Some(17), None, None);
551+
}, || {}, false, Some(0x4000 | 15), None, None);
552552

553553
run_onion_failure_test("final_incorrect_cltv_expiry", 1, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || {
554554
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
@@ -1099,11 +1099,14 @@ fn test_phantom_failure_too_low_cltv() {
10991099
commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false);
11001100

11011101
// Ensure the payment fails with the expected error.
1102-
let error_data = Vec::new();
1102+
let mut error_data = recv_value_msat.to_be_bytes().to_vec();
1103+
error_data.extend_from_slice(
1104+
&nodes[0].node.best_block.read().unwrap().height().to_be_bytes(),
1105+
);
11031106
let mut fail_conditions = PaymentFailedConditions::new()
11041107
.blamed_scid(phantom_scid)
1105-
.expected_htlc_error_data(17, &error_data);
1106-
expect_payment_failed_conditions(&nodes[0], payment_hash, false, fail_conditions);
1108+
.expected_htlc_error_data(0x4000 | 15, &error_data);
1109+
expect_payment_failed_conditions(&nodes[0], payment_hash, true, fail_conditions);
11071110
}
11081111

11091112
#[test]

0 commit comments

Comments
 (0)