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],
&peer->short_channel_ids[REMOTE]))
peer_failed(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,
&peer->short_channel_ids[LOCAL]),
type_to_string(peer, struct short_channel_id,
&peer->short_channel_ids[REMOTE]));
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,
&peer->short_channel_ids[LOCAL]),
type_to_string(peer, struct short_channel_id,
&peer->short_channel_ids[REMOTE]));
}
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;
if (!fromwire_funding_locked(msg, &chanid,
&peer->remote_per_commit))
peer_failed(peer->pps,
&peer->channel_id,
"Bad funding_locked %s", tal_hex(msg, msg));
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,
"Wrong channel id in %s (expected %s)",
tal_hex(tmpctx, msg),
type_to_string(msg, struct channel_id,
&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,
&peer->channel_id));
peer->tx_sigs_allowed = false;
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->announcement_node_sigs[REMOTE],
&peer->announcement_bitcoin_sigs[REMOTE]))
peer_failed(peer->pps,
&peer->channel_id,
"Bad announcement_signatures %s",
tal_hex(msg, msg));
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,
"Wrong channel_id: expected %s, got %s",
type_to_string(tmpctx, struct channel_id,
&peer->channel_id),
type_to_string(tmpctx, struct channel_id, &chanid));
peer_failed_err(peer->pps, &chanid,
"Wrong channel_id: expected %s, got %s",
type_to_string(tmpctx, struct channel_id,
&peer->channel_id),
type_to_string(tmpctx, struct channel_id, &chanid));
}
peer->have_sigs[REMOTE] = true;
@ -624,9 +619,8 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
, tlvs
#endif
))
peer_failed(peer->pps,
&peer->channel_id,
"Bad peer_add_htlc %s", tal_hex(msg, msg));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad peer_add_htlc %s", tal_hex(msg, msg));
#if EXPERIMENTAL_FEATURES
blinding = tlvs->blinding;
@ -635,10 +629,9 @@ 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,
"Bad peer_add_htlc: %s",
channel_add_err_name(add_err));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad peer_add_htlc: %s",
channel_add_err_name(add_err));
}
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;
if (!fromwire_update_fee(msg, &channel_id, &feerate)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fee %s", tal_hex(msg, msg));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fee %s", tal_hex(msg, msg));
}
/* BOLT #2:
@ -660,9 +652,8 @@ 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,
"update_fee from non-opener?");
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee from non-opener?");
status_debug("update_fee %u, range %u-%u",
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.
*/
if (feerate < peer->feerate_min || feerate > peer->feerate_max)
peer_failed(peer->pps,
&peer->channel_id,
"update_fee %u outside range %u-%u",
feerate, peer->feerate_min, peer->feerate_max);
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee %u outside range %u-%u",
feerate, peer->feerate_min, peer->feerate_max);
/* 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.
*/
if (!channel_update_feerate(peer->channel, feerate))
peer_failed(peer->pps,
&peer->channel_id,
"update_fee %u unaffordable",
feerate);
peer_failed_warn(peer->pps, &peer->channel_id,
"update_fee %u unaffordable",
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,
peer->next_index[LOCAL]);
if (peer->last_empty_commitment == peer->next_index[LOCAL] - 1)
peer_failed(peer->pps,
&peer->channel_id,
"commit_sig with no changes (again!)");
peer_failed_warn(peer->pps, &peer->channel_id,
"commit_sig with no changes (again!)");
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,
&channel_id, &commit_sig.s, &raw_sigs))
peer_failed(peer->pps,
&peer->channel_id,
"Bad commit_sig %s", tal_hex(msg, msg));
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;
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,
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
dump_htlcs(peer->channel, "receiving commit_sig");
peer_failed(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,
&commit_sig),
type_to_string(msg, struct bitcoin_tx, txs[0]),
tal_hex(msg, funding_wscript),
type_to_string(msg, struct pubkey,
&peer->channel->funding_pubkey
[REMOTE]),
channel_feerate(peer->channel, LOCAL));
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,
&commit_sig),
type_to_string(msg, struct bitcoin_tx, txs[0]),
tal_hex(msg, funding_wscript),
type_to_string(msg, struct pubkey,
&peer->channel->funding_pubkey
[REMOTE]),
channel_feerate(peer->channel, LOCAL));
}
/* BOLT #2:
@ -1356,10 +1342,9 @@ 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,
"Expected %zu htlc sigs, not %zu",
tal_count(txs) - 1, tal_count(htlc_sigs));
peer_failed_warn(peer->pps, &peer->channel_id,
"Expected %zu htlc sigs, not %zu",
tal_count(txs) - 1, tal_count(htlc_sigs));
/* 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,
&remote_htlckey, &htlc_sigs[i]))
peer_failed(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]),
tal_hex(msg, wscript),
type_to_string(msg, struct pubkey,
&remote_htlckey));
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]),
tal_hex(msg, wscript),
type_to_string(msg, struct pubkey,
&remote_htlckey));
}
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,
&next_per_commit)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad revoke_and_ack %s", tal_hex(msg, msg));
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,
"Unexpected revoke_and_ack");
peer_failed_warn(peer->pps, &peer->channel_id,
"Unexpected revoke_and_ack");
}
/* 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));
if (!pubkey_from_privkey(&privkey, &per_commit_point)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad privkey %s",
type_to_string(msg, struct privkey, &privkey));
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,
"Wrong privkey %s for %"PRIu64" %s",
type_to_string(msg, struct privkey, &privkey),
peer->next_index[LOCAL]-2,
type_to_string(msg, struct pubkey,
&peer->old_remote_per_commit));
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,
type_to_string(msg, struct pubkey,
&peer->old_remote_per_commit));
}
/* 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,
&id, &preimage)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg));
}
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_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fulfill_htlc: failed to fulfill %"
PRIu64 " error %s", id, channel_remove_err_name(e));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fulfill_htlc: failed to fulfill %"
PRIu64 " error %s", id, channel_remove_err_name(e));
}
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 */
if (!fromwire_update_fail_htlc(msg, msg,
&channel_id, &id, &reason)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fail_htlc %s", tal_hex(msg, msg));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_htlc %s", tal_hex(msg, msg));
}
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_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fail_htlc: failed to remove %"
PRIu64 " error %s", id,
channel_remove_err_name(e));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_htlc: failed to remove %"
PRIu64 " error %s", id,
channel_remove_err_name(e));
}
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,
&sha256_of_onion,
&failure_code)) {
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fail_malformed_htlc %s",
tal_hex(msg, msg));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_malformed_htlc %s",
tal_hex(msg, msg));
}
/* BOLT #2:
@ -1626,10 +1601,9 @@ 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,
"Bad update_fail_malformed_htlc failure code %u",
failure_code);
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad update_fail_malformed_htlc failure code %u",
failure_code);
}
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_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(peer->pps,
&peer->channel_id,
"Bad update_fail_malformed_htlc: failed to remove %"
PRIu64 " error %s", id, channel_remove_err_name(e));
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));
}
abort();
}
@ -1664,9 +1637,8 @@ 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,
"Bad shutdown %s", tal_hex(peer, shutdown));
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad shutdown %s", tal_hex(peer, shutdown));
/* BOLT #2:
*
@ -1681,9 +1653,8 @@ 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,
"scriptpubkey %s is not as agreed upfront (%s)",
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,8 +1720,8 @@ 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,
"Unexpected `tx_signatures`");
peer_failed_warn(peer->pps, &peer->channel_id,
"Unexpected `tx_signatures`");
peer->tx_sigs_allowed = false;
}
@ -1770,9 +1740,8 @@ 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,
"Bad channel_reestablish %s", tal_hex(peer, msg));
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? */
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.
* Fail the channel they sent, not the channel we are actively
* handling. */
peer_failed(peer->pps, &channel_id,
"Peer sent unexpected message %u, (%s) "
"for nonexistent channel %s",
WIRE_CHANNEL_REESTABLISH, "WIRE_CHANNEL_REESTABLISH",
type_to_string(tmpctx, struct channel_id,
&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",
type_to_string(tmpctx, struct channel_id,
&channel_id));
}
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. */
&& type != WIRE_UPDATE_FEE
&& type != WIRE_ANNOUNCEMENT_SIGNATURES) {
peer_failed(peer->pps,
&peer->channel_id,
"%s (%u) before funding locked",
peer_wire_name(type), type);
peer_failed_warn(peer->pps, &peer->channel_id,
"%s (%u) before funding locked",
peer_wire_name(type), type);
}
}
@ -1934,10 +1902,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
abort();
}
peer_failed(peer->pps,
&peer->channel_id,
"Peer sent unknown message %u (%s)",
type, peer_wire_name(type));
peer_failed_warn(peer->pps, &peer->channel_id,
"Peer sent unknown message %u (%s)",
type, peer_wire_name(type));
}
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,
h->r);
} else
peer_failed(peer->pps,
&peer->channel_id,
"HTLC %"PRIu64" state %s not failed/fulfilled",
h->id, htlc_state_name(h->state));
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,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
* then they asked for a retransmit */
if (!h)
peer_failed(peer->pps,
&peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
peer_failed_warn(peer->pps, &peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
if (h->state == SENT_REMOVE_COMMIT)
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
* then they asked for a retransmit */
if (!h)
peer_failed(peer->pps,
&peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
peer_failed_warn(peer->pps, &peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
if (h->state == SENT_ADD_COMMIT) {
#if EXPERIMENTAL_FEATURES
@ -2140,12 +2104,12 @@ static void check_future_dataloss_fields(struct peer *peer,
tal_hex(tmpctx, msg));
if (!correct)
peer_failed(peer->pps,
&peer->channel_id,
"bad future last_local_per_commit_secret: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL] - 1);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad future last_local_per_commit_secret: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL] - 1);
/* Oh shit, they really are from the future! */
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)));
/* 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,15 +2187,15 @@ 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->channel_id,
"bad reestablish: your_last_per_commitment_secret %"PRIu64
": %s should be %s",
next_revocation_number,
type_to_string(tmpctx, struct secret,
last_local_per_commit_secret),
type_to_string(tmpctx, struct secret,
&old_commit_secret));
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish: your_last_per_commitment_secret %"PRIu64
": %s should be %s",
next_revocation_number,
type_to_string(tmpctx, struct secret,
last_local_per_commit_secret),
type_to_string(tmpctx, struct secret,
&old_commit_secret));
if (!remote_current_per_commitment_point) {
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 (!pubkey_eq(remote_current_per_commitment_point,
&peer->old_remote_per_commit)) {
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
"is %s; expected %s (new is %s).",
next_commitment_number - 1,
type_to_string(tmpctx, struct pubkey,
remote_current_per_commitment_point),
type_to_string(tmpctx, struct pubkey,
&peer->old_remote_per_commit),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit));
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
"is %s; expected %s (new is %s).",
next_commitment_number - 1,
type_to_string(tmpctx, struct pubkey,
remote_current_per_commitment_point),
type_to_string(tmpctx, struct pubkey,
&peer->old_remote_per_commit),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit));
}
} else {
/* 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->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
"is %s; expected %s (old is %s).",
next_commitment_number - 1,
type_to_string(tmpctx, struct pubkey,
remote_current_per_commitment_point),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey,
&peer->old_remote_per_commit));
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish: remote's "
"my_current_per_commitment_point %"PRIu64
"is %s; expected %s (old is %s).",
next_commitment_number - 1,
type_to_string(tmpctx, struct pubkey,
remote_current_per_commitment_point),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey,
&peer->old_remote_per_commit));
}
}
@ -2400,11 +2365,11 @@ 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->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}
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) {
/* Don't try to retransmit revocation index -1! */
if (peer->next_index[LOCAL] < 2) {
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"
PRIu64,
next_revocation_number);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"
PRIu64,
next_revocation_number);
}
retransmit_revoke_and_ack = true;
} else if (next_revocation_number < peer->next_index[LOCAL] - 1) {
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL]);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL]);
} else if (next_revocation_number > peer->next_index[LOCAL] - 1) {
if (!check_extra_fields)
/* They don't support option_data_loss_protect or
* option_static_remotekey, we fail it due to
* unexpected number */
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL] - 1);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
next_revocation_number,
peer->next_index[LOCAL] - 1);
/* Remote claims it's ahead of us: can it prove it?
* Does not return. */
@ -2502,11 +2467,11 @@ 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->channel_id,
"bad reestablish commitment_number: %"
PRIu64,
next_commitment_number);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish commitment_number: %"
PRIu64,
next_commitment_number);
retransmit_commitment_signed = true;
@ -2519,12 +2484,12 @@ 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->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %"PRIu64,
next_commitment_number,
peer->next_index[REMOTE]);
peer_failed_err(peer->pps,
&peer->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %"PRIu64,
next_commitment_number,
peer->next_index[REMOTE]);
else
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[REMOTE] = out[REMOTE];
if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee))
peer_failed(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,
&out[LOCAL]),
type_to_string(tmpctx, struct amount_sat,
&out[REMOTE]));
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,
&out[LOCAL]),
type_to_string(tmpctx, struct amount_sat,
&out[REMOTE]));
status_debug("Making close tx at = %s/%s fee %s",
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],
dust_limit);
if (!tx)
peer_failed(pps, channel_id,
"Both outputs below dust limit:"
" funding = %s"
" fee = %s"
" dust_limit = %s"
" LOCAL = %s"
" REMOTE = %s",
type_to_string(tmpctx, struct amount_sat, &funding),
type_to_string(tmpctx, struct amount_sat, &fee),
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[REMOTE]));
peer_failed_err(pps, channel_id,
"Both outputs below dust limit:"
" funding = %s"
" fee = %s"
" dust_limit = %s"
" LOCAL = %s"
" REMOTE = %s",
type_to_string(tmpctx, struct amount_sat, &funding),
type_to_string(tmpctx, struct amount_sat, &fee),
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[REMOTE]));
return tx;
}
@ -201,10 +201,10 @@ static void do_reconnect(struct per_peer_state *pps,
&next_remote_revocation_number,
&their_secret,
&next_commitment_point)) {
peer_failed(pps, channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
peer_failed_warn(pps, channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
}
status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64,
next_local_commitment_number,
@ -360,9 +360,9 @@ 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,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));
peer_failed_warn(pps, channel_id,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));
/* BOLT #2:
*
@ -412,17 +412,17 @@ 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,
"Bad closing_signed signature for"
" %s (and trimmed version %s)",
type_to_string(tmpctx,
struct bitcoin_tx,
tx),
trimmed ?
type_to_string(tmpctx,
struct bitcoin_tx,
trimmed)
: "NONE");
peer_failed_warn(pps, channel_id,
"Bad closing_signed signature for"
" %s (and trimmed version %s)",
type_to_string(tmpctx,
struct bitcoin_tx,
tx),
trimmed ?
type_to_string(tmpctx,
struct bitcoin_tx,
trimmed)
: "NONE");
}
tx = trimmed;
}
@ -507,10 +507,10 @@ 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,
"Fee offer %s min too large",
type_to_string(tmpctx, struct amount_sat,
&feerange->min));
peer_failed_warn(pps, channel_id,
"Fee offer %s min too large",
type_to_string(tmpctx, struct amount_sat,
&feerange->min));
if (amount_sat_greater_eq(min_plus_one, feerange->max))
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? */
if (!amount_sat_sub(&range_len, feerange->max, min_fee_to_accept))
peer_failed(pps, channel_id,
"Feerange %s-%s"
" below minimum acceptable %s",
type_to_string(tmpctx, struct amount_sat,
&feerange->min),
type_to_string(tmpctx, struct amount_sat,
&feerange->max),
type_to_string(tmpctx, struct amount_sat,
&min_fee_to_accept));
peer_failed_warn(pps, channel_id,
"Feerange %s-%s"
" below minimum acceptable %s",
type_to_string(tmpctx, struct amount_sat,
&feerange->min),
type_to_string(tmpctx, struct amount_sat,
&feerange->max),
type_to_string(tmpctx, struct amount_sat,
&min_fee_to_accept));
if (fee_negotiation_step_unit ==
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/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,
const struct channel_id *channel_id,
const char *fmt, ...)
static void NORETURN
peer_failed(struct per_peer_state *pps,
bool warn,
const struct channel_id *channel_id,
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,

21
common/peer_failed.h

@ -8,14 +8,25 @@ 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,
const struct channel_id *channel_id,
const char *fmt, ...)
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;
/* 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;
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,
"scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(state, scriptpubkey),
tal_hex(state,
state->upfront_shutdown_script[REMOTE]));
peer_failed_warn(state->pps, &state->channel_id,
"scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(state, scriptpubkey),
tal_hex(state,
state->upfront_shutdown_script[REMOTE]));
wire_sync_write(REQ_FD,
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.
*/
if (!channel_id_eq(id_in, orig_id))
peer_failed(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));
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));
}
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(
struct witness_stack ***,
&ws)))
peer_failed(state->pps,
&state->channel_id,
"Bad tx_signatures %s",
tal_hex(msg, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Bad tx_signatures %s",
tal_hex(msg, msg));
/* Maybe they didn't get our funding_locked message ? */
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
* gotten our funding_locked yet */
if (state->funding_locked[REMOTE] && !state->reconnected)
peer_failed(state->pps,
&state->channel_id,
"tx_signatures sent after funding_locked %s",
tal_hex(msg, msg));
peer_failed_warn(state->pps, &state->channel_id,
"tx_signatures sent after funding_locked %s",
tal_hex(msg, msg));
if (state->remote_funding_sigs_rcvd) {
status_info("Got duplicate WIRE_TX_SIGNATURES, "
@ -825,9 +823,10 @@ static void handle_tx_sigs(struct state *state, const u8 *msg)
continue;
if (j == tal_count(ws))
peer_failed(state->pps, &state->channel_id,
"Mismatch witness stack count %s",
tal_hex(msg, msg));
peer_failed_warn(state->pps,
&state->channel_id,
"Mismatch witness stack count %s",
tal_hex(msg, msg));
elem = cast_const2(const struct 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 */
if (!updated_psbt)
peer_failed(state->pps, &state->channel_id,
"Unable to determine next tx update");
peer_failed_err(state->pps, &state->channel_id,
"Unable to determine next tx update");
state->changeset = tal_free(state->changeset);
state->changeset = psbt_get_changeset(state, *psbt, updated_psbt);
@ -1096,9 +1095,9 @@ static bool run_tx_interactive(struct state *state,
cast_const2(u8 **,
&redeemscript),
add_tlvs))
peer_failed(state->pps, &state->channel_id,
"Parsing tx_add_input %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Parsing tx_add_input %s",
tal_hex(tmpctx, msg));
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`
* messages */
if (++state->tx_msg_count[TX_ADD_INPUT] > MAX_TX_MSG_RCVD)
peer_failed(state->pps, &state->channel_id,
"Too many `tx_add_input`s"
" received");
peer_failed_warn(state->pps, &state->channel_id,
"Too many `tx_add_input`s"
" received");
/*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
* - if is the `initiator`:
@ -1122,9 +1121,9 @@ 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,
"Invalid serial_id rcvd. %"PRIu64,
serial_id);
peer_failed_warn(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %"PRIu64,
serial_id);
/*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
* - MUST fail the transaction collaboration if:
@ -1132,20 +1131,20 @@ 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,
"Duplicate serial_id rcvd."
" %"PRIu64, serial_id);
peer_failed_warn(state->pps, &state->channel_id,
"Duplicate serial_id rcvd."
" %"PRIu64, serial_id);
/* Convert tx_bytes to a tx! */
len = tal_bytelen(tx_bytes);
tx = pull_bitcoin_tx(state, &tx_bytes, &len);
if (!tx || len != 0)
peer_failed(state->pps, &state->channel_id,
"Invalid tx sent.");
peer_failed_warn(state->pps, &state->channel_id,
"Invalid tx sent.");
if (outnum >= tx->wtx->num_outputs)
peer_failed(state->pps, &state->channel_id,
"Invalid tx outnum sent. %u", outnum);
peer_failed_warn(state->pps, &state->channel_id,
"Invalid tx outnum sent. %u", outnum);
/*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
* - 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],
redeemscript))
peer_failed(state->pps, &state->channel_id,
"Invalid tx sent. Not SegWit %s",
type_to_string(tmpctx,
struct bitcoin_tx,
tx));
peer_failed_warn(state->pps, &state->channel_id,
"Invalid tx sent. Not SegWit %s",
type_to_string(tmpctx,
struct bitcoin_tx,
tx));
/*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
@ -1173,9 +1172,10 @@ 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,
"Unable to add input - "
"already present");
peer_failed_warn(state->pps,
&state->channel_id,
"Unable to add input - "
"already present");
/*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
@ -1189,8 +1189,8 @@ static bool run_tx_interactive(struct state *state,
NULL,
redeemscript);
if (!in)
peer_failed(state->pps, &state->channel_id,
"Unable to add input");
peer_failed_warn(state->pps, &state->channel_id,
"Unable to add input");
tal_wally_start();
wally_psbt_input_set_utxo(in, tx->wtx);
@ -1220,9 +1220,9 @@ 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,
"Parsing tx_remove_input %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Parsing tx_remove_input %s",
tal_hex(tmpctx, msg));
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`
* messages */
if (++state->tx_msg_count[TX_RM_INPUT] > MAX_TX_MSG_RCVD)
peer_failed(state->pps, &state->channel_id,
"Too many `tx_rm_input`s"
" received");
peer_failed_warn(state->pps, &state->channel_id,
"Too many `tx_rm_input`s"
" received");
/* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2
* The sending node:
* - 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,
"Invalid serial_id rcvd. %"PRIu64,
serial_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,
"No input added with serial_id"
" %"PRIu64, serial_id);
peer_failed_err(state->pps, &state->channel_id,
"No input added with serial_id"
" %"PRIu64, serial_id);
psbt_rm_input(psbt, input_index);
break;
@ -1263,9 +1263,10 @@ 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,
"Parsing tx_add_output %s",
tal_hex(tmpctx, msg));
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,9 +1276,9 @@ 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,
"Too many `tx_add_output`s"
" received");
peer_failed_warn(state->pps, &state->channel_id,
"Too many `tx_add_output`s"
" received");
/* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2
* 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
* incorrect parity */
if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %"PRIu64,
serial_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,
"Duplicate serial_id rcvd."
" %"PRIu64, serial_id);
peer_failed_warn(state->pps, &state->channel_id,
"Duplicate serial_id rcvd."
" %"PRIu64, serial_id);
amt = amount_sat(value);
out = psbt_append_output(psbt, scriptpubkey, amt);
psbt_output_set_serial_id(psbt, out, serial_id);
@ -1304,9 +1305,9 @@ 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,
"Parsing tx_remove_output %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Parsing tx_remove_output %s",
tal_hex(tmpctx, msg));
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`
* messages */
if (++state->tx_msg_count[TX_RM_OUTPUT] > MAX_TX_MSG_RCVD)
peer_failed(state->pps, &state->channel_id,
"Too many `tx_rm_output`s"
" received");
peer_failed_warn(state->pps, &state->channel_id,
"Too many `tx_rm_output`s"
" received");
/* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2
* The sending node:
* - 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,
"Invalid serial_id rcvd."
" %"PRIu64, serial_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,
"No output added with serial_id"
" %"PRIu64, serial_id);
peer_failed_warn(state->pps,
&state->channel_id,
"No output added with serial_id"
" %"PRIu64, serial_id);
psbt_rm_output(psbt, output_index);
break;
}
case WIRE_TX_COMPLETE:
if (!fromwire_tx_complete(msg, &cid))
peer_failed(state->pps, &state->channel_id,
"Parsing tx_complete %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps,
&state->channel_id,
"Parsing tx_complete %s",
tal_hex(tmpctx, msg));
check_channel_id(state, &cid, &state->channel_id);
they_complete = true;
break;
@ -1381,9 +1385,9 @@ 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,
"Unexpected wire message %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Unexpected wire message %s",
tal_hex(tmpctx, msg));
return false;
}
@ -1443,9 +1447,9 @@ 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,
"Parsing open_channel2 %s",
tal_hex(tmpctx, oc2_msg));
peer_failed_err(state->pps, &state->channel_id,
"Parsing open_channel2 %s",
tal_hex(tmpctx, oc2_msg));
if (open_tlv->option_upfront_shutdown_script) {
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 */
if (!amount_sat_add(&total, state->opener_funding,
state->accepter_funding))
peer_failed(state->pps, &state->channel_id,
"Amount overflow. Local sats %s. "
"Remote sats %s",
type_to_string(tmpctx, struct amount_sat,
&state->accepter_funding),
type_to_string(tmpctx, struct amount_sat,
&state->opener_funding));
peer_failed_err(state->pps, &state->channel_id,
"Amount overflow. Local sats %s. "
"Remote sats %s",
type_to_string(tmpctx, struct amount_sat,
&state->accepter_funding),
type_to_string(tmpctx, struct amount_sat,
&state->opener_funding));
/* Check that total funding doesn't exceed allowed channel capacity */
/* BOLT #2:
@ -1634,11 +1638,11 @@ 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,
"Expected output %s not found on funding tx %s",
tal_hex(tmpctx, scriptpubkey_p2wsh(tmpctx, wscript)),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
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,
state->psbt));
/* Check tx funds are sane */
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,
&remote_sig.s,
&htlc_sigs))
peer_failed(state->pps, &state->channel_id,
"Parsing commitment signed %s",
tal_hex(tmpctx, msg));
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,
"Must not send HTLCs with first"
" commitment. %s",
tal_hex(tmpctx, msg));
peer_failed_err(state->pps, &state->channel_id,
"Must not send HTLCs with first"
" commitment. %s",
tal_hex(tmpctx, msg));
if (!amount_sat_to_msat(&our_msats, state->accepter_funding))
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
* twisted by coding in Go, Scala and Rust that they can no
* longer read C code. */
peer_failed(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,
&remote_sig),
type_to_string(tmpctx, struct bitcoin_tx,
local_commit),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey),
/* This is the first place we'd discover
* the funding tx doesn't match up */
type_to_string(tmpctx, struct bitcoin_txid,
&state->funding_txid),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
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,
&remote_sig),
type_to_string(tmpctx, struct bitcoin_tx,
local_commit),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey),
/* This is the first place we'd discover
* the funding tx doesn't match up */
type_to_string(tmpctx, struct bitcoin_txid,
&state->funding_txid),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
}
/* Create commitment tx signatures for remote */
@ -1950,8 +1953,8 @@ 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,
"Parsing accept_channel2 %s", tal_hex(msg, msg));
peer_failed_err(state->pps, &state->channel_id,
"Parsing accept_channel2 %s", tal_hex(msg, msg));
if (a_tlv->option_upfront_shutdown_script) {
state->upfront_shutdown_script[REMOTE]
@ -1967,12 +1970,12 @@ 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,
"accept_channel2 ids don't match: "
"expected %s, got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &cid));
peer_failed_err(state->pps, &cid,
"accept_channel2 ids don't match: "
"expected %s, got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &cid));
/* BOLT-5fcbda56901af9e3b1d057cc41d0c5cfa60a2b94 #2:
* The receiving node:
@ -1982,22 +1985,22 @@ 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,
"Invalid feerate %d chosen. Valid min %d,"
" valid max %d", state->feerate_per_kw_funding,
feerate_min, feerate_max);
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);
/* 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,
"Amount overflow. Local sats %s. "
"Remote sats %s",
type_to_string(tmpctx, struct amount_sat,
&state->opener_funding),
type_to_string(tmpctx, struct amount_sat,
&state->accepter_funding));
peer_failed_warn(state->pps, &state->channel_id,
"Amount overflow. Local sats %s. "
"Remote sats %s",
type_to_string(tmpctx, struct amount_sat,
&state->opener_funding),
type_to_string(tmpctx, struct amount_sat,
&state->accepter_funding));
/* Check that total funding doesn't exceed allowed channel capacity */
/* BOLT #2:
@ -2071,11 +2074,11 @@ 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,
"Expected output %s not found on funding tx %s",
tal_hex(tmpctx, scriptpubkey_p2wsh(tmpctx, wscript)),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
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,
state->psbt));
/* Check tx funds are sane */
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,
&remote_sig.s,
&htlc_sigs))
peer_failed(state->pps, &state->channel_id,
"Parsing commitment signed %s",
tal_hex(tmpctx, msg));
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,
"Must not send HTLCs with first"
" commitment. %s",
tal_hex(tmpctx, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Must not send HTLCs with first"
" commitment. %s",
tal_hex(tmpctx, msg));
local_commit = initial_channel_tx(state, &wscript, state->channel,
&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
* twisted by coding in Go, Scala and Rust that they can no
* longer read C code. */
peer_failed(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,
&remote_sig),
type_to_string(tmpctx, struct bitcoin_tx,
local_commit),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey),
/* This is the first place we'd discover the
* funding tx doesn't match up */
type_to_string(tmpctx, struct bitcoin_txid,
&state->funding_txid),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
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,
&remote_sig),
type_to_string(tmpctx, struct bitcoin_tx,
local_commit),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey),
/* This is the first place we'd discover the
* funding tx doesn't match up */
type_to_string(tmpctx, struct bitcoin_txid,
&state->funding_txid),
type_to_string(tmpctx, struct wally_psbt,
state->psbt));
}
if (direct_outputs[LOCAL])
@ -2274,23 +2276,22 @@ 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,
"Bad funding_locked %s", tal_hex(msg, msg));
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,
"funding_locked ids don't match: "
"expected %s, got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &cid));
peer_failed_err(state->pps, &cid,
"funding_locked ids don't match: "
"expected %s, got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &cid));
/* 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,
"funding_locked sent before tx_signatures %s",
tal_hex(msg, msg));
peer_failed_warn(state->pps, &state->channel_id,
"funding_locked sent before tx_signatures %s",
tal_hex(msg, msg));
}
state->funding_locked[REMOTE] = true;
@ -2440,11 +2441,11 @@ check_future_dataloss_fields(struct state *state,
tal_hex(tmpctx, msg));
if (!correct)
peer_failed(state->pps,
&state->channel_id,
"bad future last_local_per_commit_secret: %"PRIu64
" vs %d",
next_revocation_number, 0);
peer_failed_err(state->pps,
&state->channel_id,
"bad future last_local_per_commit_secret: %"PRIu64
" vs %d",
next_revocation_number, 0);
/* Oh shit, they really are from the future! */
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)));
/* 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,11 +2512,10 @@ 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,
"Bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
peer_failed_warn(state->pps, &state->channel_id,
"Bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
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)
peer_failed(state->pps,
&state->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %d",
next_commitment_number, 1);
peer_failed_err(state->pps, &state->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %d",
next_commitment_number, 1);
/* It's possible we sent our sigs, but they didn't get them.
* 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->first_per_commitment_point[REMOTE],
accept_tlvs)) {
peer_failed(state->pps,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
peer_failed_err(state->pps,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
}
state->upfront_shutdown_script[REMOTE]
= 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. */
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,
"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,
&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,
&state->channel_id));
if (amount_sat_greater(state->remoteconf.dust_limit,
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,
* new_initial_channel will fail to create absurd channels */
if (!state->channel)
peer_failed(state->pps,
&state->channel_id,
"could not create channel with given config");
peer_failed_err(state->pps,
&state->channel_id,
"could not create channel with given config");
/* BOLT #2:
*
@ -592,9 +591,8 @@ 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,
"Parsing funding_signed: %s", tal_hex(msg, msg));
peer_failed_err(state->pps, &state->channel_id,
"Parsing funding_signed: %s", tal_hex(msg, msg));
/* BOLT #2:
*
* 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;
if (!channel_id_eq(&id_in, &state->channel_id))
peer_failed(state->pps, &id_in,
"funding_signed ids don't match: expected %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &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),
type_to_string(msg, struct channel_id, &id_in));
/* 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)) {
peer_failed(state->pps,
&state->channel_id,
"Bad signature %s on tx %s using key %s",
type_to_string(tmpctx, struct bitcoin_signature,
sig),
type_to_string(tmpctx, struct bitcoin_tx, *tx),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey));
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),
type_to_string(tmpctx, struct bitcoin_tx, *tx),
type_to_string(tmpctx, struct pubkey,
&state->their_funding_pubkey));
}
/* 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],
&channel_flags,
open_tlvs))
peer_failed(state->pps,
&state->channel_id,
"Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));
peer_failed_err(state->pps,
&state->channel_id,
"Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));
state->upfront_shutdown_script[REMOTE]
= 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.
*/
if (amount_msat_greater_sat(state->push_msat, state->funding)) {
peer_failed(state->pps,
&state->channel_id,
"Their push_msat %s"
" would be too large for funding_satoshis %s",
type_to_string(tmpctx, struct amount_msat,
&state->push_msat),
type_to_string(tmpctx, struct amount_sat,
&state->funding));
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,
&state->push_msat),
type_to_string(tmpctx, struct amount_sat,
&state->funding));
return NULL;
}
@ -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,11 +971,11 @@ 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,
"funding_created ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
type_to_string(msg, struct channel_id, &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),
type_to_string(msg, struct channel_id, &id_in));
/* Now we can create the channel structure. */
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
* internal sanity checks. */
if (!state->channel)
peer_failed(state->pps,
&state->channel_id,
"We could not create channel with given config");
peer_failed_err(state->pps, &state->channel_id,
"We could not create channel with given config");
/* 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
* twisted by coding in Go, Scala and Rust that they can no
* longer read C code. */
peer_failed(state->pps,
&state->channel_id,
"Bad signature %s on tx %s using key %s",
type_to_string(tmpctx, struct bitcoin_signature,
&theirsig),
type_to_string(tmpctx, struct bitcoin_tx, local_commit),
type_to_string(tmpctx, struct pubkey,
&their_funding_pubkey));
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),
type_to_string(tmpctx, struct bitcoin_tx, local_commit),
type_to_string(tmpctx, struct pubkey,
&their_funding_pubkey));
}
/* 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.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