Browse Source

common: remove peer_failed in favor of peer_failed_warn/peer_failed_err

And make all the callers choose which one.  In general, I prefer warn,
which lets them reconnect and try again, however some places are either
stated that they must be errors in the spec itself, or in openingd
where we abandon the channel when we close the connection anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: we now send warning messages and close the connection, except on unrecoverable errors.
master
Rusty Russell 4 years ago
parent
commit
f4ee41a989
  1. 135
      channeld/channeld.c
  2. 14
      closingd/closingd.c
  3. 58
      common/peer_failed.c
  4. 17
      common/peer_failed.h
  5. 115
      openingd/dualopend.c
  6. 31
      openingd/openingd.c
  7. 14
      tests/test_connection.py
  8. 9
      tests/test_misc.py
  9. 3
      tests/test_pay.py

135
channeld/channeld.c

@ -445,8 +445,7 @@ static void check_short_ids_match(struct peer *peer)
if (!short_channel_id_eq(&peer->short_channel_ids[LOCAL],
&peer->short_channel_ids[REMOTE]))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"We disagree on short_channel_ids:"
" I have %s, you say %s",
type_to_string(peer, struct short_channel_id,
@ -550,13 +549,11 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
peer->old_remote_per_commit = peer->remote_per_commit;
if (!fromwire_funding_locked(msg, &chanid,
&peer->remote_per_commit))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad funding_locked %s", tal_hex(msg, msg));
if (!channel_id_eq(&chanid, &peer->channel_id))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_err(peer->pps, &chanid,
"Wrong channel id in %s (expected %s)",
tal_hex(tmpctx, msg),
type_to_string(msg, struct channel_id,
@ -581,15 +578,13 @@ static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg
&peer->short_channel_ids[REMOTE],
&peer->announcement_node_sigs[REMOTE],
&peer->announcement_bitcoin_sigs[REMOTE]))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad announcement_signatures %s",
tal_hex(msg, msg));
/* Make sure we agree on the channel ids */
if (!channel_id_eq(&chanid, &peer->channel_id)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_err(peer->pps, &chanid,
"Wrong channel_id: expected %s, got %s",
type_to_string(tmpctx, struct channel_id,
&peer->channel_id),
@ -624,8 +619,7 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
, tlvs
#endif
))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad peer_add_htlc %s", tal_hex(msg, msg));
#if EXPERIMENTAL_FEATURES
@ -635,8 +629,7 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
cltv_expiry, &payment_hash,
onion_routing_packet, blinding, &htlc, NULL);
if (add_err != CHANNEL_ERR_ADD_OK)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad peer_add_htlc: %s",
channel_add_err_name(add_err));
}
@ -647,8 +640,7 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
u32 feerate;
if (!fromwire_update_fee(msg, &channel_id, &feerate)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fee %s", tal_hex(msg, msg));
}
@ -660,8 +652,7 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* - MUST fail the channel.
*/
if (peer->channel->opener != REMOTE)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee from non-opener?");
status_debug("update_fee %u, range %u-%u",
@ -675,8 +666,7 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* - SHOULD fail the channel.
*/
if (feerate < peer->feerate_min || feerate > peer->feerate_max)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee %u outside range %u-%u",
feerate, peer->feerate_min, peer->feerate_max);
@ -688,8 +678,7 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* - but MAY delay this check until the `update_fee` is committed.
*/
if (!channel_update_feerate(peer->channel, feerate))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee %u unaffordable",
feerate);
@ -1275,8 +1264,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
status_debug("Oh hi LND! Empty commitment at #%"PRIu64,
peer->next_index[LOCAL]);
if (peer->last_empty_commitment == peer->next_index[LOCAL] - 1)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"commit_sig with no changes (again!)");
peer->last_empty_commitment = peer->next_index[LOCAL];
}
@ -1293,8 +1281,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!fromwire_commitment_signed(tmpctx, msg,
&channel_id, &commit_sig.s, &raw_sigs))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad commit_sig %s", tal_hex(msg, msg));
/* SIGHASH_ALL is implied. */
commit_sig.sighash_type = SIGHASH_ALL;
@ -1333,8 +1320,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!check_tx_sig(txs[0], 0, NULL, funding_wscript,
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
dump_htlcs(peer->channel, "receiving commit_sig");
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s feerate %u",
peer->next_index[LOCAL],
type_to_string(msg, struct bitcoin_signature,
@ -1356,8 +1342,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
* - MUST fail the channel.
*/
if (tal_count(htlc_sigs) != tal_count(txs) - 1)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Expected %zu htlc sigs, not %zu",
tal_count(txs) - 1, tal_count(htlc_sigs));
@ -1375,8 +1360,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!check_tx_sig(txs[1+i], 0, NULL, wscript,
&remote_htlckey, &htlc_sigs[i]))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad commit_sig signature %s for htlc %s wscript %s key %s",
type_to_string(msg, struct bitcoin_signature, &htlc_sigs[i]),
type_to_string(msg, struct bitcoin_tx, txs[1+i]),
@ -1460,14 +1444,12 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
if (!fromwire_revoke_and_ack(msg, &channel_id, &old_commit_secret,
&next_per_commit)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad revoke_and_ack %s", tal_hex(msg, msg));
}
if (peer->revocations_received != peer->next_index[REMOTE] - 2) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Unexpected revoke_and_ack");
}
@ -1480,14 +1462,12 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
*/
memcpy(&privkey, &old_commit_secret, sizeof(privkey));
if (!pubkey_from_privkey(&privkey, &per_commit_point)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad privkey %s",
type_to_string(msg, struct privkey, &privkey));
}
if (!pubkey_eq(&per_commit_point, &peer->old_remote_per_commit)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_err(peer->pps, &peer->channel_id,
"Wrong privkey %s for %"PRIu64" %s",
type_to_string(msg, struct privkey, &privkey),
peer->next_index[LOCAL]-2,
@ -1532,8 +1512,7 @@ static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
if (!fromwire_update_fulfill_htlc(msg, &channel_id,
&id, &preimage)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg));
}
@ -1551,8 +1530,7 @@ static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_UNCOMMITTED:
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fulfill_htlc: failed to fulfill %"
PRIu64 " error %s", id, channel_remove_err_name(e));
}
@ -1571,8 +1549,7 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
/* reason is not an onionreply because spec doesn't know about that */
if (!fromwire_update_fail_htlc(msg, msg,
&channel_id, &id, &reason)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_htlc %s", tal_hex(msg, msg));
}
@ -1591,8 +1568,7 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_UNCOMMITTED:
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_htlc: failed to remove %"
PRIu64 " error %s", id,
channel_remove_err_name(e));
@ -1613,8 +1589,7 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
if (!fromwire_update_fail_malformed_htlc(msg, &channel_id, &id,
&sha256_of_onion,
&failure_code)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_malformed_htlc %s",
tal_hex(msg, msg));
}
@ -1626,8 +1601,7 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
* - MUST fail the channel.
*/
if (!(failure_code & BADONION)) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_malformed_htlc failure code %u",
failure_code);
}
@ -1647,8 +1621,7 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_UNCOMMITTED:
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_malformed_htlc: failed to remove %"
PRIu64 " error %s", id, channel_remove_err_name(e));
}
@ -1664,8 +1637,7 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
send_channel_update(peer, ROUTING_FLAGS_DISABLED);
if (!fromwire_shutdown(tmpctx, shutdown, &channel_id, &scriptpubkey))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad shutdown %s", tal_hex(peer, shutdown));
/* BOLT #2:
@ -1681,8 +1653,7 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
&& !memeq(scriptpubkey, tal_count(scriptpubkey),
peer->remote_upfront_shutdown_script,
tal_count(peer->remote_upfront_shutdown_script)))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_err(peer->pps, &peer->channel_id,
"scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(peer, scriptpubkey),
tal_hex(peer, peer->remote_upfront_shutdown_script));
@ -1741,8 +1712,7 @@ static void handle_unexpected_tx_sigs(struct peer *peer, const u8 *msg)
* but they did not receive our funding_locked. */
if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid,
cast_const3(struct witness_stack ***, &ws)))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad tx_signatures %s",
tal_hex(msg, msg));
@ -1750,7 +1720,7 @@ static void handle_unexpected_tx_sigs(struct peer *peer, const u8 *msg)
peer->tx_sigs_allowed ? "Allowing." : "Failing.");
if (!peer->tx_sigs_allowed)
peer_failed(peer->pps, &peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Unexpected `tx_signatures`");
peer->tx_sigs_allowed = false;
@ -1770,8 +1740,7 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point))
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad channel_reestablish %s", tal_hex(peer, msg));
/* Is it the same as the peer channel ID? */
@ -1803,7 +1772,7 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
* peer getting its wires crossed somewhere.
* Fail the channel they sent, not the channel we are actively
* handling. */
peer_failed(peer->pps, &channel_id,
peer_failed_err(peer->pps, &channel_id,
"Peer sent unexpected message %u, (%s) "
"for nonexistent channel %s",
WIRE_CHANNEL_REESTABLISH, "WIRE_CHANNEL_REESTABLISH",
@ -1848,8 +1817,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
/* lnd sends these early; it's harmless. */
&& type != WIRE_UPDATE_FEE
&& type != WIRE_ANNOUNCEMENT_SIGNATURES) {
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"%s (%u) before funding locked",
peer_wire_name(type), type);
}
@ -1934,8 +1902,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
abort();
}
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Peer sent unknown message %u (%s)",
type, peer_wire_name(type));
}
@ -1968,8 +1935,7 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
msg = towire_update_fulfill_htlc(NULL, &peer->channel_id, h->id,
h->r);
} else
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"HTLC %"PRIu64" state %s not failed/fulfilled",
h->id, htlc_state_name(h->state));
sync_crypto_write(peer->pps, take(msg));
@ -2029,8 +1995,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
/* I think this can happen if we actually received revoke_and_ack
* then they asked for a retransmit */
if (!h)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
@ -2049,8 +2014,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
/* I think this can happen if we actually received revoke_and_ack
* then they asked for a retransmit */
if (!h)
peer_failed(peer->pps,
&peer->channel_id,
peer_failed_warn(peer->pps, &peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
@ -2140,7 +2104,7 @@ static void check_future_dataloss_fields(struct peer *peer,
tal_hex(tmpctx, msg));
if (!correct)
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad future last_local_per_commit_secret: %"PRIu64
" vs %"PRIu64,
@ -2165,7 +2129,8 @@ static void check_future_dataloss_fields(struct peer *peer,
remote_current_per_commitment_point)));
/* We have to send them an error to trigger dropping to chain. */
peer_failed(peer->pps, &peer->channel_id, "Awaiting unilateral close");
peer_failed_err(peer->pps, &peer->channel_id,
"Awaiting unilateral close");
}
/* BOLT #2:
@ -2222,7 +2187,7 @@ static void check_current_dataloss_fields(struct peer *peer,
if (!secret_eq_consttime(&old_commit_secret,
last_local_per_commit_secret))
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish: your_last_per_commitment_secret %"PRIu64
": %s should be %s",
@ -2248,7 +2213,7 @@ static void check_current_dataloss_fields(struct peer *peer,
if (next_commitment_number == peer->revocations_received + 1) {
if (!pubkey_eq(remote_current_per_commitment_point,
&peer->old_remote_per_commit)) {
peer_failed(peer->pps,
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
@ -2265,7 +2230,7 @@ static void check_current_dataloss_fields(struct peer *peer,
/* We've sent a commit sig but haven't gotten a revoke+ack back */
if (!pubkey_eq(remote_current_per_commitment_point,
&peer->remote_per_commit)) {
peer_failed(peer->pps,
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
@ -2400,7 +2365,7 @@ static void peer_reconnect(struct peer *peer,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point)) {
peer_failed(peer->pps,
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
@ -2455,7 +2420,7 @@ static void peer_reconnect(struct peer *peer,
if (next_revocation_number == peer->next_index[LOCAL] - 2) {
/* Don't try to retransmit revocation index -1! */
if (peer->next_index[LOCAL] < 2) {
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"
PRIu64,
@ -2463,7 +2428,7 @@ static void peer_reconnect(struct peer *peer,
}
retransmit_revoke_and_ack = true;
} else if (next_revocation_number < peer->next_index[LOCAL] - 1) {
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
@ -2474,7 +2439,7 @@ static void peer_reconnect(struct peer *peer,
/* They don't support option_data_loss_protect or
* option_static_remotekey, we fail it due to
* unexpected number */
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
@ -2502,7 +2467,7 @@ static void peer_reconnect(struct peer *peer,
if (next_commitment_number == peer->next_index[REMOTE] - 1) {
/* We completed opening, we don't re-transmit that one! */
if (next_commitment_number == 0)
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish commitment_number: %"
PRIu64,
@ -2519,7 +2484,7 @@ static void peer_reconnect(struct peer *peer,
* - SHOULD fail the channel.
*/
} else if (next_commitment_number != peer->next_index[REMOTE])
peer_failed(peer->pps,
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %"PRIu64,

14
closingd/closingd.c

@ -51,7 +51,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
out_minus_fee[LOCAL] = out[LOCAL];
out_minus_fee[REMOTE] = out[REMOTE];
if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee))
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"Funder cannot afford fee %s (%s and %s)",
type_to_string(tmpctx, struct amount_sat, &fee),
type_to_string(tmpctx, struct amount_sat,
@ -76,7 +76,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
out_minus_fee[REMOTE],
dust_limit);
if (!tx)
peer_failed(pps, channel_id,
peer_failed_err(pps, channel_id,
"Both outputs below dust limit:"
" funding = %s"
" fee = %s"
@ -201,7 +201,7 @@ static void do_reconnect(struct per_peer_state *pps,
&next_remote_revocation_number,
&their_secret,
&next_commitment_point)) {
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
@ -360,7 +360,7 @@ receive_offer(struct per_peer_state *pps,
their_sig.sighash_type = SIGHASH_ALL;
if (!fromwire_closing_signed(msg, &their_channel_id,
&received_fee, &their_sig.s))
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));
@ -412,7 +412,7 @@ receive_offer(struct per_peer_state *pps,
if (!trimmed
|| !check_tx_sig(trimmed, 0, NULL, funding_wscript,
&funding_pubkey[REMOTE], &their_sig)) {
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"Bad closing_signed signature for"
" %s (and trimmed version %s)",
type_to_string(tmpctx,
@ -507,7 +507,7 @@ adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id,
/* Within 1 satoshi? Agree. */
if (!amount_sat_add(&min_plus_one, feerange->min, AMOUNT_SAT(1)))
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"Fee offer %s min too large",
type_to_string(tmpctx, struct amount_sat,
&feerange->min));
@ -524,7 +524,7 @@ adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id,
/* Max is below our minimum acceptable? */
if (!amount_sat_sub(&range_len, feerange->max, min_fee_to_accept))
peer_failed(pps, channel_id,
peer_failed_warn(pps, channel_id,
"Feerange %s-%s"
" below minimum acceptable %s",
type_to_string(tmpctx, struct amount_sat,

58
common/peer_failed.c

@ -1,3 +1,4 @@
#include <assert.h>
#include <ccan/breakpoint/breakpoint.h>
#include <ccan/tal/str/str.h>
#include <common/crypto_sync.h>
@ -24,34 +25,59 @@ peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)
}
/* We only support one channel per peer anyway */
void peer_failed(struct per_peer_state *pps,
static void NORETURN
peer_failed(struct per_peer_state *pps,
bool warn,
const struct channel_id *channel_id,
const char *fmt, ...)
const char *desc)
{
va_list ap;
const char *desc;
u8 *msg, *err;
va_start(ap, fmt);
desc = tal_vfmt(NULL, fmt, ap);
va_end(ap);
u8 *msg;
/* Tell peer the error. */
err = towire_errorfmt(desc, channel_id, "%s", desc);
sync_crypto_write(pps, err);
if (warn) {
msg = towire_warningfmt(desc, channel_id, "%s", desc);
} else {
msg = towire_errorfmt(desc, channel_id, "%s", desc);
}
sync_crypto_write(pps, msg);
/* Tell master the error so it can re-xmit. */
msg = towire_status_peer_error(NULL, channel_id,
desc,
/* all-channels errors should not close channels */
channel_id_is_all(channel_id),
warn,
pps,
err);
msg);
peer_billboard(true, desc);
tal_free(desc);
peer_fatal_continue(take(msg), pps);
}
void peer_failed_warn(struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *fmt, ...)
{
va_list ap;
const char *desc;
va_start(ap, fmt);
desc = tal_vfmt(tmpctx, fmt, ap);
va_end(ap);
peer_failed(pps, true, channel_id, desc);
}
void peer_failed_err(struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *fmt, ...)
{
va_list ap;
const char *desc;
va_start(ap, fmt);
desc = tal_vfmt(tmpctx, fmt, ap);
va_end(ap);
peer_failed(pps, false, channel_id, desc);
}
/* We're failing because peer sent us an error/warning message */
void peer_failed_received_errmsg(struct per_peer_state *pps,
const char *desc,

17
common/peer_failed.h

@ -8,12 +8,23 @@ struct channel_id;
struct per_peer_state;
/**
* peer_failed - Exit with error for peer.
* peer_failed_warn - Send a warning msg and close the connection.
* @pps: the per-peer state.
* @channel_id: channel with error, or NULL for all.
* @channel_id: channel with error, or NULL for no particular channel.
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
*/
void peer_failed(struct per_peer_state *pps,
void peer_failed_warn(struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *fmt, ...)
PRINTF_FMT(3,4) NORETURN;
/**
* peer_failed_err - Send a warning msg and close the channel.
* @pps: the per-peer state.
* @channel_id: channel with error.
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
*/
void peer_failed_err(struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *fmt, ...)
PRINTF_FMT(3,4) NORETURN;

115
openingd/dualopend.c

@ -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, &cid,
"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, &cid,
"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);

31
openingd/openingd.c

@ -400,7 +400,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
&state->their_points.htlc,
&state->first_per_commitment_point[REMOTE],
accept_tlvs)) {
peer_failed(state->pps,
peer_failed_err(state->pps,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
}
@ -413,8 +413,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
* `temporary_channel_id` in the `open_channel` message. */
if (!channel_id_eq(&id_in, &state->channel_id))
/* In this case we exit, since we don't know what's going on. */
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &id_in,
"accept_channel ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id, &id_in),
type_to_string(msg, struct channel_id,
@ -510,7 +509,7 @@ static bool funder_finalize_channel_setup(struct state *state,
/* We were supposed to do enough checks above, but just in case,
* new_initial_channel will fail to create absurd channels */
if (!state->channel)
peer_failed(state->pps,
peer_failed_err(state->pps,
&state->channel_id,
"could not create channel with given config");
@ -592,8 +591,7 @@ static bool funder_finalize_channel_setup(struct state *state,
sig->sighash_type = SIGHASH_ALL;
if (!fromwire_funding_signed(msg, &id_in, &sig->s))
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &state->channel_id,
"Parsing funding_signed: %s", tal_hex(msg, msg));
/* BOLT #2:
*
@ -621,7 +619,7 @@ static bool funder_finalize_channel_setup(struct state *state,
state->channel_id = cid;
if (!channel_id_eq(&id_in, &state->channel_id))
peer_failed(state->pps, &id_in,
peer_failed_err(state->pps, &id_in,
"funding_signed ids don't match: expected %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
@ -645,8 +643,7 @@ static bool funder_finalize_channel_setup(struct state *state,
}
if (!check_tx_sig(*tx, 0, NULL, wscript, &state->their_funding_pubkey, sig)) {
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &state->channel_id,
"Bad signature %s on tx %s using key %s",
type_to_string(tmpctx, struct bitcoin_signature,
sig),
@ -764,7 +761,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&state->first_per_commitment_point[REMOTE],
&channel_flags,
open_tlvs))
peer_failed(state->pps,
peer_failed_err(state->pps,
&state->channel_id,
"Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));
state->upfront_shutdown_script[REMOTE]
@ -809,8 +806,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* - `push_msat` is greater than `funding_satoshis` * 1000.
*/
if (amount_msat_greater_sat(state->push_msat, state->funding)) {
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &state->channel_id,
"Their push_msat %s"
" would be too large for funding_satoshis %s",
type_to_string(tmpctx, struct amount_msat,
@ -966,8 +962,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&state->funding_txid,
&state->funding_txout,
&theirsig.s))
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &state->channel_id,
"Parsing funding_created");
/* BOLT #2:
@ -976,7 +971,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* `temporary_channel_id` in the `open_channel` message.
*/
if (!channel_id_eq(&id_in, &state->channel_id))
peer_failed(state->pps, &id_in,
peer_failed_err(state->pps, &id_in,
"funding_created ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
@ -1003,8 +998,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
/* We don't expect this to fail, but it does do some additional
* internal sanity checks. */
if (!state->channel)
peer_failed(state->pps,
&state->channel_id,
peer_failed_err(state->pps, &state->channel_id,
"We could not create channel with given config");
/* BOLT #2:
@ -1038,8 +1032,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_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",
type_to_string(tmpctx, struct bitcoin_signature,
&theirsig),

14
tests/test_connection.py

@ -1971,7 +1971,19 @@ def test_fee_limits(node_factory, bitcoind):
l1.set_feerates((15, 15, 15, 15), False)
l1.start()
l1.daemon.wait_for_log('Peer transient failure in CHANNELD_NORMAL: channeld: .*: update_fee 253 outside range 1875-75000')
l1.daemon.wait_for_log('Peer transient failure in CHANNELD_NORMAL: channeld WARNING: .*: update_fee 253 outside range 1875-75000')
# Closes, but does not error. Make sure it's noted in their status though.
assert 'update_fee 253 outside range 1875-75000' in only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['status'][0]
assert 'update_fee 253 outside range 1875-75000' in only_one(only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['channels'])['status'][0]
# Make l2 accept those fees, and it should recover.
l2.stop()
l2.set_feerates((15, 15, 15, 15), False)
l2.start()
l1.rpc.close(l2.info['id'])
# Make sure the resolution of this one doesn't interfere with the next!
# Note: may succeed, may fail with insufficient fee, depending on how
# bitcoind feels!

9
tests/test_misc.py

@ -1352,13 +1352,14 @@ def test_reserve_enforcement(node_factory, executor):
l2.start()
wait_for(lambda: only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected'])
# This should be impossible to pay entire thing back: l1 should
# kill us for trying to violate reserve.
# This should be impossible to pay entire thing back: l1 should warn and
# close connection for trying to violate reserve.
executor.submit(l2.pay, l1, 1000000)
l1.daemon.wait_for_log(
'Peer permanent failure in CHANNELD_NORMAL: channeld: sent '
'ERROR Bad peer_add_htlc: CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED'
'Peer transient failure in CHANNELD_NORMAL: channeld.*'
' CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED'
)
assert only_one(l1.rpc.listpeers()['peers'])['connected'] is False
@unittest.skipIf(not DEVELOPER, "needs dev_disconnect")

3
tests/test_pay.py

@ -263,7 +263,8 @@ def test_pay_disconnect(node_factory, bitcoind):
# Wait for l1 notice
l1.daemon.wait_for_log(r'Peer transient failure in CHANNELD_NORMAL: channeld: .*: update_fee \d+ outside range 1875-75000')
# l2 fails hard.
# Make l2 fail hard.
l2.rpc.close(l1.info['id'], unilateraltimeout=1)
l2.daemon.wait_for_log('sendrawtx exit')
bitcoind.generate_block(1, wait_for_mempool=1)
sync_blockheight(bitcoind, [l1, l2])

Loading…
Cancel
Save