@@ -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 ,
@@ -272,7 +282,7 @@ static struct command_result *handle_failure(struct routefail *r)
272282 if (* result -> erring_index == 0 )
273283 node_type = ORIGIN_NODE ;
274284
275- switch (result -> failcode ) {
285+ switch (failcode ) {
276286 // intermediate only
277287 case WIRE_INVALID_ONION_VERSION :
278288 case WIRE_INVALID_ONION_HMAC :
@@ -282,8 +292,8 @@ static struct command_result *handle_failure(struct routefail *r)
282292 payment_note (payment , LOG_UNUSUAL ,
283293 "Final node reported strange "
284294 "error code %04x (%s)" ,
285- result -> failcode ,
286- onion_wire_name (result -> failcode ));
295+ failcode ,
296+ onion_wire_name (failcode ));
287297 break ;
288298 case ORIGIN_NODE :
289299 case INTERMEDIATE_NODE :
@@ -299,8 +309,8 @@ static struct command_result *handle_failure(struct routefail *r)
299309 route_final_error (
300310 route , PAY_DESTINATION_PERM_FAIL ,
301311 "Received error code %04x (%s) at final node." ,
302- result -> failcode ,
303- onion_wire_name (result -> failcode ));
312+ failcode ,
313+ onion_wire_name (failcode ));
304314
305315 break ;
306316 case INTERMEDIATE_NODE :
@@ -313,7 +323,7 @@ static struct command_result *handle_failure(struct routefail *r)
313323 payment_disable_node (
314324 payment , route -> hops [* result -> erring_index ].node_id ,
315325 LOG_DBG , "received %s from previous hop" ,
316- onion_wire_name (result -> failcode ));
326+ onion_wire_name (failcode ));
317327 break ;
318328 case UNKNOWN_NODE :
319329 break ;
@@ -329,8 +339,8 @@ static struct command_result *handle_failure(struct routefail *r)
329339 payment_note (payment , LOG_UNUSUAL ,
330340 "Intermediate node reported strange "
331341 "error code %04x (%s)" ,
332- result -> failcode ,
333- onion_wire_name (result -> failcode ));
342+ failcode ,
343+ onion_wire_name (failcode ));
334344 break ;
335345 case ORIGIN_NODE :
336346 case FINAL_NODE :
@@ -347,15 +357,15 @@ static struct command_result *handle_failure(struct routefail *r)
347357 route_final_error (
348358 route , PAY_DESTINATION_PERM_FAIL ,
349359 "Received error code %04x (%s) at final node." ,
350- result -> failcode ,
351- onion_wire_name (result -> failcode ));
360+ failcode ,
361+ onion_wire_name (failcode ));
352362 break ;
353363 case ORIGIN_NODE :
354364 route_final_error (
355365 route , PAY_UNSPECIFIED_ERROR ,
356366 "Error code %04x (%s) reported at the origin." ,
357- result -> failcode ,
358- onion_wire_name (result -> failcode ));
367+ failcode ,
368+ onion_wire_name (failcode ));
359369 break ;
360370 case INTERMEDIATE_NODE :
361371 if (!route -> hops )
@@ -364,7 +374,7 @@ static struct command_result *handle_failure(struct routefail *r)
364374 payment ,
365375 route -> hops [* result -> erring_index - 1 ].node_id ,
366376 LOG_INFORM , "received error %s" ,
367- onion_wire_name (result -> failcode ));
377+ onion_wire_name (failcode ));
368378 break ;
369379 case UNKNOWN_NODE :
370380 break ;
@@ -382,22 +392,22 @@ static struct command_result *handle_failure(struct routefail *r)
382392 payment_note (payment , LOG_UNUSUAL ,
383393 "Final node reported strange "
384394 "error code %04x (%s)" ,
385- result -> failcode ,
386- onion_wire_name (result -> failcode ));
395+ failcode ,
396+ onion_wire_name (failcode ));
387397
388398 route_final_error (
389399 route , PAY_DESTINATION_PERM_FAIL ,
390400 "Received error code %04x (%s) at final node." ,
391- result -> failcode ,
392- onion_wire_name (result -> failcode ));
401+ failcode ,
402+ onion_wire_name (failcode ));
393403
394404 break ;
395405 case ORIGIN_NODE :
396406 payment_note (payment , LOG_UNUSUAL ,
397407 "First node reported strange "
398408 "error code %04x (%s)" ,
399- result -> failcode ,
400- onion_wire_name (result -> failcode ));
409+ failcode ,
410+ onion_wire_name (failcode ));
401411
402412 break ;
403413 case INTERMEDIATE_NODE :
@@ -407,7 +417,7 @@ static struct command_result *handle_failure(struct routefail *r)
407417 .scid = route -> hops [* result -> erring_index ].scid ,
408418 .dir = route -> hops [* result -> erring_index ].direction };
409419 payment_disable_chan (payment , scidd , LOG_INFORM , "%s" ,
410- onion_wire_name (result -> failcode ));
420+ onion_wire_name (failcode ));
411421
412422 break ;
413423 case UNKNOWN_NODE :
@@ -425,16 +435,16 @@ static struct command_result *handle_failure(struct routefail *r)
425435 payment_note (payment , LOG_UNUSUAL ,
426436 "Intermediate node reported strange "
427437 "error code %04x (%s)" ,
428- result -> failcode ,
429- onion_wire_name (result -> failcode ));
438+ failcode ,
439+ onion_wire_name (failcode ));
430440
431441 if (!route -> hops )
432442 break ;
433443 payment_disable_node (
434444 payment ,
435445 route -> hops [* result -> erring_index - 1 ].node_id ,
436446 LOG_INFORM , "received error %s" ,
437- onion_wire_name (result -> failcode ));
447+ onion_wire_name (failcode ));
438448
439449 break ;
440450 case ORIGIN_NODE :
@@ -454,22 +464,22 @@ static struct command_result *handle_failure(struct routefail *r)
454464 payment_note (payment , LOG_UNUSUAL ,
455465 "Final node reported strange "
456466 "error code %04x (%s)" ,
457- result -> failcode ,
458- onion_wire_name (result -> failcode ));
467+ failcode ,
468+ onion_wire_name (failcode ));
459469
460470 route_final_error (
461471 route , PAY_DESTINATION_PERM_FAIL ,
462472 "Received error code %04x (%s) at final node." ,
463- result -> failcode ,
464- onion_wire_name (result -> failcode ));
473+ failcode ,
474+ onion_wire_name (failcode ));
465475
466476 break ;
467477 case ORIGIN_NODE :
468478 payment_note (payment , LOG_UNUSUAL ,
469479 "First node reported strange "
470480 "error code %04x (%s)" ,
471- result -> failcode ,
472- onion_wire_name (result -> failcode ));
481+ failcode ,
482+ onion_wire_name (failcode ));
473483
474484 break ;
475485 case INTERMEDIATE_NODE :
@@ -483,7 +493,7 @@ static struct command_result *handle_failure(struct routefail *r)
483493 .dir = route -> hops [* result -> erring_index ].direction };
484494 payment_warn_chan (payment , scidd , LOG_INFORM ,
485495 "received error %s" ,
486- onion_wire_name (result -> failcode ));
496+ onion_wire_name (failcode ));
487497
488498 break ;
489499 case UNKNOWN_NODE :
@@ -501,14 +511,14 @@ static struct command_result *handle_failure(struct routefail *r)
501511 payment_note (payment , LOG_UNUSUAL ,
502512 "Final node reported strange "
503513 "error code %04x (%s)" ,
504- result -> failcode ,
505- onion_wire_name (result -> failcode ));
514+ failcode ,
515+ onion_wire_name (failcode ));
506516
507517 route_final_error (
508518 route , PAY_DESTINATION_PERM_FAIL ,
509519 "Received error code %04x (%s) at final node." ,
510- result -> failcode ,
511- onion_wire_name (result -> failcode ));
520+ failcode ,
521+ onion_wire_name (failcode ));
512522
513523 break ;
514524 case INTERMEDIATE_NODE :
0 commit comments