Add mpp_timeout and invalid_onion_payload descriptions & handling
authorDuncan Dean <duncangleeddean@gmail.com>
Sat, 30 Oct 2021 08:25:44 +0000 (10:25 +0200)
committerDuncan Dean <duncangleeddean@gmail.com>
Tue, 14 Dec 2021 19:11:32 +0000 (21:11 +0200)
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/onion_utils.rs
lightning/src/util/errors.rs

index 05b108fbf25e678e18f16cc36fb7c7a87793d44f..4feae104d759a11fb47ee0b21b1f8f4be20b2311 100644 (file)
@@ -563,4 +563,13 @@ fn test_onion_failure() {
                msg.cltv_expiry = htlc_cltv;
                msg.onion_routing_packet = onion_packet;
        }, ||{}, true, Some(21), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), Some(route.paths[0][0].short_channel_id));
+
+       run_onion_failure_test_with_fail_intercept("mpp_timeout", 200, &nodes, &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
+               // Tamper returning error message
+               let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
+               let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
+               msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], 23, &[0;0]);
+       }, ||{
+               nodes[2].node.fail_htlc_backwards(&payment_hash);
+       }, true, Some(23), None, None);
 }
index c1767c025a3531fe61e523ea39a7250eef5f9732..12dc0e03b264a06b1c012b918fecda8a02a8fead 100644 (file)
@@ -380,7 +380,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
                                                // indicate that payment parameter has failed and no need to
                                                // update Route object
                                                let payment_failed = match error_code & 0xff {
-                                                       15|16|17|18|19 => true,
+                                                       15|16|17|18|19|23 => true,
                                                        _ => false,
                                                } && is_from_final_node; // PERM bit observed below even if this error is from the intermediate nodes
 
index 0c6099f7d5a5e2e8de07bafa1906da8f1edc6538..820bf31c6e090931634b2c58be1f6254060d7c98 100644 (file)
@@ -119,6 +119,8 @@ pub(crate) fn get_onion_error_description(error_code: u16) -> (&'static str, &'s
                _c if _c == 19 => ("The final node indicated the amount in the HTLC does not match the value in the onion", "final_incorrect_htlc_amount"),
                _c if _c == UPDATE|20 => ("Node indicated the outbound channel has been disabled", "channel_disabled"),
                _c if _c == 21 => ("Node indicated the CLTV expiry in the HTLC is too far in the future", "expiry_too_far"),
+               _c if _c == PERM|22 => ("Node indicated that the decrypted onion per-hop payload was not understood by it or is incomplete", "invalid_onion_payload"),
+               _c if _c == 23 => ("The final node indicated the complete amount of the multi-part payment was not received within a reasonable time", "mpp_timeout"),
                _ => ("Unknown", ""),
        }
 }