@ -341,14 +341,14 @@ static void handle_peer_shutdown(struct state *state, u8 *msg)
struct channel_id cid ;
if ( ! fromwire_shutdown ( tmpctx , msg , & cid , & scriptpubkey ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Bad shutdown %s " , tal_hex ( msg , msg ) ) ;
if ( tal_count ( state - > upfront_shutdown_script [ REMOTE ] )
& & ! memeq ( scriptpubkey , tal_count ( scriptpubkey ) ,
state - > upfront_shutdown_script [ REMOTE ] ,
tal_count ( state - > upfront_shutdown_script [ REMOTE ] ) ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" scriptpubkey %s is not as agreed upfront (%s) " ,
tal_hex ( state , scriptpubkey ) ,
tal_hex ( state ,
@ -391,7 +391,7 @@ static void check_channel_id(struct state *state,
* the ` temporary_channel_id ` in the ` open_channel ` message .
*/
if ( ! channel_id_eq ( id_in , orig_id ) )
peer_failed ( state - > pps , id_in ,
peer_failed_err ( state - > pps , id_in ,
" channel ids don't match. expected %s, got %s " ,
type_to_string ( tmpctx , struct channel_id , orig_id ) ,
type_to_string ( tmpctx , struct channel_id , id_in ) ) ;
@ -778,8 +778,7 @@ static void handle_tx_sigs(struct state *state, const u8 *msg)
cast_const3 (
struct witness_stack * * * ,
& ws ) ) )
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Bad tx_signatures %s " ,
tal_hex ( msg , msg ) ) ;
@ -796,8 +795,7 @@ static void handle_tx_sigs(struct state *state, const u8 *msg)
/* On reconnect, we expect them to resend tx_sigs if they haven't
* gotten our funding_locked yet */
if ( state - > funding_locked [ REMOTE ] & & ! state - > reconnected )
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" tx_signatures sent after funding_locked %s " ,
tal_hex ( msg , msg ) ) ;
@ -825,7 +823,8 @@ static void handle_tx_sigs(struct state *state, const u8 *msg)
continue ;
if ( j = = tal_count ( ws ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" Mismatch witness stack count %s " ,
tal_hex ( msg , msg ) ) ;
@ -929,7 +928,7 @@ static bool send_next(struct state *state, struct wally_psbt **psbt)
/* We should always get a updated psbt back */
if ( ! updated_psbt )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Unable to determine next tx update " ) ;
state - > changeset = tal_free ( state - > changeset ) ;
@ -1096,7 +1095,7 @@ static bool run_tx_interactive(struct state *state,
cast_const2 ( u8 * * ,
& redeemscript ) ,
add_tlvs ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Parsing tx_add_input %s " ,
tal_hex ( tmpctx , msg ) ) ;
@ -1109,7 +1108,7 @@ static bool run_tx_interactive(struct state *state,
* - it receives more than 2 ^ 12 ` tx_add_input `
* messages */
if ( + + state - > tx_msg_count [ TX_ADD_INPUT ] > MAX_TX_MSG_RCVD )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Too many `tx_add_input`s "
" received " ) ;
/*
@ -1122,7 +1121,7 @@ static bool run_tx_interactive(struct state *state,
* with the incorrect parity
*/
if ( serial_id % 2 = = our_role )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid serial_id rcvd. % " PRIu64 ,
serial_id ) ;
/*
@ -1132,7 +1131,7 @@ static bool run_tx_interactive(struct state *state,
* - it recieves a duplicate ` serial_id `
*/
if ( psbt_find_serial_input ( psbt , serial_id ) ! = - 1 )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Duplicate serial_id rcvd. "
" % " PRIu64 , serial_id ) ;
@ -1140,11 +1139,11 @@ static bool run_tx_interactive(struct state *state,
len = tal_bytelen ( tx_bytes ) ;
tx = pull_bitcoin_tx ( state , & tx_bytes , & len ) ;
if ( ! tx | | len ! = 0 )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid tx sent. " ) ;
if ( outnum > = tx - > wtx - > num_outputs )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid tx outnum sent. %u " , outnum ) ;
/*
* BOLT - fe0351ca2cea3105c4f2eb18c571afca9d21c85b # 2 :
@ -1155,7 +1154,7 @@ static bool run_tx_interactive(struct state *state,
*/
if ( ! is_segwit_output ( & tx - > wtx - > outputs [ outnum ] ,
redeemscript ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid tx sent. Not SegWit %s " ,
type_to_string ( tmpctx ,
struct bitcoin_tx ,
@ -1173,7 +1172,8 @@ static bool run_tx_interactive(struct state *state,
*/
bitcoin_txid ( tx , & txid ) ;
if ( psbt_has_input ( psbt , & txid , outnum ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" Unable to add input - "
" already present " ) ;
@ -1189,7 +1189,7 @@ static bool run_tx_interactive(struct state *state,
NULL ,
redeemscript ) ;
if ( ! in )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Unable to add input " ) ;
tal_wally_start ( ) ;
@ -1220,7 +1220,7 @@ static bool run_tx_interactive(struct state *state,
int input_index ;
if ( ! fromwire_tx_remove_input ( msg , & cid , & serial_id ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Parsing tx_remove_input %s " ,
tal_hex ( tmpctx , msg ) ) ;
@ -1233,7 +1233,7 @@ static bool run_tx_interactive(struct state *state,
* - it receives more than 2 ^ 12 ` tx_rm_input `
* messages */
if ( + + state - > tx_msg_count [ TX_RM_INPUT ] > MAX_TX_MSG_RCVD )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Too many `tx_rm_input`s "
" received " ) ;
@ -1242,13 +1242,13 @@ static bool run_tx_interactive(struct state *state,
* - MUST NOT send a ` tx_remove_input ` for an
* input which is not theirs */
if ( serial_id % 2 = = our_role )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid serial_id rcvd. % " PRIu64 ,
serial_id ) ;
input_index = psbt_find_serial_input ( psbt , serial_id ) ;
if ( input_index = = - 1 )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" No input added with serial_id "
" % " PRIu64 , serial_id ) ;
@ -1263,7 +1263,8 @@ static bool run_tx_interactive(struct state *state,
if ( ! fromwire_tx_add_output ( tmpctx , msg , & cid ,
& serial_id , & value ,
& scriptpubkey ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" Parsing tx_add_output %s " ,
tal_hex ( tmpctx , msg ) ) ;
check_channel_id ( state , & cid , & state - > channel_id ) ;
@ -1275,7 +1276,7 @@ static bool run_tx_interactive(struct state *state,
* - it receives more than 2 ^ 12 ` tx_add_output `
* messages */
if ( + + state - > tx_msg_count [ TX_ADD_OUTPUT ] > MAX_TX_MSG_RCVD )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Too many `tx_add_output`s "
" received " ) ;
@ -1287,12 +1288,12 @@ static bool run_tx_interactive(struct state *state,
* - it receives a ` serial_id ` from the peer with the
* incorrect parity */
if ( serial_id % 2 = = our_role )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid serial_id rcvd. % " PRIu64 ,
serial_id ) ;
if ( psbt_find_serial_output ( psbt , serial_id ) ! = - 1 )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Duplicate serial_id rcvd. "
" % " PRIu64 , serial_id ) ;
amt = amount_sat ( value ) ;
@ -1304,7 +1305,7 @@ static bool run_tx_interactive(struct state *state,
int output_index ;
if ( ! fromwire_tx_remove_output ( msg , & cid , & serial_id ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Parsing tx_remove_output %s " ,
tal_hex ( tmpctx , msg ) ) ;
@ -1317,7 +1318,7 @@ static bool run_tx_interactive(struct state *state,
* - it receives more than 2 ^ 12 ` tx_rm_output `
* messages */
if ( + + state - > tx_msg_count [ TX_RM_OUTPUT ] > MAX_TX_MSG_RCVD )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Too many `tx_rm_output`s "
" received " ) ;
@ -1326,13 +1327,15 @@ static bool run_tx_interactive(struct state *state,
* - MUST NOT send a ` tx_remove_ouput ` for an
* input which is not theirs */
if ( serial_id % 2 = = our_role )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" Invalid serial_id rcvd. "
" % " PRIu64 , serial_id ) ;
output_index = psbt_find_serial_output ( psbt , serial_id ) ;
if ( output_index = = - 1 )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" No output added with serial_id "
" % " PRIu64 , serial_id ) ;
psbt_rm_output ( psbt , output_index ) ;
@ -1340,7 +1343,8 @@ static bool run_tx_interactive(struct state *state,
}
case WIRE_TX_COMPLETE :
if ( ! fromwire_tx_complete ( msg , & cid ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps ,
& state - > channel_id ,
" Parsing tx_complete %s " ,
tal_hex ( tmpctx , msg ) ) ;
check_channel_id ( state , & cid , & state - > channel_id ) ;
@ -1381,7 +1385,7 @@ static bool run_tx_interactive(struct state *state,
case WIRE_REPLY_SHORT_CHANNEL_IDS_END :
case WIRE_PING :
case WIRE_PONG :
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Unexpected wire message %s " ,
tal_hex ( tmpctx , msg ) ) ;
return false ;
@ -1443,7 +1447,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
& state - > first_per_commitment_point [ REMOTE ] ,
& channel_flags ,
open_tlv ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Parsing open_channel2 %s " ,
tal_hex ( tmpctx , oc2_msg ) ) ;
@ -1533,7 +1537,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
/* Check that total funding doesn't overflow */
if ( ! amount_sat_add ( & total , state - > opener_funding ,
state - > accepter_funding ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Amount overflow. Local sats %s. "
" Remote sats %s " ,
type_to_string ( tmpctx , struct amount_sat ,
@ -1634,7 +1638,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
if ( ! find_txout ( state - > psbt ,
scriptpubkey_p2wsh ( tmpctx , wscript ) ,
& state - > funding_txout ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Expected output %s not found on funding tx %s " ,
tal_hex ( tmpctx , scriptpubkey_p2wsh ( tmpctx , wscript ) ) ,
type_to_string ( tmpctx , struct wally_psbt ,
@ -1661,14 +1665,14 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
if ( ! fromwire_commitment_signed ( tmpctx , msg , & cid ,
& remote_sig . s ,
& htlc_sigs ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Parsing commitment signed %s " ,
tal_hex ( tmpctx , msg ) ) ;
check_channel_id ( state , & cid , & state - > channel_id ) ;
if ( htlc_sigs ! = NULL )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Must not send HTLCs with first "
" commitment. %s " ,
tal_hex ( tmpctx , msg ) ) ;
@ -1730,8 +1734,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
* a courtesy to other implementaters whose brains may be so
* twisted by coding in Go , Scala and Rust that they can no
* longer read C code . */
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Bad signature %s on tx %s using key %s "
" (funding txid %s, psbt %s) " ,
type_to_string ( tmpctx , struct bitcoin_signature ,
@ -1950,7 +1953,7 @@ static void opener_start(struct state *state, u8 *msg)
& state - > their_points . htlc ,
& state - > first_per_commitment_point [ REMOTE ] ,
a_tlv ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Parsing accept_channel2 %s " , tal_hex ( msg , msg ) ) ;
if ( a_tlv - > option_upfront_shutdown_script ) {
@ -1967,7 +1970,7 @@ static void opener_start(struct state *state, u8 *msg)
& state - > their_points . revocation ) ;
if ( ! channel_id_eq ( & cid , & state - > channel_id ) )
peer_failed ( state - > pps , & state - > channel_ id,
peer_failed_err ( state - > pps , & c id,
" accept_channel2 ids don't match: "
" expected %s, got %s " ,
type_to_string ( msg , struct channel_id ,
@ -1982,7 +1985,7 @@ static void opener_start(struct state *state, u8 *msg)
*/
if ( feerate_min > state - > feerate_per_kw_funding
| | feerate_max < state - > feerate_per_kw_funding )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Invalid feerate %d chosen. Valid min %d, "
" valid max %d " , state - > feerate_per_kw_funding ,
feerate_min , feerate_max ) ;
@ -1991,7 +1994,7 @@ static void opener_start(struct state *state, u8 *msg)
/* Check that total funding doesn't overflow */
if ( ! amount_sat_add ( & total , state - > opener_funding ,
state - > accepter_funding ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Amount overflow. Local sats %s. "
" Remote sats %s " ,
type_to_string ( tmpctx , struct amount_sat ,
@ -2071,7 +2074,7 @@ static void opener_start(struct state *state, u8 *msg)
/* Figure out the txout */
if ( ! find_txout ( state - > psbt , scriptpubkey_p2wsh ( tmpctx , wscript ) ,
& state - > funding_txout ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Expected output %s not found on funding tx %s " ,
tal_hex ( tmpctx , scriptpubkey_p2wsh ( tmpctx , wscript ) ) ,
type_to_string ( tmpctx , struct wally_psbt ,
@ -2168,12 +2171,12 @@ static void opener_start(struct state *state, u8 *msg)
if ( ! fromwire_commitment_signed ( tmpctx , msg , & cid ,
& remote_sig . s ,
& htlc_sigs ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Parsing commitment signed %s " ,
tal_hex ( tmpctx , msg ) ) ;
if ( htlc_sigs ! = NULL )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Must not send HTLCs with first "
" commitment. %s " ,
tal_hex ( tmpctx , msg ) ) ;
@ -2212,8 +2215,7 @@ static void opener_start(struct state *state, u8 *msg)
* a courtesy to other implementaters whose brains may be so
* twisted by coding in Go , Scala and Rust that they can no
* longer read C code . */
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Bad signature %s on tx %s using key %s "
" (funding txid %s, psbt %s) " ,
type_to_string ( tmpctx , struct bitcoin_signature ,
@ -2274,11 +2276,11 @@ static u8 *handle_funding_locked(struct state *state, u8 *msg)
struct pubkey remote_per_commit ;
if ( ! fromwire_funding_locked ( msg , & cid , & remote_per_commit ) )
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Bad funding_locked %s " , tal_hex ( msg , msg ) ) ;
if ( ! channel_id_eq ( & cid , & state - > channel_id ) )
peer_failed ( state - > pps , & state - > channel_ id,
peer_failed_err ( state - > pps , & c id,
" funding_locked ids don't match: "
" expected %s, got %s " ,
type_to_string ( msg , struct channel_id ,
@ -2287,8 +2289,7 @@ static u8 *handle_funding_locked(struct state *state, u8 *msg)
/* If we haven't gotten their tx_sigs yet, this is a protocol error */
if ( ! state - > remote_funding_sigs_rcvd ) {
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" funding_locked sent before tx_signatures %s " ,
tal_hex ( msg , msg ) ) ;
}
@ -2440,7 +2441,7 @@ check_future_dataloss_fields(struct state *state,
tal_hex ( tmpctx , msg ) ) ;
if ( ! correct )
peer_failed ( state - > pps ,
peer_failed_err ( state - > pps ,
& state - > channel_id ,
" bad future last_local_per_commit_secret: % " PRIu64
" vs %d " ,
@ -2460,7 +2461,7 @@ check_future_dataloss_fields(struct state *state,
take ( towire_dualopend_fail_fallen_behind ( NULL ) ) ) ;
/* We have to send them an error to trigger dropping to chain. */
peer_failed ( state - > pps , & state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" Awaiting unilateral close " ) ;
}
@ -2511,8 +2512,7 @@ static void do_reconnect_dance(struct state *state)
& next_revocation_number ,
& last_local_per_commit_secret ,
& remote_current_per_commit_point ) )
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_warn ( state - > pps , & state - > channel_id ,
" Bad reestablish msg: %s %s " ,
peer_wire_name ( fromwire_peektype ( msg ) ) ,
tal_hex ( msg , msg ) ) ;
@ -2541,8 +2541,7 @@ static void do_reconnect_dance(struct state *state)
}
if ( next_commitment_number ! = 1 )
peer_failed ( state - > pps ,
& state - > channel_id ,
peer_failed_err ( state - > pps , & state - > channel_id ,
" bad reestablish commitment_number: % " PRIu64
" vs %d " ,
next_commitment_number , 1 ) ;