@ -1724,92 +1724,6 @@ static struct io_plan *handle_txout_reply(struct io_conn *conn,
return daemon_conn_read_next ( conn , daemon - > master ) ;
return daemon_conn_read_next ( conn , daemon - > master ) ;
}
}
/* Fix up the channel_update to include the type if it doesn't currently have
* one . See ElementsProject / lightning # 1730 and lightningnetwork / lnd # 1599 for the
* in - depth discussion on why we break message parsing here . . . */
static u8 * patch_channel_update ( const tal_t * ctx , u8 * channel_update TAKES )
{
u8 * fixed ;
if ( channel_update ! = NULL & &
fromwire_peektype ( channel_update ) ! = WIRE_CHANNEL_UPDATE ) {
/* This should be a channel_update, prefix with the
* WIRE_CHANNEL_UPDATE type , but isn ' t . Let ' s prefix it . */
fixed = tal_arr ( ctx , u8 , 0 ) ;
towire_u16 ( & fixed , WIRE_CHANNEL_UPDATE ) ;
towire ( & fixed , channel_update , tal_bytelen ( channel_update ) ) ;
if ( taken ( channel_update ) )
tal_free ( channel_update ) ;
return fixed ;
} else {
return tal_dup_talarr ( ctx , u8 , channel_update ) ;
}
}
/* Return NULL if the wrapped onion error message has no channel_update field,
* or return the embedded channel_update message otherwise . */
static u8 * channel_update_from_onion_error ( const tal_t * ctx ,
const u8 * onion_message )
{
u8 * channel_update = NULL ;
struct amount_msat unused_msat ;
u32 unused32 ;
/* Identify failcodes that have some channel_update.
*
* TODO > BOLT 1.0 : Add new failcodes when updating to a
* new BOLT version . */
if ( ! fromwire_temporary_channel_failure ( ctx ,
onion_message ,
& channel_update ) & &
! fromwire_amount_below_minimum ( ctx ,
onion_message , & unused_msat ,
& channel_update ) & &
! fromwire_fee_insufficient ( ctx ,
onion_message , & unused_msat ,
& channel_update ) & &
! fromwire_incorrect_cltv_expiry ( ctx ,
onion_message , & unused32 ,
& channel_update ) & &
! fromwire_expiry_too_soon ( ctx ,
onion_message ,
& channel_update ) )
/* No channel update. */
return NULL ;
return patch_channel_update ( ctx , take ( channel_update ) ) ;
}
/*~ lightningd tells us when a payment has failed; we mark the channel (or
* node ) unusable here if it ' s a permanent failure , and unpack any
* channel_update contained in the error . */
static struct io_plan * handle_payment_failure ( struct io_conn * conn ,
struct daemon * daemon ,
const u8 * msg )
{
u8 * error ;
u8 * channel_update ;
if ( ! fromwire_gossipd_payment_failure ( msg , msg , & error ) )
master_badmsg ( WIRE_GOSSIPD_PAYMENT_FAILURE , msg ) ;
channel_update = channel_update_from_onion_error ( tmpctx , error ) ;
if ( channel_update ) {
status_debug ( " Extracted channel_update %s from onionreply %s " ,
tal_hex ( tmpctx , channel_update ) ,
tal_hex ( tmpctx , error ) ) ;
u8 * err = handle_channel_update ( daemon - > rstate , channel_update ,
NULL , NULL , true ) ;
if ( err ) {
status_info ( " extracted bad channel_update %s from onionreply %s " ,
sanitize_error ( err , err , NULL ) ,
error ) ;
tal_free ( err ) ;
}
}
return daemon_conn_read_next ( conn , daemon - > master ) ;
}
/*~ lightningd tells us when about a gossip message directly, when told to by
/*~ lightningd tells us when about a gossip message directly, when told to by
* the addgossip RPC call . That ' s usually used when a plugin gets an update
* the addgossip RPC call . That ' s usually used when a plugin gets an update
* returned in an payment error . */
* returned in an payment error . */
@ -1938,9 +1852,6 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_GET_TXOUT_REPLY :
case WIRE_GOSSIPD_GET_TXOUT_REPLY :
return handle_txout_reply ( conn , daemon , msg ) ;
return handle_txout_reply ( conn , daemon , msg ) ;
case WIRE_GOSSIPD_PAYMENT_FAILURE :
return handle_payment_failure ( conn , daemon , msg ) ;
case WIRE_GOSSIPD_OUTPOINT_SPENT :
case WIRE_GOSSIPD_OUTPOINT_SPENT :
return handle_outpoint_spent ( conn , daemon , msg ) ;
return handle_outpoint_spent ( conn , daemon , msg ) ;