@@ -253,6 +253,16 @@ static struct command_result *handle_failure(struct routefail *r)
253253 if (route -> hops )
254254 path_len = tal_count (route -> hops );
255255
256+ enum onion_wire failcode ;
257+ if (result -> failcode )
258+ failcode = * result -> failcode ;
259+ else {
260+ payment_note (
261+ payment , LOG_UNUSUAL ,
262+ "The failcode is unknown we skip error handling" );
263+ goto finish ;
264+ }
265+
256266 if (!result -> erring_index ) {
257267 payment_note (
258268 payment , LOG_UNUSUAL ,
@@ -270,7 +280,7 @@ static struct command_result *handle_failure(struct routefail *r)
270280 node_type = INTERMEDIATE_NODE ;
271281 }
272282
273- switch (result -> failcode ) {
283+ switch (failcode ) {
274284 // intermediate only
275285 case WIRE_INVALID_ONION_VERSION :
276286 case WIRE_INVALID_ONION_HMAC :
@@ -280,8 +290,8 @@ static struct command_result *handle_failure(struct routefail *r)
280290 payment_note (payment , LOG_UNUSUAL ,
281291 "Final node reported strange "
282292 "error code %04x (%s)" ,
283- result -> failcode ,
284- onion_wire_name (result -> failcode ));
293+ failcode ,
294+ onion_wire_name (failcode ));
285295 break ;
286296 case ORIGIN_NODE :
287297 case INTERMEDIATE_NODE :
@@ -297,8 +307,8 @@ static struct command_result *handle_failure(struct routefail *r)
297307 route_final_error (
298308 route , PAY_DESTINATION_PERM_FAIL ,
299309 "Received error code %04x (%s) at final node." ,
300- result -> failcode ,
301- onion_wire_name (result -> failcode ));
310+ failcode ,
311+ onion_wire_name (failcode ));
302312
303313 break ;
304314 case INTERMEDIATE_NODE :
@@ -311,7 +321,7 @@ static struct command_result *handle_failure(struct routefail *r)
311321 payment_disable_node (
312322 payment , route -> hops [* result -> erring_index ].node_id ,
313323 LOG_DBG , "received %s from previous hop" ,
314- onion_wire_name (result -> failcode ));
324+ onion_wire_name (failcode ));
315325 break ;
316326 case UNKNOWN_NODE :
317327 break ;
@@ -353,8 +363,8 @@ static struct command_result *handle_failure(struct routefail *r)
353363 payment_note (payment , LOG_UNUSUAL ,
354364 "Intermediate node reported strange "
355365 "error code %04x (%s)" ,
356- result -> failcode ,
357- onion_wire_name (result -> failcode ));
366+ failcode ,
367+ onion_wire_name (failcode ));
358368 break ;
359369 case ORIGIN_NODE :
360370 case FINAL_NODE :
@@ -371,15 +381,15 @@ static struct command_result *handle_failure(struct routefail *r)
371381 route_final_error (
372382 route , PAY_DESTINATION_PERM_FAIL ,
373383 "Received error code %04x (%s) at final node." ,
374- result -> failcode ,
375- onion_wire_name (result -> failcode ));
384+ failcode ,
385+ onion_wire_name (failcode ));
376386 break ;
377387 case ORIGIN_NODE :
378388 route_final_error (
379389 route , PAY_UNSPECIFIED_ERROR ,
380390 "Error code %04x (%s) reported at the origin." ,
381- result -> failcode ,
382- onion_wire_name (result -> failcode ));
391+ failcode ,
392+ onion_wire_name (failcode ));
383393 break ;
384394 case INTERMEDIATE_NODE :
385395 if (!route -> hops )
@@ -388,7 +398,7 @@ static struct command_result *handle_failure(struct routefail *r)
388398 payment ,
389399 route -> hops [* result -> erring_index - 1 ].node_id ,
390400 LOG_INFORM , "received error %s" ,
391- onion_wire_name (result -> failcode ));
401+ onion_wire_name (failcode ));
392402 break ;
393403 case UNKNOWN_NODE :
394404 break ;
@@ -406,22 +416,22 @@ static struct command_result *handle_failure(struct routefail *r)
406416 payment_note (payment , LOG_UNUSUAL ,
407417 "Final node reported strange "
408418 "error code %04x (%s)" ,
409- result -> failcode ,
410- onion_wire_name (result -> failcode ));
419+ failcode ,
420+ onion_wire_name (failcode ));
411421
412422 route_final_error (
413423 route , PAY_DESTINATION_PERM_FAIL ,
414424 "Received error code %04x (%s) at final node." ,
415- result -> failcode ,
416- onion_wire_name (result -> failcode ));
425+ failcode ,
426+ onion_wire_name (failcode ));
417427
418428 break ;
419429 case ORIGIN_NODE :
420430 payment_note (payment , LOG_UNUSUAL ,
421431 "First node reported strange "
422432 "error code %04x (%s)" ,
423- result -> failcode ,
424- onion_wire_name (result -> failcode ));
433+ failcode ,
434+ onion_wire_name (failcode ));
425435
426436 break ;
427437 case INTERMEDIATE_NODE :
@@ -431,7 +441,7 @@ static struct command_result *handle_failure(struct routefail *r)
431441 .scid = route -> hops [* result -> erring_index ].scid ,
432442 .dir = route -> hops [* result -> erring_index ].direction };
433443 payment_disable_chan (payment , scidd , LOG_INFORM , "%s" ,
434- onion_wire_name (result -> failcode ));
444+ onion_wire_name (failcode ));
435445
436446 break ;
437447 case UNKNOWN_NODE :
@@ -449,16 +459,16 @@ static struct command_result *handle_failure(struct routefail *r)
449459 payment_note (payment , LOG_UNUSUAL ,
450460 "Intermediate node reported strange "
451461 "error code %04x (%s)" ,
452- result -> failcode ,
453- onion_wire_name (result -> failcode ));
462+ failcode ,
463+ onion_wire_name (failcode ));
454464
455465 if (!route -> hops )
456466 break ;
457467 payment_disable_node (
458468 payment ,
459469 route -> hops [* result -> erring_index - 1 ].node_id ,
460470 LOG_INFORM , "received error %s" ,
461- onion_wire_name (result -> failcode ));
471+ onion_wire_name (failcode ));
462472
463473 break ;
464474 case ORIGIN_NODE :
@@ -478,22 +488,22 @@ static struct command_result *handle_failure(struct routefail *r)
478488 payment_note (payment , LOG_UNUSUAL ,
479489 "Final node reported strange "
480490 "error code %04x (%s)" ,
481- result -> failcode ,
482- onion_wire_name (result -> failcode ));
491+ failcode ,
492+ onion_wire_name (failcode ));
483493
484494 route_final_error (
485495 route , PAY_DESTINATION_PERM_FAIL ,
486496 "Received error code %04x (%s) at final node." ,
487- result -> failcode ,
488- onion_wire_name (result -> failcode ));
497+ failcode ,
498+ onion_wire_name (failcode ));
489499
490500 break ;
491501 case ORIGIN_NODE :
492502 payment_note (payment , LOG_UNUSUAL ,
493503 "First node reported strange "
494504 "error code %04x (%s)" ,
495- result -> failcode ,
496- onion_wire_name (result -> failcode ));
505+ failcode ,
506+ onion_wire_name (failcode ));
497507
498508 break ;
499509 case INTERMEDIATE_NODE :
@@ -507,7 +517,7 @@ static struct command_result *handle_failure(struct routefail *r)
507517 .dir = route -> hops [* result -> erring_index ].direction };
508518 payment_warn_chan (payment , scidd , LOG_INFORM ,
509519 "received error %s" ,
510- onion_wire_name (result -> failcode ));
520+ onion_wire_name (failcode ));
511521
512522 break ;
513523 case UNKNOWN_NODE :
@@ -525,14 +535,14 @@ static struct command_result *handle_failure(struct routefail *r)
525535 payment_note (payment , LOG_UNUSUAL ,
526536 "Final node reported strange "
527537 "error code %04x (%s)" ,
528- result -> failcode ,
529- onion_wire_name (result -> failcode ));
538+ failcode ,
539+ onion_wire_name (failcode ));
530540
531541 route_final_error (
532542 route , PAY_DESTINATION_PERM_FAIL ,
533543 "Received error code %04x (%s) at final node." ,
534- result -> failcode ,
535- onion_wire_name (result -> failcode ));
544+ failcode ,
545+ onion_wire_name (failcode ));
536546
537547 break ;
538548 case INTERMEDIATE_NODE :
0 commit comments