Skip to content

Commit

Permalink
Drop the stale final_expiry_too_soon error code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Dec 1, 2022
1 parent 5ced282 commit 201dbcd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,10 +2042,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
// Also, ensure that, in the case of an unknown preimage for the received payment hash, our
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
if (hop_data.outgoing_cltv_value as u64) <= self.best_block.read().unwrap().height() as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
let current_height: u32 = self.best_block.read().unwrap().height();
if (hop_data.outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
let mut err_data = Vec::with_capacity(12);
err_data.extend_from_slice(&amt_msat.to_be_bytes());
err_data.extend_from_slice(&current_height.to_be_bytes());
return Err(ReceiveError {
err_code: 17,
err_data: Vec::new(),
err_code: 0x4000 | 15, err_data,
msg: "The final CLTV expiry is too soon to handle",
});
}
Expand Down
11 changes: 7 additions & 4 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ fn test_onion_failure() {
connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
connect_blocks(&nodes[1], height - nodes[1].best_block_info().1);
connect_blocks(&nodes[2], height - nodes[2].best_block_info().1);
}, || {}, true, Some(17), None, None);
}, || {}, false, Some(0x4000 | 15), None, None);

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

// Ensure the payment fails with the expected error.
let error_data = Vec::new();
let mut error_data = recv_value_msat.to_be_bytes().to_vec();
error_data.extend_from_slice(
&nodes[0].node.best_block.read().unwrap().height().to_be_bytes(),
);
let mut fail_conditions = PaymentFailedConditions::new()
.blamed_scid(phantom_scid)
.expected_htlc_error_data(17, &error_data);
expect_payment_failed_conditions(&nodes[0], payment_hash, false, fail_conditions);
.expected_htlc_error_data(0x4000 | 15, &error_data);
expect_payment_failed_conditions(&nodes[0], payment_hash, true, fail_conditions);
}

#[test]
Expand Down

0 comments on commit 201dbcd

Please sign in to comment.