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. 433
      channeld/channeld.c
  2. 100
      closingd/closingd.c
  3. 60
      common/peer_failed.c
  4. 21
      common/peer_failed.h
  5. 407
      openingd/dualopend.c
  6. 107
      openingd/openingd.c
  7. 14
      tests/test_connection.py
  8. 9
      tests/test_misc.py
  9. 3
      tests/test_pay.py

433
channeld/channeld.c

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

100
closingd/closingd.c

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

60
common/peer_failed.c

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

21
common/peer_failed.h

@ -8,14 +8,25 @@ struct channel_id;
struct per_peer_state; 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. * @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) * @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 struct channel_id *channel_id,
const char *fmt, ...) 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; PRINTF_FMT(3,4) NORETURN;
/* We're failing because peer sent us an error message: NULL /* We're failing because peer sent us an error message: NULL

407
openingd/dualopend.c

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

107
openingd/openingd.c

@ -400,9 +400,9 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
&state->their_points.htlc, &state->their_points.htlc,
&state->first_per_commitment_point[REMOTE], &state->first_per_commitment_point[REMOTE],
accept_tlvs)) { accept_tlvs)) {
peer_failed(state->pps, peer_failed_err(state->pps,
&state->channel_id, &state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg)); "Parsing accept_channel %s", tal_hex(msg, msg));
} }
state->upfront_shutdown_script[REMOTE] state->upfront_shutdown_script[REMOTE]
= tal_steal(state, accept_tlvs->upfront_shutdown_script); = tal_steal(state, accept_tlvs->upfront_shutdown_script);
@ -413,12 +413,11 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
* `temporary_channel_id` in the `open_channel` message. */ * `temporary_channel_id` in the `open_channel` message. */
if (!channel_id_eq(&id_in, &state->channel_id)) if (!channel_id_eq(&id_in, &state->channel_id))
/* In this case we exit, since we don't know what's going on. */ /* In this case we exit, since we don't know what's going on. */
peer_failed(state->pps, peer_failed_err(state->pps, &id_in,
&state->channel_id, "accept_channel ids don't match: sent %s got %s",
"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, &id_in), type_to_string(msg, struct channel_id,
type_to_string(msg, struct channel_id, &state->channel_id));
&state->channel_id));
if (amount_sat_greater(state->remoteconf.dust_limit, if (amount_sat_greater(state->remoteconf.dust_limit,
state->localconf.channel_reserve)) { state->localconf.channel_reserve)) {
@ -510,9 +509,9 @@ static bool funder_finalize_channel_setup(struct state *state,
/* We were supposed to do enough checks above, but just in case, /* We were supposed to do enough checks above, but just in case,
* new_initial_channel will fail to create absurd channels */ * new_initial_channel will fail to create absurd channels */
if (!state->channel) if (!state->channel)
peer_failed(state->pps, peer_failed_err(state->pps,
&state->channel_id, &state->channel_id,
"could not create channel with given config"); "could not create channel with given config");
/* BOLT #2: /* BOLT #2:
* *
@ -592,9 +591,8 @@ static bool funder_finalize_channel_setup(struct state *state,
sig->sighash_type = SIGHASH_ALL; sig->sighash_type = SIGHASH_ALL;
if (!fromwire_funding_signed(msg, &id_in, &sig->s)) if (!fromwire_funding_signed(msg, &id_in, &sig->s))
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id, "Parsing funding_signed: %s", tal_hex(msg, msg));
"Parsing funding_signed: %s", tal_hex(msg, msg));
/* BOLT #2: /* BOLT #2:
* *
* This message introduces the `channel_id` to identify the channel. * This message introduces the `channel_id` to identify the channel.
@ -621,11 +619,11 @@ static bool funder_finalize_channel_setup(struct state *state,
state->channel_id = cid; state->channel_id = cid;
if (!channel_id_eq(&id_in, &state->channel_id)) 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", "funding_signed ids don't match: expected %s got %s",
type_to_string(msg, struct channel_id, type_to_string(msg, struct channel_id,
&state->channel_id), &state->channel_id),
type_to_string(msg, struct channel_id, &id_in)); type_to_string(msg, struct channel_id, &id_in));
/* BOLT #2: /* BOLT #2:
* *
@ -645,14 +643,13 @@ static bool funder_finalize_channel_setup(struct state *state,
} }
if (!check_tx_sig(*tx, 0, NULL, wscript, &state->their_funding_pubkey, sig)) { if (!check_tx_sig(*tx, 0, NULL, wscript, &state->their_funding_pubkey, sig)) {
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id, "Bad signature %s on tx %s using key %s",
"Bad signature %s on tx %s using key %s", type_to_string(tmpctx, struct bitcoin_signature,
type_to_string(tmpctx, struct bitcoin_signature, sig),
sig), type_to_string(tmpctx, struct bitcoin_tx, *tx),
type_to_string(tmpctx, struct bitcoin_tx, *tx), type_to_string(tmpctx, struct pubkey,
type_to_string(tmpctx, struct pubkey, &state->their_funding_pubkey));
&state->their_funding_pubkey));
} }
/* We save their sig to our first commitment tx */ /* We save their sig to our first commitment tx */
@ -764,9 +761,9 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&state->first_per_commitment_point[REMOTE], &state->first_per_commitment_point[REMOTE],
&channel_flags, &channel_flags,
open_tlvs)) open_tlvs))
peer_failed(state->pps, peer_failed_err(state->pps,
&state->channel_id, &state->channel_id,
"Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg)); "Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));
state->upfront_shutdown_script[REMOTE] state->upfront_shutdown_script[REMOTE]
= tal_steal(state, open_tlvs->upfront_shutdown_script); = tal_steal(state, open_tlvs->upfront_shutdown_script);
@ -809,14 +806,13 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* - `push_msat` is greater than `funding_satoshis` * 1000. * - `push_msat` is greater than `funding_satoshis` * 1000.
*/ */
if (amount_msat_greater_sat(state->push_msat, state->funding)) { if (amount_msat_greater_sat(state->push_msat, state->funding)) {
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id, "Their push_msat %s"
"Their push_msat %s" " would be too large for funding_satoshis %s",
" would be too large for funding_satoshis %s", type_to_string(tmpctx, struct amount_msat,
type_to_string(tmpctx, struct amount_msat, &state->push_msat),
&state->push_msat), type_to_string(tmpctx, struct amount_sat,
type_to_string(tmpctx, struct amount_sat, &state->funding));
&state->funding));
return NULL; return NULL;
} }
@ -966,8 +962,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&state->funding_txid, &state->funding_txid,
&state->funding_txout, &state->funding_txout,
&theirsig.s)) &theirsig.s))
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id,
"Parsing funding_created"); "Parsing funding_created");
/* BOLT #2: /* BOLT #2:
@ -976,11 +971,11 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* `temporary_channel_id` in the `open_channel` message. * `temporary_channel_id` in the `open_channel` message.
*/ */
if (!channel_id_eq(&id_in, &state->channel_id)) 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", "funding_created ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id, type_to_string(msg, struct channel_id,
&state->channel_id), &state->channel_id),
type_to_string(msg, struct channel_id, &id_in)); type_to_string(msg, struct channel_id, &id_in));
/* Now we can create the channel structure. */ /* Now we can create the channel structure. */
state->channel = new_initial_channel(state, state->channel = new_initial_channel(state,
@ -1003,9 +998,8 @@ 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 /* We don't expect this to fail, but it does do some additional
* internal sanity checks. */ * internal sanity checks. */
if (!state->channel) if (!state->channel)
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id, "We could not create channel with given config");
"We could not create channel with given config");
/* BOLT #2: /* BOLT #2:
* *
@ -1038,14 +1032,13 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* a courtesy to other implementaters whose brains may be so * a courtesy to other implementaters whose brains may be so
* twisted by coding in Go, Scala and Rust that they can no * twisted by coding in Go, Scala and Rust that they can no
* longer read C code. */ * longer read C code. */
peer_failed(state->pps, peer_failed_err(state->pps, &state->channel_id,
&state->channel_id, "Bad signature %s on tx %s using key %s",
"Bad signature %s on tx %s using key %s", type_to_string(tmpctx, struct bitcoin_signature,
type_to_string(tmpctx, struct bitcoin_signature, &theirsig),
&theirsig), type_to_string(tmpctx, struct bitcoin_tx, local_commit),
type_to_string(tmpctx, struct bitcoin_tx, local_commit), type_to_string(tmpctx, struct pubkey,
type_to_string(tmpctx, struct pubkey, &their_funding_pubkey));
&their_funding_pubkey));
} }
/* BOLT #2: /* BOLT #2:

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.set_feerates((15, 15, 15, 15), False)
l1.start() 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! # Make sure the resolution of this one doesn't interfere with the next!
# Note: may succeed, may fail with insufficient fee, depending on how # Note: may succeed, may fail with insufficient fee, depending on how
# bitcoind feels! # bitcoind feels!

9
tests/test_misc.py

@ -1352,13 +1352,14 @@ def test_reserve_enforcement(node_factory, executor):
l2.start() l2.start()
wait_for(lambda: only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected']) wait_for(lambda: only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected'])
# This should be impossible to pay entire thing back: l1 should # This should be impossible to pay entire thing back: l1 should warn and
# kill us for trying to violate reserve. # close connection for trying to violate reserve.
executor.submit(l2.pay, l1, 1000000) executor.submit(l2.pay, l1, 1000000)
l1.daemon.wait_for_log( l1.daemon.wait_for_log(
'Peer permanent failure in CHANNELD_NORMAL: channeld: sent ' 'Peer transient failure in CHANNELD_NORMAL: channeld.*'
'ERROR Bad peer_add_htlc: CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED' ' CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED'
) )
assert only_one(l1.rpc.listpeers()['peers'])['connected'] is False
@unittest.skipIf(not DEVELOPER, "needs dev_disconnect") @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 # Wait for l1 notice
l1.daemon.wait_for_log(r'Peer transient failure in CHANNELD_NORMAL: channeld: .*: update_fee \d+ outside range 1875-75000') 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') l2.daemon.wait_for_log('sendrawtx exit')
bitcoind.generate_block(1, wait_for_mempool=1) bitcoind.generate_block(1, wait_for_mempool=1)
sync_blockheight(bitcoind, [l1, l2]) sync_blockheight(bitcoind, [l1, l2])

Loading…
Cancel
Save