diff --git a/channeld/channeld.c b/channeld/channeld.c index fb38b7586bdc..756039cd0127 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -297,10 +297,8 @@ static void handle_stfu(struct peer *peer, const u8 *stfu) if (!channel_id_eq(&channel_id, &peer->channel_id)) { peer_failed_err(peer->pps, &channel_id, "Wrong stfu channel_id: expected %s, got %s", - type_to_string(tmpctx, struct channel_id, - &peer->channel_id), - type_to_string(tmpctx, struct channel_id, - &channel_id)); + fmt_channel_id(tmpctx, &peer->channel_id), + fmt_channel_id(tmpctx, &channel_id)); } /* Sanity check */ @@ -464,8 +462,8 @@ static void check_mutual_splice_locked(struct peer *peer) peer->channel->view[REMOTE].lowest_splice_amnt[REMOTE] = 0; status_debug("mutual splice_locked, scid LOCAL & REMOTE updated to: %s", - type_to_string(tmpctx, struct short_channel_id, - &peer->splice_state->short_channel_id)); + fmt_short_channel_id(tmpctx, + peer->splice_state->short_channel_id)); inflight = NULL; for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) @@ -478,11 +476,11 @@ static void check_mutual_splice_locked(struct peer *peer) "Unable to find inflight txid amoung %zu" " inflights. new funding txid: %s", tal_count(peer->splice_state->inflights), - type_to_string(tmpctx, struct bitcoin_txid, - &peer->splice_state->locked_txid)); + fmt_bitcoin_txid(tmpctx, + &peer->splice_state->locked_txid)); status_debug("mutual splice_locked, updating change from: %s", - type_to_string(tmpctx, struct channel, peer->channel)); + fmt_channel(tmpctx, peer->channel)); error = channel_update_funding(peer->channel, &inflight->outpoint, inflight->amnt, @@ -493,7 +491,7 @@ static void check_mutual_splice_locked(struct peer *peer) error); status_debug("mutual splice_locked, channel updated to: %s", - type_to_string(tmpctx, struct channel, peer->channel)); + fmt_channel(tmpctx, peer->channel)); /* ensure the signer is locking at the same time */ lock_signer_outpoint(&inflight->outpoint); @@ -525,8 +523,7 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg) "Wrong splice lock channel id in %s " "(expected %s)", tal_hex(tmpctx, msg), - type_to_string(msg, struct channel_id, - &peer->channel_id)); + fmt_channel_id(msg, &peer->channel_id)); /* If we've `mutual_splice_locked` but our peer hasn't, we can ignore * this message harmlessly */ @@ -568,8 +565,7 @@ static void handle_peer_channel_ready(struct peer *peer, const u8 *msg) 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)); + fmt_channel_id(msg, &peer->channel_id)); peer->tx_sigs_allowed = false; peer->channel_ready[REMOTE] = true; @@ -577,8 +573,7 @@ static void handle_peer_channel_ready(struct peer *peer, const u8 *msg) if (tlvs->short_channel_id != NULL) { status_debug( "Peer told us that they'll use alias=%s for this channel", - type_to_string(tmpctx, struct short_channel_id, - tlvs->short_channel_id)); + fmt_short_channel_id(tmpctx, *tlvs->short_channel_id)); peer->short_channel_ids[REMOTE] = *tlvs->short_channel_id; } wire_sync_write(MASTER_FD, @@ -974,12 +969,10 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx, status_debug("Creating commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s", commit_index, - type_to_string(tmpctx, struct bitcoin_signature, - commit_sig), - type_to_string(tmpctx, struct bitcoin_tx, txs[0]), + fmt_bitcoin_signature(tmpctx, commit_sig), + fmt_bitcoin_tx(tmpctx, txs[0]), tal_hex(tmpctx, funding_wscript), - type_to_string(tmpctx, struct pubkey, - &peer->channel->funding_pubkey[LOCAL])); + fmt_pubkey(tmpctx, &peer->channel->funding_pubkey[LOCAL])); dump_htlcs(peer->channel, "Sending commit_sig"); if (!derive_simple_key(&peer->channel->basepoints[LOCAL].htlc, @@ -1013,12 +1006,10 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx, tal_hex(tmpctx, msg)); status_debug("Creating HTLC signature %s for tx %s wscript %s key %s", - type_to_string(tmpctx, struct bitcoin_signature, - &htlc_sigs[i]), - type_to_string(tmpctx, struct bitcoin_tx, txs[1+i]), + fmt_bitcoin_signature(tmpctx, &htlc_sigs[i]), + fmt_bitcoin_tx(tmpctx, txs[1+i]), tal_hex(tmpctx, wscript), - type_to_string(tmpctx, struct pubkey, - &local_htlckey)); + fmt_pubkey(tmpctx, &local_htlckey)); assert(check_tx_sig(txs[1+i], 0, NULL, wscript, &local_htlckey, &htlc_sigs[i])); @@ -1341,9 +1332,9 @@ static void send_commit(struct peer *peer) " feechange %s (%s)" " blockheight %s (%s)", want_fee_update(peer, NULL) ? "wanted": "not wanted", - type_to_string(tmpctx, struct fee_states, peer->channel->fee_states), + fmt_fee_states(tmpctx, peer->channel->fee_states), want_blockheight_update(peer, NULL) ? "wanted" : "not wanted", - type_to_string(tmpctx, struct height_states, peer->channel->blockheight_states)); + fmt_height_states(tmpctx, peer->channel->blockheight_states)); /* Covers the case where we've just been told to shutdown. */ maybe_send_shutdown(peer); @@ -1713,9 +1704,7 @@ static bool missing_user_signatures(const struct peer *peer, if (!psbt_get_serial_id(&in->unknowns, &in_serial)) { status_broken("PSBT input %"PRIu32" missing serial_id" " %s", i, - type_to_string(tmpctx, - struct wally_psbt, - inflight->psbt)); + fmt_wally_psbt(tmpctx, inflight->psbt)); return true; } if (in_serial % 2 == our_role && i != splice_funding_index) @@ -1890,10 +1879,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, if (!channel_id_eq(&active_id, cs_tlv->splice_info)) { status_info("Ignoring stale commit_sig for channel_id" " %s, as %s is locked in now.", - type_to_string(tmpctx, struct channel_id, - cs_tlv->splice_info), - type_to_string(tmpctx, struct channel_id, - &active_id)); + fmt_channel_id(tmpctx, cs_tlv->splice_info), + fmt_channel_id(tmpctx, &active_id)); return NULL; } } @@ -1964,11 +1951,9 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, status_failed(STATUS_FAIL_INTERNAL_ERROR, "Deriving remote_htlckey"); status_debug("Derived key %s from basepoint %s, point %s", - type_to_string(tmpctx, struct pubkey, &remote_htlckey), - type_to_string(tmpctx, struct pubkey, - &peer->channel->basepoints[REMOTE].htlc), - type_to_string(tmpctx, struct pubkey, - local_per_commit)); + fmt_pubkey(tmpctx, &remote_htlckey), + fmt_pubkey(tmpctx, &peer->channel->basepoints[REMOTE].htlc), + fmt_pubkey(tmpctx, local_per_commit)); /* BOLT #2: * * A receiving node: @@ -1987,20 +1972,16 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, " %s, splice_info: %s, race_await_commit: %s," " inflight splice count: %zu", local_index, - type_to_string(msg, struct bitcoin_signature, - &commit_sig), - type_to_string(msg, struct bitcoin_tx, txs[0]), + fmt_bitcoin_signature(msg, &commit_sig), + fmt_bitcoin_tx(msg, txs[0]), tal_hex(msg, funding_wscript), - type_to_string(msg, struct pubkey, - &peer->channel->funding_pubkey - [REMOTE]), + fmt_pubkey(msg, + &peer->channel->funding_pubkey[REMOTE]), channel_feerate(peer->channel, LOCAL), - type_to_string(tmpctx, struct channel_id, - &active_id), + fmt_channel_id(tmpctx, &active_id), cs_tlv && cs_tlv->splice_info - ? type_to_string(tmpctx, - struct channel_id, - cs_tlv->splice_info) + ? fmt_channel_id(tmpctx, + cs_tlv->splice_info) : "N/A", peer->splice_state->await_commitment_succcess ? "yes" : "no", @@ -2038,11 +2019,10 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, &remote_htlckey, &htlc_sigs[i])) 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]), + fmt_bitcoin_signature(msg, &htlc_sigs[i]), + fmt_bitcoin_tx(msg, txs[1+i]), tal_hex(msg, wscript), - type_to_string(msg, struct pubkey, - &remote_htlckey)); + fmt_pubkey(msg, &remote_htlckey)); } status_debug("Received commit_sig with %zu htlc sigs", @@ -2254,15 +2234,14 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg) if (!pubkey_from_privkey(&privkey, &per_commit_point)) { peer_failed_err(peer->pps, &peer->channel_id, "Bad privkey %s", - type_to_string(msg, struct privkey, &privkey)); + fmt_privkey(msg, &privkey)); } if (!pubkey_eq(&per_commit_point, &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), + fmt_privkey(msg, &privkey), peer->next_index[LOCAL]-2, - type_to_string(msg, struct pubkey, - &peer->old_remote_per_commit)); + fmt_pubkey(msg, &peer->old_remote_per_commit)); } /* We start timer even if this returns false: we might have delayed @@ -2285,10 +2264,8 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg) peer->remote_per_commit = next_per_commit; status_debug("revoke_and_ack %s: remote_per_commit = %s, old_remote_per_commit = %s", side_to_str(peer->channel->opener), - type_to_string(tmpctx, struct pubkey, - &peer->remote_per_commit), - type_to_string(tmpctx, struct pubkey, - &peer->old_remote_per_commit)); + fmt_pubkey(tmpctx, &peer->remote_per_commit), + fmt_pubkey(tmpctx, &peer->old_remote_per_commit)); peer->splice_state->await_commitment_succcess = false; @@ -2578,8 +2555,7 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg) /* Log this event as unusual. */ status_unusual("Got repeated WIRE_CHANNEL_REESTABLISH " "for channel %s, ignoring: %s", - type_to_string(tmpctx, struct channel_id, - &peer->channel_id), + fmt_channel_id(tmpctx, &peer->channel_id), tal_hex(tmpctx, msg)); /* This is a mitigation for a known bug in some peer software * that sometimes double-sends a reestablish message. @@ -2606,8 +2582,7 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg) "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)); + fmt_channel_id(tmpctx, &channel_id)); } static bool is_initiators_serial(const struct wally_map *unknowns) @@ -3098,10 +3073,8 @@ static struct amount_sat check_balances(struct peer *peer, splice_abort(peer, "%s fee (%s) was too low, must be at least %s", opener ? "Our" : "Your", - type_to_string(tmpctx, struct amount_msat, - &initiator_fee), - type_to_string(tmpctx, struct amount_sat, - &min_initiator_fee)); + fmt_amount_msat(tmpctx, initiator_fee), + fmt_amount_sat(tmpctx, min_initiator_fee)); } if (!peer->splicing->force_feerate && opener && amount_msat_greater_sat(initiator_fee, max_initiator_fee)) { @@ -3111,10 +3084,8 @@ static struct amount_sat check_balances(struct peer *peer, splice_abort(peer, "Our own fee (%s) was too high, max without" " forcing is %s.", - type_to_string(tmpctx, struct amount_msat, - &initiator_fee), - type_to_string(tmpctx, struct amount_sat, - &max_initiator_fee)); + fmt_amount_msat(tmpctx, initiator_fee), + fmt_amount_sat(tmpctx, max_initiator_fee)); } /* Check accepter fee */ if (amount_msat_less_sat(accepter_fee, min_accepter_fee)) { @@ -3124,10 +3095,8 @@ static struct amount_sat check_balances(struct peer *peer, splice_abort(peer, "%s fee (%s) was too low, must be at least %s", opener ? "Your" : "Our", - type_to_string(tmpctx, struct amount_msat, - &accepter_fee), - type_to_string(tmpctx, struct amount_sat, - &min_accepter_fee)); + fmt_amount_msat(tmpctx, accepter_fee), + fmt_amount_sat(tmpctx, min_accepter_fee)); } if (!peer->splicing->force_feerate && !opener && amount_msat_greater_sat(accepter_fee, max_accepter_fee)) { @@ -3137,10 +3106,8 @@ static struct amount_sat check_balances(struct peer *peer, splice_abort(peer, "Our own fee (%s) was too high, max without" " forcing is %s.", - type_to_string(tmpctx, struct amount_msat, - &accepter_fee), - type_to_string(tmpctx, struct amount_sat, - &max_accepter_fee)); + fmt_amount_msat(tmpctx, accepter_fee), + fmt_amount_sat(tmpctx, max_accepter_fee)); } /* BOLT-??? #2: @@ -3176,12 +3143,11 @@ static struct amount_sat check_balances(struct peer *peer, "splice error: msat of total funding %s should" " always add up to a full sat. original local bal" " %s, original remote bal %s,", - type_to_string(tmpctx, struct amount_msat, - &funding_amount), - type_to_string(tmpctx, struct amount_msat, - &peer->channel->view->owed[LOCAL]), - type_to_string(tmpctx, struct amount_msat, - &peer->channel->view->owed[REMOTE])); + fmt_amount_msat(tmpctx, funding_amount), + fmt_amount_msat(tmpctx, + peer->channel->view->owed[LOCAL]), + fmt_amount_msat(tmpctx, + peer->channel->view->owed[REMOTE])); } return funding_amount_res; @@ -3324,12 +3290,10 @@ static void resume_splice_negotiation(struct peer *peer, "my signature: %s " "psbt: %s", splice_funding_index, - type_to_string(tmpctx, struct pubkey, - &peer->channel->funding_pubkey[LOCAL]), - type_to_string(tmpctx, struct bitcoin_signature, - &splice_sig), - type_to_string(tmpctx, struct wally_psbt, - current_psbt)); + fmt_pubkey(tmpctx, + &peer->channel->funding_pubkey[LOCAL]), + fmt_bitcoin_signature(tmpctx, &splice_sig), + fmt_wally_psbt(tmpctx, current_psbt)); txsig_tlvs = tlv_txsigs_tlvs_new(tmpctx); der_len = signature_to_der(der, &splice_sig); @@ -3433,15 +3397,9 @@ static void resume_splice_negotiation(struct peer *peer, "signature: %s " "psbt: %s", splice_funding_index, - type_to_string(tmpctx, - struct pubkey, - their_pubkey), - type_to_string(tmpctx, - struct bitcoin_signature, - &their_sig), - type_to_string(tmpctx, - struct wally_psbt, - current_psbt)); + fmt_pubkey(tmpctx, their_pubkey), + fmt_bitcoin_signature(tmpctx, &their_sig), + fmt_wally_psbt(tmpctx, current_psbt)); } psbt_input_set_witscript(current_psbt, @@ -3463,8 +3421,7 @@ static void resume_splice_negotiation(struct peer *peer, if (!psbt_get_serial_id(&in->unknowns, &in_serial)) { status_broken("PSBT input %zu missing serial_id" " %s", i, - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, current_psbt)); return; } @@ -4122,10 +4079,8 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Signed PSBT txid %s does not match" " current_psbt_txid %s", - type_to_string(tmpctx, struct bitcoin_txid, - &signed_psbt_txid), - type_to_string(tmpctx, struct bitcoin_txid, - ¤t_psbt_txid)); + fmt_bitcoin_txid(tmpctx, &signed_psbt_txid), + fmt_bitcoin_txid(tmpctx, ¤t_psbt_txid)); peer->splicing->current_psbt = tal_free(peer->splicing->current_psbt); @@ -4686,10 +4641,8 @@ static void check_current_dataloss_fields(struct peer *peer, "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)); + fmt_secret(tmpctx, last_local_per_commit_secret), + fmt_secret(tmpctx, &old_commit_secret)); if (!remote_current_per_commitment_point) { status_debug("option_static_remotekey: fields are correct"); @@ -4708,17 +4661,17 @@ static void check_current_dataloss_fields(struct peer *peer, if (!pubkey_eq(remote_current_per_commitment_point, &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 (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->channel_id, + "bad reestablish: remote's " + "my_current_per_commitment_point %"PRIu64 + "is %s; expected %s (new is %s).", + next_commitment_number - 1, + fmt_pubkey(tmpctx, + remote_current_per_commitment_point), + fmt_pubkey(tmpctx, + &peer->old_remote_per_commit), + fmt_pubkey(tmpctx, + &peer->remote_per_commit)); } } else { /* We've sent a commit sig but haven't gotten a revoke+ack back */ @@ -4730,12 +4683,12 @@ static void check_current_dataloss_fields(struct peer *peer, "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)); + fmt_pubkey(tmpctx, + remote_current_per_commitment_point), + fmt_pubkey(tmpctx, + &peer->remote_per_commit), + fmt_pubkey(tmpctx, + &peer->old_remote_per_commit)); } } @@ -4966,8 +4919,7 @@ static void peer_reconnect(struct peer *peer, peer_failed_err(peer->pps, &channel_id, "bad reestablish msg for unknown channel %s: %s", - type_to_string(tmpctx, struct channel_id, - &channel_id), + fmt_channel_id(tmpctx, &channel_id), tal_hex(msg, msg)); } @@ -5018,26 +4970,21 @@ static void peer_reconnect(struct peer *peer, " txid %s that matches our current" " active funding txid %s. Should be %s" " or NULL", - type_to_string(tmpctx, - struct bitcoin_txid, - remote_next_funding), - type_to_string(tmpctx, - struct bitcoin_txid, - &peer->channel->funding.txid), - type_to_string(tmpctx, - struct bitcoin_txid, - &inflight->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, + remote_next_funding), + fmt_bitcoin_txid(tmpctx, + &peer->channel->funding.txid), + fmt_bitcoin_txid(tmpctx, + &inflight->outpoint.txid)); } else { /* remote_next_funding set but unrecognized */ peer_failed_err(peer->pps, &peer->channel_id, "Invalid reestablish with unrecognized" " next_funding txid %s, should be %s", - type_to_string(tmpctx, - struct bitcoin_txid, - remote_next_funding), - type_to_string(tmpctx, - struct bitcoin_txid, - &inflight->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, + remote_next_funding), + fmt_bitcoin_txid(tmpctx, + &inflight->outpoint.txid)); } } else if (remote_next_funding) { /* No current inflight */ if (bitcoin_txid_eq(remote_next_funding, @@ -5070,7 +5017,7 @@ static void peer_reconnect(struct peer *peer, tlvs->short_channel_id = &peer->local_alias; status_debug("Retransmitting channel_ready for channel %s", - type_to_string(tmpctx, struct channel_id, &peer->channel_id)); + fmt_channel_id(tmpctx, &peer->channel_id)); /* Contains per commit point #1, for first post-opening commit */ msg = towire_channel_ready(NULL, &peer->channel_id, @@ -5387,17 +5334,14 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg) peer->splice_state->short_channel_id = *scid; status_debug("Current channel id is %s, " "splice_short_channel_id now set to %s", - type_to_string(tmpctx, - struct short_channel_id, - &peer->short_channel_ids[LOCAL]), - type_to_string(tmpctx, - struct short_channel_id, - &peer->splice_state->short_channel_id)); + fmt_short_channel_id(tmpctx, + peer->short_channel_ids[LOCAL]), + fmt_short_channel_id(tmpctx, + peer->splice_state->short_channel_id)); } else { status_debug("handle_funding_depth: Setting short_channel_ids[LOCAL] to %s", - type_to_string(tmpctx, - struct short_channel_id, - (scid ? scid : &peer->local_alias))); + fmt_short_channel_id(tmpctx, + (scid ? *scid : peer->local_alias))); /* If we know an actual short_channel_id prefer to use * that, otherwise fill in the alias. From channeld's * point of view switching from zeroconf to an actual @@ -5412,8 +5356,8 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg) status_debug("channel_ready: sending commit index" " %"PRIu64": %s", peer->next_index[LOCAL], - type_to_string(tmpctx, struct pubkey, - &peer->next_local_per_commit)); + fmt_pubkey(tmpctx, + &peer->next_local_per_commit)); tlvs = tlv_channel_ready_tlvs_new(tmpctx); tlvs->short_channel_id = &peer->local_alias; @@ -5480,7 +5424,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg) &htlc_fee, true); status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s", peer->htlc_id, - type_to_string(tmpctx, struct amount_msat, &amount), + fmt_amount_msat(tmpctx, amount), cltv_expiry, channel_add_err_name(e)); @@ -5520,9 +5464,8 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg) case CHANNEL_ERR_HTLC_BELOW_MINIMUM: failwiremsg = towire_amount_below_minimum(inmsg, amount, NULL); failstr = tal_fmt(inmsg, "HTLC too small (%s minimum)", - type_to_string(tmpctx, - struct amount_msat, - &peer->channel->config[REMOTE].htlc_minimum)); + fmt_amount_msat(tmpctx, + peer->channel->config[REMOTE].htlc_minimum)); goto failed; case CHANNEL_ERR_TOO_MANY_HTLCS: failwiremsg = towire_temporary_channel_failure(inmsg, NULL); @@ -5990,15 +5933,13 @@ static void init_channel(struct peer *peer) " feerates %s range %u-%u" " blockheights %s, our current %u", side_to_str(opener), - type_to_string(tmpctx, struct pubkey, - &peer->remote_per_commit), - type_to_string(tmpctx, struct pubkey, - &peer->old_remote_per_commit), + fmt_pubkey(tmpctx, &peer->remote_per_commit), + fmt_pubkey(tmpctx, &peer->old_remote_per_commit), peer->next_index[LOCAL], peer->next_index[REMOTE], peer->revocations_received, - type_to_string(tmpctx, struct fee_states, fee_states), + fmt_fee_states(tmpctx, fee_states), peer->feerate_min, peer->feerate_max, - type_to_string(tmpctx, struct height_states, blockheight_states), + fmt_height_states(tmpctx, blockheight_states), peer->our_blockheight); /* First commit is used for opening: if we've sent 0, we're on diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 443841537df7..e36796bb1365 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -356,8 +356,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * However, valgrind will warn us something wierd is happening */ SUPERVERBOSE("# to_remote amount %"PRIu64" P2WPKH(%s)\n", amount.satoshis, /* Raw: BOLT 3 output match */ - type_to_string(tmpctx, struct pubkey, - &keyset->other_payment_key)); + fmt_pubkey(tmpctx, &keyset->other_payment_key)); n++; to_remote = true; diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 97a7ccc823e1..940e62413639 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -424,10 +424,8 @@ static bool get_room_above_reserve(const struct channel *channel, status_debug("%s cannot afford htlc: would make balance %s" " below reserve %s", side_to_str(side), - type_to_string(tmpctx, struct amount_msat, - remainder), - type_to_string(tmpctx, struct amount_sat, - &reserve)); + fmt_amount_msat(tmpctx, *remainder), + fmt_amount_sat(tmpctx, reserve)); return false; } return true; @@ -570,8 +568,8 @@ static bool local_opener_has_fee_headroom(const struct channel *channel, status_debug("Adding HTLC would leave us only %s: we need %s for" " another HTLC if fees increase by 100%% to %uperkw", - type_to_string(tmpctx, struct amount_msat, &remainder), - type_to_string(tmpctx, struct amount_sat, &fee), + fmt_amount_msat(tmpctx, remainder), + fmt_amount_sat(tmpctx, fee), feerate + feerate); return false; } @@ -775,10 +773,8 @@ static enum channel_add_err add_htlc(struct channel *channel, if (channel->opener== sender) { if (amount_msat_less_sat(remainder, fee)) { status_debug("Cannot afford fee %s with %s above reserve", - type_to_string(tmpctx, struct amount_sat, - &fee), - type_to_string(tmpctx, struct amount_msat, - &remainder)); + fmt_amount_sat(tmpctx, fee), + fmt_amount_msat(tmpctx, remainder)); return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; } @@ -819,12 +815,8 @@ static enum channel_add_err add_htlc(struct channel *channel, *htlc_fee = fee; if (amount_msat_less_sat(remainder, fee)) { status_debug("Funder could not afford own fee %s with %s above reserve", - type_to_string(tmpctx, - struct amount_sat, - &fee), - type_to_string(tmpctx, - struct amount_msat, - &remainder)); + fmt_amount_sat(tmpctx, fee), + fmt_amount_msat(tmpctx, remainder)); return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; } fee = fee_for_htlcs(channel, @@ -836,13 +828,9 @@ static enum channel_add_err add_htlc(struct channel *channel, if (htlc_fee && amount_sat_greater(fee, *htlc_fee)) *htlc_fee = fee; if (amount_msat_less_sat(remainder, fee)) { - status_debug("Funder could not afford peer's fee %s with %s above reserve", - type_to_string(tmpctx, - struct amount_sat, - &fee), - type_to_string(tmpctx, - struct amount_msat, - &remainder)); + status_debug("Funder could not afford peer's fee `%s with %s above reserve", + fmt_amount_sat(tmpctx, fee), + fmt_amount_msat(tmpctx, remainder)); return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; } } @@ -1192,8 +1180,8 @@ static int change_htlcs(struct channel *channel, "%s: %s balance underflow: %s -> %"PRId64, side_to_str(sidechanged), side_to_str(i), - type_to_string(tmpctx, struct amount_msat, - &channel->view[sidechanged].owed[i]), + fmt_amount_msat(tmpctx, + channel->view[sidechanged].owed[i]), owed[i].msat); } } @@ -1349,8 +1337,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw && !amount_sat_add(&fee, fee, AMOUNT_SAT(660))) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Cannot add 660 sats to %s for anchor", - type_to_string(tmpctx, struct amount_sat, - &fee)); + fmt_amount_sat(tmpctx, fee)); /* BOLT #2: * @@ -1366,10 +1353,9 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw channel->config[!channel->opener].channel_reserve)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Cannot add fee %s and reserve %s", - type_to_string(tmpctx, struct amount_sat, - &fee), - type_to_string(tmpctx, struct amount_sat, - &channel->config[!channel->opener].channel_reserve)); + fmt_amount_sat(tmpctx, fee), + fmt_amount_sat(tmpctx, + channel->config[!channel->opener].channel_reserve)); /* The amount we have needs to take into account that we're * adding and removing htlcs */ @@ -1387,13 +1373,13 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw } status_debug("We need %s at feerate %u for %zu untrimmed htlcs: we have %s/%s (will have %s)", - type_to_string(tmpctx, struct amount_sat, &needed), + fmt_amount_sat(tmpctx, needed), feerate_per_kw, untrimmed, - type_to_string(tmpctx, struct amount_msat, - &channel->view[LOCAL].owed[channel->opener]), - type_to_string(tmpctx, struct amount_msat, - &channel->view[REMOTE].owed[channel->opener]), - type_to_string(tmpctx, struct amount_msat, &available)); + fmt_amount_msat(tmpctx, + channel->view[LOCAL].owed[channel->opener]), + fmt_amount_msat(tmpctx, + channel->view[REMOTE].owed[channel->opener]), + fmt_amount_msat(tmpctx, available)); return amount_msat_greater_eq_sat(available, needed); } @@ -1620,11 +1606,9 @@ bool channel_force_htlcs(struct channel *channel, " payment_hash=%s %s", i, tal_count(htlcs), htlcs[i]->id, - type_to_string(tmpctx, struct amount_msat, - &htlcs[i]->amount), + fmt_amount_msat(tmpctx, htlcs[i]->amount), htlcs[i]->cltv_expiry, - type_to_string(tmpctx, struct sha256, - &htlcs[i]->payment_hash), + fmt_sha256(tmpctx, &htlcs[i]->payment_hash), htlcs[i]->payment_preimage ? "(have preimage)" : htlcs[i]->failed ? "(failed)" : ""); diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index 236540c156af..5fae1a29302c 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -330,8 +330,8 @@ static void report_htlcs(const struct bitcoin_tx *tx, printf("# signature for output #%zi (%s for htlc #%"PRIu64")\n", i, htlc_owner(htlc) == LOCAL ? "htlc-timeout" : "htlc-success", htlc->id); printf("remote_htlc_signature = %s\n", - type_to_string(tmpctx, secp256k1_ecdsa_signature, - &remotehtlcsig[i].s)); + fmt_secp256k1_ecdsa_signature(tmpctx, + &remotehtlcsig[i].s)); sign_tx_input(htlc_tx[i], 0, NULL, @@ -340,8 +340,8 @@ static void report_htlcs(const struct bitcoin_tx *tx, SIGHASH_ALL, &localhtlcsig); printf("# local_htlc_signature = %s\n", - type_to_string(tmpctx, secp256k1_ecdsa_signature, - &localhtlcsig.s)); + fmt_secp256k1_ecdsa_signature(tmpctx, + &localhtlcsig.s)); if (htlc_owner(htlc) == LOCAL) { htlc_timeout_tx_add_witness(htlc_tx[i], local_htlckey, @@ -403,7 +403,7 @@ static void report(struct bitcoin_tx *tx, SIGHASH_ALL, &remotesig); printf("remote_signature = %s\n", - type_to_string(tmpctx, secp256k1_ecdsa_signature, &remotesig.s)); + fmt_secp256k1_ecdsa_signature(tmpctx, &remotesig.s)); sign_tx_input(tx, 0, NULL, wscript, @@ -411,7 +411,7 @@ static void report(struct bitcoin_tx *tx, SIGHASH_ALL, &localsig); printf("# local_signature = %s\n", - type_to_string(tmpctx, secp256k1_ecdsa_signature, &localsig.s)); + fmt_secp256k1_ecdsa_signature(tmpctx, &localsig.s)); witness = bitcoin_witness_2of2(tx, &localsig, &remotesig, @@ -618,51 +618,42 @@ int main(int argc, const char *argv[]) local_funding_privkey.secret = secret_from_hex("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f374901"); x_remote_funding_privkey.secret = secret_from_hex("1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e1301"); SUPERVERBOSE("INTERNAL: remote_funding_privkey: %s01\n", - type_to_string(tmpctx, struct privkey, - &x_remote_funding_privkey)); + fmt_privkey(tmpctx, &x_remote_funding_privkey)); x_local_payment_basepoint_secret = secret_from_hex("1111111111111111111111111111111111111111111111111111111111111111"); SUPERVERBOSE("INTERNAL: local_payment_basepoint_secret: %s\n", - type_to_string(tmpctx, struct secret, - &x_local_payment_basepoint_secret)); + fmt_secret(tmpctx, &x_local_payment_basepoint_secret)); x_remote_revocation_basepoint_secret = secret_from_hex("2222222222222222222222222222222222222222222222222222222222222222"); SUPERVERBOSE("INTERNAL: remote_revocation_basepoint_secret: %s\n", - type_to_string(tmpctx, struct secret, - &x_remote_revocation_basepoint_secret)); + fmt_secret(tmpctx, &x_remote_revocation_basepoint_secret)); x_local_delayed_payment_basepoint_secret = secret_from_hex("3333333333333333333333333333333333333333333333333333333333333333"); SUPERVERBOSE("INTERNAL: local_delayed_payment_basepoint_secret: %s\n", - type_to_string(tmpctx, struct secret, - &x_local_delayed_payment_basepoint_secret)); + fmt_secret(tmpctx, &x_local_delayed_payment_basepoint_secret)); x_remote_payment_basepoint_secret = secret_from_hex("4444444444444444444444444444444444444444444444444444444444444444"); SUPERVERBOSE("INTERNAL: remote_payment_basepoint_secret: %s\n", - type_to_string(tmpctx, struct secret, - &x_remote_payment_basepoint_secret)); + fmt_secret(tmpctx, &x_remote_payment_basepoint_secret)); x_local_per_commitment_secret = secret_from_hex("0x1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"); SUPERVERBOSE("x_local_per_commitment_secret: %s\n", - type_to_string(tmpctx, struct secret, - &x_local_per_commitment_secret)); + fmt_secret(tmpctx, &x_local_per_commitment_secret)); if (!pubkey_from_secret(&x_remote_revocation_basepoint_secret, &x_remote_revocation_basepoint)) abort(); SUPERVERBOSE("# From remote_revocation_basepoint_secret\n" "INTERNAL: remote_revocation_basepoint: %s\n", - type_to_string(tmpctx, struct pubkey, - &x_remote_revocation_basepoint)); + fmt_pubkey(tmpctx, &x_remote_revocation_basepoint)); if (!pubkey_from_secret(&x_local_delayed_payment_basepoint_secret, &x_local_delayed_payment_basepoint)) abort(); SUPERVERBOSE("# From local_delayed_payment_basepoint_secret\n" "INTERNAL: local_delayed_payment_basepoint: %s\n", - type_to_string(tmpctx, struct pubkey, - &x_local_delayed_payment_basepoint)); + fmt_pubkey(tmpctx, &x_local_delayed_payment_basepoint)); if (!pubkey_from_secret(&x_local_per_commitment_secret, &x_local_per_commitment_point)) abort(); SUPERVERBOSE("INTERNAL: local_per_commitment_point: %s\n", - type_to_string(tmpctx, struct pubkey, - &x_local_per_commitment_point)); + fmt_pubkey(tmpctx, &x_local_per_commitment_point)); if (!pubkey_from_secret(&x_local_payment_basepoint_secret, &local_payment_basepoint)) @@ -684,7 +675,7 @@ int main(int argc, const char *argv[]) &x_remote_htlcsecretkey)) abort(); SUPERVERBOSE("INTERNAL: remote_secretkey: %s\n", - type_to_string(tmpctx, struct privkey, &x_remote_htlcsecretkey)); + fmt_privkey(tmpctx, &x_remote_htlcsecretkey)); if (!derive_simple_privkey(&x_local_delayed_payment_basepoint_secret, &x_local_delayed_payment_basepoint, @@ -693,14 +684,13 @@ int main(int argc, const char *argv[]) abort(); SUPERVERBOSE("# From local_delayed_payment_basepoint_secret, local_per_commitment_point and local_delayed_payment_basepoint\n" "INTERNAL: local_delayed_secretkey: %s\n", - type_to_string(tmpctx, struct privkey, - &x_local_delayed_secretkey)); + fmt_privkey(tmpctx, &x_local_delayed_secretkey)); /* These two needed to calculate obscuring factor */ printf("local_payment_basepoint: %s\n", - type_to_string(tmpctx, struct pubkey, &local_payment_basepoint)); + fmt_pubkey(tmpctx, &local_payment_basepoint)); printf("remote_payment_basepoint: %s\n", - type_to_string(tmpctx, struct pubkey,&remote_payment_basepoint)); + fmt_pubkey(tmpctx,&remote_payment_basepoint)); cn_obscurer = commit_number_obscurer(&local_payment_basepoint, &remote_payment_basepoint); printf("# obscured commitment transaction number = 0x%"PRIx64" ^ %"PRIu64"\n", @@ -708,16 +698,16 @@ int main(int argc, const char *argv[]) printf("local_funding_privkey: %s01\n", - type_to_string(tmpctx, struct privkey, &local_funding_privkey)); + fmt_privkey(tmpctx, &local_funding_privkey)); if (!pubkey_from_privkey(&local_funding_privkey, &local_funding_pubkey)) abort(); printf("local_funding_pubkey: %s\n", - type_to_string(tmpctx, struct pubkey, &local_funding_pubkey)); + fmt_pubkey(tmpctx, &local_funding_pubkey)); if (!pubkey_from_privkey(&x_remote_funding_privkey, &remote_funding_pubkey)) abort(); printf("remote_funding_pubkey: %s\n", - type_to_string(tmpctx, struct pubkey, &remote_funding_pubkey)); + fmt_pubkey(tmpctx, &remote_funding_pubkey)); if (!derive_simple_privkey(&x_local_htlc_basepoint_secret, &local_payment_basepoint, @@ -725,14 +715,14 @@ int main(int argc, const char *argv[]) &local_htlcsecretkey)) abort(); printf("local_secretkey: %s\n", - type_to_string(tmpctx, struct privkey, &local_htlcsecretkey)); + fmt_privkey(tmpctx, &local_htlcsecretkey)); if (!derive_simple_key(&local_payment_basepoint, &x_local_per_commitment_point, &localkey)) abort(); printf("localkey: %s\n", - type_to_string(tmpctx, struct pubkey, &localkey)); + fmt_pubkey(tmpctx, &localkey)); if (option_static_remotekey) remotekey = remote_payment_basepoint; @@ -743,7 +733,7 @@ int main(int argc, const char *argv[]) abort(); } printf("remotekey: %s\n", - type_to_string(tmpctx, struct pubkey, &remotekey)); + fmt_pubkey(tmpctx, &remotekey)); if (!pubkey_from_privkey(&local_htlcsecretkey, &local_htlckey)) abort(); @@ -753,14 +743,14 @@ int main(int argc, const char *argv[]) abort(); assert(pubkey_eq(&tmpkey, &local_htlckey)); printf("local_htlckey: %s\n", - type_to_string(tmpctx, struct pubkey, &local_htlckey)); + fmt_pubkey(tmpctx, &local_htlckey)); if (!derive_simple_key(&remote_htlc_basepoint, &x_local_per_commitment_point, &remote_htlckey)) abort(); printf("remote_htlckey: %s\n", - type_to_string(tmpctx, struct pubkey, &remote_htlckey)); + fmt_pubkey(tmpctx, &remote_htlckey)); if (!pubkey_from_privkey(&x_local_delayed_secretkey, &local_delayedkey)) abort(); @@ -770,14 +760,14 @@ int main(int argc, const char *argv[]) abort(); assert(pubkey_eq(&tmpkey, &local_delayedkey)); printf("local_delayedkey: %s\n", - type_to_string(tmpctx, struct pubkey, &local_delayedkey)); + fmt_pubkey(tmpctx, &local_delayedkey)); if (!derive_revocation_key(&x_remote_revocation_basepoint, &x_local_per_commitment_point, &remote_revocation_key)) abort(); printf("remote_revocation_key: %s\n", - type_to_string(tmpctx, struct pubkey, &remote_revocation_key)); + fmt_pubkey(tmpctx, &remote_revocation_key)); wscript = bitcoin_redeem_2of2(tmpctx, &local_funding_pubkey, &remote_funding_pubkey); diff --git a/channeld/watchtower.c b/channeld/watchtower.c index e1ef1785b579..40eb7a9c3d04 100644 --- a/channeld/watchtower.c +++ b/channeld/watchtower.c @@ -58,8 +58,7 @@ penalty_tx_create(const tal_t *ctx, if (!pubkey_from_secret(&remote_per_commitment_secret, &remote_per_commitment_point)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Failed derive from per_commitment_secret %s", - type_to_string(tmpctx, struct secret, - &remote_per_commitment_secret)); + fmt_secret(tmpctx, &remote_per_commitment_secret)); if (!derive_keyset(&remote_per_commitment_point, &basepoints[REMOTE], @@ -95,8 +94,8 @@ penalty_tx_create(const tal_t *ctx, if (!amount_sat_add(&min_out, dust_limit, fee)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Cannot add dust_limit %s and fee %s", - type_to_string(tmpctx, struct amount_sat, &dust_limit), - type_to_string(tmpctx, struct amount_sat, &fee)); + fmt_amount_sat(tmpctx, dust_limit), + fmt_amount_sat(tmpctx, fee)); if (amount_sat_less(to_them_sats, min_out)) { /* FIXME: We should use SIGHASH_NONE so others can take it */ @@ -112,7 +111,7 @@ penalty_tx_create(const tal_t *ctx, status_failed(STATUS_FAIL_INTERNAL_ERROR, "TX can't afford minimal feerate" "; setting output to %s", - type_to_string(tmpctx, struct amount_sat, &amt)); + fmt_amount_sat(tmpctx, amt)); } bitcoin_tx_output_set_amount(tx, 0, amt); bitcoin_tx_finalize(tx); diff --git a/closingd/closingd.c b/closingd/closingd.c index 02e734eacff3..dc4adae8dacc 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -72,16 +72,14 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx, if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee)) 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])); + fmt_amount_sat(tmpctx, fee), + fmt_amount_sat(tmpctx, out[LOCAL]), + fmt_amount_sat(tmpctx, out[REMOTE])); 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[REMOTE]), - type_to_string(tmpctx, struct amount_sat, &fee)); + fmt_amount_sat(tmpctx, out[LOCAL]), + fmt_amount_sat(tmpctx, out[REMOTE]), + fmt_amount_sat(tmpctx, fee)); /* FIXME: We need to allow this! */ tx = create_close_tx(ctx, @@ -102,11 +100,11 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx, " dust_limit = %s" " LOCAL = %s" " REMOTE = %s", - type_to_string(tmpctx, struct amount_sat, &funding_sats), - 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])); + fmt_amount_sat(tmpctx, funding_sats), + fmt_amount_sat(tmpctx, fee), + fmt_amount_sat(tmpctx, dust_limit), + fmt_amount_sat(tmpctx, out[LOCAL]), + fmt_amount_sat(tmpctx, out[REMOTE])); if (wrong_funding) bitcoin_tx_input_set_outpoint(tx, 0, wrong_funding); @@ -186,7 +184,7 @@ static void send_offer(struct per_peer_state *pps, tal_hex(tmpctx, msg)); status_debug("sending fee offer %s", - type_to_string(tmpctx, struct amount_sat, &fee_to_offer)); + fmt_amount_sat(tmpctx, fee_to_offer)); /* Add the new close_tlvs with our fee range */ if (tlv_fees) { @@ -195,9 +193,9 @@ static void send_offer(struct per_peer_state *pps, = cast_const(struct tlv_closing_signed_tlvs_fee_range *, tlv_fees); notify(LOG_INFORM, "Sending closing fee offer %s, with range %s-%s", - type_to_string(tmpctx, struct amount_sat, &fee_to_offer), - type_to_string(tmpctx, struct amount_sat, &tlv_fees->min_fee_satoshis), - type_to_string(tmpctx, struct amount_sat, &tlv_fees->max_fee_satoshis)); + fmt_amount_sat(tmpctx, fee_to_offer), + fmt_amount_sat(tmpctx, tlv_fees->min_fee_satoshis), + fmt_amount_sat(tmpctx, tlv_fees->max_fee_satoshis)); } else close_tlvs = NULL; @@ -341,12 +339,10 @@ receive_offer(struct per_peer_state *pps, peer_failed_warn(pps, channel_id, "Bad closing_signed signature for" " %s (and trimmed version %s)", - type_to_string(tmpctx, - struct bitcoin_tx, + fmt_bitcoin_tx(tmpctx, tx), trimmed ? - type_to_string(tmpctx, - struct bitcoin_tx, + fmt_bitcoin_tx(tmpctx, trimmed) : "NONE"); } @@ -354,7 +350,7 @@ receive_offer(struct per_peer_state *pps, } status_debug("Received fee offer %s", - type_to_string(tmpctx, struct amount_sat, &received_fee)); + fmt_amount_sat(tmpctx, received_fee)); if (tlv_fees) { if (close_tlvs) { @@ -366,14 +362,14 @@ receive_offer(struct per_peer_state *pps, if (close_tlvs && close_tlvs->fee_range) { notify(LOG_INFORM, "Received closing fee offer %s, with range %s-%s", - type_to_string(tmpctx, struct amount_sat, &received_fee), - type_to_string(tmpctx, struct amount_sat, - &close_tlvs->fee_range->min_fee_satoshis), - type_to_string(tmpctx, struct amount_sat, - &close_tlvs->fee_range->max_fee_satoshis)); + fmt_amount_sat(tmpctx, received_fee), + fmt_amount_sat(tmpctx, + close_tlvs->fee_range->min_fee_satoshis), + fmt_amount_sat(tmpctx, + close_tlvs->fee_range->max_fee_satoshis)); } else { notify(LOG_INFORM, "Received closing fee offer %s, without range", - type_to_string(tmpctx, struct amount_sat, &received_fee)); + fmt_amount_sat(tmpctx, received_fee)); } /* Master sorts out what is best offer, we just tell it any above min */ @@ -411,8 +407,8 @@ static void init_feerange(struct feerange *feerange, feerange->higher_side = REMOTE; status_debug("Feerange init %s-%s, %s higher", - type_to_string(tmpctx, struct amount_sat, &feerange->min), - type_to_string(tmpctx, struct amount_sat, &feerange->max), + fmt_amount_sat(tmpctx, feerange->min), + fmt_amount_sat(tmpctx, feerange->max), feerange->higher_side == LOCAL ? "local" : "remote"); } @@ -434,9 +430,9 @@ static void adjust_feerange(struct feerange *feerange, status_debug("Feerange %s update %s: now %s-%s", side == LOCAL ? "local" : "remote", - type_to_string(tmpctx, struct amount_sat, &offer), - type_to_string(tmpctx, struct amount_sat, &feerange->min), - type_to_string(tmpctx, struct amount_sat, &feerange->max)); + fmt_amount_sat(tmpctx, offer), + fmt_amount_sat(tmpctx, feerange->min), + fmt_amount_sat(tmpctx, feerange->max)); if (!ok) status_failed(STATUS_FAIL_INTERNAL_ERROR, @@ -483,8 +479,7 @@ adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id, if (!amount_sat_add(&min_plus_one, feerange->min, AMOUNT_SAT(1))) peer_failed_warn(pps, channel_id, "Fee offer %s min too large", - type_to_string(tmpctx, struct amount_sat, - &feerange->min)); + fmt_amount_sat(tmpctx, feerange->min)); if (amount_sat_greater_eq(min_plus_one, feerange->max)) return remote_offer; @@ -501,12 +496,9 @@ adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id, 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)); + fmt_amount_sat(tmpctx, feerange->min), + fmt_amount_sat(tmpctx, feerange->max), + fmt_amount_sat(tmpctx, min_fee_to_accept)); if (fee_negotiation_step_unit == CLOSING_FEE_NEGOTIATION_STEP_UNIT_SATOSHI) { @@ -630,7 +622,7 @@ static void calc_fee_bounds(size_t expected_weight, *maxfee = amount_tx_fee(max_feerate, expected_weight); status_debug("deriving max fee from rate %u -> %s", max_feerate, - type_to_string(tmpctx, struct amount_sat, maxfee)); + fmt_amount_sat(tmpctx, *maxfee)); } /* Can't exceed maxfee. */ @@ -640,25 +632,25 @@ static void calc_fee_bounds(size_t expected_weight, if (amount_sat_less(*desiredfee, *minfee)) { status_unusual("Our ideal fee is %s (%u sats/perkw)," " but our minimum is %s: using that", - type_to_string(tmpctx, struct amount_sat, desiredfee), + fmt_amount_sat(tmpctx, *desiredfee), desired_feerate, - type_to_string(tmpctx, struct amount_sat, minfee)); + fmt_amount_sat(tmpctx, *minfee)); *desiredfee = *minfee; } if (amount_sat_greater(*desiredfee, *maxfee)) { status_unusual("Our ideal fee is %s (%u sats/perkw)," " but our maximum is %s: using that", - type_to_string(tmpctx, struct amount_sat, desiredfee), + fmt_amount_sat(tmpctx, *desiredfee), desired_feerate, - type_to_string(tmpctx, struct amount_sat, maxfee)); + fmt_amount_sat(tmpctx, *maxfee)); *desiredfee = *maxfee; } status_debug("Expected closing weight = %zu, fee %s (min %s, max %s)", expected_weight, - type_to_string(tmpctx, struct amount_sat, desiredfee), - type_to_string(tmpctx, struct amount_sat, minfee), - type_to_string(tmpctx, struct amount_sat, maxfee)); + fmt_amount_sat(tmpctx, *desiredfee), + fmt_amount_sat(tmpctx, *minfee), + fmt_amount_sat(tmpctx, *maxfee)); } /* We've received one offer; if we're opener, that means we've already sent one @@ -695,26 +687,16 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], peer_failed_warn(pps, channel_id, "Unable to agree on a feerate." " Our range %s-%s, other range %s-%s", - type_to_string(tmpctx, - struct amount_sat, - &our_feerange->min_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &our_feerange->max_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &their_feerange->min_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &their_feerange->max_fee_satoshis)); + fmt_amount_sat(tmpctx, our_feerange->min_fee_satoshis), + fmt_amount_sat(tmpctx, our_feerange->max_fee_satoshis), + fmt_amount_sat(tmpctx, their_feerange->min_fee_satoshis), + fmt_amount_sat(tmpctx, their_feerange->max_fee_satoshis)); return; } status_info("performing quickclose in range %s-%s", - type_to_string(tmpctx, struct amount_sat, - &overlap.min_fee_satoshis), - type_to_string(tmpctx, struct amount_sat, - &overlap.max_fee_satoshis)); + fmt_amount_sat(tmpctx, overlap.min_fee_satoshis), + fmt_amount_sat(tmpctx, overlap.max_fee_satoshis)); /* BOLT #2: * - otherwise: @@ -730,20 +712,11 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], peer_failed_warn(pps, channel_id, "Your fee %s was not in range:" " Our range %s-%s, other range %s-%s", - type_to_string(tmpctx, - struct amount_sat, &offer[REMOTE]), - type_to_string(tmpctx, - struct amount_sat, - &our_feerange->min_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &our_feerange->max_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &their_feerange->min_fee_satoshis), - type_to_string(tmpctx, - struct amount_sat, - &their_feerange->max_fee_satoshis)); + fmt_amount_sat(tmpctx, offer[REMOTE]), + fmt_amount_sat(tmpctx, our_feerange->min_fee_satoshis), + fmt_amount_sat(tmpctx, our_feerange->max_fee_satoshis), + fmt_amount_sat(tmpctx, their_feerange->min_fee_satoshis), + fmt_amount_sat(tmpctx, their_feerange->max_fee_satoshis)); return; } /* Only reply if we didn't already completely agree. */ @@ -776,17 +749,13 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], offer[LOCAL] = overlap.max_fee_satoshis; status_unusual("Lowered offer to max allowable" " %s", - type_to_string(tmpctx, - struct amount_sat, - &offer[LOCAL])); + fmt_amount_sat(tmpctx, offer[LOCAL])); } else if (amount_sat_less(offer[LOCAL], overlap.min_fee_satoshis)) { offer[LOCAL] = overlap.min_fee_satoshis; status_unusual("Increased offer to min allowable" " %s", - type_to_string(tmpctx, - struct amount_sat, - &offer[LOCAL])); + fmt_amount_sat(tmpctx, offer[LOCAL])); } } send_offer(pps, chainparams, @@ -824,10 +793,8 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], if (!amount_sat_eq(offer[LOCAL], offer[REMOTE])) { peer_failed_warn(pps, channel_id, "Your fee %s was not equal to %s", - type_to_string(tmpctx, - struct amount_sat, &offer[REMOTE]), - type_to_string(tmpctx, - struct amount_sat, &offer[LOCAL])); + fmt_amount_sat(tmpctx, offer[REMOTE]), + fmt_amount_sat(tmpctx, offer[LOCAL])); return; } } @@ -835,7 +802,7 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], peer_billboard(true, "We agreed on a closing fee of %"PRIu64" satoshi for tx:%s", offer[LOCAL], - type_to_string(tmpctx, struct bitcoin_txid, closing_txid)); + fmt_bitcoin_txid(tmpctx, closing_txid)); } int main(int argc, char *argv[]) @@ -933,26 +900,26 @@ int main(int argc, char *argv[]) : "sat"); status_debug("out = %s/%s", - type_to_string(tmpctx, struct amount_sat, &out[LOCAL]), - type_to_string(tmpctx, struct amount_sat, &out[REMOTE])); + fmt_amount_sat(tmpctx, out[LOCAL]), + fmt_amount_sat(tmpctx, out[REMOTE])); status_debug("dustlimit = %s", - type_to_string(tmpctx, struct amount_sat, &our_dust_limit)); + fmt_amount_sat(tmpctx, our_dust_limit)); status_debug("fee = %s", - type_to_string(tmpctx, struct amount_sat, &offer[LOCAL])); + fmt_amount_sat(tmpctx, offer[LOCAL])); status_debug("fee negotiation step = %s", fee_negotiation_step_str); if (wrong_funding) status_unusual("Setting wrong_funding_txid to %s:%u", - type_to_string(tmpctx, struct bitcoin_txid, - &wrong_funding->txid), + fmt_bitcoin_txid(tmpctx, + &wrong_funding->txid), wrong_funding->n); peer_billboard( true, "Negotiating closing fee between %s and %s satoshi (ideal %s) " "using step %s", - type_to_string(tmpctx, struct amount_sat, &min_fee_to_accept), - type_to_string(tmpctx, struct amount_sat, &max_fee_to_accept), - type_to_string(tmpctx, struct amount_sat, &offer[LOCAL]), + fmt_amount_sat(tmpctx, min_fee_to_accept), + fmt_amount_sat(tmpctx, max_fee_to_accept), + fmt_amount_sat(tmpctx, offer[LOCAL]), fee_negotiation_step_str); /* BOLT #2: @@ -982,9 +949,7 @@ int main(int argc, char *argv[]) peer_billboard(false, "Waiting for their initial" " closing fee offer:" " ours was %s", - type_to_string(tmpctx, - struct amount_sat, - &offer[LOCAL])); + fmt_amount_sat(tmpctx, offer[LOCAL])); offer[REMOTE] = receive_offer(pps, chainparams, &channel_id, funding_pubkey, @@ -1073,7 +1038,7 @@ int main(int argc, char *argv[]) peer_billboard(true, "We agreed on a closing fee of %"PRIu64" satoshi for tx:%s", offer[LOCAL], - type_to_string(tmpctx, struct bitcoin_txid, &closing_txid)); + fmt_bitcoin_txid(tmpctx, &closing_txid)); exit_thru_the_giftshop: /* We don't listen for master commands, so always check memleak here */ diff --git a/common/blindedpath.c b/common/blindedpath.c index 5721c36ad7f4..f30eabc2b2b7 100644 --- a/common/blindedpath.c +++ b/common/blindedpath.c @@ -25,7 +25,7 @@ static bool blind_node(const struct privkey *blinding, if (!blindedpath_get_alias(ss, node, node_alias)) return false; SUPERVERBOSE("\t\"blinded_node_id\": \"%s\",\n", - type_to_string(tmpctx, struct pubkey, node_alias)); + fmt_pubkey(tmpctx, node_alias)); /* BOLT #4: * - `E(i+1) = SHA256(E(i) || ss(i)) * E(i)` @@ -34,7 +34,7 @@ static bool blind_node(const struct privkey *blinding, if (!pubkey_from_privkey(blinding, &blinding_pubkey)) return false; SUPERVERBOSE("\t\"E\": \"%s\",\n", - type_to_string(tmpctx, struct pubkey, &blinding_pubkey)); + fmt_pubkey(tmpctx, &blinding_pubkey)); /* BOLT #4: * - `e(i+1) = SHA256(E(i) || ss(i)) * e(i)` @@ -42,10 +42,10 @@ static bool blind_node(const struct privkey *blinding, */ blinding_hash_e_and_ss(&blinding_pubkey, ss, &h); SUPERVERBOSE("\t\"H(E || ss)\": \"%s\",\n", - type_to_string(tmpctx, struct sha256, &h)); + fmt_sha256(tmpctx, &h)); blinding_next_privkey(blinding, &h, next_blinding); SUPERVERBOSE("\t\"next_e\": \"%s\",\n", - type_to_string(tmpctx, struct privkey, next_blinding)); + fmt_privkey(tmpctx, next_blinding)); return true; } @@ -72,7 +72,7 @@ static u8 *enctlv_from_encmsg_raw(const tal_t *ctx, NULL, NULL) != 1) return NULL; SUPERVERBOSE("\t\"ss\": \"%s\",\n", - type_to_string(tmpctx, struct secret, &ss)); + fmt_secret(tmpctx, &ss)); /* This calculates the node's alias, and next blinding */ if (!blind_node(blinding, &ss, node, node_alias, next_blinding)) @@ -86,7 +86,7 @@ static u8 *enctlv_from_encmsg_raw(const tal_t *ctx, */ subkey_from_hmac("rho", &ss, &rho); SUPERVERBOSE("\t\"rho\": \"%s\",\n", - type_to_string(tmpctx, struct secret, &rho)); + fmt_secret(tmpctx, &rho)); /* BOLT #4: * - MUST encrypt each `encrypted_data_tlv(i)` with ChaCha20-Poly1305 using @@ -228,8 +228,7 @@ bool blindedpath_get_alias(const struct secret *ss, */ subkey_from_hmac("blinded_node_id", ss, &node_id_blinding); SUPERVERBOSE("\t\"HMAC256('blinded_node_id', ss)\": \"%s\",\n", - type_to_string(tmpctx, struct secret, - &node_id_blinding)); + fmt_secret(tmpctx, &node_id_blinding)); *alias = *my_id; return secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, diff --git a/common/bolt12_merkle.c b/common/bolt12_merkle.c index 870e440ee4ab..8a817e182cc0 100644 --- a/common/bolt12_merkle.c +++ b/common/bolt12_merkle.c @@ -50,7 +50,7 @@ static void h_simpletag_ctx(struct sha256_ctx *sctx, const char *tag) sha256_update(sctx, &sha, sizeof(sha)); SUPERVERBOSE("tag=SHA256(%s) -> %s", tal_hexstr(tmpctx, tag, strlen(tag)), - type_to_string(tmpctx, struct sha256, &sha)); + fmt_sha256(tmpctx, &sha)); } @@ -73,7 +73,7 @@ static void h_lnnonce_ctx(struct sha256_ctx *sctx, const struct tlv_field *field sha256_update_tlvfield(&inner_sctx, &fields[0]); sha256_done(&inner_sctx, &sha); SUPERVERBOSE(") -> %s\n", - type_to_string(tmpctx, struct sha256, &sha)); + fmt_sha256(tmpctx, &sha)); sha256_init(sctx); sha256_update(sctx, &sha, sizeof(sha)); @@ -92,7 +92,7 @@ static void calc_nonce(const struct sha256_ctx *lnnonce_ctx, sha256_update_bigsize(&ctx, field->numtype); sha256_done(&ctx, hash); - SUPERVERBOSE(") = %s\n", type_to_string(tmpctx, struct sha256, hash)); + SUPERVERBOSE(") = %s\n", fmt_sha256(tmpctx, hash)); } static void calc_lnleaf(const struct tlv_field *field, struct sha256 *hash) @@ -104,7 +104,7 @@ static void calc_lnleaf(const struct tlv_field *field, struct sha256 *hash) SUPERVERBOSE(","); sha256_update_tlvfield(&sctx, field); sha256_done(&sctx, hash); - SUPERVERBOSE(") -> %s\n", type_to_string(tmpctx, struct sha256, hash)); + SUPERVERBOSE(") -> %s\n", fmt_sha256(tmpctx, hash)); } /* BOLT-offers #12: @@ -130,7 +130,7 @@ static struct sha256 *merkle_pair(const tal_t *ctx, res = tal(ctx, struct sha256); sha256_done(&sctx, res); - SUPERVERBOSE(") -> %s\n", type_to_string(tmpctx, struct sha256, res)); + SUPERVERBOSE(") -> %s\n", fmt_sha256(tmpctx, res)); return res; } diff --git a/common/coin_mvt.c b/common/coin_mvt.c index f7d82b12812d..7a571aaea09e 100644 --- a/common/coin_mvt.c +++ b/common/coin_mvt.c @@ -207,7 +207,7 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx, mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, 0, take(new_tag_arr(NULL, CHANNEL_PROPOSED)), amount, true, output_val, 0); - mvt->account_name = type_to_string(mvt, struct channel_id, chan_id); + mvt->account_name = fmt_channel_id(mvt, chan_id); mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); /* If we're the opener, add to the tag list */ @@ -235,7 +235,7 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, blockheight, take(new_tag_arr(NULL, CHANNEL_OPEN)), amount, true, output_val, 0); - mvt->account_name = type_to_string(mvt, struct channel_id, chan_id); + mvt->account_name = fmt_channel_id(mvt, chan_id); mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); /* If we're the opener, add to the tag list */ @@ -423,8 +423,7 @@ struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, { struct coin_mvt *mvt = tal(ctx, struct coin_mvt); - mvt->account_id = type_to_string(mvt, struct channel_id, - &chan_mvt->chan_id); + mvt->account_id = fmt_channel_id(mvt, &chan_mvt->chan_id); /* channel moves don't have external events! */ mvt->originating_acct = NULL; mvt->hrp_name = tal_strdup(mvt, hrp_name); diff --git a/common/initial_channel.c b/common/initial_channel.c index 46538be9f3a1..d08d36738850 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -231,10 +231,8 @@ static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) { return tal_fmt(ctx, "{ owed_local=%s," " owed_remote=%s }", - type_to_string(tmpctx, struct amount_msat, - &view->owed[LOCAL]), - type_to_string(tmpctx, struct amount_msat, - &view->owed[REMOTE])); + fmt_amount_msat(tmpctx, view->owed[LOCAL]), + fmt_amount_msat(tmpctx, view->owed[REMOTE])); } /* FIXME: This should reference HTLCs somehow, and feerates! */ @@ -244,8 +242,7 @@ char *fmt_channel(const tal_t *ctx, const struct channel *channel) " opener=%s," " local=%s," " remote=%s }", - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats), + fmt_amount_sat(tmpctx, channel->funding_sats), side_to_str(channel->opener), fmt_channel_view(ctx, &channel->view[LOCAL]), fmt_channel_view(ctx, &channel->view[REMOTE])); diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 73e1a37b4b55..c7f7e52ff59a 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -176,12 +176,9 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, " nor other amount %s" " exceed reserve %s" " on initial commitment transaction", - type_to_string(tmpctx, struct amount_msat, - &self_pay), - type_to_string(tmpctx, struct amount_msat, - &other_pay), - type_to_string(tmpctx, struct amount_sat, - &self_reserve)); + fmt_amount_msat(tmpctx, self_pay), + fmt_amount_msat(tmpctx, other_pay), + fmt_amount_sat(tmpctx, self_reserve)); return NULL; } diff --git a/common/interactivetx.c b/common/interactivetx.c index d4c903bad5c6..1950bcb35157 100644 --- a/common/interactivetx.c +++ b/common/interactivetx.c @@ -484,9 +484,7 @@ char *process_interactivetx_updates(const tal_t *ctx, NULL)) return tal_fmt(ctx, "Invalid tx sent. Not SegWit %s", - type_to_string(ctx, - struct bitcoin_tx, - tx)); + fmt_bitcoin_tx(ctx, tx)); /* * BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2: @@ -501,9 +499,7 @@ char *process_interactivetx_updates(const tal_t *ctx, return tal_fmt(ctx, "Unable to add input %s- " "already present", - type_to_string(ctx, - struct bitcoin_outpoint, - &outpoint)); + fmt_bitcoin_outpoint(ctx, &outpoint)); /* * BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2: @@ -528,9 +524,7 @@ char *process_interactivetx_updates(const tal_t *ctx, if (!in) return tal_fmt(ctx, "Unable to add input %s", - type_to_string(ctx, - struct bitcoin_outpoint, - &outpoint)); + fmt_bitcoin_outpoint(ctx, &outpoint)); tal_wally_start(); wally_psbt_input_set_utxo(in, tx->wtx); diff --git a/common/key_derive.c b/common/key_derive.c index 52c78ac5e9ad..d2672192e449 100644 --- a/common/key_derive.c +++ b/common/key_derive.c @@ -49,9 +49,9 @@ bool derive_simple_key(const struct pubkey *basepoint, return false; #ifdef SUPERVERBOSE printf("# + basepoint (0x%s)\n", - type_to_string(tmpctx, struct pubkey, basepoint)); + fmt_pubkey(tmpctx, basepoint)); printf("# = 0x%s\n", - type_to_string(tmpctx, struct pubkey, key)); + fmt_pubkey(tmpctx, key)); #endif return true; } @@ -141,7 +141,7 @@ bool derive_revocation_key(const struct pubkey *basepoint, return false; #ifdef SUPERVERBOSE printf("# x revocation_basepoint = 0x%s\n", - type_to_string(tmpctx, secp256k1_pubkey, &add[0])); + fmt_secp256k1_pubkey(tmpctx, &add[0])); #endif pubkey_to_der(der_keys, per_commitment_point); @@ -160,7 +160,7 @@ bool derive_revocation_key(const struct pubkey *basepoint, return false; #ifdef SUPERVERBOSE printf("# x per_commitment_point = 0x%s\n", - type_to_string(tmpctx, secp256k1_pubkey, &add[1])); + fmt_secp256k1_pubkey(tmpctx, &add[1])); #endif args[0] = &add[0]; @@ -171,9 +171,9 @@ bool derive_revocation_key(const struct pubkey *basepoint, #ifdef SUPERVERBOSE printf("# 0x%s + 0x%s => 0x%s\n", - type_to_string(tmpctx, secp256k1_pubkey, args[0]), - type_to_string(tmpctx, secp256k1_pubkey, args[1]), - type_to_string(tmpctx, struct pubkey, key)); + fmt_secp256k1_pubkey(tmpctx, args[0]), + fmt_secp256k1_pubkey(tmpctx, args[1]), + fmt_pubkey(tmpctx, key)); #endif return true; } diff --git a/common/onion_message_parse.c b/common/onion_message_parse.c index 8bf4ef82ce44..0530eada5065 100644 --- a/common/onion_message_parse.c +++ b/common/onion_message_parse.c @@ -114,7 +114,7 @@ bool onion_message_parse(const tal_t *ctx, if (!rs) { status_peer_debug(peer, "onion_message_parse: can't process onionpacket ss=%s", - type_to_string(tmpctx, struct secret, &onion_ss)); + fmt_secret(tmpctx, &onion_ss)); return false; } diff --git a/common/test/run-blindedpath_enctlv.c b/common/test/run-blindedpath_enctlv.c index 3f0357a4b974..d779f6fb14a7 100644 --- a/common/test/run-blindedpath_enctlv.c +++ b/common/test/run-blindedpath_enctlv.c @@ -163,17 +163,17 @@ int main(int argc, char *argv[]) printf("[{"); json_strfield("test name", "Simple encrypted_recipient_data for Alice, next is Bob"); json_strfield("node_privkey", - type_to_string(tmpctx, struct privkey, &alice)); + fmt_privkey(tmpctx, &alice)); json_strfield("node_id", - type_to_string(tmpctx, struct pubkey, &alice_id)); + fmt_pubkey(tmpctx, &alice_id)); json_strfield("blinding_secret", - type_to_string(tmpctx, struct privkey, &blinding)); + fmt_privkey(tmpctx, &blinding)); json_strfield("blinding", - type_to_string(tmpctx, struct pubkey, &blinding_pub)); + fmt_pubkey(tmpctx, &blinding_pub)); printf("\t\"encrypted_data_tlv\": {\n" "\t\t\"next_node_id\": \"%s\"\n" "\t},\n", - type_to_string(tmpctx, struct pubkey, &bob_id)); + fmt_pubkey(tmpctx, &bob_id)); tlv = tlv_encrypted_data_tlv_new(tmpctx); tlv->next_node_id = &bob_id; @@ -193,19 +193,19 @@ int main(int argc, char *argv[]) json_strfield("test name", "Blinding-key-override encrypted_recipient_data for Bob, next is Carol"); json_strfield("node_privkey", - type_to_string(tmpctx, struct privkey, &bob)); + fmt_privkey(tmpctx, &bob)); json_strfield("node_id", - type_to_string(tmpctx, struct pubkey, &bob_id)); + fmt_pubkey(tmpctx, &bob_id)); json_strfield("blinding_secret", - type_to_string(tmpctx, struct privkey, &blinding)); + fmt_privkey(tmpctx, &blinding)); json_strfield("blinding", - type_to_string(tmpctx, struct pubkey, &blinding_pub)); + fmt_pubkey(tmpctx, &blinding_pub)); printf("\t\"encrypted_data_tlv\": {\n" "\t\t\"next_node_id\": \"%s\",\n" "\t\t\"blinding\": \"%s\"\n" "\t},\n", - type_to_string(tmpctx, struct pubkey, &carol_id), - type_to_string(tmpctx, struct privkey, &override_blinding)); + fmt_pubkey(tmpctx, &carol_id), + fmt_privkey(tmpctx, &override_blinding)); tlv = tlv_encrypted_data_tlv_new(tmpctx); tlv->next_node_id = &carol_id; @@ -225,18 +225,18 @@ int main(int argc, char *argv[]) printf("{"); json_strfield("test name", "Padded encrypted_recipient_data for Carol, next is Dave"); json_strfield("node_privkey", - type_to_string(tmpctx, struct privkey, &carol)); + fmt_privkey(tmpctx, &carol)); json_strfield("node_id", - type_to_string(tmpctx, struct pubkey, &carol_id)); + fmt_pubkey(tmpctx, &carol_id)); json_strfield("blinding_secret", - type_to_string(tmpctx, struct privkey, &blinding)); + fmt_privkey(tmpctx, &blinding)); json_strfield("blinding", - type_to_string(tmpctx, struct pubkey, &blinding_pub)); + fmt_pubkey(tmpctx, &blinding_pub)); printf("\t\"encrypted_data_tlv\": {\n" "\t\t\"next_node_id\": \"%s\",\n" "\t\t\"padding\": \"%s\"\n" "\t},\n", - type_to_string(tmpctx, struct pubkey, &dave_id), + fmt_pubkey(tmpctx, &dave_id), tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35))); tlv = tlv_encrypted_data_tlv_new(tmpctx); @@ -255,17 +255,17 @@ int main(int argc, char *argv[]) printf("{"); json_strfield("test name", "Final enctlv for Dave"); json_strfield("node_privkey", - type_to_string(tmpctx, struct privkey, &dave)); + fmt_privkey(tmpctx, &dave)); json_strfield("node_id", - type_to_string(tmpctx, struct pubkey, &dave_id)); + fmt_pubkey(tmpctx, &dave_id)); json_strfield("blinding_secret", - type_to_string(tmpctx, struct privkey, &blinding)); + fmt_privkey(tmpctx, &blinding)); json_strfield("blinding", - type_to_string(tmpctx, struct pubkey, &blinding_pub)); + fmt_pubkey(tmpctx, &blinding_pub)); printf("\t\"encrypted_data_tlv\": {\n" "\t\t\"self_id\": \"%s\"\n" "\t},\n", - type_to_string(tmpctx, struct secret, &self_id)); + fmt_secret(tmpctx, &self_id)); tlv = tlv_encrypted_data_tlv_new(tmpctx); tlv->path_id = tal_dup_arr(tlv, u8, diff --git a/common/test/run-blindedpath_onion.c b/common/test/run-blindedpath_onion.c index 33793ee512a2..b94ccc51afc6 100644 --- a/common/test/run-blindedpath_onion.c +++ b/common/test/run-blindedpath_onion.c @@ -252,20 +252,18 @@ int main(int argc, char *argv[]) printf("{\n"); json_strfield("node name", names[i]); json_strfield("node_secret", - type_to_string(tmpctx, struct privkey, - &nodekey[i])); + fmt_privkey(tmpctx, &nodekey[i])); json_strfield("node_id", - type_to_string(tmpctx, struct pubkey, &id[i])); + fmt_pubkey(tmpctx, &id[i])); printf("\t\"onion_message\": {"); json_strfield("raw", tal_hex(tmpctx, omsg)); json_strfield("blinding_secret", - type_to_string(tmpctx, struct privkey, - &blinding[i])); + fmt_privkey(tmpctx, &blinding[i])); json_strfield("blinding", - type_to_string(tmpctx, struct pubkey, &blinding_pub[i])); + fmt_pubkey(tmpctx, &blinding_pub[i])); json_strfield("blinded_alias", - type_to_string(tmpctx, struct pubkey, &alias[i])); + fmt_pubkey(tmpctx, &alias[i])); json_strfield("onionmsg_tlv", tal_hex(tmpctx, onionmsg_tlv[i])); printf("\"enctlv\": \"%s\"}\n", tal_hex(tmpctx, enctlv[i])); diff --git a/common/test/run-bolt12_merkle.c b/common/test/run-bolt12_merkle.c index 0ab4904eb302..edeb52cd176d 100644 --- a/common/test/run-bolt12_merkle.c +++ b/common/test/run-bolt12_merkle.c @@ -110,9 +110,9 @@ static struct sha256 *H(const void *tag, const void *msg) printf("test: H(tag=%s,msg=%s) -> SHA256(%s|%s|msg) -> %s\n", tal_hex(tmpctx, tag), tal_hex(tmpctx, msg), - type_to_string(tmpctx, struct sha256, taghash), - type_to_string(tmpctx, struct sha256, taghash), - type_to_string(tmpctx, struct sha256, ret)); + fmt_sha256(tmpctx, taghash), + fmt_sha256(tmpctx, taghash), + fmt_sha256(tmpctx, ret)); return ret; } @@ -193,16 +193,16 @@ int main(int argc, char *argv[]) H(concat(LnNonce, tlv1), tlv_type(tlv1)))); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,tlv1-type)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" }", tal_hex(tmpctx, tlv1), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv1)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv1))), - type_to_string(tmpctx, struct sha256, leaf[0])); + fmt_sha256(tmpctx, H(LnLeaf, tlv1)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv1))), + fmt_sha256(tmpctx, leaf[0])); json_out("],"); m = leaf[0]; json_out("\"branches\": [],"); json_out("\"merkle\": \"%s\"", - type_to_string(tmpctx, struct sha256, m)); + fmt_sha256(tmpctx, m)); json_out("},"); /* Create, linearize (populates ->fields) */ @@ -226,14 +226,14 @@ int main(int argc, char *argv[]) json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,tlv1-type)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" },", tal_hex(tmpctx, tlv1), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv1)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv1))), - type_to_string(tmpctx, struct sha256, leaf[0])); + fmt_sha256(tmpctx, H(LnLeaf, tlv1)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv1))), + fmt_sha256(tmpctx, leaf[0])); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,tlv2-type)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" }", tal_hex(tmpctx, tlv2), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv2)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv2))), - type_to_string(tmpctx, struct sha256, leaf[1])); + fmt_sha256(tmpctx, H(LnLeaf, tlv2)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv2))), + fmt_sha256(tmpctx, leaf[1])); json_out("],"); json_out("\"branches\": ["); @@ -245,7 +245,7 @@ int main(int argc, char *argv[]) m = H(LnBranch, ordered(leaf[0], leaf[1])); json_out("\"merkle\": \"%s\"", - type_to_string(tmpctx, struct sha256, m)); + fmt_sha256(tmpctx, m)); json_out("},"); n1->tlv2 = tal(n1, struct short_channel_id); @@ -268,19 +268,19 @@ int main(int argc, char *argv[]) H(concat(LnNonce, tlv1), tlv_type(tlv3)))); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,1)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" },", tal_hex(tmpctx, tlv1), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv1)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv1))), - type_to_string(tmpctx, struct sha256, leaf[0])); + fmt_sha256(tmpctx, H(LnLeaf, tlv1)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv1))), + fmt_sha256(tmpctx, leaf[0])); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,2)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" },", tal_hex(tmpctx, tlv2), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv2)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv2))), - type_to_string(tmpctx, struct sha256, leaf[1])); + fmt_sha256(tmpctx, H(LnLeaf, tlv2)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv2))), + fmt_sha256(tmpctx, leaf[1])); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,3)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" }", tal_hex(tmpctx, tlv3), - type_to_string(tmpctx, struct sha256, H(LnLeaf, tlv3)), - type_to_string(tmpctx, struct sha256, H(concat(LnNonce, tlv1), tlv_type(tlv3))), - type_to_string(tmpctx, struct sha256, leaf[2])); + fmt_sha256(tmpctx, H(LnLeaf, tlv3)), + fmt_sha256(tmpctx, H(concat(LnNonce, tlv1), tlv_type(tlv3))), + fmt_sha256(tmpctx, leaf[2])); json_out("],"); json_out("\"branches\": ["); @@ -300,7 +300,7 @@ int main(int argc, char *argv[]) ordered(H(LnBranch, ordered(leaf[0], leaf[1])), leaf[2])); json_out("\"merkle\": \"%s\"", - type_to_string(tmpctx, struct sha256, m)); + fmt_sha256(tmpctx, m)); json_out("},"); n1->tlv3 = tal(n1, struct tlv_n1_tlv3); @@ -375,12 +375,12 @@ int main(int argc, char *argv[]) H(concat(LnNonce, fieldwires[0]), tlv_type(fieldwires[i])))); json_out("{ \"H(`LnLeaf`,%s)\": \"%s\", \"H(`LnNonce`|first-tlv,%u)\": \"%s\", \"H(`LnBranch`,leaf+nonce)\": \"%s\" }%s", tal_hex(tmpctx, fieldwires[i]), - type_to_string(tmpctx, struct sha256, + fmt_sha256(tmpctx, H(LnLeaf, fieldwires[i])), tlv_type(fieldwires[i])[0], /* Works becuase they're all 1-byte types! */ - type_to_string(tmpctx, struct sha256, + fmt_sha256(tmpctx, H(concat(LnNonce, fieldwires[0]), tlv_type(fieldwires[i]))), - type_to_string(tmpctx, struct sha256, leaf[i]), + fmt_sha256(tmpctx, leaf[i]), i == ARRAY_SIZE(fieldwires) - 1 ? "" : ","); } json_out("],"); @@ -420,10 +420,10 @@ int main(int argc, char *argv[]) json_out("],"); json_out("\"merkle\": \"%s\",", - type_to_string(tmpctx, struct sha256, m)); + fmt_sha256(tmpctx, m)); json_out("\"signature_tag\": \"lightninginvoice_requestsignature\","); - json_out("\"H(signature_tag,merkle)\": \"%s\",", type_to_string(tmpctx, struct sha256, &sha)); - json_out("\"signature\": \"%s\"", type_to_string(tmpctx, struct bip340sig, invreq->signature)); + json_out("\"H(signature_tag,merkle)\": \"%s\",", fmt_sha256(tmpctx, &sha)); + json_out("\"signature\": \"%s\"", fmt_bip340sig(tmpctx, invreq->signature)); json_out("}]"); assert(sha256_eq(&test_m, m)); diff --git a/common/test/run-key_derive.c b/common/test/run-key_derive.c index 301767d11c1e..360b2de68f91 100644 --- a/common/test/run-key_derive.c +++ b/common/test/run-key_derive.c @@ -137,15 +137,15 @@ int main(int argc, char *argv[]) base_secret.data)) abort(); printf("base_point: 0x%s\n", - type_to_string(tmpctx, struct pubkey, &base_point)); + fmt_pubkey(tmpctx, &base_point)); printf("per_commitment_point: 0x%s\n", - type_to_string(tmpctx, struct pubkey, &per_commitment_point)); + fmt_pubkey(tmpctx, &per_commitment_point)); /* FIXME: Annotate internal steps. */ if (!derive_simple_key(&base_point, &per_commitment_point, &pubkey)) abort(); printf("localkey: 0x%s\n", - type_to_string(tmpctx, struct pubkey, &pubkey)); + fmt_pubkey(tmpctx, &pubkey)); if (!derive_simple_privkey(&base_secret, &base_point, &per_commitment_point, &privkey)) abort(); @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) if (!derive_revocation_key(&base_point, &per_commitment_point, &pubkey)) abort(); printf("revocationkey: 0x%s\n", - type_to_string(tmpctx, struct pubkey, &pubkey)); + fmt_pubkey(tmpctx, &pubkey)); if (!derive_revocation_privkey(&base_secret, &per_commitment_secret, &base_point, &per_commitment_point, &privkey)) diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c index 96b94489a611..eaa4afb6996a 100644 --- a/common/test/run-route_blinding_test.c +++ b/common/test/run-route_blinding_test.c @@ -18,6 +18,9 @@ #include /* AUTOGENERATED MOCKS START */ +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) diff --git a/common/wire_error.c b/common/wire_error.c index bb9c6c5b98cf..fc38abf0628f 100644 --- a/common/wire_error.c +++ b/common/wire_error.c @@ -121,7 +121,7 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg, tag, channel_id_is_all(channel_id) ? "": " channel ", channel_id_is_all(channel_id) ? "" - : type_to_string(tmpctx, struct channel_id, channel_id), + : fmt_channel_id(tmpctx, channel_id), (int)tal_count(data), (char *)data); } diff --git a/connectd/connectd.c b/connectd/connectd.c index f3641ef023ac..a169b2b7b2c8 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -491,8 +491,7 @@ static struct io_plan *websocket_connection_in(struct io_conn *conn, return io_close(conn); status_debug("Websocket connection in from %s", - type_to_string(tmpctx, struct wireaddr_internal, - &conn_in_arg.addr)); + fmt_wireaddr_internal(tmpctx, &conn_in_arg.addr)); if (socketpair(AF_LOCAL, SOCK_STREAM, 0, childmsg) != 0) goto fail; @@ -598,8 +597,7 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect) /* This shouldn't happen: lightningd should not give invalid ids! */ if (!pubkey_from_node_id(&outkey, &connect->id)) { status_broken("Connection out to invalid id %s", - type_to_string(tmpctx, struct node_id, - &connect->id)); + fmt_node_id(tmpctx, &connect->id)); return io_close(conn); } @@ -680,8 +678,8 @@ static void destroy_io_conn(struct io_conn *conn, struct connecting *connect) add_errors_to_error_list(connect, tal_fmt(tmpctx, "%s: %s: %s", - type_to_string(tmpctx, struct wireaddr_internal, - &connect->addrs[connect->addrnum]), + fmt_wireaddr_internal(tmpctx, + &connect->addrs[connect->addrnum]), connect->connstate, errstr)); connect->addrnum++; connect->conn = NULL; @@ -834,9 +832,7 @@ static void try_connect_one_addr(struct connecting *connect) if (!use_dns) { /* ignore DNS when we can't use it */ tal_append_fmt(&connect->errors, "%s: dns disabled. ", - type_to_string(tmpctx, - struct wireaddr_internal, - addr)); + fmt_wireaddr_internal(tmpctx, addr)); goto next; } /* Resolve with getaddrinfo */ @@ -852,9 +848,7 @@ static void try_connect_one_addr(struct connecting *connect) if (gai_err != 0) { tal_append_fmt(&connect->errors, "%s: getaddrinfo error '%s'. ", - type_to_string(tmpctx, - struct wireaddr_internal, - addr), + fmt_wireaddr_internal(tmpctx, addr), gai_strerror(gai_err)); goto next; } @@ -890,9 +884,7 @@ static void try_connect_one_addr(struct connecting *connect) if (!connect->daemon->proxyaddr) { tal_append_fmt(&connect->errors, "%s: need a proxy. ", - type_to_string(tmpctx, - struct wireaddr_internal, - addr)); + fmt_wireaddr_internal(tmpctx, addr)); goto next; } af = connect->daemon->proxyaddr->ai_family; @@ -901,8 +893,7 @@ static void try_connect_one_addr(struct connecting *connect) if (af == -1) { tal_append_fmt(&connect->errors, "%s: not supported. ", - type_to_string(tmpctx, struct wireaddr_internal, - addr)); + fmt_wireaddr_internal(tmpctx, addr)); goto next; } @@ -910,8 +901,7 @@ static void try_connect_one_addr(struct connecting *connect) if (fd < 0) { tal_append_fmt(&connect->errors, "%s: opening %i socket gave %s. ", - type_to_string(tmpctx, struct wireaddr_internal, - addr), + fmt_wireaddr_internal(tmpctx, addr), af, strerror(errno)); goto next; } @@ -993,9 +983,7 @@ static struct listen_fd *make_listen_fd(const tal_t *ctx, const char *es = strerror(errno); *errstr = tal_fmt(ctx, "Failed to create socket for %s%s: %s", is_websocket ? "websocket " : "", - type_to_string(tmpctx, - struct wireaddr_internal, - wi), + fmt_wireaddr_internal(tmpctx, wi), es); status_debug("Failed to create %u socket: %s", domain, es); return NULL; @@ -1010,9 +998,7 @@ static struct listen_fd *make_listen_fd(const tal_t *ctx, const char *es = strerror(errno); *errstr = tal_fmt(ctx, "Failed to bind socket for %s%s: %s", is_websocket ? "websocket " : "", - type_to_string(tmpctx, - struct wireaddr_internal, - wi), + fmt_wireaddr_internal(tmpctx, wi), es); status_debug("Failed to bind %u socket: %s", domain, es); goto fail; @@ -1021,7 +1007,7 @@ static struct listen_fd *make_listen_fd(const tal_t *ctx, *errstr = NULL; status_debug("Created %slistener on %s", is_websocket ? "websocket ": "", - type_to_string(tmpctx, struct wireaddr_internal, wi)); + fmt_wireaddr_internal(tmpctx, wi)); return listen_fd_new(ctx, wi, fd, listen_mayfail, is_websocket); fail: @@ -1431,8 +1417,7 @@ static void connect_init(struct daemon *daemon, const u8 *msg) if (!pubkey_from_node_id(&daemon->mykey, &daemon->id)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Invalid id for me %s", - type_to_string(tmpctx, struct node_id, - &daemon->id)); + fmt_node_id(tmpctx, &daemon->id)); /* Resolve Tor proxy address if any: we need an addrinfo to connect() * to. */ @@ -1526,9 +1511,8 @@ static void connect_activate(struct daemon *daemon, const u8 *msg) } errmsg = tal_fmt(tmpctx, "Failed to listen on socket %s: %s", - type_to_string(tmpctx, - struct wireaddr_internal, - &daemon->listen_fds[i]->wi), + fmt_wireaddr_internal(tmpctx, + &daemon->listen_fds[i]->wi), strerror(errno)); break; } @@ -1604,8 +1588,8 @@ static void add_seed_addrs(struct wireaddr_internal **addrs, a.u.wireaddr.is_websocket = false; a.u.wireaddr.wireaddr = new_addrs[j]; status_peer_debug(id, "Resolved %s to %s", hostnames[i], - type_to_string(tmpctx, struct wireaddr, - &a.u.wireaddr.wireaddr)); + fmt_wireaddr(tmpctx, + &a.u.wireaddr.wireaddr)); tal_arr_expand(addrs, a); } /* Other seeds will likely have the same information. */ diff --git a/connectd/handshake.c b/connectd/handshake.c index 7af730816994..ed92da71e11a 100644 --- a/connectd/handshake.c +++ b/connectd/handshake.c @@ -548,7 +548,7 @@ static struct io_plan *act_two_initiator2(struct io_conn *conn, h->act2.pubkey, sizeof(h->act2.pubkey)) != 1) return handshake_failed(conn, h); - SUPERVERBOSE("# re=0x%s", type_to_string(tmpctx, struct pubkey, &h->re)); + SUPERVERBOSE("# re=0x%s", fmt_pubkey(tmpctx, &h->re)); /* BOLT #8: * @@ -634,7 +634,7 @@ static struct io_plan *act_one_initiator(struct io_conn *conn, SUPERVERBOSE("e.priv: 0x%s", tal_hexstr(tmpctx, &h->e.priv, sizeof(h->e.priv))); SUPERVERBOSE("e.pub: 0x%s", - type_to_string(tmpctx, struct pubkey, &h->e.pub)); + fmt_pubkey(tmpctx, &h->e.pub)); /* BOLT #8: * @@ -811,7 +811,7 @@ static struct io_plan *act_two_responder(struct io_conn *conn, */ h->e = generate_key(); SUPERVERBOSE("# e.pub=0x%s e.priv=0x%s", - type_to_string(tmpctx, struct pubkey, &h->e.pub), + fmt_pubkey(tmpctx, &h->e.pub), tal_hexstr(tmpctx, &h->e.priv, sizeof(h->e.priv))); /* BOLT #8: @@ -900,7 +900,7 @@ static struct io_plan *act_one_responder2(struct io_conn *conn, h->act1.pubkey, sizeof(h->act1.pubkey)) != 1) return handshake_failed(conn, h); - SUPERVERBOSE("# re=0x%s", type_to_string(tmpctx, struct pubkey, &h->re)); + SUPERVERBOSE("# re=0x%s", fmt_pubkey(tmpctx, &h->re)); /* BOLT #8: * diff --git a/connectd/onion_message.c b/connectd/onion_message.c index 85c7c44b959a..c71129f472f6 100644 --- a/connectd/onion_message.c +++ b/connectd/onion_message.c @@ -90,9 +90,7 @@ void handle_onion_message(struct daemon *daemon, if (!next_peer) { status_peer_debug(&peer->id, "onion msg: unknown next peer %s", - type_to_string(tmpctx, - struct pubkey, - &next_node)); + fmt_pubkey(tmpctx, &next_node)); return; } inject_peer_msg(next_peer, take(next_onion_msg)); diff --git a/devtools/bolt11-cli.c b/devtools/bolt11-cli.c index 917984b3f85b..76aa0f8ded12 100644 --- a/devtools/bolt11-cli.c +++ b/devtools/bolt11-cli.c @@ -92,14 +92,14 @@ int main(int argc, char *argv[]) printf("expiry: %"PRIu64" (%s)\n", b11->expiry, fmt_time(ctx, b11->timestamp + b11->expiry)); printf("payee: %s\n", - type_to_string(ctx, struct node_id, &b11->receiver_id)); + fmt_node_id(ctx, &b11->receiver_id)); printf("payment_hash: %s\n", tal_hexstr(ctx, &b11->payment_hash, sizeof(b11->payment_hash))); printf("min_final_cltv_expiry: %u\n", b11->min_final_cltv_expiry); if (b11->msat) { printf("msatoshi: %"PRIu64"\n", b11->msat->millisatoshis); /* Raw: raw int for backwards compat */ printf("amount_msat: %s\n", - type_to_string(tmpctx, struct amount_msat, b11->msat)); + fmt_amount_msat(tmpctx, *b11->msat)); } if (b11->description) printf("description: '%s'\n", b11->description); @@ -153,10 +153,10 @@ int main(int argc, char *argv[]) printf("route: (node/chanid/fee/expirydelta) "); for (size_t n = 0; n < tal_count(b11->routes[i]); n++) { printf(" %s/%s/%u/%u/%u", - type_to_string(ctx, struct node_id, - &b11->routes[i][n].pubkey), - type_to_string(ctx, struct short_channel_id, - &b11->routes[i][n].short_channel_id), + fmt_node_id(ctx, + &b11->routes[i][n].pubkey), + fmt_short_channel_id(ctx, + b11->routes[i][n].short_channel_id), b11->routes[i][n].fee_base_msat, b11->routes[i][n].fee_proportional_millionths, b11->routes[i][n].cltv_expiry_delta); @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) } printf("signature: %s\n", - type_to_string(ctx, secp256k1_ecdsa_signature, &b11->sig)); + fmt_secp256k1_ecdsa_signature(ctx, &b11->sig)); tal_free(ctx); common_shutdown(); return NO_ERROR; diff --git a/devtools/bolt12-cli.c b/devtools/bolt12-cli.c index 0a33e229d140..145e678b8585 100644 --- a/devtools/bolt12-cli.c +++ b/devtools/bolt12-cli.c @@ -70,7 +70,7 @@ static void print_offer_chains(const struct bitcoin_blkid *chains) { printf("offer_chains:"); for (size_t i = 0; i < tal_count(chains); i++) { - printf(" %s", type_to_string(tmpctx, struct bitcoin_blkid, &chains[i])); + printf(" %s", fmt_bitcoin_blkid(tmpctx, &chains[i])); } printf("\n"); } @@ -84,7 +84,7 @@ static void print_hex(const char *fieldname, const u8 *bin) static void print_invreq_chain(const struct bitcoin_blkid *chain) { printf("invreq_chain: %s\n", - type_to_string(tmpctx, struct bitcoin_blkid, chain)); + fmt_bitcoin_blkid(tmpctx, chain)); } static bool print_offer_amount(const struct bitcoin_blkid *chains, @@ -117,9 +117,8 @@ static bool print_offer_amount(const struct bitcoin_blkid *chains, ch = chainparams_by_chainhash(&chains[0]); if (!ch) { currency = tal_fmt(tmpctx, "UNKNOWN CHAINHASH %s", - type_to_string(tmpctx, - struct bitcoin_blkid, - &chains[0])); + fmt_bitcoin_blkid(tmpctx, + &chains[0])); ok = false; } else currency = ch->lightning_hrp; @@ -165,7 +164,7 @@ static bool print_utf8(const char *fieldname, const char *description) static void print_node_id(const char *fieldname, const struct pubkey *node_id) { printf("%s: %s\n", - fieldname, type_to_string(tmpctx, struct pubkey, node_id)); + fieldname, fmt_pubkey(tmpctx, node_id)); } static void print_u64(const char *fieldname, u64 max) @@ -271,14 +270,14 @@ static bool print_blindedpaths(const char *fieldname, printf("%s %zu/%zu: blinding %s", fieldname, i, tal_count(paths), - type_to_string(tmpctx, struct pubkey, + fmt_pubkey(tmpctx, &paths[i]->blinding)); printf("%s %zu/%zu: path ", fieldname, i, tal_count(paths)); for (size_t j = 0; j < tal_count(p); j++) { printf(" %s:%s", - type_to_string(tmpctx, struct pubkey, + fmt_pubkey(tmpctx, &p[j]->blinded_node_id), tal_hex(tmpctx, p[j]->encrypted_recipient_data)); if (blindedpay) { @@ -322,7 +321,7 @@ static bool print_signature(const char *messagename, } printf("%s: %s\n", fieldname, - type_to_string(tmpctx, struct bip340sig, sig)); + fmt_bip340sig(tmpctx, sig)); return true; } @@ -353,7 +352,7 @@ static bool print_recurrence_counter_with_base(const u32 *recurrence_counter, static void print_hash(const char *fieldname, const struct sha256 *hash) { printf("%s: %s\n", - fieldname, type_to_string(tmpctx, struct sha256, hash)); + fieldname, fmt_sha256(tmpctx, hash)); } static void print_relative_expiry(u64 *created_at, u32 *relative) diff --git a/devtools/dump-gossipstore.c b/devtools/dump-gossipstore.c index e096d49c7dde..f9129684155b 100644 --- a/devtools/dump-gossipstore.c +++ b/devtools/dump-gossipstore.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) if (fromwire_gossip_store_channel_amount(msg, &sat)) { printf("channel_amount: %s\n", - type_to_string(tmpctx, struct amount_sat, &sat)); + fmt_amount_sat(tmpctx, sat)); } else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) { printf("t=%u channel_announcement: %s\n", be32_to_cpu(hdr.timestamp), @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) } else if (fromwire_gossip_store_private_channel_obs(msg, msg, &sat, &inner)) { printf("private channel_announcement: %s %s\n", - type_to_string(tmpctx, struct amount_sat, &sat), + fmt_amount_sat(tmpctx, sat), tal_hex(msg, inner)); } else if (fromwire_gossip_store_private_update_obs(msg, msg, &inner)) { @@ -120,12 +120,10 @@ int main(int argc, char *argv[]) tal_hex(msg, inner)); } else if (fromwire_gossip_store_delete_chan(msg, &scid)) { printf("delete channel: %s\n", - type_to_string(tmpctx, struct short_channel_id, - &scid)); + fmt_short_channel_id(tmpctx, scid)); } else if (fromwire_gossip_store_chan_dying(msg, &scid, &blockheight)) { printf("dying channel: %s (deadline %u)\n", - type_to_string(tmpctx, struct short_channel_id, - &scid), + fmt_short_channel_id(tmpctx, scid), blockheight); } else { warnx("Unknown message %u", diff --git a/devtools/mkclose.c b/devtools/mkclose.c index 71c1a1a9d7dc..b8796ca782ad 100644 --- a/devtools/mkclose.c +++ b/devtools/mkclose.c @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) if (!amount_msat_sub_sat(&local_msat, local_msat, fee)) errx(1, "Can't afford fee %s", - type_to_string(NULL, struct amount_sat, &fee)); + fmt_amount_sat(NULL, fee)); if (!amount_sat_sub_msat(&remote_msat, funding_amount, local_msat)) errx(1, "Can't afford local_msat"); diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 1d54f8caba0f..e4b1db6e9e06 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -100,29 +100,29 @@ static void print_basepoints(const char *desc, printf("## %s\n", desc); printf("# funding_privkey=%s\n", - type_to_string(NULL, struct secret, &secrets->funding_privkey.secret)); + fmt_secret(NULL, &secrets->funding_privkey.secret)); printf("funding_pubkey=%s\n", - type_to_string(NULL, struct pubkey, fundingkey)); + fmt_pubkey(NULL, fundingkey)); printf("# revocation_basepoint_secret=%s\n", - type_to_string(NULL, struct secret, + fmt_secret(NULL, &secrets->revocation_basepoint_secret)); printf("revocation_basepoint=%s\n", - type_to_string(NULL, struct pubkey, &basepoints->revocation)); + fmt_pubkey(NULL, &basepoints->revocation)); printf("# payment_basepoint_secret=%s\n", - type_to_string(NULL, struct secret, + fmt_secret(NULL, &secrets->payment_basepoint_secret)); printf("payment_basepoint=%s\n", - type_to_string(NULL, struct pubkey, &basepoints->payment)); + fmt_pubkey(NULL, &basepoints->payment)); printf("# delayed_payment_basepoint_secret=%s\n", - type_to_string(NULL, struct secret, + fmt_secret(NULL, &secrets->delayed_payment_basepoint_secret)); printf("delayed_payment_basepoint=%s\n", - type_to_string(NULL, struct pubkey, &basepoints->delayed_payment)); + fmt_pubkey(NULL, &basepoints->delayed_payment)); printf("# htlc_basepoint_secret=%s\n", - type_to_string(NULL, struct secret, + fmt_secret(NULL, &secrets->htlc_basepoint_secret)); printf("htlc_basepoint=%s\n", - type_to_string(NULL, struct pubkey, &basepoints->htlc)); + fmt_pubkey(NULL, &basepoints->htlc)); if (!per_commit_secret(shaseed, &per_commitment_secret, commitnum)) errx(1, "Bad deriving %s per_commitment_secret #%"PRIu64, desc, commitnum); @@ -130,13 +130,13 @@ static void print_basepoints(const char *desc, errx(1, "Bad deriving %s per_commitment_point #%"PRIu64, desc, commitnum); printf("# shachain seed=%s\n", - type_to_string(NULL, struct sha256, shaseed)); + fmt_sha256(NULL, shaseed)); printf("# per_commitment_secret %"PRIu64"=%s\n", commitnum, - type_to_string(NULL, struct secret, &per_commitment_secret)); + fmt_secret(NULL, &per_commitment_secret)); printf("per_commitment_point %"PRIu64"=%s\n\n", commitnum, - type_to_string(NULL, struct pubkey, &per_commitment_point)); + fmt_pubkey(NULL, &per_commitment_point)); } static int parse_config(char *argv[], @@ -196,9 +196,9 @@ static int parse_htlc(char *argv[], struct existing_htlc ***htlcs) printf("# HTLC %"PRIu64": %s amount=%s preimage=%s payment_hash=%s cltv=%u\n", exist->id, argv[0], - type_to_string(tmpctx, struct amount_msat, &exist->amount), - type_to_string(tmpctx, struct preimage, exist->payment_preimage), - type_to_string(tmpctx, struct sha256, &exist->payment_hash), + fmt_amount_msat(tmpctx, exist->amount), + fmt_preimage(tmpctx, exist->payment_preimage), + fmt_sha256(tmpctx, &exist->payment_hash), exist->cltv_expiry); tal_arr_expand(htlcs, exist); @@ -230,7 +230,7 @@ static char *sig_notation(const struct sha256_double *hash, const struct bitcoin_signature *sig) { const char *pstr = tal_hexstr(NULL, privkey->secret.data, sizeof(privkey->secret.data)); - const char *hstr = type_to_string(NULL, struct sha256_double, hash); + const char *hstr = fmt_sha256_double(NULL, hash); if (verbose) return tal_fmt(NULL, @@ -430,9 +430,9 @@ int main(int argc, char *argv[]) printf("## local_commitment\n" "# input amount %s, funding_wscript %s, pubkey %s\n", - type_to_string(NULL, struct amount_sat, &funding_amount), + fmt_amount_sat(NULL, funding_amount), tal_hex(NULL, funding_wscript), - type_to_string(NULL, struct pubkey, &funding_localkey)); + fmt_pubkey(NULL, &funding_localkey)); printf("# unsigned local commitment tx: %s\n", tal_hex(NULL, linearize_tx(NULL, local_txs[0]))); @@ -541,9 +541,9 @@ int main(int argc, char *argv[]) printf("## remote_commitment\n" "# input amount %s, funding_wscript %s, key %s\n", - type_to_string(NULL, struct amount_sat, &funding_amount), + fmt_amount_sat(NULL, funding_amount), tal_hex(NULL, funding_wscript), - type_to_string(NULL, struct pubkey, &funding_remotekey)); + fmt_pubkey(NULL, &funding_remotekey)); printf("# unsigned remote commitment tx: %s\n", tal_hex(NULL, linearize_tx(NULL, remote_txs[0]))); diff --git a/devtools/mkfunding.c b/devtools/mkfunding.c index d31ddb4ebe25..f35e709530fd 100644 --- a/devtools/mkfunding.c +++ b/devtools/mkfunding.c @@ -141,8 +141,8 @@ int main(int argc, char *argv[]) fee = amount_tx_fee(feerate_per_kw, weight); if (!amount_sat_sub(&funding_amount, input.amount, fee)) errx(1, "Input %s can't afford fee %s", - type_to_string(NULL, struct amount_sat, &input.amount), - type_to_string(NULL, struct amount_sat, &fee)); + fmt_amount_sat(NULL, input.amount), + fmt_amount_sat(NULL, fee)); /* Find the P2WPKH script from input pubkey */ input.scriptPubkey = scriptpubkey_p2wpkh(NULL, &inputkey); @@ -165,11 +165,11 @@ int main(int argc, char *argv[]) printf("\t%s\n", tal_hex(NULL, witnesses[i])); printf("# ]\n"); printf("# funding amount: %s\n", - type_to_string(NULL, struct amount_sat, &funding_amount)); + fmt_amount_sat(NULL, funding_amount)); bitcoin_txid(tx, &txid); printf("# funding txid: %s\n", - type_to_string(NULL, struct bitcoin_txid, &txid)); + fmt_bitcoin_txid(NULL, &txid)); printf("tx: %s\n", tal_hex(NULL, linearize_tx(NULL, tx))); common_shutdown(); diff --git a/devtools/mkgossip.c b/devtools/mkgossip.c index 0c1eef3a910f..36dbf8a01ae1 100644 --- a/devtools/mkgossip.c +++ b/devtools/mkgossip.c @@ -78,8 +78,7 @@ static char *sig_notation(const struct privkey *privkey, { const char *pstr = tal_hexstr(NULL, privkey->secret.data, sizeof(privkey->secret.data)); - const char *hstr = - type_to_string(NULL, struct sha256_double, hash); + const char *hstr = fmt_sha256_double(NULL, hash); if (verbose) return tal_fmt(NULL, diff --git a/devtools/print_wire.c b/devtools/print_wire.c index 36bd780f7a95..a7697d272072 100644 --- a/devtools/print_wire.c +++ b/devtools/print_wire.c @@ -326,7 +326,7 @@ bool printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen, return false; } -#define PRINTWIRE_TYPE_TO_STRING(T, N) \ +#define PRINTWIRE_TYPE_TO_STRING(T, N, ADDR) \ bool printwire_##N(const char *fieldname, const u8 **cursor, \ size_t *plen) \ { \ @@ -336,7 +336,7 @@ bool printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen, printf("**TRUNCATED " stringify(N) "\n"); \ return false; \ } \ - const char *s = type_to_string(NULL, T, &v); \ + const char *s = fmt_##N(NULL, ADDR v); \ printf("%s\n", s); \ tal_free(s); \ return true; \ @@ -351,14 +351,16 @@ bool printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen, printf("**TRUNCATED " stringify(N) "\n"); \ return false; \ } \ - const char *s = type_to_string(NULL, struct N, &v); \ + const char *s = fmt_##N(NULL, v); \ printf("%s\n", s); \ tal_free(s); \ return true; \ } #define PRINTWIRE_STRUCT_TYPE_TO_STRING(T) \ - PRINTWIRE_TYPE_TO_STRING(struct T, T) + PRINTWIRE_TYPE_TO_STRING(struct T, T, &) +#define PRINTWIRE_STRUCT_TYPE_TO_STRING_NOADDR_FMT(T) \ + PRINTWIRE_TYPE_TO_STRING(struct T, T, ) PRINTWIRE_STRUCT_TYPE_TO_STRING(bip340sig) PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_blkid) @@ -369,7 +371,7 @@ PRINTWIRE_STRUCT_TYPE_TO_STRING(preimage) PRINTWIRE_STRUCT_TYPE_TO_STRING(pubkey) PRINTWIRE_STRUCT_TYPE_TO_STRING(sha256) PRINTWIRE_STRUCT_TYPE_TO_STRING(secret) -PRINTWIRE_STRUCT_TYPE_TO_STRING(short_channel_id) +PRINTWIRE_STRUCT_TYPE_TO_STRING_NOADDR_FMT(short_channel_id) PRINTWIRE_ASSIGNABLE_STRUCT_TO_STRING(amount_sat) PRINTWIRE_ASSIGNABLE_STRUCT_TO_STRING(amount_msat) -PRINTWIRE_TYPE_TO_STRING(secp256k1_ecdsa_signature, secp256k1_ecdsa_signature) +PRINTWIRE_TYPE_TO_STRING(secp256k1_ecdsa_signature, secp256k1_ecdsa_signature, &) diff --git a/devtools/route.c b/devtools/route.c index 30a87a26796a..88e6a8c0ec4f 100644 --- a/devtools/route.c +++ b/devtools/route.c @@ -57,7 +57,7 @@ static struct route_hop *least_cost(struct gossmap *map, if (!amount_msat_sub(&fee, path[0].amount, sent)) abort(); printf("# path fee %s\n", - type_to_string(tmpctx, struct amount_msat, &fee)); + fmt_amount_msat(tmpctx, fee)); tal_free(dij); return path; } @@ -110,8 +110,8 @@ int main(int argc, char *argv[]) gossmap_node_get_id(map, n, &srcid); printf("# %s->%s\n", - type_to_string(tmpctx, struct node_id, &srcid), - type_to_string(tmpctx, struct node_id, &dstid)); + fmt_node_id(tmpctx, &srcid), + fmt_node_id(tmpctx, &dstid)); tal_free(least_cost(map, n, dst)); } } else { @@ -128,11 +128,9 @@ int main(int argc, char *argv[]) exit(1); for (size_t i = 0; i < tal_count(path); i++) { printf("%s->%s via %s\n", - type_to_string(tmpctx, struct node_id, &srcid), - type_to_string(tmpctx, struct node_id, - &path[i].node_id), - type_to_string(tmpctx, struct short_channel_id, - &path[i].scid)); + fmt_node_id(tmpctx, &srcid), + fmt_node_id(tmpctx, &path[i].node_id), + fmt_short_channel_id(tmpctx, path[i].scid)); srcid = path[i].node_id; } } diff --git a/devtools/topology.c b/devtools/topology.c index 5fb3d7d7e325..e1f73f0b5d8b 100644 --- a/devtools/topology.c +++ b/devtools/topology.c @@ -145,15 +145,6 @@ static size_t count_possible_destinations(const struct gossmap *map, n = gossmap_next_node(map, n)) { if (dijkstra_distance(dij, gossmap_node_idx(map, n)) <= distance_budget) num++; -#if 0 - else - printf("Can't reach %s (%u) if we exclude %s\n", - type_to_string(tmpctx, struct node_id, - gossmap_node_get_id(map, n)), - dijkstra_distance(dij, gossmap_node_idx(map, n)), - type_to_string(tmpctx, struct node_id, - gossmap_node_get_id(map, exclude))); -#endif } /* Now double-check with flood-fill. */ @@ -182,7 +173,7 @@ static bool measure_least_cost(struct gossmap *map, gossmap_node_get_id(map, src, &srcid); printf("# src %s (%u channels)\n", - type_to_string(tmpctx, struct node_id, &srcid), + fmt_node_id(tmpctx, &srcid), src->num_chans); tstart = time_mono(); @@ -212,7 +203,7 @@ static bool measure_least_cost(struct gossmap *map, if (!amount_msat_sub(&fee, path[0].amount, sent)) abort(); printf("# path fee %s\n", - type_to_string(tmpctx, struct amount_msat, &fee)); + fmt_amount_msat(tmpctx, fee)); /* Count possible sources */ for (size_t i = 0; i < tal_count(path); i++) { diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 778e48cd696e..a248298d57d3 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -119,7 +119,7 @@ static void connectd_new_peer(struct daemon *daemon, const u8 *msg) if (find_peer(daemon, &peer->id)) { status_broken("Peer %s already here?", - type_to_string(tmpctx, struct node_id, &peer->id)); + fmt_node_id(tmpctx, &peer->id)); tal_free(find_peer(daemon, &peer->id)); } @@ -159,7 +159,7 @@ static void connectd_peer_gone(struct daemon *daemon, const u8 *msg) peer = find_peer(daemon, &id); if (!peer) status_broken("Peer %s already gone?", - type_to_string(tmpctx, struct node_id, &id)); + fmt_node_id(tmpctx, &id)); tal_free(peer); } @@ -201,7 +201,7 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg) if (!peer) { status_broken("connectd sent gossip msg %s from unknown peer %s", peer_wire_name(fromwire_peektype(msg)), - type_to_string(tmpctx, struct node_id, &source)); + fmt_node_id(tmpctx, &source)); return; } @@ -284,7 +284,7 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg) status_failed(STATUS_FAIL_INTERNAL_ERROR, "connectd sent unexpected gossip msg %s for peer %s", peer_wire_name(fromwire_peektype(msg)), - type_to_string(tmpctx, struct node_id, &peer->id)); + fmt_node_id(tmpctx, &peer->id)); handled_msg_errmsg: if (errmsg) diff --git a/gossipd/gossmap_manage.c b/gossipd/gossmap_manage.c index 06c972ce96bf..3ebc35697702 100644 --- a/gossipd/gossmap_manage.c +++ b/gossipd/gossmap_manage.c @@ -379,14 +379,12 @@ static void prune_network(struct gossmap_manage *gm) || gossmap_nth_node(gossmap, chan, 1) == me) { int local = (gossmap_nth_node(gossmap, chan, 1) == me); status_unusual("Pruning local channel %s from gossip_store: local channel_update time %u, remote %u", - type_to_string(tmpctx, struct short_channel_id, - &scid), + fmt_short_channel_id(tmpctx, scid), timestamp[local], timestamp[!local]); } status_debug("Pruning channel %s from network view (ages %u and %u)", - type_to_string(tmpctx, struct short_channel_id, - &scid), + fmt_short_channel_id(tmpctx, scid), timestamp[0], timestamp[1]); remove_channel(gm, gossmap, chan, scid); @@ -418,7 +416,7 @@ static void report_bad_update(struct gossmap *map, struct gossmap_manage *gm) { status_debug("Update for %s has silly values, disabling (cltv=%u, fee=%u+%u)", - type_to_string(tmpctx, struct short_channel_id_dir, scidd), + fmt_short_channel_id_dir(tmpctx, scidd), cltv_expiry_delta, fee_base_msat, fee_proportional_millionths); } @@ -780,8 +778,7 @@ static const char *process_channel_update(const tal_t *ctx, status_peer_debug(source_peer, "Received channel_update for channel %s/%d now %s", - type_to_string(tmpctx, struct short_channel_id, - &scid), + fmt_short_channel_id(tmpctx, scid), dir, channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE"); return NULL; @@ -918,7 +915,7 @@ static void process_node_announcement(struct gossmap_manage *gm, status_peer_debug(source_peer, "Received node_announcement for node %s", - type_to_string(tmpctx, struct node_id, node_id)); + fmt_node_id(tmpctx, node_id)); } const char *gossmap_manage_node_announcement(const tal_t *ctx, @@ -1136,13 +1133,13 @@ static void kill_spent_channel(struct gossmap_manage *gm, chan = gossmap_find_chan(gossmap, &scid); if (!chan) { status_broken("Dying channel %s already deleted?", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); return; } status_debug("Deleting channel %s due to the funding outpoint being " "spent", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); remove_channel(gm, gossmap, chan, scid); } @@ -1227,7 +1224,7 @@ void gossmap_manage_channel_spent(struct gossmap_manage *gm, /* Remember locally so we can kill it in 12 blocks */ status_debug("channel %s closing soon due" " to the funding outpoint being spent", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); /* Save to gossip_store in case we restart */ msg = towire_gossip_store_chan_dying(tmpctx, &cd.scid, cd.deadline); diff --git a/gossipd/queries.c b/gossipd/queries.c index 4f11cc53d789..391047a46893 100644 --- a/gossipd/queries.c +++ b/gossipd/queries.c @@ -205,7 +205,7 @@ const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg) if (!bitcoin_blkid_eq(&chainparams->genesis_blockhash, &chain)) { status_peer_debug(&peer->id, "sent query_short_channel_ids chainhash %s", - type_to_string(tmpctx, struct bitcoin_blkid, &chain)); + fmt_bitcoin_blkid(tmpctx, &chain)); return towire_reply_short_channel_ids_end(peer, &chain, 0); } @@ -633,8 +633,7 @@ const u8 *handle_query_channel_range(struct peer *peer, const u8 *msg) if (!bitcoin_blkid_eq(&chainparams->genesis_blockhash, &chain_hash)) { status_peer_debug(&peer->id, "query_channel_range with chainhash %s", - type_to_string(tmpctx, struct bitcoin_blkid, - &chain_hash)); + fmt_bitcoin_blkid(tmpctx, &chain_hash)); u8 *end = towire_reply_channel_range(NULL, &chain_hash, first_blocknum, number_of_blocks, false, NULL, NULL); queue_peer_msg(peer->daemon, &peer->id, take(end)); diff --git a/gossipd/sigcheck.c b/gossipd/sigcheck.c index 1ca94fdecb65..db503537b484 100644 --- a/gossipd/sigcheck.c +++ b/gossipd/sigcheck.c @@ -37,12 +37,8 @@ const char *sigcheck_channel_update(const tal_t *ctx, return tal_fmt(ctx, "Bad signature for %s hash %s" " on channel_update %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - node_sig), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, node_sig), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, update)); return NULL; } @@ -84,48 +80,36 @@ const char *sigcheck_channel_announcement(const tal_t *ctx, return tal_fmt(ctx, "Bad node_signature_1 %s hash %s" " on channel_announcement %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - node1_sig), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, + node1_sig), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, announcement)); } if (!check_signed_hash_nodeid(&hash, node2_sig, node2_id)) { return tal_fmt(ctx, "Bad node_signature_2 %s hash %s" " on channel_announcement %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - node2_sig), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, + node2_sig), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, announcement)); } if (!check_signed_hash(&hash, bitcoin1_sig, bitcoin1_key)) { return tal_fmt(ctx, "Bad bitcoin_signature_1 %s hash %s" " on channel_announcement %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - bitcoin1_sig), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, + bitcoin1_sig), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, announcement)); } if (!check_signed_hash(&hash, bitcoin2_sig, bitcoin2_key)) { return tal_fmt(ctx, "Bad bitcoin_signature_2 %s hash %s" " on channel_announcement %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - bitcoin2_sig), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, + bitcoin2_sig), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, announcement)); } return NULL; @@ -171,12 +155,9 @@ const char *sigcheck_node_announcement(const tal_t *ctx, return tal_fmt(ctx, "Bad signature for %s hash %s" " on node_announcement %s", - type_to_string(tmpctx, - secp256k1_ecdsa_signature, - signature), - type_to_string(tmpctx, - struct sha256_double, - &hash), + fmt_secp256k1_ecdsa_signature(tmpctx, + signature), + fmt_sha256_double(tmpctx, &hash), tal_hex(tmpctx, node_announcement)); } diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index 41150da75984..9a8dad10c036 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -129,7 +129,7 @@ static struct io_plan *bad_req_fmt(struct io_conn *conn, } /*~ Nobody should give us bad requests; it's a sign something is broken */ - status_broken("%s: %s", type_to_string(tmpctx, struct node_id, &c->id), str); + status_broken("%s: %s", fmt_node_id(tmpctx, &c->id), str); /*~ Note the use of NULL as the ctx arg to towire_hsmstatus_: only * use NULL as the allocation when we're about to immediately free it @@ -192,8 +192,7 @@ static struct client *new_client(const tal_t *ctx, if (!node_id_valid(id)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Invalid node id %s", - type_to_string(tmpctx, struct node_id, - id)); + fmt_node_id(tmpctx, id)); } else { memset(&c->id, 0, sizeof(c->id)); } diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index f3578d99e227..f6fc745cdb21 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -515,7 +515,7 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey, hsm_unilateral_close_privkey(privkey, utxo->close_info); pubkey_from_privkey(privkey, pubkey); hsmd_status_debug("Derived public key %s from unilateral close", - type_to_string(tmpctx, struct pubkey, pubkey)); + fmt_pubkey(tmpctx, pubkey)); } else { /* Simple case: just get derive via HD-derivation */ bitcoin_key(privkey, pubkey, utxo->keyindex); @@ -572,10 +572,8 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR, "Received wally_err attempting to " "sign input %zu with key %s. PSBT: %s", - j, type_to_string(tmpctx, struct pubkey, - &pubkey), - type_to_string(tmpctx, struct wally_psbt, - psbt)); + j, fmt_pubkey(tmpctx, &pubkey), + fmt_wally_psbt(tmpctx, psbt)); } tal_wally_end(psbt); } @@ -630,10 +628,8 @@ static u8 *handle_check_pubkey(struct hsmd_client *c, const u8 *msg_in) "BIP32 derivation index %u differed:" " they got %s, we got %s", index, - type_to_string(tmpctx, struct pubkey, - &their_pubkey), - type_to_string(tmpctx, struct pubkey, - &our_pubkey)); + fmt_pubkey(tmpctx, &their_pubkey), + fmt_pubkey(tmpctx, &our_pubkey)); } return towire_hsmd_check_pubkey_reply(NULL, true); @@ -1624,10 +1620,8 @@ static u8 *handle_sign_anchorspend(struct hsmd_client *c, const u8 *msg_in) hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR, "Received wally_err attempting to " "sign anchor key %s. PSBT: %s", - type_to_string(tmpctx, struct pubkey, - &local_funding_pubkey), - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_pubkey(tmpctx, &local_funding_pubkey), + fmt_wally_psbt(tmpctx, psbt)); } return towire_hsmd_sign_anchorspend_reply(NULL, psbt); diff --git a/lightningd/anchorspend.c b/lightningd/anchorspend.c index 0a0131487443..ffb833215990 100644 --- a/lightningd/anchorspend.c +++ b/lightningd/anchorspend.c @@ -387,7 +387,7 @@ static struct bitcoin_tx *spend_anchor(const tal_t *ctx, if (!psbt_finalize(psbt)) fatal("Non-final PSBT from hsm: %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); /* Update fee so we know for next time */ anch->anchor_spend_fee = fee; @@ -415,12 +415,12 @@ static bool refresh_anchor_spend(struct channel *channel, bitcoin_txid(replace, &txid); log_info(channel->log, "RBF anchor %s commit tx spend %s: fee was %s now %s", anch->commit_side == LOCAL ? "local" : "remote", - type_to_string(tmpctx, struct bitcoin_txid, &txid), + fmt_bitcoin_txid(tmpctx, &txid), fmt_amount_sat(tmpctx, old_fee), fmt_amount_sat(tmpctx, anch->anchor_spend_fee)); log_debug(channel->log, "RBF anchor spend: Old tx %s new %s", - type_to_string(tmpctx, struct bitcoin_tx, *tx), - type_to_string(tmpctx, struct bitcoin_tx, replace)); + fmt_bitcoin_tx(tmpctx, *tx), + fmt_bitcoin_tx(tmpctx, replace)); tal_free(*tx); *tx = replace; } @@ -443,7 +443,7 @@ static void create_and_broadcast_anchor(struct channel *channel, bitcoin_txid(newtx, &txid); log_info(channel->log, "Creating anchor spend for %s commit tx %s: we're paying fee %s", anch->commit_side == LOCAL ? "local" : "remote", - type_to_string(tmpctx, struct bitcoin_txid, &txid), + fmt_bitcoin_txid(tmpctx, &txid), fmt_amount_sat(tmpctx, anch->anchor_spend_fee)); /* Send it! */ diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index d5b121f5b19b..2040582da6c4 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -246,7 +246,7 @@ static void broadcast_done(struct bitcoind *bitcoind, bitcoind->ld->topology->log, "Not adding %s to list of outgoing transactions, already " "present", - type_to_string(tmpctx, struct bitcoin_txid, &otx->txid)); + fmt_bitcoin_txid(tmpctx, &otx->txid)); tal_free(otx); return; } @@ -288,7 +288,7 @@ void broadcast_tx_(const tal_t *ctx, * we have block N-1! */ if (get_block_height(topo) + 1 < otx->minblock) { log_debug(topo->log, "Deferring broadcast of txid %s until block %u", - type_to_string(tmpctx, struct bitcoin_txid, &otx->txid), + fmt_bitcoin_txid(tmpctx, &otx->txid), otx->minblock - 1); /* For continual rebroadcasting, until channel freed. */ @@ -299,7 +299,7 @@ void broadcast_tx_(const tal_t *ctx, } log_debug(topo->log, "Broadcasting txid %s%s%s", - type_to_string(tmpctx, struct bitcoin_txid, &otx->txid), + fmt_bitcoin_txid(tmpctx, &otx->txid), cmd_id ? " for " : "", cmd_id ? cmd_id : ""); wallet_transaction_add(topo->ld->wallet, tx->wtx, 0, 0); @@ -322,12 +322,8 @@ static enum watch_result closeinfo_txid_confirmed(struct lightningd *ld, bitcoin_txid(tx, &txid2); if (!bitcoin_txid_eq(txid, &txid2)) { fatal("Txid for %s is not %s", - type_to_string(tmpctx, - struct bitcoin_tx, - tx), - type_to_string(tmpctx, - struct bitcoin_txid, - txid)); + fmt_bitcoin_tx(tmpctx, tx), + fmt_bitcoin_txid(tmpctx, txid)); } } @@ -910,7 +906,7 @@ static void record_wallet_spend(struct lightningd *ld, utxo = wallet_utxo_get(tmpctx, ld->wallet, outpoint); if (!utxo) { log_broken(ld->log, "No record of utxo %s", - type_to_string(tmpctx, struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, outpoint)); return; } @@ -1015,7 +1011,7 @@ static struct block *new_block(struct chain_topology *topo, bitcoin_block_blkid(blk, &b->blkid); log_debug(topo->log, "Adding block %u: %s", height, - type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); + fmt_bitcoin_blkid(tmpctx, &b->blkid)); assert(!block_map_get(topo->block_map, &b->blkid)); b->next = NULL; b->prev = NULL; @@ -1039,7 +1035,7 @@ static void remove_tip(struct chain_topology *topo) log_debug(topo->log, "Removing stale block %u: %s", topo->tip->height, - type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); + fmt_bitcoin_blkid(tmpctx, &b->blkid)); /* Move tip back one. */ topo->tip = b->prev; @@ -1047,7 +1043,7 @@ static void remove_tip(struct chain_topology *topo) if (!topo->tip) fatal("Initial block %u (%s) reorganized out!", b->height, - type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); + fmt_bitcoin_blkid(tmpctx, &b->blkid)); txs = wallet_transactions_by_height(b, topo->ld->wallet, b->height); n = tal_count(txs); diff --git a/lightningd/channel.c b/lightningd/channel.c index 6b025a4e052a..5c37cbb6c84a 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -361,18 +361,16 @@ struct amount_msat htlc_max_possible_send(const struct channel *channel) channel->channel_info.their_config.channel_reserve)) { log_broken(channel->log, "%s: their reserve %s > funding %s!", __func__, - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats), - type_to_string(tmpctx, struct amount_sat, - &channel->channel_info.their_config.channel_reserve)); + fmt_amount_sat(tmpctx, channel->funding_sats), + fmt_amount_sat(tmpctx, + channel->channel_info.their_config.channel_reserve)); return AMOUNT_MSAT(0); } if (!amount_sat_to_msat(&lower_bound_msat, lower_bound)) { log_broken(channel->log, "%s: impossible size channel %s!", __func__, - type_to_string(tmpctx, struct amount_sat, - &lower_bound)); + fmt_amount_sat(tmpctx, lower_bound)); return AMOUNT_MSAT(0); } diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 413fdedb46a5..1596d2b82fdc 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -113,7 +113,7 @@ static void try_update_blockheight(struct lightningd *ld, return; log_debug(channel->log, "attempting update blockheight %s", - type_to_string(tmpctx, struct channel_id, &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); if (!topology_synced(ld->topology)) { log_debug(channel->log, "chain not synced," @@ -315,12 +315,10 @@ static void handle_splice_abort(struct lightningd *ld, channel_internal_error(channel, "abort outpoint %s does not" " match ours %s", - type_to_string(tmpctx, - struct bitcoin_outpoint, - outpoint), - type_to_string(tmpctx, - struct bitcoin_outpoint, - &inflight->funding->outpoint)); + fmt_bitcoin_outpoint(tmpctx, + outpoint), + fmt_bitcoin_outpoint(tmpctx, + &inflight->funding->outpoint)); wallet_inflight_del(ld->wallet, channel, inflight); tal_free(inflight); @@ -462,9 +460,7 @@ static void handle_splice_lookup_tx(struct lightningd *ld, if (!tx) { channel_internal_error(channel, "channel control unable to find txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); return; } @@ -527,17 +523,16 @@ static void check_utxo_block(struct bitcoind *bitcoind UNUSED, "tx: %s. Unsent tx discarded " "%s.", info->err_msg, - type_to_string(tmpctx, - struct wally_tx, - info->final_tx->wtx))); + fmt_wally_tx(tmpctx, + info->final_tx->wtx))); log_unusual(info->channel->log, "Error broadcasting splice " "tx: %s. Unsent tx discarded " "%s.", info->err_msg, - type_to_string(tmpctx, struct wally_tx, - info->final_tx->wtx)); + fmt_wally_tx(tmpctx, + info->final_tx->wtx)); } else handle_tx_broadcast(info); @@ -580,7 +575,7 @@ static void send_splice_tx(struct channel *channel, log_debug(channel->log, "Broadcasting splice tx %s for channel %s.", tal_hex(tmpctx, tx_bytes), - type_to_string(tmpctx, struct channel_id, &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); struct send_splice_info *info = tal(NULL, struct send_splice_info); @@ -623,9 +618,7 @@ static void handle_splice_confirmed_signed(struct lightningd *ld, if (!inflight) channel_internal_error(channel, "Unable to load inflight for" " splice_confirmed_signed txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); inflight->remote_tx_sigs = true; wallet_inflight_save(ld->wallet, inflight); @@ -673,7 +666,7 @@ static enum watch_result splice_depth_cb(struct lightningd *ld, if (inflight->channel->state != CHANNELD_AWAITING_SPLICE) { log_info(inflight->channel->log, "Splice inflight event but not" " in AWAITING_SPLICE, ending watch of txid %s", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); return DELETE_WATCH; } @@ -684,7 +677,7 @@ static enum watch_result splice_depth_cb(struct lightningd *ld, if (inflight->channel->owner) { log_info(inflight->channel->log, "splice_depth_cb: sending funding depth scid: %s", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); subd_send_msg(inflight->channel->owner, take(towire_channeld_funding_depth( NULL, &scid, @@ -700,8 +693,8 @@ void watch_splice_inflight(struct lightningd *ld, struct channel_inflight *inflight) { log_info(inflight->channel->log, "Watching splice inflight %s", - type_to_string(tmpctx, struct bitcoin_txid, - &inflight->funding->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, + &inflight->funding->outpoint.txid)); watch_txid(inflight, ld->topology, &inflight->funding->outpoint.txid, splice_depth_cb, inflight); @@ -735,9 +728,7 @@ static void handle_splice_sending_sigs(struct lightningd *ld, if (!inflight) channel_internal_error(channel, "Unable to load inflight for" " splice_confirmed_signed txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); /* Signing a splice after it has confirmed is safe and can happen during * reestablish if one node is late seeing blocks */ @@ -798,8 +789,8 @@ bool depthcb_update_scid(struct channel *channel, /* We freaked out if required when original was * removed, so just update now */ log_info(channel->log, "Short channel id changed from %s->%s", - type_to_string(tmpctx, struct short_channel_id, channel->scid), - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, *channel->scid), + fmt_short_channel_id(tmpctx, scid)); *channel->scid = scid; channel_gossip_scid_changed(channel); } @@ -854,8 +845,8 @@ static void handle_add_inflight(struct lightningd *ld, force_sign_first); log_debug(channel->log, "lightningd adding inflight with txid %s", - type_to_string(tmpctx, struct bitcoin_txid, - &inflight->funding->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, + &inflight->funding->outpoint.txid)); wallet_inflight_add(ld->wallet, inflight); @@ -885,17 +876,13 @@ static void handle_update_inflight(struct lightningd *ld, if (!inflight) channel_internal_error(channel, "Unable to load inflight for" " update_inflight txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); if (!!last_tx != !!last_sig) channel_internal_error(channel, "Must set last_tx and last_sig" " together at the same time for" " update_inflight txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); if (last_tx) { tal_free(inflight->last_tx); @@ -909,11 +896,9 @@ static void handle_update_inflight(struct lightningd *ld, if (wally_psbt_combine(inflight->funding_psbt, psbt) != WALLY_OK) { channel_internal_error(channel, "Unable to combine PSBTs: %s, %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, inflight->funding_psbt), - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, psbt)); tal_wally_end(inflight->funding_psbt); return; @@ -936,18 +921,14 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p if (!amount_msat_add(&start_balance, channel->our_msat, channel->push)) fatal("Unable to add push_msat (%s) + our_msat (%s)", - type_to_string(tmpctx, struct amount_msat, - &channel->push), - type_to_string(tmpctx, struct amount_msat, - &channel->our_msat)); + fmt_amount_msat(tmpctx, channel->push), + fmt_amount_msat(tmpctx, channel->our_msat)); } else { if (!amount_msat_sub(&start_balance, channel->our_msat, channel->push)) fatal("Unable to sub our_msat (%s) - push (%s)", - type_to_string(tmpctx, struct amount_msat, - &channel->our_msat), - type_to_string(tmpctx, struct amount_msat, - &channel->push)); + fmt_amount_msat(tmpctx, channel->our_msat), + fmt_amount_msat(tmpctx, channel->push)); } /* If it's not in a block yet, send a proposal */ @@ -1078,9 +1059,7 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg) if(!inflight) channel_internal_error(channel, "Unable to load inflight for" " locked_txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, - &locked_txid)); + fmt_bitcoin_txid(tmpctx, &locked_txid)); wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel, &inflight->funding->outpoint); @@ -1117,8 +1096,7 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg) txw = splice_inflight_txwatch(channel, inflight); if (!txw) log_unusual(channel->log, "Can't unwatch txid %s", - type_to_string(tmpctx, struct bitcoin_txid, - &locked_txid)); + fmt_bitcoin_txid(tmpctx, &locked_txid)); tal_free(txw); } @@ -1777,7 +1755,7 @@ void channeld_tell_depth(struct channel *channel, if (!channel->owner) { log_debug(channel->log, "Funding tx %s confirmed, but peer disconnected", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); return; } @@ -1884,8 +1862,7 @@ void channel_notify_new_block(struct lightningd *ld, "We are fundee and can forget channel without " "loss of funds.", block_height - channel->first_blocknum, - type_to_string(tmpctx, struct bitcoin_txid, - &channel->funding.txid)); + fmt_bitcoin_txid(tmpctx, &channel->funding.txid)); /* FIXME: Send an error packet for this case! */ /* And forget it. */ delete_channel(channel); @@ -1969,8 +1946,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd, "No channels being opened or " "awaiting lock-in for " "peer_id %s", - type_to_string(tmpctx, struct node_id, - &peer->id)); + fmt_node_id(tmpctx, &peer->id)); cc->cid = cancel_channel->cid; if (cancel_channel->opener == REMOTE) @@ -2033,8 +2009,7 @@ static struct command_result *param_channel_for_splice(struct command *cmd, if (!*channel) return command_fail(cmd, SPLICE_UNKNOWN_CHANNEL, "Unknown channel %s", - type_to_string(tmpctx, struct channel_id, - cid)); + fmt_channel_id(tmpctx, cid)); if (!feature_negotiated(cmd->ld->our_features, (*channel)->peer->their_features, diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index 819609b05bb1..9636f3da36ae 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -1022,15 +1022,14 @@ void channel_gossip_set_remote_update(struct lightningd *ld, && !node_id_eq(source, &channel->peer->id)) { log_unusual(ld->log, "Bad gossip order: %s sent us a channel update for a " "channel owned by %s (%s)", - type_to_string(tmpctx, struct node_id, source), - type_to_string(tmpctx, struct node_id, - &channel->peer->id), - type_to_string(tmpctx, struct short_channel_id, &update->scid)); + fmt_node_id(tmpctx, source), + fmt_node_id(tmpctx, &channel->peer->id), + fmt_short_channel_id(tmpctx, update->scid)); return; } log_debug(ld->log, "updating channel %s with inbound settings", - type_to_string(tmpctx, struct short_channel_id, &update->scid)); + fmt_short_channel_id(tmpctx, update->scid)); tal_free(cg->peer_update); cg->peer_update = tal_dup(cg, struct peer_update, update); wallet_channel_save(ld->wallet, channel); diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 2ac534109f43..5c04121882b6 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -193,8 +193,8 @@ static struct amount_sat calc_tx_fee(struct amount_sat sat_in, if (!amount_sat_sub(&fee, fee, amount_asset_to_sat(&amt))) fatal("Tx spends more than input %s? %s", - type_to_string(tmpctx, struct amount_sat, &sat_in), - type_to_string(tmpctx, struct bitcoin_tx, tx)); + fmt_amount_sat(tmpctx, sat_in), + fmt_bitcoin_tx(tmpctx, tx)); } return fee; } @@ -218,8 +218,8 @@ static bool closing_fee_is_acceptable(struct lightningd *ld, log_debug(channel->log, "Their actual closing tx fee is %s" " vs previous %s: weight is %"PRIu64, - type_to_string(tmpctx, struct amount_sat, &fee), - type_to_string(tmpctx, struct amount_sat, &last_fee), + fmt_amount_sat(tmpctx, fee), + fmt_amount_sat(tmpctx, last_fee), weight); if (!channel->ignore_fee_limits && !ld->config.ignore_fee_limits) { @@ -233,7 +233,7 @@ static bool closing_fee_is_acceptable(struct lightningd *ld, if (amount_sat_less(fee, min_fee)) { log_debug(channel->log, "... That's below our min %s" " for weight %"PRIu64" at feerate %u", - type_to_string(tmpctx, struct amount_sat, &min_fee), + fmt_amount_sat(tmpctx, min_fee), weight, min_feerate); return false; } @@ -442,10 +442,8 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd) if (!amount_sat_sub_msat(&their_msat, channel->funding_sats, channel->our_msat)) { log_broken(channel->log, "our_msat overflow funding %s minus %s", - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats), - type_to_string(tmpctx, struct amount_msat, - &channel->our_msat)); + fmt_amount_sat(tmpctx, channel->funding_sats), + fmt_amount_msat(tmpctx, channel->our_msat)); channel_fail_permanent(channel, REASON_LOCAL, "our_msat overflow on closing"); diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c index 937c7154d1ca..b97c939db0c3 100644 --- a/lightningd/coin_mvts.c +++ b/lightningd/coin_mvts.c @@ -145,9 +145,7 @@ void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight) if (report_chan_balance(chan)) { bal = tal(snap, struct account_balance); bal->bip173_name = chainparams->lightning_hrp; - bal->acct_id = type_to_string(bal, - struct channel_id, - &chan->cid); + bal->acct_id = fmt_channel_id(bal, &chan->cid); bal->balance = chan->our_msat; tal_arr_expand(&snap->accts, bal); } diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index d366c6091bf1..68594b3a4c35 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -238,7 +238,7 @@ static struct command_result *json_connect(struct command *cmd, peer = peer_by_id(cmd->ld, &id_addr.id); if (peer && peer->connected == PEER_CONNECTED) { log_debug(cmd->ld->log, "Already connected via %s", - type_to_string(tmpctx, struct wireaddr_internal, + fmt_wireaddr_internal(tmpctx, &peer->addr)); return connect_cmd_succeed(cmd, peer, peer->connected_incoming, @@ -850,7 +850,7 @@ static struct command_result *json_sendcustommsg(struct command *cmd, if (!peer) { return command_fail(cmd, JSONRPC2_INVALID_REQUEST, "No such peer: %s", - type_to_string(cmd, struct node_id, dest)); + fmt_node_id(cmd, dest)); } /* We allow messages from plugins responding to peer_connected hook, diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index f07b0d932730..2c66cb7bed35 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -347,7 +347,7 @@ openchannel2_changed_hook_serialize(struct openchannel2_psbt_payload *payload, json_object_start(stream, "openchannel2_changed"); json_add_psbt(stream, "psbt", payload->psbt); json_add_string(stream, "channel_id", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &payload->channel->cid)); json_add_bool(stream, "require_confirmed_inputs", payload->channel->req_confirmed_ins[REMOTE]); @@ -362,7 +362,7 @@ openchannel2_sign_hook_serialize(struct openchannel2_psbt_payload *payload, json_object_start(stream, "openchannel2_sign"); json_add_psbt(stream, "psbt", payload->psbt); json_add_string(stream, "channel_id", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &payload->channel->cid)); json_object_end(stream); } @@ -625,8 +625,7 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload, if (payload->psbt && !psbt_has_required_fields(payload->psbt)) fatal("Plugin supplied PSBT that's missing" " required fields: %s", - type_to_string(tmpctx, struct wally_psbt, - payload->psbt)); + fmt_wally_psbt(tmpctx, payload->psbt)); if (!hook_extract_amount(dualopend, buffer, toks, "our_funding_msat", &payload->our_funding)) fatal("Plugin failed to supply our_funding_msat field"); @@ -832,7 +831,7 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload, */ if (payload->psbt && !psbt_has_required_fields(payload->psbt)) fatal("Plugin supplied PSBT that's missing required fields. %s", - type_to_string(tmpctx, struct wally_psbt, payload->psbt)); + fmt_wally_psbt(tmpctx, payload->psbt)); if (!hook_extract_amount(dualopend, buffer, toks, "our_funding_msat", @@ -888,7 +887,7 @@ openchannel2_changed_deserialize(struct openchannel2_psbt_payload *payload, */ if (!psbt_has_required_fields(psbt)) fatal("Plugin supplied PSBT that's missing required fields. %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); if (payload->psbt) tal_free(payload->psbt); @@ -939,7 +938,7 @@ openchannel2_signed_deserialize(struct openchannel2_psbt_payload *payload, */ if (!psbt_has_required_fields(psbt)) fatal("Plugin supplied PSBT that's missing required fields. %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); /* NOTE - The psbt_contribs_changed function nulls lots of * fields in place to compare the PSBTs. This removes the @@ -956,10 +955,8 @@ openchannel2_signed_deserialize(struct openchannel2_psbt_payload *payload, if (psbt_contribs_changed(payload->psbt, psbt_clone)) fatal("Plugin must not change psbt input/output set. " "orig: %s. updated: %s", - type_to_string(tmpctx, struct wally_psbt, - payload->psbt), - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, payload->psbt), + fmt_wally_psbt(tmpctx, psbt)); if (payload->psbt) tal_free(payload->psbt); @@ -978,13 +975,13 @@ static void dualopend_tell_depth(struct channel *channel, if (!channel->owner) { log_debug(channel->log, "Funding tx %s confirmed, but peer disconnected", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); return; } log_debug(channel->log, "Funding tx %s confirmed, telling peer", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); if (depth < channel->minimum_depth) { to_go = channel->minimum_depth - depth; } else @@ -1050,8 +1047,8 @@ static enum watch_result opening_depth_cb(struct lightningd *ld, /* We freaked out if required when original was * removed, so just update now */ log_info(inflight->channel->log, "Short channel id changed from %s->%s", - type_to_string(tmpctx, struct short_channel_id, inflight->channel->scid), - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, *inflight->channel->scid), + fmt_short_channel_id(tmpctx, scid)); *inflight->channel->scid = scid; wallet_channel_save(ld->wallet, inflight->channel); } @@ -1090,8 +1087,7 @@ openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS) log_broken(channel->log, "Plugin must return a 'psbt' with signatures " "for their inputs %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, payload->psbt)); msg = towire_dualopend_fail(NULL, "Peer error with PSBT" " signatures."); @@ -1111,10 +1107,9 @@ openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS) if (!bitcoin_txid_eq(&inflight->funding->outpoint.txid, &txid)) { log_broken(channel->log, "PSBT's txid does not match. %s != %s", - type_to_string(tmpctx, struct bitcoin_txid, - &txid), - type_to_string(tmpctx, struct bitcoin_txid, - &inflight->funding->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, &txid), + fmt_bitcoin_txid(tmpctx, + &inflight->funding->outpoint.txid)); msg = towire_dualopend_fail(NULL, "Peer error with PSBT" " signatures."); goto send_msg; @@ -1350,8 +1345,8 @@ wallet_update_channel_commit(struct lightningd *ld, REASON_LOCAL, "Invalid commitment txid." " expected (inflight's) %s, got %s", - type_to_string(tmpctx, struct bitcoin_txid, &inflight_txid), - type_to_string(tmpctx, struct bitcoin_txid, &txid)); + fmt_bitcoin_txid(tmpctx, &inflight_txid), + fmt_bitcoin_txid(tmpctx, &txid)); } return false; } @@ -1694,9 +1689,7 @@ static void check_utxo_block(struct bitcoind *bitcoind UNUSED, "tx: %s. Unsent tx discarded " "%s.", cs->err_msg, - type_to_string(tmpctx, - struct wally_tx, - wtx))); + fmt_wally_tx(tmpctx, wtx))); cs->channel->openchannel_signed_cmd = NULL; } @@ -1705,7 +1698,7 @@ static void check_utxo_block(struct bitcoind *bitcoind UNUSED, "tx: %s. Unsent tx discarded " "%s.", cs->err_msg, - type_to_string(tmpctx, struct wally_tx, wtx)); + fmt_wally_tx(tmpctx, wtx)); } else handle_tx_broadcast(cs); @@ -1724,8 +1717,7 @@ static void sendfunding_done(struct bitcoind *bitcoind UNUSED, log_unusual(channel->log, "No outstanding command for channel %s," " funding sent was success? %d", - type_to_string(tmpctx, struct channel_id, - &channel->cid), + fmt_channel_id(tmpctx, &channel->cid), success); if (success) { @@ -1768,9 +1760,9 @@ static void send_funding_tx(struct channel *channel, wally_txid(wtx, &txid); log_debug(channel->log, "Broadcasting funding tx %s for channel %s. %s", - type_to_string(tmpctx, struct bitcoin_txid, &txid), - type_to_string(tmpctx, struct channel_id, &channel->cid), - type_to_string(tmpctx, struct wally_tx, cs->wtx)); + fmt_bitcoin_txid(tmpctx, &txid), + fmt_channel_id(tmpctx, &channel->cid), + fmt_wally_tx(tmpctx, cs->wtx)); bitcoind_sendrawtx(ld->topology->bitcoind, ld->topology->bitcoind, @@ -1821,8 +1813,7 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend, channel_internal_error(channel, "Unable to extract final tx" " from PSBT %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, inflight->funding_psbt)); return; } @@ -1865,9 +1856,8 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend, " of %dperkw. Failing channel." " Offending PSBT: %s", inflight->funding->feerate, - type_to_string(tmpctx, - struct wally_psbt, - inflight->funding_psbt)); + fmt_wally_psbt(tmpctx, + inflight->funding_psbt)); /* Notify the peer we're failing */ subd_send_msg(dualopend, @@ -2144,11 +2134,9 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend, if (wally_psbt_combine(inflight->funding_psbt, psbt) != WALLY_OK) { channel_internal_error(channel, "Unable to combine PSBTs: %s, %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, inflight->funding_psbt), - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, psbt)); tal_wally_end(inflight->funding_psbt); return; @@ -2170,8 +2158,7 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend, channel_internal_error(channel, "Unable to extract final tx" " from PSBT %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, inflight->funding_psbt)); return; } @@ -2211,9 +2198,8 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend, " of %dperkw. Failing channel." " Offending PSBT: %s", inflight->funding->feerate, - type_to_string(tmpctx, - struct wally_psbt, - inflight->funding_psbt)); + fmt_wally_psbt(tmpctx, + inflight->funding_psbt)); /* Notify the peer we're failing */ subd_send_msg(dualopend, @@ -2245,7 +2231,7 @@ static bool verify_option_will_fund_signature(struct peer *peer, if (!pubkey_from_node_id(&their_pubkey, &peer->id)) { log_broken(peer->ld->log, "Unable to extract pubkey from peer's node id %s", - type_to_string(tmpctx, struct node_id, &peer->id)); + fmt_node_id(tmpctx, &peer->id)); return false; } @@ -2344,11 +2330,9 @@ static void handle_validate_rbf(struct subd *dualopend, errmsg = tal_fmt(tmpctx, "No overlapping input" " present. New: %s, last: %s", - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, candidate_psbt), - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, inflight->funding_psbt)); msg = towire_dualopend_fail(NULL, errmsg); goto send_msg; @@ -2372,12 +2356,8 @@ static void handle_validate_rbf(struct subd *dualopend, if (!amount_sat_greater(candidate_fee, last_fee)) { char *errmsg = tal_fmt(tmpctx, "Proposed funding tx fee (%s)" " less than/equal to last (%s)", - type_to_string(tmpctx, - struct amount_sat, - &candidate_fee), - type_to_string(tmpctx, - struct amount_sat, - &last_fee)); + fmt_amount_sat(tmpctx, candidate_fee), + fmt_amount_sat(tmpctx, last_fee)); msg = towire_dualopend_fail(NULL, errmsg); goto send_msg; } @@ -2407,8 +2387,7 @@ json_openchannel_abort(struct command *cmd, if (!channel) return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, "Unknown channel %s", - type_to_string(tmpctx, struct channel_id, - cid)); + fmt_channel_id(tmpctx, cid)); if (!channel->owner) return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, @@ -2503,9 +2482,7 @@ json_openchannel_bump(struct command *cmd, return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Overflow in adding PSBT input" " values. %s", - type_to_string(tmpctx, - struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); } /* If they don't pass in at least enough in the PSBT to cover @@ -2514,12 +2491,8 @@ json_openchannel_bump(struct command *cmd, return command_fail(cmd, FUND_CANNOT_AFFORD, "Provided PSBT cannot afford funding of " "amount %s. %s", - type_to_string(tmpctx, - struct amount_sat, - amount), - type_to_string(tmpctx, - struct wally_psbt, - psbt)); + fmt_amount_sat(tmpctx, *amount), + fmt_wally_psbt(tmpctx, psbt)); if (!topology_synced(cmd->ld->topology)) { return command_fail(cmd, FUNDING_STILL_SYNCING_BITCOIN, @@ -2531,8 +2504,7 @@ json_openchannel_bump(struct command *cmd, if (!channel) return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, "Unknown channel %s", - type_to_string(tmpctx, struct channel_id, - cid)); + fmt_channel_id(tmpctx, cid)); last_feerate_perkw = channel_last_funding_feerate(channel); next_feerate_min = last_feerate_perkw * 65 / 64; @@ -2560,8 +2532,8 @@ json_openchannel_bump(struct command *cmd, && amount_sat_greater(*amount, chainparams->max_funding)) return command_fail(cmd, FUND_MAX_EXCEEDED, "Amount exceeded %s", - type_to_string(tmpctx, struct amount_sat, - &chainparams->max_funding)); + fmt_amount_sat(tmpctx, + chainparams->max_funding)); /* It's possible that the last open failed/was aborted. * So now we restart the attempt! */ @@ -2624,8 +2596,7 @@ json_openchannel_bump(struct command *cmd, if (!psbt_has_required_fields(psbt)) return command_fail(cmd, FUNDING_PSBT_INVALID, "PSBT is missing required fields %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); subd_send_msg(channel->owner, take(towire_dualopend_rbf_init(NULL, *amount, @@ -2677,10 +2648,10 @@ json_openchannel_signed(struct command *cmd, "Txid for passed in PSBT does not match" " funding txid for channel. Expected %s, " "received %s", - type_to_string(tmpctx, struct bitcoin_txid, - &channel->funding.txid), - type_to_string(tmpctx, struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, + &channel->funding.txid), + fmt_bitcoin_txid(tmpctx, + &txid)); inflight = list_tail(&channel->inflights, struct channel_inflight, @@ -2693,11 +2664,11 @@ json_openchannel_signed(struct command *cmd, return command_fail(cmd, LIGHTNINGD, "Current inflight transaction is %s," " not %s", - type_to_string(tmpctx, struct bitcoin_txid, - &txid), - type_to_string(tmpctx, struct bitcoin_txid, - &inflight->funding - ->outpoint.txid)); + fmt_bitcoin_txid(tmpctx, + &txid), + fmt_bitcoin_txid(tmpctx, + &inflight->funding + ->outpoint.txid)); if (!inflight->last_tx) return command_fail(cmd, FUNDING_STATE_INVALID, @@ -2786,9 +2757,7 @@ static void validate_input_unspent(struct bitcoind *bitcoind, err = tal_fmt(pv, "Requested only confirmed" " inputs for this open." " Input %s is not confirmed.", - type_to_string(tmpctx, - struct bitcoin_outpoint, - &outpoint)); + fmt_bitcoin_outpoint(tmpctx, &outpoint)); pv->invalid_input(pv, err); return; } @@ -2866,9 +2835,7 @@ static struct json_stream *build_commit_response(struct command *cmd, response = json_stream_success(cmd); json_add_string(response, "channel_id", - type_to_string(tmpctx, - struct channel_id, - &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); json_add_psbt(response, "psbt", inflight->funding_psbt); json_add_channel_type(response, "channel_type", channel->type); json_add_bool(response, "commitments_secured", inflight->last_tx != NULL); @@ -2913,8 +2880,7 @@ static struct command_result *json_openchannel_update(struct command *cmd, if (!channel) return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, "Unknown channel %s", - type_to_string(tmpctx, struct channel_id, - cid)); + fmt_channel_id(tmpctx, cid)); if (!channel->owner) return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, "Peer not connected"); @@ -2949,8 +2915,7 @@ static struct command_result *json_openchannel_update(struct command *cmd, if (!psbt_has_required_fields(psbt)) return command_fail(cmd, FUNDING_PSBT_INVALID, "PSBT is missing required fields %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); if (command_check_only(cmd)) return command_check_done(cmd); @@ -3052,9 +3017,7 @@ static struct command_result *json_openchannel_init(struct command *cmd, return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Overflow in adding PSBT input" " values. %s", - type_to_string(tmpctx, - struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); } /* If they don't pass in at least enough in the PSBT to cover @@ -3063,12 +3026,8 @@ static struct command_result *json_openchannel_init(struct command *cmd, return command_fail(cmd, FUND_CANNOT_AFFORD, "Provided PSBT cannot afford funding of " "amount %s. %s", - type_to_string(tmpctx, - struct amount_sat, - amount), - type_to_string(tmpctx, - struct wally_psbt, - psbt)); + fmt_amount_sat(tmpctx, *amount), + fmt_wally_psbt(tmpctx, psbt)); res = init_set_feerate(cmd, &feerate_per_kw, &feerate_per_kw_funding); if (res) @@ -3112,8 +3071,7 @@ static struct command_result *json_openchannel_init(struct command *cmd, && amount_sat_greater(*amount, chainparams->max_funding)) return command_fail(cmd, FUND_MAX_EXCEEDED, "Amount exceeded %s", - type_to_string(tmpctx, struct amount_sat, - &chainparams->max_funding)); + fmt_amount_sat(tmpctx, chainparams->max_funding)); /* Add serials to any input that's missing them */ psbt_add_serials(psbt, TX_INITIATOR); @@ -3128,8 +3086,7 @@ static struct command_result *json_openchannel_init(struct command *cmd, if (!psbt_has_required_fields(psbt)) return command_fail(cmd, FUNDING_PSBT_INVALID, "PSBT is missing required fields %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); if (command_check_only(cmd)) return command_check_done(cmd); @@ -3159,7 +3116,7 @@ static struct command_result *json_openchannel_init(struct command *cmd, channel->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; log_info(peer->ld->log, "Will open private channel with node %s", - type_to_string(tmpctx, struct node_id, id)); + fmt_node_id(tmpctx, id)); } /* Needs to be stolen away from cmd */ @@ -3350,8 +3307,7 @@ static void handle_psbt_changed(struct subd *dualopend, channel->cid = cid; response = json_stream_success(cmd); json_add_string(response, "channel_id", - type_to_string(tmpctx, struct channel_id, - &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); json_add_psbt(response, "psbt", psbt); json_add_channel_type(response, "channel_type", channel->type); json_add_bool(response, "commitments_secured", false); @@ -3458,8 +3414,7 @@ static void handle_commit_ready(struct subd *dualopend, channel_internal_error(channel, "wallet_commit_channel failed" " (chan %s)", - type_to_string(tmpctx, - struct channel_id, + fmt_channel_id(tmpctx, &channel->cid)); channel->open_attempt = tal_free(channel->open_attempt); @@ -3486,8 +3441,7 @@ static void handle_commit_ready(struct subd *dualopend, channel_internal_error(channel, "wallet_update_channel failed" " (chan %s)", - type_to_string(tmpctx, - struct channel_id, + fmt_channel_id(tmpctx, &channel->cid)); channel->open_attempt = tal_free(channel->open_attempt); @@ -3738,8 +3692,8 @@ static struct command_result *json_queryrates(struct command *cmd, && amount_sat_greater(*amount, chainparams->max_funding)) return command_fail(cmd, FUND_MAX_EXCEEDED, "Amount exceeded %s", - type_to_string(tmpctx, struct amount_sat, - &chainparams->max_funding)); + fmt_amount_sat(tmpctx, + chainparams->max_funding)); if (command_check_only(cmd)) return command_check_done(cmd); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 37bdb48df4f7..984cb8273c46 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -130,8 +130,7 @@ static void handle_init_cupdate(struct lightningd *ld, const u8 *msg) channel = any_channel_by_scid(ld, &scid, true); if (!channel) { log_broken(ld->log, "init_cupdate for unknown scid %s", - type_to_string(tmpctx, struct short_channel_id, - &scid)); + fmt_short_channel_id(tmpctx, scid)); return; } diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c index 1b636bdb6c0d..58ea8dfe2390 100644 --- a/lightningd/hsm_control.c +++ b/lightningd/hsm_control.c @@ -70,7 +70,7 @@ static unsigned int hsm_msg(struct subd *hsmd, /* This should, of course, never happen. */ log_broken(hsmd->log, "client %s %s (request %s)", - type_to_string(tmpctx, struct node_id, &client_id), + fmt_node_id(tmpctx, &client_id), desc, tal_hex(tmpctx, bad_msg)); return 0; } @@ -204,7 +204,7 @@ void bip32_pubkey(struct lightningd *ld, struct pubkey *pubkey, u32 index) fatal("Invalid check_pubkey_reply from hsm"); if (!ok) fatal("HSM said key derivation of %u != %s", - index, type_to_string(tmpctx, struct pubkey, pubkey)); + index, fmt_pubkey(tmpctx, pubkey)); } } diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c index 626df0f51057..d47dcbf8da59 100644 --- a/lightningd/htlc_end.c +++ b/lightningd/htlc_end.c @@ -179,10 +179,8 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout, if (amount_msat_less(hout->in->msat, hout->msat)) return corrupt(abortstr, "Input amount %s" " less than %s", - type_to_string(tmpctx, struct amount_msat, - &hout->in->msat), - type_to_string(tmpctx, struct amount_msat, - &hout->msat)); + fmt_amount_msat(tmpctx, hout->in->msat), + fmt_amount_msat(tmpctx, hout->msat)); if (hout->in->cltv_expiry <= hout->cltv_expiry) return corrupt(abortstr, "Input cltv_expiry %u" " less than %u", @@ -306,12 +304,8 @@ struct htlc_out *new_htlc_out(const tal_t *ctx, if (!amount_msat_sub(&hout->fees, msat, final_msat)) return corrupt("new_htlc_out", "overflow subtract %s-%s", - type_to_string(tmpctx, - struct amount_msat, - &msat), - type_to_string(tmpctx, - struct amount_msat, - &final_msat)); + fmt_amount_msat(tmpctx, msat), + fmt_amount_msat(tmpctx, final_msat)); } hout->in = NULL; @@ -322,12 +316,8 @@ struct htlc_out *new_htlc_out(const tal_t *ctx, if (!amount_msat_sub(&hout->fees, in->msat, msat)) return corrupt("new_htlc_out", "overflow subtract %s-%s", - type_to_string(tmpctx, - struct amount_msat, - &in->msat), - type_to_string(tmpctx, - struct amount_msat, - &msat)); + fmt_amount_msat(tmpctx, in->msat), + fmt_amount_msat(tmpctx, msat)); } return htlc_out_check(hout, "new_htlc_out"); diff --git a/lightningd/htlc_set.c b/lightningd/htlc_set.c index 81e5b19c6d23..abbf3af705c5 100644 --- a/lightningd/htlc_set.c +++ b/lightningd/htlc_set.c @@ -124,8 +124,7 @@ void htlc_set_add(struct lightningd *ld, if (feature_is_set(details->features, COMPULSORY_FEATURE(OPT_PAYMENT_SECRET)) && !payment_secret) { log_debug(ld->log, "Missing payment_secret, but required for %s", - type_to_string(tmpctx, struct sha256, - &hin->payment_hash)); + fmt_sha256(tmpctx, &hin->payment_hash)); local_fail_in_htlc(hin, take(failmsg_incorrect_or_unknown(NULL, ld, hin))); return; @@ -167,12 +166,9 @@ void htlc_set_add(struct lightningd *ld, if (!amount_msat_eq(total_msat, set->total_msat)) { log_unusual(ld->log, "Failing HTLC set %s:" " total_msat %s new htlc total %s", - type_to_string(tmpctx, struct sha256, - &set->payment_hash), - type_to_string(tmpctx, struct amount_msat, - &set->total_msat), - type_to_string(tmpctx, struct amount_msat, - &total_msat)); + fmt_sha256(tmpctx, &set->payment_hash), + fmt_amount_msat(tmpctx, set->total_msat), + fmt_amount_msat(tmpctx, total_msat)); htlc_set_fail(set, take(towire_final_incorrect_htlc_amount(NULL, hin->msat))); @@ -182,12 +178,9 @@ void htlc_set_add(struct lightningd *ld, if (!amount_msat_add(&set->so_far, set->so_far, hin->msat)) { log_unusual(ld->log, "Failing HTLC set %s:" " overflow adding %s+%s", - type_to_string(tmpctx, struct sha256, - &set->payment_hash), - type_to_string(tmpctx, struct amount_msat, - &set->so_far), - type_to_string(tmpctx, struct amount_msat, - &hin->msat)); + fmt_sha256(tmpctx, &set->payment_hash), + fmt_amount_msat(tmpctx, set->so_far), + fmt_amount_msat(tmpctx, hin->msat)); htlc_set_fail(set, take(towire_final_incorrect_htlc_amount(NULL, hin->msat))); @@ -197,8 +190,8 @@ void htlc_set_add(struct lightningd *ld, log_debug(ld->log, "HTLC set contains %zu HTLCs, for a total of %s out of %s (%spayment_secret)", tal_count(set->htlcs), - type_to_string(tmpctx, struct amount_msat, &set->so_far), - type_to_string(tmpctx, struct amount_msat, &total_msat), + fmt_amount_msat(tmpctx, set->so_far), + fmt_amount_msat(tmpctx, total_msat), payment_secret ? "" : "no " ); diff --git a/lightningd/invoice.c b/lightningd/invoice.c index b2f3ab5c93ff..aabd146bff0b 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -339,7 +339,7 @@ invoice_payment_hooks_done(struct invoice_payment_hook_payload *payload STEALS) log_info(ld->log, "Resolved invoice '%s' with amount %s in %zu htlcs", payload->label->s, - type_to_string(tmpctx, struct amount_msat, &payload->msat), + fmt_amount_msat(tmpctx, payload->msat), payload->set ? tal_count(payload->set->htlcs) : 0); if (payload->set) htlc_set_fulfill(payload->set, &payload->preimage); @@ -404,10 +404,10 @@ invoice_check_payment(const tal_t *ctx, if (!invoices_find_unpaid(ld->wallet->invoices, &inv_dbid, payment_hash)) { if (invoices_find_by_rhash(ld->wallet->invoices, &inv_dbid, payment_hash)) { *err = tal_fmt(ctx, "Already paid or expired invoice %s", - type_to_string(tmpctx, struct sha256, payment_hash)); + fmt_sha256(tmpctx, payment_hash)); } else { *err = tal_fmt(ctx, "Unknown invoice %s", - type_to_string(tmpctx, struct sha256, payment_hash)); + fmt_sha256(tmpctx, payment_hash)); } return NULL; } @@ -423,7 +423,7 @@ invoice_check_payment(const tal_t *ctx, if (feature_is_set(details->features, COMPULSORY_FEATURE(OPT_VAR_ONION)) && !payment_secret) { *err = tal_fmt(ctx, "Attempt to pay %s without secret", - type_to_string(tmpctx, struct sha256, &details->rhash)); + fmt_sha256(tmpctx, &details->rhash)); return tal_free(details); } @@ -436,8 +436,7 @@ invoice_check_payment(const tal_t *ctx, invoice_secret(&details->r, &expected); if (!secret_eq_consttime(payment_secret, &expected)) { *err = tal_fmt(ctx, "Attempt to pay %s with wrong secret", - type_to_string(tmpctx, struct sha256, - &details->rhash)); + fmt_sha256(tmpctx, &details->rhash)); return tal_free(details); } } @@ -454,20 +453,18 @@ invoice_check_payment(const tal_t *ctx, if (amount_msat_less(msat, *details->msat)) { *err = tal_fmt(ctx, "Attempt to pay %s with amount %s < %s", - type_to_string(tmpctx, struct sha256, - &details->rhash), - type_to_string(tmpctx, struct amount_msat, &msat), - type_to_string(tmpctx, struct amount_msat, details->msat)); + fmt_sha256(tmpctx, &details->rhash), + fmt_amount_msat(tmpctx, msat), + fmt_amount_msat(tmpctx, *details->msat)); return tal_free(details); } if (amount_msat_add(&twice, *details->msat, *details->msat) && amount_msat_greater(msat, twice)) { *err = tal_fmt(ctx, "Attempt to pay %s with amount %s > %s", - type_to_string(tmpctx, struct sha256, - &details->rhash), - type_to_string(tmpctx, struct amount_msat, &msat), - type_to_string(tmpctx, struct amount_msat, &twice)); + fmt_sha256(tmpctx, &details->rhash), + fmt_amount_msat(tmpctx, msat), + fmt_amount_msat(tmpctx, twice)); /* BOLT #4: * * - if the amount paid is more than twice the amount @@ -610,10 +607,10 @@ static struct route_info **select_inchan(const tal_t *ctx, if (!amount_sat_add(&cumulative_reserve, candidates[i].c->our_config.channel_reserve, candidates[i].c->channel_info.their_config.channel_reserve) - || !amount_sat_to_msat(&capacity, candidates[i].c->funding_sats) - || !amount_msat_sub_sat(&capacity, capacity, cumulative_reserve)) { + || !amount_sat_to_msat(&capacity, candidates[i].c->funding_sats) + || !amount_msat_sub_sat(&capacity, capacity, cumulative_reserve)) { log_broken(ld->log, "Channel %s capacity overflow!", - type_to_string(tmpctx, struct short_channel_id, candidates[i].c->scid)); + fmt_short_channel_id(tmpctx, *candidates[i].c->scid)); continue; } @@ -621,9 +618,8 @@ static struct route_info **select_inchan(const tal_t *ctx, * only one! So bump it by 1 msat */ if (!amount_msat_add(&excess, excess, AMOUNT_MSAT(1))) { log_broken(ld->log, "Channel %s excess overflow!", - type_to_string(tmpctx, - struct short_channel_id, - candidates[i].c->scid)); + fmt_short_channel_id(tmpctx, + *candidates[i].c->scid)); continue; } excess_frac = amount_msat_ratio(excess, capacity); @@ -687,9 +683,8 @@ static struct route_info **select_inchan_mpp(const tal_t *ctx, log_broken(ld->log, "Gathered channel capacity overflow: " "%s + %s", - type_to_string(tmpctx, struct amount_msat, &gathered), - type_to_string(tmpctx, struct amount_msat, - &candidates[i].capacity)); + fmt_amount_msat(tmpctx, gathered), + fmt_amount_msat(tmpctx, candidates[i].capacity)); continue; } tal_arr_expand(&routehints, @@ -797,24 +792,20 @@ add_routehints(struct invoice_info *info, } log_debug(info->cmd->ld->log, "needed = %s, avail_capacity = %s, private_capacity = %s, offline_capacity = %s, deadend_capacity = %s", - type_to_string(tmpctx, struct amount_msat, &needed), - type_to_string(tmpctx, struct amount_msat, &avail_capacity), - type_to_string(tmpctx, struct amount_msat, &private_capacity), - type_to_string(tmpctx, struct amount_msat, &offline_capacity), - type_to_string(tmpctx, struct amount_msat, &deadend_capacity)); + fmt_amount_msat(tmpctx, needed), + fmt_amount_msat(tmpctx, avail_capacity), + fmt_amount_msat(tmpctx, private_capacity), + fmt_amount_msat(tmpctx, offline_capacity), + fmt_amount_msat(tmpctx, deadend_capacity)); if (!amount_msat_add(&total, avail_capacity, offline_capacity) || !amount_msat_add(&total, total, deadend_capacity) || !amount_msat_add(&total, total, private_capacity)) fatal("Cannot add %s + %s + %s + %s", - type_to_string(tmpctx, struct amount_msat, - &avail_capacity), - type_to_string(tmpctx, struct amount_msat, - &offline_capacity), - type_to_string(tmpctx, struct amount_msat, - &deadend_capacity), - type_to_string(tmpctx, struct amount_msat, - &private_capacity)); + fmt_amount_msat(tmpctx, avail_capacity), + fmt_amount_msat(tmpctx, offline_capacity), + fmt_amount_msat(tmpctx, deadend_capacity), + fmt_amount_msat(tmpctx, private_capacity)); /* If we literally didn't have capacity at all, warn. */ *warning_capacity = amount_msat_greater_eq(needed, total); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 99dba8adeade..161515284b75 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -1363,7 +1363,7 @@ int main(int argc, char *argv[]) * so it can use tal_bytelen() to get the length. */ log_info(ld->log, "--------------------------------------------------"); log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s", - type_to_string(tmpctx, struct node_id, &ld->id), + fmt_node_id(tmpctx, &ld->id), json_escape(tmpctx, (const char *)ld->alias)->s, tal_hex(tmpctx, ld->rgb), version()); ld->state = LD_STATE_RUNNING; diff --git a/lightningd/notification.c b/lightningd/notification.c index c8f2c9c32bd4..78ba847bd7b4 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -423,15 +423,15 @@ static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type, /* some 'journal entries' don't have a txid */ if (id->tx_txid) json_add_string(stream, "txid", - type_to_string(tmpctx, struct bitcoin_txid, - id->tx_txid)); + fmt_bitcoin_txid(tmpctx, + id->tx_txid)); /* some chain ledger entries aren't associated with a utxo * e.g. journal updates (due to penalty/state loss) and * chain_fee entries */ if (id->outpoint) { json_add_string(stream, "utxo_txid", - type_to_string(tmpctx, struct bitcoin_txid, - &id->outpoint->txid)); + fmt_bitcoin_txid(tmpctx, + &id->outpoint->txid)); json_add_u32(stream, "vout", id->outpoint->n); } @@ -439,13 +439,13 @@ static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type, if (id->payment_hash) json_add_sha256(stream, "payment_hash", id->payment_hash); return; - case CHANNEL_MVT: - /* push funding / leases don't have a payment_hash */ - if (id->payment_hash) - json_add_sha256(stream, "payment_hash", id->payment_hash); - if (id->part_id) - json_add_u64(stream, "part_id", *id->part_id); - return; + case CHANNEL_MVT: + /* push funding / leases don't have a payment_hash */ + if (id->payment_hash) + json_add_sha256(stream, "payment_hash", id->payment_hash); + if (id->part_id) + json_add_u64(stream, "part_id", *id->part_id); + return; } abort(); } @@ -531,10 +531,10 @@ void notify_balance_snapshot(struct lightningd *ld, } static void json_add_block_added_fields(struct json_stream *stream, - const struct block *block) + const struct block *block) { json_add_string(stream, "hash", - type_to_string(tmpctx, struct bitcoin_blkid, &block->blkid)); + fmt_bitcoin_blkid(tmpctx, &block->blkid)); json_add_u32(stream, "height", block->height); } diff --git a/lightningd/offer.c b/lightningd/offer.c index 61cb07d84cec..741097095479 100644 --- a/lightningd/offer.c +++ b/lightningd/offer.c @@ -68,8 +68,8 @@ static void hsm_sign_b12(struct lightningd *ld, sighash_from_merkle(messagename, fieldname, merkle, &sighash); if (!check_schnorr_sig(&sighash, &key->pubkey, sig)) fatal("HSM gave bad signature %s for pubkey %s", - type_to_string(tmpctx, struct bip340sig, sig), - type_to_string(tmpctx, struct pubkey, (struct pubkey *)key)); + fmt_bip340sig(tmpctx, sig), + fmt_pubkey(tmpctx, key)); } static struct command_result *json_createoffer(struct command *cmd, diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 448e86903a56..46ae3f2247ad 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -174,12 +174,8 @@ static enum watch_result onchain_tx_watched(struct lightningd *ld, bitcoin_txid(tx, &txid2); if (!bitcoin_txid_eq(txid, &txid2)) { channel_internal_error(channel, "Txid for %s is not %s", - type_to_string(tmpctx, - struct bitcoin_tx, - tx), - type_to_string(tmpctx, - struct bitcoin_txid, - txid)); + fmt_bitcoin_tx(tmpctx, tx), + fmt_bitcoin_txid(tmpctx, txid)); return DELETE_WATCH; } } @@ -276,10 +272,10 @@ static void handle_onchain_log_coin_move(struct channel *channel, const u8 *msg) /* Any 'ignored' payments get registed to the wallet */ if (!mvt->account_name) - mvt->account_name = type_to_string(mvt, struct channel_id, + mvt->account_name = fmt_channel_id(mvt, &channel->cid); else - mvt->originating_acct = type_to_string(mvt, struct channel_id, + mvt->originating_acct = fmt_channel_id(mvt, &channel->cid); notify_chain_mvt(channel->peer->ld, mvt); tal_free(mvt); @@ -300,7 +296,7 @@ static void handle_onchain_unwatch_tx(struct channel *channel, const u8 *msg) onchain_tx_watched, channel); if (!txw) log_unusual(channel->log, "Can't unwatch txid %s", - type_to_string(tmpctx, struct bitcoin_txid, &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); tal_free(txw); } @@ -412,7 +408,7 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg) outpointfilter_add(channel->peer->ld->wallet->owned_outpoints, &outpoint); log_debug(channel->log, "adding utxo to watch %s, csv %u", - type_to_string(tmpctx, struct bitcoin_outpoint, &outpoint), + fmt_bitcoin_outpoint(tmpctx, &outpoint), csv_lock); wallet_add_onchaind_utxo(channel->peer->ld->wallet, @@ -423,7 +419,7 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg) mvt = new_coin_wallet_deposit(msg, &outpoint, blockheight, amount, DEPOSIT); - mvt->originating_acct = type_to_string(mvt, struct channel_id, + mvt->originating_acct = fmt_channel_id(mvt, &channel->cid); notify_chain_mvt(channel->peer->ld, mvt); @@ -715,9 +711,8 @@ static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, block_target, block_target - get_block_height(ld->topology), feerate, - type_to_string(tmpctx, struct amount_sat, fee), - type_to_string(tmpctx, struct amount_sat, - &info->out_sats)); + fmt_amount_sat(tmpctx, *fee), + fmt_amount_sat(tmpctx, info->out_sats)); /* If we can afford fee and it's not dust, we're done */ if (amount_sat_sub(&amt, info->out_sats, *fee) @@ -734,7 +729,7 @@ static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, *fee = AMOUNT_SAT(0); log_broken(channel->log, "TX can't afford minimal feerate" "; setting output to %s", - type_to_string(tmpctx, struct amount_sat, &amt)); + fmt_amount_sat(tmpctx, amt)); break; } } @@ -747,7 +742,7 @@ static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, log_unusual(channel->log, "Lowballing feerate for %s sats from %u to %u (deadline %u->%"PRIu64"):" " won't count on it being spent!", - type_to_string(tmpctx, struct amount_sat, &info->out_sats), + fmt_amount_sat(tmpctx, info->out_sats), feerate_for_target(ld->topology, info->deadline_block), feerate_for_target(ld->topology, block_target), info->deadline_block, block_target); @@ -758,7 +753,7 @@ static struct bitcoin_tx *onchaind_tx_unsigned(const tal_t *ctx, if (block_target != info->deadline_block) log_debug(channel->log, "Had to adjust deadline from %u to %"PRIu64" for %s", info->deadline_block, block_target, - type_to_string(tmpctx, struct amount_sat, &info->out_sats)); + fmt_amount_sat(tmpctx, info->out_sats)); bitcoin_tx_output_set_amount(tx, 0, amt); bitcoin_tx_finalize(tx); @@ -836,15 +831,15 @@ static bool consider_onchain_rebroadcast(struct channel *channel, amount_sat_less_eq(newfee, info->fee) ? LOG_DBG : LOG_INFORM, NULL, false, "RBF onchain txid %s (fee %s) with txid %s (fee %s)", - type_to_string(tmpctx, struct bitcoin_txid, &oldtxid), + fmt_bitcoin_txid(tmpctx, &oldtxid), fmt_amount_sat(tmpctx, info->fee), - type_to_string(tmpctx, struct bitcoin_txid, &newtxid), + fmt_bitcoin_txid(tmpctx, &newtxid), fmt_amount_sat(tmpctx, newfee)); log_debug(channel->log, "RBF %s->%s", - type_to_string(tmpctx, struct bitcoin_tx, *tx), - type_to_string(tmpctx, struct bitcoin_tx, newtx)); + fmt_bitcoin_tx(tmpctx, *tx), + fmt_bitcoin_tx(tmpctx, newtx)); /* FIXME: This is ugly, but we want the same parent as old tx. */ tal_steal(tal_parent(*tx), newtx); @@ -957,7 +952,7 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel, if (!psbt_finalize(psbt)) fatal("Non-final PSBT from hsm: %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); newtx = tal(tal_parent(*tx), struct bitcoin_tx); newtx->chainparams = chainparams; @@ -976,9 +971,9 @@ static bool consider_onchain_htlc_tx_rebroadcast(struct channel *channel, amount_sat_less_eq(newfee, oldfee) ? LOG_DBG : LOG_INFORM, NULL, false, "RBF HTLC txid %s (fee %s) with txid %s (fee %s)", - type_to_string(tmpctx, struct bitcoin_txid, &oldtxid), + fmt_bitcoin_txid(tmpctx, &oldtxid), fmt_amount_sat(tmpctx, oldfee), - type_to_string(tmpctx, struct bitcoin_txid, &newtxid), + fmt_bitcoin_txid(tmpctx, &newtxid), fmt_amount_sat(tmpctx, newfee)); tal_free(*tx); @@ -1055,7 +1050,7 @@ static void create_onchain_tx(struct channel *channel, } log_debug(channel->log, "Broadcast for onchaind tx %s%s", - type_to_string(tmpctx, struct bitcoin_tx, tx), + fmt_bitcoin_tx(tmpctx, tx), worthwhile ? "" : "(NOT WORTHWHILE, LOWBALL FEE!)"); /* We allow "excessive" fees, as we may be fighting with censors and @@ -1259,7 +1254,7 @@ static void handle_onchaind_spend_htlc_success(struct channel *channel, info); log_debug(channel->log, "Broadcast for onchaind tx %s", - type_to_string(tmpctx, struct bitcoin_tx, tx)); + fmt_bitcoin_tx(tmpctx, tx)); broadcast_tx(channel, channel->peer->ld->topology, channel, take(tx), NULL, false, info->minblock, NULL, @@ -1341,7 +1336,7 @@ static void handle_onchaind_spend_htlc_timeout(struct channel *channel, info); log_debug(channel->log, "Broadcast for onchaind tx %s", - type_to_string(tmpctx, struct bitcoin_tx, tx)); + fmt_bitcoin_tx(tmpctx, tx)); broadcast_tx(channel, channel->peer->ld->topology, channel, take(tx), NULL, false, info->minblock, NULL, diff --git a/lightningd/onion_message.c b/lightningd/onion_message.c index 272176b721a3..a2ff80517310 100644 --- a/lightningd/onion_message.c +++ b/lightningd/onion_message.c @@ -293,15 +293,14 @@ static struct command_result *json_blindedpath(struct command *cmd, /* Final id should be us! */ if (!pubkey_from_node_id(&me, &cmd->ld->id)) fatal("My id %s is invalid?", - type_to_string(tmpctx, struct node_id, &cmd->ld->id)); + fmt_node_id(tmpctx, &cmd->ld->id)); path->first_node_id = ids[0]; if (!pubkey_eq(&ids[nhops-1], &me)) return command_fail(cmd, LIGHTNINGD, "Final of ids must be this node (%s), not %s", - type_to_string(tmpctx, struct pubkey, &me), - type_to_string(tmpctx, struct pubkey, - &ids[nhops-1])); + fmt_pubkey(tmpctx, &me), + fmt_pubkey(tmpctx, &ids[nhops-1])); randombytes_buf(&first_blinding, sizeof(first_blinding)); if (!pubkey_from_privkey(&first_blinding, &path->blinding)) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index b1f42610f5ac..0f7c3dccea05 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -132,10 +132,8 @@ wallet_commit_channel(struct lightningd *ld, if (uc->fc) { if (!amount_sat_sub_msat(&our_msat, funding_sats, push)) { log_broken(uc->log, "push %s exceeds funding %s", - type_to_string(tmpctx, struct amount_msat, - &push), - type_to_string(tmpctx, struct amount_sat, - &funding_sats)); + fmt_amount_msat(tmpctx, push), + fmt_amount_sat(tmpctx, funding_sats)); return NULL; } local_funding = funding_sats; @@ -307,7 +305,7 @@ static void funding_success(struct channel *channel) response = json_stream_success(cmd); json_add_string(response, "channel_id", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &channel->cid)); json_add_bool(response, "commitments_secured", true); was_pending(command_success(cmd, response)); @@ -424,7 +422,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, peer_fd = new_peer_fd_arr(resp, fds); log_debug(ld->log, - "%s", type_to_string(tmpctx, struct pubkey, + "%s", fmt_pubkey(tmpctx, &channel_info.remote_per_commit)); /* Saved with channel to disk */ @@ -551,7 +549,7 @@ static void opening_fundee_finished(struct subd *openingd, } log_debug(channel->log, "Watching funding tx %s", - type_to_string(reply, struct bitcoin_txid, + fmt_bitcoin_txid(reply, &channel->funding.txid)); channel_watch_funding(ld, channel); @@ -819,8 +817,7 @@ openchannel_hook_deserialize(struct openchannel_hook_payload *payload, log_debug(openingd->ld->log, "Setting reserve=%s for this channel as requested by " "the openchannel hook", - type_to_string(tmpctx, struct amount_sat, - payload->uc->reserve)); + fmt_amount_sat(tmpctx, *payload->uc->reserve)); } return true; @@ -1061,8 +1058,7 @@ static struct command_result *json_fundchannel_complete(struct command *cmd, " should be %s", funding_psbt->outputs [*funding_txout_num].amount, - type_to_string(tmpctx, struct amount_sat, - &fc->funding_sats)); + fmt_amount_sat(tmpctx, fc->funding_sats)); funding_txid = tal(cmd, struct bitcoin_txid); psbt_txid(NULL, funding_psbt, funding_txid, NULL); @@ -1190,8 +1186,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd, return command_fail(cmd, FUND_CANNOT_AFFORD, "Requested to push_msat of %s is greater than " "available funding amount %s", - type_to_string(tmpctx, struct amount_msat, push_msat), - type_to_string(tmpctx, struct amount_sat, amount)); + fmt_amount_msat(tmpctx, *push_msat), + fmt_amount_sat(tmpctx, *amount)); fc->funding_sats = *amount; if (!feerate_non_anchor) { @@ -1279,8 +1275,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd, && amount_sat_greater(*amount, chainparams->max_funding)) return command_fail(cmd, FUND_MAX_EXCEEDED, "Amount exceeded %s", - type_to_string(tmpctx, struct amount_sat, - &chainparams->max_funding)); + fmt_amount_sat(tmpctx, + chainparams->max_funding)); if (command_check_only(cmd)) return command_check_done(cmd); @@ -1290,7 +1286,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd, if (!*announce_channel) { fc->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; log_info(peer->ld->log, "Will open private channel with node %s", - type_to_string(fc, struct node_id, id)); + fmt_node_id(fc, id)); } peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc); @@ -1397,7 +1393,7 @@ static struct channel *stub_chan(struct command *cmd, if (peer) { if (find_channel_by_id(peer, &cid)) { log_debug(cmd->ld->log, "channel %s already exists!", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); return NULL; } } else { @@ -1423,10 +1419,8 @@ static struct channel *stub_chan(struct command *cmd, ,sig); if (!pubkey_from_der(tal_hexdata(cmd, - type_to_string(tmpctx, - struct node_id, - &nodeid), - 66), + fmt_node_id(tmpctx, &nodeid), + 66), 33, &pk)) { diff --git a/lightningd/options.c b/lightningd/options.c index 6299c29b8ab6..ca683538faae 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -405,7 +405,7 @@ static char *opt_add_addr_withtype(const char *arg, if (wireaddr_internal_eq(&ld->proposed_wireaddr[i], &wi)) return tal_fmt(tmpctx, "Duplicate %s address %s", ala & ADDR_ANNOUNCE ? "announce" : "listen", - type_to_string(tmpctx, struct wireaddr_internal, &wi)); + fmt_wireaddr_internal(tmpctx, &wi)); } tal_arr_expand(&ld->proposed_listen_announce, ala); diff --git a/lightningd/pay.c b/lightningd/pay.c index 2ed7c0d97611..76edc5dc3763 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -524,8 +524,7 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, log_unusual(hout->key.channel->log, "No payment for %s:" " was this an old database?", - type_to_string(tmpctx, struct sha256, - &hout->payment_hash)); + fmt_sha256(tmpctx, &hout->payment_hash)); return; } #else @@ -645,8 +644,7 @@ static struct command_result *wait_payment(struct lightningd *ld, "Never attempted payment part %"PRIu64 " for '%s'", partid, - type_to_string(tmpctx, struct sha256, - payment_hash)); + fmt_sha256(tmpctx, payment_hash)); } log_debug(cmd->ld->log, "Payment part %"PRIu64"/%"PRIu64"/%"PRIu64" status %u", @@ -757,14 +755,12 @@ static struct command_result *check_invoice_request_usage(struct command *cmd, NULL, &status)) return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID, "Unknown invoice_request %s", - type_to_string(tmpctx, struct sha256, - local_invreq_id)); + fmt_sha256(tmpctx, local_invreq_id)); if (!offer_status_active(status)) return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID, "Inactive invoice_request %s", - type_to_string(tmpctx, struct sha256, - local_invreq_id)); + fmt_sha256(tmpctx, local_invreq_id)); if (!offer_status_single(status)) return NULL; @@ -782,16 +778,14 @@ static struct command_result *check_invoice_request_usage(struct command *cmd, return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID, "Single-use invoice_request already paid" " with %s", - type_to_string(tmpctx, struct sha256, - &payment - ->payment_hash)); + fmt_sha256(tmpctx, + &payment->payment_hash)); case PAYMENT_PENDING: return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID, "Single-use invoice_request already" " in progress with %s", - type_to_string(tmpctx, struct sha256, - &payment - ->payment_hash)); + fmt_sha256(tmpctx, + &payment->payment_hash)); case PAYMENT_FAILED: break; } @@ -839,7 +833,7 @@ find_channel_for_htlc_add(struct lightningd *ld, log_debug(ld->log, "No channel found for selector %s (%s)", fmt_short_channel_id(tmpctx, *scid_or_alias), - type_to_string(tmpctx, struct amount_msat, amount)); + fmt_amount_msat(tmpctx, *amount)); return NULL; found: @@ -847,9 +841,9 @@ find_channel_for_htlc_add(struct lightningd *ld, log_debug( ld->log, "Selected channel %s (%s) for selector %s (%s)", fmt_short_channel_id(tmpctx, *scid), - type_to_string(tmpctx, struct amount_msat, &channel->our_msat), + fmt_amount_msat(tmpctx, channel->our_msat), fmt_short_channel_id(tmpctx, *scid_or_alias), - type_to_string(tmpctx, struct amount_msat, amount)); + fmt_amount_msat(tmpctx, *amount)); return channel; } @@ -880,8 +874,7 @@ static struct command_result *check_progress(struct lightningd *ld, payment = payment_get_details(tmpctx, stmt); log_debug(ld->log, "Payment: %s %s", - type_to_string(tmpctx, struct amount_msat, - &payment->msatoshi), + fmt_amount_msat(tmpctx, payment->msatoshi), payment->status == PAYMENT_COMPLETE ? "COMPLETE" : payment->status == PAYMENT_PENDING ? "PENDING" : "FAILED"); @@ -899,20 +892,18 @@ static struct command_result *check_progress(struct lightningd *ld, return command_fail(cmd, PAY_RHASH_ALREADY_USED, "Already succeeded " "with amount %s (not %s)", - type_to_string(tmpctx, - struct amount_msat, - &payment->msatoshi), - type_to_string(tmpctx, - struct amount_msat, &msat)); + fmt_amount_msat(tmpctx, + payment->msatoshi), + fmt_amount_msat(tmpctx, + msat)); } if (payment->destination && destination && !node_id_eq(payment->destination, destination)) { return command_fail(cmd, PAY_RHASH_ALREADY_USED, "Already succeeded to %s", - type_to_string(tmpctx, - struct node_id, - payment->destination)); + fmt_node_id(tmpctx, + payment->destination)); } return sendpay_success(cmd, payment); @@ -944,19 +935,17 @@ static struct command_result *check_progress(struct lightningd *ld, return command_fail(cmd, PAY_RHASH_ALREADY_USED, "Already pending " "with amount %s (not %s)", - type_to_string(tmpctx, - struct amount_msat, - &payment->msatoshi), - type_to_string(tmpctx, - struct amount_msat, &msat)); + fmt_amount_msat(tmpctx, + payment->msatoshi), + fmt_amount_msat(tmpctx, + msat)); } if (payment->destination && destination && !node_id_eq(payment->destination, destination)) { return command_fail(cmd, PAY_RHASH_ALREADY_USED, "Already pending to %s", - type_to_string(tmpctx, - struct node_id, + fmt_node_id(tmpctx, payment->destination)); } return json_sendpay_in_progress(cmd, payment); @@ -968,12 +957,10 @@ static struct command_result *check_progress(struct lightningd *ld, tal_free(stmt); return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "msatoshi was previously %s, now %s", - type_to_string(tmpctx, - struct amount_msat, - &payment->total_msat), - type_to_string(tmpctx, - struct amount_msat, - &total_msat)); + fmt_amount_msat(tmpctx, + payment->total_msat), + fmt_amount_msat(tmpctx, + total_msat)); } if (!amount_msat_add(&msat_already_pending, @@ -983,12 +970,10 @@ static struct command_result *check_progress(struct lightningd *ld, return command_fail(cmd, LIGHTNINGD, "Internal amount overflow!" " %s + %s", - type_to_string(tmpctx, - struct amount_msat, - &msat_already_pending), - type_to_string(tmpctx, - struct amount_msat, - &payment->msatoshi)); + fmt_amount_msat(tmpctx, + msat_already_pending), + fmt_amount_msat(tmpctx, + payment->msatoshi)); } break; @@ -1009,7 +994,7 @@ static struct command_result *check_progress(struct lightningd *ld, "groupid=%" PRIu64 ", partid=%" PRIu64 ". Either change the partid, or wait for the " "payment to complete and start a new group.", - type_to_string(tmpctx, struct sha256, rhash), group, + fmt_sha256(tmpctx, rhash), group, partid); } } @@ -1030,10 +1015,9 @@ static struct command_result *check_progress(struct lightningd *ld, && amount_msat_greater_eq(msat_already_pending, total_msat)) { return command_fail(cmd, PAY_IN_PROGRESS, "Already have %s of %s payments in progress", - type_to_string(tmpctx, struct amount_msat, - &msat_already_pending), - type_to_string(tmpctx, struct amount_msat, - &total_msat)); + fmt_amount_msat(tmpctx, + msat_already_pending), + fmt_amount_msat(tmpctx, total_msat)); } return NULL; @@ -1500,7 +1484,7 @@ static struct command_result *self_payment(struct lightningd *ld, log_info(ld->log, "Self-resolved invoice '%s' with amount %s", inv->label->s, - type_to_string(tmpctx, struct amount_msat, &msat)); + fmt_amount_msat(tmpctx, msat)); notify_invoice_payment(ld, msat, &inv->r, inv->label, NULL); /* Now resolve the payment */ @@ -1574,10 +1558,8 @@ static struct command_result *json_sendpay(struct command *cmd, "Do not specify msatoshi (%s) without" " partid: if you do, it must be exactly" " the final amount (%s)", - type_to_string(tmpctx, struct amount_msat, - msat), - type_to_string(tmpctx, struct amount_msat, - &final_amount)); + fmt_amount_msat(tmpctx, *msat), + fmt_amount_msat(tmpctx, final_amount)); /* For MPP, the total we send must *exactly* equal the amount * we promise to send (msatoshi). So no single payment can be @@ -1587,12 +1569,8 @@ static struct command_result *json_sendpay(struct command *cmd, return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Final amount %s is greater than" " %s, despite MPP", - type_to_string(tmpctx, - struct amount_msat, - &final_amount), - type_to_string(tmpctx, - struct amount_msat, - msat)); + fmt_amount_msat(tmpctx, final_amount), + fmt_amount_msat(tmpctx, *msat)); } if (*partid && !payment_secret) @@ -1677,7 +1655,7 @@ static u64 sendpay_index_inc(struct lightningd *ld, "=partid", tal_fmt(tmpctx, "%"PRIu64, partid), "=groupid", tal_fmt(tmpctx, "%"PRIu64, groupid), "payment_hash", - type_to_string(tmpctx, struct sha256, payment_hash), + fmt_sha256(tmpctx, payment_hash), NULL); } @@ -1879,7 +1857,7 @@ static struct command_result *json_delpay(struct command *cmd, stmt = payments_by_hash(cmd->ld->wallet, payment_hash); if (!stmt) return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s", - type_to_string(tmpctx, struct sha256, payment_hash)); + fmt_sha256(tmpctx, payment_hash)); payments = tal_arr(cmd, const struct wallet_payment *, 0); for (; stmt; stmt = payments_next(cmd->ld->wallet, stmt)) { @@ -1899,7 +1877,7 @@ static struct command_result *json_delpay(struct command *cmd, if (tal_count(payments) == 0) { if (found_status) return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Payment with hash %s has %s status but it different from the one provided %s", - type_to_string(tmpctx, struct sha256, payment_hash), + fmt_sha256(tmpctx, payment_hash), payment_status_to_string(*found_status), payment_status_to_string(*status)); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index ead4f76a2255..b6743db8ecd4 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -344,7 +344,7 @@ static enum watch_result closed_inflight_depth_cb(struct lightningd *ld, channel_fail_permanent(inflight->channel, REASON_UNKNOWN, "Inflight tx %s confirmed after mutual close", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); return DELETE_WATCH; } @@ -906,7 +906,7 @@ static void json_add_channel(struct lightningd *ld, node_id_idx(&ld->id, &channel->peer->id)); json_add_string(response, "channel_id", - type_to_string(tmpctx, struct channel_id, &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); json_add_txid(response, "funding_txid", &channel->funding.txid); json_add_num(response, "funding_outnum", channel->funding.n); @@ -1022,10 +1022,8 @@ static void json_add_channel(struct lightningd *ld, channel->our_funds)) { log_broken(channel->log, "Overflow subtracing funding %s, our funds %s", - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats), - type_to_string(tmpctx, struct amount_sat, - &channel->our_funds)); + fmt_amount_sat(tmpctx, channel->funding_sats), + fmt_amount_sat(tmpctx, channel->our_funds)); peer_funded_sats = AMOUNT_SAT(0); } @@ -1037,8 +1035,7 @@ static void json_add_channel(struct lightningd *ld, log_broken(channel->log, "Can't convert channel->push %s to sats" " (lease fees?)", - type_to_string(tmpctx, struct amount_msat, - &channel->push)); + fmt_amount_msat(tmpctx, channel->push)); funds = AMOUNT_SAT(0); } @@ -1093,8 +1090,7 @@ static void json_add_channel(struct lightningd *ld, if (!amount_sat_to_msat(&funding_msat, channel->funding_sats)) { log_broken(channel->log, "Overflow converting funding %s", - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats)); + fmt_amount_sat(tmpctx, channel->funding_sats)); funding_msat = AMOUNT_MSAT(0); } json_add_amount_msat(response, "to_us_msat", channel->our_msat); @@ -1235,11 +1231,11 @@ peer_connected_serialize(struct peer_connected_hook_payload *payload, json_add_string(stream, "direction", payload->incoming ? "in" : "out"); json_add_string( stream, "addr", - type_to_string(stream, struct wireaddr_internal, &payload->addr)); + fmt_wireaddr_internal(stream, &payload->addr)); if (payload->remote_addr) json_add_string( stream, "remote_addr", - type_to_string(stream, struct wireaddr, payload->remote_addr)); + fmt_wireaddr(stream, payload->remote_addr)); /* Since this is start of hook, peer is always in table! */ json_add_hex_talarr(stream, "features", peer_by_id(payload->ld, &payload->peer_id) @@ -1536,7 +1532,7 @@ static const struct wireaddr *best_remote_addr(const tal_t *ctx, daddr.addr = *peer->remote_addr; daddr.addr.port = ld->config.ip_discovery_port; log_debug(ld->log, "best_remote_addr: peer %s gave addr %s (%s)", - type_to_string(tmpctx, struct node_id, &peer->id), + fmt_node_id(tmpctx, &peer->id), fmt_wireaddr(tmpctx, &daddr.addr), daddr.preferred ? "preferred" : "no chan"); tal_arr_expand(&daddrs, daddr); @@ -1884,7 +1880,7 @@ void peer_spoke(struct lightningd *ld, const u8 *msg) /* Weird message? Log and reply with error. */ log_peer_unusual(ld->log, &peer->id, "Unknown channel %s for %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &channel_id), peer_wire_name(msgtype)); error = towire_errorfmt(tmpctx, &channel_id, @@ -1991,10 +1987,9 @@ void update_channel_from_inflight(struct lightningd *ld, " an invalid satoshi amount wrapping," " channel: %s, initial funds: %s, splice" " banace change: %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &channel->cid), - type_to_string(tmpctx, struct amount_sat, - &channel->our_funds), + fmt_amount_sat(tmpctx, channel->our_funds), inflight->funding->splice_amnt); } @@ -2042,7 +2037,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, channel->depth = depth; log_debug(channel->log, "Funding tx %s depth %u of %u", - type_to_string(tmpctx, struct bitcoin_txid, txid), + fmt_bitcoin_txid(tmpctx, txid), depth, channel->minimum_depth); /* Reorged out? */ @@ -2062,7 +2057,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, case CHANNELD_AWAITING_LOCKIN: /* That's not entirely unexpected in early states */ log_debug(channel->log, "Funding tx %s reorganized out!", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); channel->scid = tal_free(channel->scid); return KEEP_WATCHING; @@ -2076,7 +2071,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, str = tal_fmt(tmpctx, "Funding tx %s reorganized out, but %s...", - type_to_string(tmpctx, struct bitcoin_txid, txid), + fmt_bitcoin_txid(tmpctx, txid), channel->opener == LOCAL ? "we opened it" : "zeroconf anyway"); /* Log even if not connected! */ @@ -2122,7 +2117,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, /* If not awaiting lockin/announce, it doesn't care any more */ log_debug(channel->log, "Funding tx %s confirmed, but peer in state %s", - type_to_string(tmpctx, struct bitcoin_txid, txid), + fmt_bitcoin_txid(tmpctx, txid), channel_state_name(channel)); return DELETE_WATCH; @@ -2192,7 +2187,7 @@ void channel_watch_wrong_funding(struct lightningd *ld, struct channel *channel) void channel_watch_funding(struct lightningd *ld, struct channel *channel) { log_debug(channel->log, "Watching for funding txid: %s", - type_to_string(tmpctx, struct bitcoin_txid, &channel->funding.txid)); + fmt_bitcoin_txid(tmpctx, &channel->funding.txid)); watch_txid(channel, ld->topology, &channel->funding.txid, funding_depth_cb, channel); @@ -2223,9 +2218,7 @@ static void json_add_peer(struct lightningd *ld, if (p->connected == PEER_CONNECTED) { json_array_start(response, "netaddr"); json_add_string(response, NULL, - type_to_string(tmpctx, - struct wireaddr_internal, - &p->addr)); + fmt_wireaddr_internal(tmpctx, &p->addr)); json_array_end(response); /* If peer reports our IP remote_addr, add that here */ if (p->remote_addr) @@ -3059,7 +3052,7 @@ static void set_channel_config(struct command *cmd, struct channel *channel, json_object_start(response, NULL); json_add_node_id(response, "peer_id", &channel->peer->id); json_add_string(response, "channel_id", - type_to_string(tmpctx, struct channel_id, &channel->cid)); + fmt_channel_id(tmpctx, &channel->cid)); if (channel->scid) json_add_short_channel_id(response, "short_channel_id", channel->scid); diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 2cd4e289f428..575db466a2a9 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -289,8 +289,7 @@ static bool check_fwd_amount(struct htlc_in *hin, if (!amount_msat_fee(&fee, amt_to_forward, feerate_base, feerate_ppm)) { log_broken(hin->key.channel->log, "Fee overflow forwarding %s!", - type_to_string(tmpctx, struct amount_msat, - &amt_to_forward)); + fmt_amount_msat(tmpctx, amt_to_forward)); return false; } @@ -301,9 +300,9 @@ static bool check_fwd_amount(struct htlc_in *hin, log_debug(hin->key.channel->log, "HTLC %"PRIu64" incorrect amount:" " %s in, %s out, fee reqd %s", hin->key.id, - type_to_string(tmpctx, struct amount_msat, &amt_in_htlc), - type_to_string(tmpctx, struct amount_msat, &amt_to_forward), - type_to_string(tmpctx, struct amount_msat, &fee)); + fmt_amount_msat(tmpctx, amt_in_htlc), + fmt_amount_msat(tmpctx, amt_to_forward), + fmt_amount_msat(tmpctx, fee)); return false; } @@ -395,9 +394,8 @@ static void handle_localpay(struct htlc_in *hin, "HTLC %"PRIu64" final incorrect amount:" " %s in, %s expected", hin->key.id, - type_to_string(tmpctx, struct amount_msat, &hin->msat), - type_to_string(tmpctx, struct amount_msat, - &amt_to_forward)); + fmt_amount_msat(tmpctx, hin->msat), + fmt_amount_msat(tmpctx, amt_to_forward)); /* BOLT #4: * 1. type: 19 (`final_incorrect_htlc_amount`) * 2. data: @@ -892,9 +890,9 @@ htlc_accepted_hook_try_resolve(struct htlc_accepted_hook_payload *request, request->channel->log, "Plugin returned a preimage (sha256(%s) = %s) that doesn't " "match the HTLC hash (%s) it tries to resolve.", - type_to_string(tmpctx, struct preimage, payment_preimage), - type_to_string(tmpctx, struct sha256, &payment_hash), - type_to_string(tmpctx, struct sha256, &hin->payment_hash)); + fmt_preimage(tmpctx, payment_preimage), + fmt_sha256(tmpctx, &payment_hash), + fmt_sha256(tmpctx, &hin->payment_hash)); unknown_details = tal_arr(NULL, u8, 0); towire_u16(&unknown_details, 0x400f); @@ -1217,16 +1215,14 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, if (p->forward_channel) { log_debug(hp->channel->log, "Looking up channel by scid=%s to forward htlc_id=%" PRIu64, - type_to_string(tmpctx, struct short_channel_id, - p->forward_channel), + fmt_short_channel_id(tmpctx, *p->forward_channel), hp->hin->key.id); c = any_channel_by_scid(ld, p->forward_channel, false); if (!c) { log_unusual(hp->channel->log, "No peer channel with scid=%s", - type_to_string(tmpctx, struct short_channel_id, - p->forward_channel)); + fmt_short_channel_id(tmpctx, *p->forward_channel)); return NULL; } @@ -1243,12 +1239,12 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, peer = peer_by_id(ld, &id); log_debug(hp->channel->log, "Looking up peer by node_id=%s", - type_to_string(tmpctx, struct node_id, &id)); + fmt_node_id(tmpctx, &id)); if (!peer) { log_unusual( hp->channel->log, "No peer with node_id=%s", - type_to_string(tmpctx, struct node_id, &id)); + fmt_node_id(tmpctx, &id)); return NULL; } c = NULL; @@ -1260,26 +1256,25 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, return NULL; log_debug(hp->channel->log, "Chose channel %s for peer %s", - type_to_string(tmpctx, struct short_channel_id, - channel_scid_or_local_alias(best)), - type_to_string(tmpctx, struct node_id, - &peer->id)); + fmt_short_channel_id(tmpctx, + *channel_scid_or_local_alias(best)), + fmt_node_id(tmpctx, &peer->id)); } else if (best != c) { log_debug(hp->channel->log, "Chose a better channel than %s: %s", - type_to_string(tmpctx, struct short_channel_id, - p->forward_channel), - type_to_string(tmpctx, struct short_channel_id, - channel_scid_or_local_alias(best))); + fmt_short_channel_id(tmpctx, + *p->forward_channel), + fmt_short_channel_id(tmpctx, + *channel_scid_or_local_alias(best))); } log_debug(hp->channel->log, "Decided to forward htlc_id=%" PRIu64 " over channel with scid=%s with peer %s", hp->hin->key.id, - type_to_string(tmpctx, struct short_channel_id, - channel_scid_or_local_alias(best)), - type_to_string(tmpctx, struct node_id, &best->peer->id)); + fmt_short_channel_id(tmpctx, + *channel_scid_or_local_alias(best)), + fmt_node_id(tmpctx, &best->peer->id)); return tal_dup(hp, struct channel_id, &best->cid); } @@ -1390,7 +1385,7 @@ static bool peer_accepted_htlc(const tal_t *ctx, "Rejecting their htlc %"PRIu64 " since onion is unprocessable %s ss=%s", id, onion_wire_name(*badonion), - type_to_string(tmpctx, struct secret, hin->shared_secret)); + fmt_secret(tmpctx, hin->shared_secret)); goto fail; } @@ -1644,7 +1639,7 @@ static void check_already_failed(const struct channel *channel, struct htlc_out hout->key.id, hout->failonion ? tal_hex(tmpctx, hout->failonion->contents) : "(null)", hout->failmsg ? tal_hex(tmpctx, hout->failmsg) : "(null)", - hout->preimage ? type_to_string(tmpctx, struct preimage, hout->preimage) : "(null)"); + hout->preimage ? fmt_preimage(tmpctx, hout->preimage) : "(null)"); if (hout->preimage) { /* Log on both ours and theirs! */ @@ -1819,17 +1814,14 @@ static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) hin->msat)) { channel_internal_error(channel, "Overflow our_msat %s + HTLC %s", - type_to_string(tmpctx, - struct amount_msat, - &channel->our_msat), - type_to_string(tmpctx, - struct amount_msat, - &hin->msat)); + fmt_amount_msat(tmpctx, + channel->our_msat), + fmt_amount_msat(tmpctx, + hin->msat)); } log_debug(channel->log, "Balance %s -> %s", - type_to_string(tmpctx, struct amount_msat, &oldamt), - type_to_string(tmpctx, struct amount_msat, - &channel->our_msat)); + fmt_amount_msat(tmpctx, oldamt), + fmt_amount_msat(tmpctx, channel->our_msat)); if (amount_msat_greater(channel->our_msat, channel->msat_to_us_max)) channel->msat_to_us_max = channel->our_msat; @@ -1872,18 +1864,15 @@ static void remove_htlc_out(struct channel *channel, struct htlc_out *hout) hout->msat)) { channel_internal_error(channel, "Underflow our_msat %s - HTLC %s", - type_to_string(tmpctx, - struct amount_msat, - &channel->our_msat), - type_to_string(tmpctx, - struct amount_msat, - &hout->msat)); + fmt_amount_msat(tmpctx, + channel->our_msat), + fmt_amount_msat(tmpctx, + hout->msat)); } log_debug(channel->log, "Balance %s -> %s", - type_to_string(tmpctx, struct amount_msat, &oldamt), - type_to_string(tmpctx, struct amount_msat, - &channel->our_msat)); + fmt_amount_msat(tmpctx, oldamt), + fmt_amount_msat(tmpctx, channel->our_msat)); if (amount_msat_less(channel->our_msat, channel->msat_to_us_min)) channel->msat_to_us_min = channel->our_msat; @@ -1986,7 +1975,7 @@ static bool valid_commitment_tx(struct channel *channel, if (tx->wtx->num_outputs == 0) { channel_internal_error(channel, "channel_got_commitsig: zero output tx! %s", - type_to_string(tmpctx, struct bitcoin_tx, tx)); + fmt_bitcoin_tx(tmpctx, tx)); return false; } return true; @@ -2145,12 +2134,9 @@ static bool channel_added_their_htlc(struct channel *channel, channel_internal_error(channel, "trying to add HTLC amount %s" " but minimum is %s", - type_to_string(tmpctx, - struct amount_msat, - &added->amount), - type_to_string(tmpctx, - struct amount_msat, - &channel->our_config.htlc_minimum)); + fmt_amount_msat(tmpctx, added->amount), + fmt_amount_msat(tmpctx, + channel->our_config.htlc_minimum)); return false; } @@ -2523,8 +2509,7 @@ void peer_got_revoke(struct channel *channel, const u8 *msg) channel_fail_permanent(channel, REASON_PROTOCOL, "Bad per_commitment_secret %s for %"PRIu64, - type_to_string(msg, struct secret, - &per_commitment_secret), + fmt_secret(msg, &per_commitment_secret), revokenum); return; } @@ -2890,9 +2875,8 @@ static void fixup_hout(struct lightningd *ld, struct htlc_out *hout) " to %s" " is missing a resolution: %s.", hout->key.id, htlc_state_name(hout->hstate), - type_to_string(tmpctx, struct amount_msat, &hout->msat), - type_to_string(tmpctx, struct node_id, - &hout->key.channel->peer->id), + fmt_amount_msat(tmpctx, hout->msat), + fmt_node_id(tmpctx, &hout->key.channel->peer->id), fix); } diff --git a/lightningd/routehint.c b/lightningd/routehint.c index 071f37213c25..546f2147cc6d 100644 --- a/lightningd/routehint.c +++ b/lightningd/routehint.c @@ -97,21 +97,16 @@ routehint_candidates(const tal_t *ctx, candidate.c = any_channel_by_scid(ld, &r->short_channel_id, true); if (!candidate.c) { log_debug(ld->log, "%s: channel not found in peer %s", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id), - type_to_string(tmpctx, - struct node_id, - &r->pubkey)); + fmt_short_channel_id(tmpctx, r->short_channel_id), + fmt_node_id(tmpctx, &r->pubkey)); continue; } /* Check channel is in CHANNELD_NORMAL or CHANNELD_AWAITING_SPLICE */ if (!channel_state_can_add_htlc(candidate.c->state)) { log_debug(ld->log, "%s: abnormal channel", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); continue; } @@ -157,17 +152,15 @@ routehint_candidates(const tal_t *ctx, && (!candidate.c->alias[REMOTE] || !scid_in_arr(hints, candidate.c->alias[REMOTE]))) { log_debug(ld->log, "scid %s not in hints", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); continue; } /* If they give us a hint, we use even if capacity 0 */ } else if (amount_msat_eq(capacity, AMOUNT_MSAT(0))) { log_debug(ld->log, "%s: deadend", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); if (!amount_msat_add(deadend_capacity, *deadend_capacity, candidate.capacity)) @@ -178,9 +171,8 @@ routehint_candidates(const tal_t *ctx, /* Is it offline? */ if (candidate.c->owner == NULL) { log_debug(ld->log, "%s: offline", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); if (!amount_msat_add(offline_capacity, *offline_capacity, candidate.capacity)) @@ -196,9 +188,8 @@ routehint_candidates(const tal_t *ctx, if (channel_has(candidate.c, OPT_SCID_ALIAS)) { if (!candidate.c->alias[REMOTE]) { log_debug(ld->log, "%s: no remote alias (yet?)", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); continue; } r->short_channel_id = *candidate.c->alias[REMOTE]; @@ -218,9 +209,8 @@ routehint_candidates(const tal_t *ctx, } else { /* Haven't got remote alias yet? Can't use ut. */ log_debug(ld->log, "%s: no alias", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); continue; } } @@ -228,35 +218,33 @@ routehint_candidates(const tal_t *ctx, /* OK, finish it and append to one of the arrays. */ if (is_public) { log_debug(ld->log, "%s: added to public", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); candidate.r = tal_steal(candidates, r); tal_arr_expand(&candidates, candidate); if (!amount_msat_add(avail_capacity, *avail_capacity, candidate.capacity)) { fatal("Overflow summing pub capacities %s + %s", - type_to_string(tmpctx, struct amount_msat, - avail_capacity), - type_to_string(tmpctx, struct amount_msat, - &candidate.capacity)); + fmt_amount_msat(tmpctx, + *avail_capacity), + fmt_amount_msat(tmpctx, + candidate.capacity)); } } else { log_debug(ld->log, "%s: added to private", - type_to_string(tmpctx, - struct short_channel_id, - &r->short_channel_id)); + fmt_short_channel_id(tmpctx, + r->short_channel_id)); candidate.r = tal_steal(privcandidates, r); tal_arr_expand(&privcandidates, candidate); if (!amount_msat_add(private_capacity, *private_capacity, candidate.capacity)) { fatal("Overflow summing priv capacities %s + %s", - type_to_string(tmpctx, struct amount_msat, - private_capacity), - type_to_string(tmpctx, struct amount_msat, - &candidate.capacity)); + fmt_amount_msat(tmpctx, + *private_capacity), + fmt_amount_msat(tmpctx, + candidate.capacity)); } } } diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 94399acaeebb..98b6fe2c5ddc 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -80,6 +80,9 @@ struct feature_set *feature_set_for_feature(const tal_t *ctx UNNEEDED, int featu bool feature_set_or(struct feature_set *a UNNEEDED, const struct feature_set *b TAKES UNNEEDED) { fprintf(stderr, "feature_set_or called!\n"); abort(); } +/* Generated stub for fmt_node_id */ +char *fmt_node_id(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED) +{ fprintf(stderr, "fmt_node_id called!\n"); abort(); } /* Generated stub for free_htlcs */ void free_htlcs(struct lightningd *ld UNNEEDED, const struct channel *channel UNNEEDED) { fprintf(stderr, "free_htlcs called!\n"); abort(); } diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index a19c13e25462..a3bdc51b15f6 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -257,6 +257,12 @@ struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED, /* Generated stub for fixup_htlcs_out */ void fixup_htlcs_out(struct lightningd *ld UNNEEDED) { fprintf(stderr, "fixup_htlcs_out called!\n"); abort(); } +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } +/* Generated stub for fmt_node_id */ +char *fmt_node_id(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED) +{ fprintf(stderr, "fmt_node_id called!\n"); abort(); } /* Generated stub for force_peer_disconnect */ void force_peer_disconnect(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED, diff --git a/lightningd/watch.c b/lightningd/watch.c index 330db7afdcda..baa9c25b63e9 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -210,13 +210,13 @@ static bool txw_fire(struct txwatch *txw, log_debug(txw->topo->log, "Got first depth change ->%u for %s", txw->depth, - type_to_string(tmpctx, struct bitcoin_txid, &txw->txid)); + fmt_bitcoin_txid(tmpctx, &txw->txid)); } else { /* zero depth signals a reorganization */ log_debug(txw->topo->log, "Got depth change %u->%u for %s%s", txw->depth, depth, - type_to_string(tmpctx, struct bitcoin_txid, &txw->txid), + fmt_bitcoin_txid(tmpctx, &txw->txid), depth ? "" : " REORG"); } txw->depth = depth; @@ -255,9 +255,9 @@ void txowatch_fire(const struct txowatch *txow, bitcoin_txid(tx, &txid); log_debug(txow->channel->log, "Got UTXO spend for %s:%u: %s", - type_to_string(tmpctx, struct bitcoin_txid, &txow->out.txid), + fmt_bitcoin_txid(tmpctx, &txow->out.txid), txow->out.n, - type_to_string(tmpctx, struct bitcoin_txid, &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); r = txow->cb(txow->channel, tx, input_num, block); switch (r) { diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index ec3de01b6a3e..f480131cf25e 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -505,8 +505,8 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx, if (!amount_sat_sub(&amount, amount, fee)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Cannot deduct htlc-timeout fee %s from tx %s", - type_to_string(tmpctx, struct amount_sat, &fee), - type_to_string(tmpctx, struct bitcoin_tx, tx)); + fmt_amount_sat(tmpctx, fee), + fmt_bitcoin_tx(tmpctx, tx)); set_amount: bitcoin_tx_output_set_amount(tx, 0, amount); @@ -535,9 +535,7 @@ static struct amount_sat get_htlc_success_fee(struct tracked_output *out) if (!amount_sat_to_msat(&htlc_amount, out->sat)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Overflow in get_htlc_success_fee %s", - type_to_string(tmpctx, - struct amount_sat, - &out->sat)); + fmt_amount_sat(tmpctx, out->sat)); tx = htlc_success_tx(tmpctx, chainparams, &out->outpoint, out->wscript, @@ -568,11 +566,10 @@ static struct amount_sat get_htlc_success_fee(struct tracked_output *out) status_failed(STATUS_FAIL_INTERNAL_ERROR, "htlc_success_fee can't be found " "for tx %s (weight %zu, feerate %u-%u), signature %s, wscript %s", - type_to_string(tmpctx, struct bitcoin_tx, tx), + fmt_bitcoin_tx(tmpctx, tx), weight, min_possible_feerate, max_possible_feerate, - type_to_string(tmpctx, - struct bitcoin_signature, + fmt_bitcoin_signature(tmpctx, out->remote_htlc_sig), tal_hex(tmpctx, out->wscript)); } @@ -611,7 +608,7 @@ new_tracked_output(struct tracked_output ***outs, struct tracked_output *out = tal(*outs, struct tracked_output); status_debug("Tracking output %s: %s/%s", - type_to_string(tmpctx, struct bitcoin_outpoint, outpoint), + fmt_bitcoin_outpoint(tmpctx, outpoint), tx_type_name(tx_type), output_type_name(output_type)); @@ -637,8 +634,7 @@ new_tracked_output(struct tracked_output ***outs, static void ignore_output(struct tracked_output *out) { status_debug("Ignoring output %s: %s/%s", - type_to_string(tmpctx, struct bitcoin_outpoint, - &out->outpoint), + fmt_bitcoin_outpoint(tmpctx, &out->outpoint), tx_type_name(out->tx_type), output_type_name(out->output_type)); @@ -797,8 +793,7 @@ static bool resolved_by_proposal(struct tracked_output *out, tx_type_name(out->tx_type), output_type_name(out->output_type), tx_type_name(out->proposal->tx_type), - type_to_string(tmpctx, struct bitcoin_txid, - &out->resolved->txid)); + fmt_bitcoin_txid(tmpctx, &out->resolved->txid)); out->resolved->depth = 0; out->resolved->tx_type = out->proposal->tx_type; @@ -819,7 +814,7 @@ static void resolved_by_other(struct tracked_output *out, tx_type_name(out->tx_type), output_type_name(out->output_type), tx_type_name(tx_type), - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); } static void unknown_spend(struct tracked_output *out, @@ -833,8 +828,7 @@ static void unknown_spend(struct tracked_output *out, status_broken("Unknown spend of %s/%s by %s", tx_type_name(out->tx_type), output_type_name(out->output_type), - type_to_string(tmpctx, struct bitcoin_txid, - &tx_parts->txid)); + fmt_bitcoin_txid(tmpctx, &tx_parts->txid)); } static u64 unmask_commit_number(const struct tx_parts *tx, @@ -949,9 +943,7 @@ static void billboard_update(struct tracked_output **outs) "%u outputs unresolved: waiting confirmation that we spent %s (%s) using %s", num_not_irrevocably_resolved(outs), output_type_name(best->output_type), - type_to_string(tmpctx, - struct bitcoin_outpoint, - &best->outpoint), + fmt_bitcoin_outpoint(tmpctx, &best->outpoint), tx_type_name(best->proposal->tx_type)); } else { peer_billboard(false, @@ -959,9 +951,7 @@ static void billboard_update(struct tracked_output **outs) num_not_irrevocably_resolved(outs), best->proposal->depth_required - best->depth, output_type_name(best->output_type), - type_to_string(tmpctx, - struct bitcoin_outpoint, - &best->outpoint), + fmt_bitcoin_outpoint(tmpctx, &best->outpoint), tx_type_name(best->proposal->tx_type)); } return; @@ -1060,8 +1050,7 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out, && preimage_item->witness_len == PUBKEY_CMPR_LEN) { status_unusual("Our cheat attempt failed, they're " "taking our htlc out (%s)", - type_to_string(tmpctx, struct amount_sat, - &out->sat)); + fmt_amount_sat(tmpctx, out->sat)); return; } status_failed(STATUS_FAIL_INTERNAL_ERROR, @@ -1079,9 +1068,8 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out, "%s/%s spent with bad preimage %s (ripemd not %s)", tx_type_name(out->tx_type), output_type_name(out->output_type), - type_to_string(tmpctx, struct preimage, &preimage), - type_to_string(tmpctx, struct ripemd160, - &out->htlc.ripemd)); + fmt_preimage(tmpctx, &preimage), + fmt_ripemd160(tmpctx, &out->htlc.ripemd)); /* we stash the payment_hash into the tracking_output so we * can pass it along, if needbe, to the coin movement tracker */ @@ -1091,7 +1079,7 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out, status_debug("%s/%s gave us preimage %s", tx_type_name(out->tx_type), output_type_name(out->output_type), - type_to_string(tmpctx, struct preimage, &preimage)); + fmt_preimage(tmpctx, &preimage)); wire_sync_write(REQ_FD, take(towire_onchaind_extracted_preimage(NULL, &preimage))); @@ -1366,7 +1354,7 @@ static void output_spent(struct tracked_output ***outs, wally_tx_input_get_txid(tx_parts->inputs[input_num], &txid); /* Not interesting to us, so unwatch the tx and all its outputs */ status_debug("Notified about tx %s output %u spend, but we don't care", - type_to_string(tmpctx, struct bitcoin_txid, &txid), + fmt_bitcoin_txid(tmpctx, &txid), tx_parts->inputs[input_num]->index); unwatch_txid(&tx_parts->txid); @@ -1856,8 +1844,7 @@ static size_t resolve_our_htlc_ourcommit(struct tracked_output *out, if (!amount_sat_to_msat(&htlc_amount, out->sat)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Overflow in our_htlc output %s", - type_to_string(tmpctx, struct amount_sat, - &out->sat)); + fmt_amount_sat(tmpctx, out->sat)); assert(tal_count(matches)); @@ -1915,11 +1902,10 @@ static size_t resolve_our_htlc_ourcommit(struct tracked_output *out, "%s%s", tal_count(matches), min_possible_feerate, max_possible_feerate, - type_to_string(tmpctx, struct bitcoin_tx, tx), - type_to_string(tmpctx, struct amount_sat, - &out->sat), - type_to_string(tmpctx, struct bitcoin_signature, - out->remote_htlc_sig), + fmt_bitcoin_tx(tmpctx, tx), + fmt_amount_sat(tmpctx, out->sat), + fmt_bitcoin_signature(tmpctx, + out->remote_htlc_sig), cltvs, wscripts, option_anchor_outputs ? " option_anchor_outputs" : "", @@ -2234,18 +2220,12 @@ static void handle_our_unilateral(const struct tx_parts *tx, " self_htlc_key: %s" " other_htlc_key: %s", commit_num, - type_to_string(tmpctx, struct pubkey, - &keyset->self_revocation_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_delayed_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_htlc_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_htlc_key)); + fmt_pubkey(tmpctx, &keyset->self_revocation_key), + fmt_pubkey(tmpctx, &keyset->self_delayed_payment_key), + fmt_pubkey(tmpctx, &keyset->self_payment_key), + fmt_pubkey(tmpctx, &keyset->other_payment_key), + fmt_pubkey(tmpctx, &keyset->self_htlc_key), + fmt_pubkey(tmpctx, &keyset->other_htlc_key)); local_wscript = to_self_wscript(tmpctx, to_self_delay[LOCAL], 1, keyset); @@ -2672,8 +2652,8 @@ static void handle_their_cheat(const struct tx_parts *tx, if (!pubkey_from_secret(remote_per_commitment_secret, k)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Failed derive from per_commitment_secret %s", - type_to_string(tmpctx, struct secret, - remote_per_commitment_secret)); + fmt_secret(tmpctx, + remote_per_commitment_secret)); status_debug("Deriving keyset %"PRIu64 ": per_commit_point=%s" @@ -2684,20 +2664,20 @@ static void handle_their_cheat(const struct tx_parts *tx, " self_delayed_basepoint=%s" " other_revocation_basepoint=%s", commit_num, - type_to_string(tmpctx, struct pubkey, - remote_per_commitment_point), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].htlc), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].htlc), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].delayed_payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].revocation)); + fmt_pubkey(tmpctx, + remote_per_commitment_point), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].payment), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].payment), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].htlc), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].htlc), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].delayed_payment), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].revocation)); /* keyset is const, we need a non-const ptr to set it up */ keyset = ks = tal(tx, struct keyset); @@ -2719,18 +2699,18 @@ static void handle_their_cheat(const struct tx_parts *tx, " other_htlc_key: %s" " (static_remotekey = %"PRIu64"/%"PRIu64")", commit_num, - type_to_string(tmpctx, struct pubkey, - &keyset->self_revocation_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_delayed_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_htlc_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_htlc_key), + fmt_pubkey(tmpctx, + &keyset->self_revocation_key), + fmt_pubkey(tmpctx, + &keyset->self_delayed_payment_key), + fmt_pubkey(tmpctx, + &keyset->self_payment_key), + fmt_pubkey(tmpctx, + &keyset->other_payment_key), + fmt_pubkey(tmpctx, + &keyset->self_htlc_key), + fmt_pubkey(tmpctx, + &keyset->other_htlc_key), static_remotekey_start[LOCAL], static_remotekey_start[REMOTE]); @@ -3012,20 +2992,20 @@ static void handle_their_unilateral(const struct tx_parts *tx, " self_delayed_basepoint=%s" " other_revocation_basepoint=%s", commit_num, - type_to_string(tmpctx, struct pubkey, - remote_per_commitment_point), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].htlc), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].htlc), - type_to_string(tmpctx, struct pubkey, - &basepoints[REMOTE].delayed_payment), - type_to_string(tmpctx, struct pubkey, - &basepoints[LOCAL].revocation)); + fmt_pubkey(tmpctx, + remote_per_commitment_point), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].payment), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].payment), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].htlc), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].htlc), + fmt_pubkey(tmpctx, + &basepoints[REMOTE].delayed_payment), + fmt_pubkey(tmpctx, + &basepoints[LOCAL].revocation)); /* keyset is const, we need a non-const ptr to set it up */ keyset = ks = tal(tx, struct keyset); @@ -3046,18 +3026,18 @@ static void handle_their_unilateral(const struct tx_parts *tx, " self_htlc_key: %s" " other_htlc_key: %s", commit_num, - type_to_string(tmpctx, struct pubkey, - &keyset->self_revocation_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_delayed_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_payment_key), - type_to_string(tmpctx, struct pubkey, - &keyset->self_htlc_key), - type_to_string(tmpctx, struct pubkey, - &keyset->other_htlc_key)); + fmt_pubkey(tmpctx, + &keyset->self_revocation_key), + fmt_pubkey(tmpctx, + &keyset->self_delayed_payment_key), + fmt_pubkey(tmpctx, + &keyset->self_payment_key), + fmt_pubkey(tmpctx, + &keyset->other_payment_key), + fmt_pubkey(tmpctx, + &keyset->self_htlc_key), + fmt_pubkey(tmpctx, + &keyset->other_htlc_key)); /* Calculate all the HTLC scripts so we can match them */ htlc_scripts = derive_htlc_scripts(htlcs_info->htlcs, REMOTE); @@ -3327,8 +3307,8 @@ static void handle_unknown_commitment(const struct tx_parts *tx, ks)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Deriving keyset for possible_remote_per_commitment_point %s", - type_to_string(tmpctx, struct pubkey, - possible_remote_per_commitment_point)); + fmt_pubkey(tmpctx, + possible_remote_per_commitment_point)); local_scripts[0] = scriptpubkey_p2wpkh(tmpctx, &ks->other_payment_key); @@ -3518,11 +3498,9 @@ int main(int argc, char *argv[]) tal_count(tx->outputs)))); status_debug("Remote per-commit point: %s", - type_to_string(tmpctx, struct pubkey, - &remote_per_commit_point)); + fmt_pubkey(tmpctx, &remote_per_commit_point)); status_debug("Old remote per-commit point: %s", - type_to_string(tmpctx, struct pubkey, - &old_remote_per_commit_point)); + fmt_pubkey(tmpctx, &old_remote_per_commit_point)); trim_maximum_feerate(funding_sats, tx); diff --git a/openingd/common.c b/openingd/common.c index d8d34313c3f2..4bf33270ac1b 100644 --- a/openingd/common.c +++ b/openingd/common.c @@ -61,8 +61,7 @@ bool check_config_bounds(const tal_t *ctx, *err_reason = tal_fmt(ctx, "channel_reserve_satoshis %s" " too large", - type_to_string(ctx, struct amount_sat, - &remoteconf->channel_reserve)); + fmt_amount_sat(ctx, remoteconf->channel_reserve)); return false; } @@ -77,8 +76,7 @@ bool check_config_bounds(const tal_t *ctx, && !amount_sat_add(&reserve, reserve, AMOUNT_SAT(660))) { *err_reason = tal_fmt(ctx, "cannot add anchors to reserve %s", - type_to_string(ctx, struct amount_sat, - &reserve)); + fmt_amount_sat(ctx, reserve)); return false; } @@ -86,12 +84,9 @@ bool check_config_bounds(const tal_t *ctx, if (!amount_sat_sub(&capacity, funding, reserve)) { *err_reason = tal_fmt(ctx, "channel_reserve_satoshis %s" " and %s too large for funding %s", - type_to_string(ctx, struct amount_sat, - &remoteconf->channel_reserve), - type_to_string(ctx, struct amount_sat, - &localconf->channel_reserve), - type_to_string(ctx, struct amount_sat, - &funding)); + fmt_amount_sat(ctx, remoteconf->channel_reserve), + fmt_amount_sat(ctx, localconf->channel_reserve), + fmt_amount_sat(ctx, funding)); return false; } @@ -104,14 +99,10 @@ bool check_config_bounds(const tal_t *ctx, *err_reason = tal_fmt(ctx, "channel_reserve_satoshis %s" " and %s plus fee %s too large for " "funding %s", - type_to_string(tmpctx, struct amount_sat, - &remoteconf->channel_reserve), - type_to_string(tmpctx, struct amount_sat, - &localconf->channel_reserve), - type_to_string(tmpctx, struct amount_sat, - &fee), - type_to_string(tmpctx, struct amount_sat, - &funding)); + fmt_amount_sat(tmpctx, remoteconf->channel_reserve), + fmt_amount_sat(tmpctx, localconf->channel_reserve), + fmt_amount_sat(tmpctx, fee), + fmt_amount_sat(tmpctx, funding)); return false; } @@ -127,12 +118,9 @@ bool check_config_bounds(const tal_t *ctx, *err_reason = tal_fmt(ctx, "htlc_minimum_msat %s" " too large for funding %s" " capacity_msat %s", - type_to_string(ctx, struct amount_msat, - &remoteconf->htlc_minimum), - type_to_string(ctx, struct amount_sat, - &funding), - type_to_string(ctx, struct amount_sat, - &capacity)); + fmt_amount_msat(ctx, remoteconf->htlc_minimum), + fmt_amount_sat(ctx, funding), + fmt_amount_sat(ctx, capacity)); return false; } @@ -148,18 +136,12 @@ bool check_config_bounds(const tal_t *ctx, " reserves %s/%s," " max_htlc_value_in_flight_msat is %s," " channel capacity is %s, which is below %s", - type_to_string(ctx, struct amount_sat, - &funding), - type_to_string(ctx, struct amount_sat, - &remoteconf->channel_reserve), - type_to_string(ctx, struct amount_sat, - &localconf->channel_reserve), - type_to_string(ctx, struct amount_msat, - &remoteconf->max_htlc_value_in_flight), - type_to_string(ctx, struct amount_sat, - &capacity), - type_to_string(ctx, struct amount_sat, - &min_effective_htlc_capacity_sat)); + fmt_amount_sat(ctx, funding), + fmt_amount_sat(ctx, remoteconf->channel_reserve), + fmt_amount_sat(ctx, localconf->channel_reserve), + fmt_amount_msat(ctx, remoteconf->max_htlc_value_in_flight), + fmt_amount_sat(ctx, capacity), + fmt_amount_sat(ctx, min_effective_htlc_capacity_sat)); return false; } diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 31471493d268..b8acc78ab084 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -288,7 +288,7 @@ static u8 *psbt_changeset_get_next(const tal_t *ctx, asset_amt = wally_psbt_output_get_amount(&out->output); sats = amount_asset_to_sat(&asset_amt); const u8 *script = wally_psbt_output_get_script(ctx, - &out->output); + &out->output); msg = towire_tx_add_output(ctx, cid, serial_id, @@ -370,7 +370,7 @@ static void open_abort(struct state *state, peer_billboard(true, errmsg); msg = towire_tx_abort(NULL, &state->channel_id, (u8 *)tal_dup_arr(tmpctx, char, errmsg, - strlen(errmsg), 0)); + strlen(errmsg), 0)); peer_write(state->pps, take(msg)); /* We're now in aborted mode, all @@ -502,17 +502,17 @@ static void handle_peer_shutdown(struct state *state, u8 *msg) if (tal_count(state->upfront_shutdown_script[REMOTE]) && !tal_arr_eq(scriptpubkey, state->upfront_shutdown_script[REMOTE])) open_err_fatal(state, - "scriptpubkey %s is not as agreed upfront (%s)", - tal_hex(state, scriptpubkey), - tal_hex(state, - state->upfront_shutdown_script[REMOTE])); + "scriptpubkey %s is not as agreed upfront (%s)", + tal_hex(state, scriptpubkey), + tal_hex(state, + state->upfront_shutdown_script[REMOTE])); /* @niftynei points out that negotiated this together, so this * hack is not required (or safe!). */ if (tlvs->wrong_funding) open_err_fatal(state, - "wrong_funding shutdown" - " invalid for dual-funding"); + "wrong_funding shutdown" + " invalid for dual-funding"); wire_sync_write(REQ_FD, take(towire_dualopend_got_shutdown(NULL, @@ -559,9 +559,9 @@ static void check_channel_id(struct state *state, if (!channel_id_eq(id_in, orig_id)) open_err_fatal(state, "channel ids don't match." " expected %s, got %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, orig_id), - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, id_in)); } @@ -583,7 +583,7 @@ static char *validate_inputs(struct state *state, * or `accept_channel2`: * - MUST fail the negotiation if: * - one of the inputs added by the other peer is unconfirmed - */ + */ u8 *msg; char *err_reason; @@ -663,7 +663,7 @@ static char *insufficient_err_msg(const tal_t *ctx, struct wally_psbt *psbt) { return tal_fmt(tmpctx, "Insufficiently funded funding tx, %s. %s", - error, type_to_string(tmpctx, struct wally_psbt, psbt)); + error, fmt_wally_psbt(tmpctx, psbt)); } static char *check_balances(const tal_t *ctx, @@ -673,10 +673,10 @@ static char *check_balances(const tal_t *ctx, u32 feerate_per_kw_funding) { struct amount_sat initiator_inputs, initiator_outs, - accepter_inputs, accepter_outs, - tot_input_amt, tot_output_amt, - initiator_fee, accepter_fee, - initiator_diff, accepter_diff; + accepter_inputs, accepter_outs, + tot_input_amt, tot_output_amt, + initiator_fee, accepter_fee, + initiator_diff, accepter_diff; bool ok; u32 funding_outnum = psbt->num_outputs; @@ -738,8 +738,8 @@ static char *check_balances(const tal_t *ctx, tx_state->accepter_funding, tx_state->opener_funding)) { return insufficient_err_msg(ctx, - "overflow adding desired funding", - tx_state->psbt); + "overflow adding desired funding", + tx_state->psbt); } /* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2: @@ -754,15 +754,13 @@ static char *check_balances(const tal_t *ctx, */ if (!amount_sat_eq(total_funding, output_val)) return insufficient_err_msg(ctx, - tal_fmt(tmpctx, "total desired funding %s != " - "funding output %s", - type_to_string(tmpctx, - struct amount_sat, - &total_funding), - type_to_string(tmpctx, - struct amount_sat, - &output_val)), - tx_state->psbt); + tal_fmt(tmpctx, "total desired funding %s != " + "funding output %s", + fmt_amount_sat(tmpctx, + total_funding), + fmt_amount_sat(tmpctx, + output_val)), + tx_state->psbt); /* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2: * @@ -902,15 +900,12 @@ static char *check_balances(const tal_t *ctx, tal_fmt(tmpctx, "initiator inputs" " less than outputs (%s < %s)" " (lease fee %s)", - type_to_string(tmpctx, - struct amount_sat, - &initiator_inputs), - type_to_string(tmpctx, - struct amount_sat, - &initiator_outs), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->lease_fee)), + fmt_amount_sat(tmpctx, + initiator_inputs), + fmt_amount_sat(tmpctx, + initiator_outs), + fmt_amount_sat(tmpctx, + tx_state->lease_fee)), tx_state->psbt); @@ -931,15 +926,12 @@ static char *check_balances(const tal_t *ctx, tal_fmt(tmpctx, "accepter inputs" " %s less than outputs %s" " (lease fee %s)", - type_to_string(tmpctx, - struct amount_sat, - &accepter_inputs), - type_to_string(tmpctx, - struct amount_sat, - &accepter_outs), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->lease_fee)), + fmt_amount_sat(tmpctx, + accepter_inputs), + fmt_amount_sat(tmpctx, + accepter_outs), + fmt_amount_sat(tmpctx, + tx_state->lease_fee)), tx_state->psbt); } @@ -966,26 +958,22 @@ static char *check_balances(const tal_t *ctx, return insufficient_err_msg(ctx, tal_fmt(ctx, "accepter fee not covered" " (need %s > have %s)", - type_to_string(ctx, - struct amount_sat, - &accepter_fee), - type_to_string(ctx, - struct amount_sat, - &accepter_diff)), + fmt_amount_sat(ctx, + accepter_fee), + fmt_amount_sat(ctx, + accepter_diff)), tx_state->psbt); if (!amount_sat_greater_eq(initiator_diff, initiator_fee)) return insufficient_err_msg(ctx, tal_fmt(ctx, "initiator fee %s" " (%zux%d) not covered %s", - type_to_string(ctx, - struct amount_sat, - &initiator_fee), + fmt_amount_sat(ctx, + initiator_fee), initiator_weight, feerate_per_kw_funding, - type_to_string(ctx, - struct amount_sat, - &initiator_diff)), + fmt_amount_sat(ctx, + initiator_diff)), tx_state->psbt); return NULL; @@ -1063,18 +1051,18 @@ static void report_channel_hsmd(const struct state *state, "to msats"); msg = towire_hsmd_setup_channel(NULL, state->our_role == TX_INITIATOR, - total, - accepter_msats, - &tx_state->funding.txid, - tx_state->funding.n, - tx_state->localconf.to_self_delay, - state->upfront_shutdown_script[LOCAL], - state->local_upfront_shutdown_wallet_index, - &state->their_points, - &state->their_funding_pubkey, - tx_state->remoteconf.to_self_delay, - state->upfront_shutdown_script[REMOTE], - state->channel_type); + total, + accepter_msats, + &tx_state->funding.txid, + tx_state->funding.n, + tx_state->localconf.to_self_delay, + state->upfront_shutdown_script[LOCAL], + state->local_upfront_shutdown_wallet_index, + &state->their_points, + &state->their_funding_pubkey, + tx_state->remoteconf.to_self_delay, + state->upfront_shutdown_script[REMOTE], + state->channel_type); wire_sync_write(HSM_FD, take(msg)); msg = wire_sync_read(tmpctx, HSM_FD); if (!fromwire_hsmd_setup_channel_reply(msg)) @@ -1126,10 +1114,10 @@ static u8 *msg_for_remote_commit(const tal_t *ctx, /* You can tell this has been a problem before, since there's a debug * message here: */ status_debug("signature %s on tx %s using key %s", - type_to_string(tmpctx, struct bitcoin_signature, &local_sig), - type_to_string(tmpctx, struct bitcoin_tx, remote_commit), - type_to_string(tmpctx, struct pubkey, - &state->our_funding_pubkey)); + fmt_bitcoin_signature(tmpctx, &local_sig), + fmt_bitcoin_tx(tmpctx, remote_commit), + fmt_pubkey(tmpctx, + &state->our_funding_pubkey)); assert(local_sig.sighash_type == SIGHASH_ALL); @@ -1142,8 +1130,8 @@ static u8 *msg_for_remote_commit(const tal_t *ctx, tal_free(remote_commit); return towire_commitment_signed(ctx, &state->channel_id, - &local_sig.s, - NULL, NULL); + &local_sig.s, + NULL, NULL); } static enum tx_role their_role(const struct state *state) @@ -1200,13 +1188,13 @@ static char *do_commit_signed_received(const tal_t *ctx, " commitment. %s", tal_hex(tmpctx, msg)); *local_commit = initial_channel_tx(ctx, &wscript, state->channel, - &state->first_per_commitment_point[LOCAL], - LOCAL, NULL, &error); + &state->first_per_commitment_point[LOCAL], + LOCAL, NULL, &error); /* This shouldn't happen either, AFAICT. */ if (!*local_commit) return tal_fmt(ctx, "Could not meet our fees" - " and reserve: %s", error); + " and reserve: %s", error); validate_initial_commitment_signature(HSM_FD, *local_commit, remote_sig); @@ -1234,24 +1222,20 @@ static char *do_commit_signed_received(const tal_t *ctx, * twisted by coding in Go, Scala and Rust that they can no * longer read C code. */ return tal_fmt(ctx, - "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, - &tx_state->funding.txid), - type_to_string(tmpctx, - struct wally_psbt, - tx_state->psbt)); + "Bad signature %s on tx %s using key %s" + " (funding txid %s, psbt %s)", + fmt_bitcoin_signature(tmpctx, + remote_sig), + fmt_bitcoin_tx(tmpctx, + *local_commit), + fmt_pubkey(tmpctx, + &state->their_funding_pubkey), + /* This is the first place we'd discover + * the funding tx doesn't match up */ + fmt_bitcoin_txid(tmpctx, + &tx_state->funding.txid), + fmt_wally_psbt(tmpctx, + tx_state->psbt)); } tx_state->has_commitments = true; @@ -1274,7 +1258,7 @@ static void handle_commit_signed(struct state *state, const u8 *msg) &local_commit, &remote_sig); if (err) open_err_fatal(state, - "They sent invalid commitment sig: %s", err); + "They sent invalid commitment sig: %s", err); /* Send the commitment_signed to lightningd; will save to db */ peer_billboard(false, "channel open: commitment received, " @@ -1298,8 +1282,8 @@ static void handle_tx_sigs(struct state *state, const u8 *msg) struct tlv_txsigs_tlvs *txsig_tlvs = tlv_txsigs_tlvs_new(tmpctx); if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid, cast_const3( - struct witness ***, - &witnesses), + struct witness ***, + &witnesses), &txsig_tlvs)) open_err_fatal(state, "Bad tx_signatures %s", tal_hex(msg, msg)); @@ -1310,15 +1294,15 @@ static void handle_tx_sigs(struct state *state, const u8 *msg) state->tx_state->remote_funding_sigs_rcvd = true; status_info("Got WIRE_TX_SIGNATURES after channel_ready " "for channel %s, ignoring: %s", - type_to_string(tmpctx, struct channel_id, - &state->channel_id), - tal_hex(tmpctx, msg)); + fmt_channel_id(tmpctx, + &state->channel_id), + tal_hex(tmpctx, msg)); } else { status_broken("Got WIRE_TX_SIGNATURES after channel_ready " - "for channel %s, ignoring: %s", - type_to_string(tmpctx, struct channel_id, - &state->channel_id), - tal_hex(tmpctx, msg)); + "for channel %s, ignoring: %s", + fmt_channel_id(tmpctx, + &state->channel_id), + tal_hex(tmpctx, msg)); } return; } @@ -1332,8 +1316,7 @@ static void handle_tx_sigs(struct state *state, const u8 *msg) open_err_warn(state, "tx_signatures for %s received," " open negotiation still in progress.", - type_to_string(tmpctx, - struct bitcoin_txid, + fmt_bitcoin_txid(tmpctx, &txid)); @@ -1341,17 +1324,15 @@ static void handle_tx_sigs(struct state *state, const u8 *msg) open_err_warn(state, "tx_signatures for %s received," "working on funding_txid %s", - type_to_string(tmpctx, - struct bitcoin_txid, + fmt_bitcoin_txid(tmpctx, &txid), - type_to_string(tmpctx, - struct bitcoin_txid, + fmt_bitcoin_txid(tmpctx, &tx_state->funding.txid)); if (!tx_state->has_commitments) open_err_fatal(state, - "tx_signatures sent before commitment sigs %s", - tal_hex(msg, msg)); + "tx_signatures sent before commitment sigs %s", + tal_hex(msg, msg)); /* We put the PSBT + sigs all together */ for (size_t i = 0, j = 0; i < tx_state->psbt->num_inputs; i++) { @@ -1361,8 +1342,7 @@ static void handle_tx_sigs(struct state *state, const u8 *msg) if (!psbt_get_serial_id(&in->unknowns, &in_serial)) { status_broken("PSBT input %zu missing serial_id %s", - i, type_to_string(tmpctx, - struct wally_psbt, + i, fmt_wally_psbt(tmpctx, tx_state->psbt)); return; } @@ -1400,10 +1380,10 @@ static void handle_send_tx_sigs(struct state *state, const u8 *msg) "TXID for passed in PSBT does not match" " funding txid for channel. Expected %s, " "received %s", - type_to_string(tmpctx, struct bitcoin_txid, - &tx_state->funding.txid), - type_to_string(tmpctx, struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, + &tx_state->funding.txid), + fmt_bitcoin_txid(tmpctx, + &txid)); tal_wally_start(); if (wally_psbt_combine(tx_state->psbt, psbt) != WALLY_OK) { @@ -1411,9 +1391,9 @@ static void handle_send_tx_sigs(struct state *state, const u8 *msg) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to combine PSBTs. received %s\n" "local %s", - type_to_string(tmpctx, struct wally_psbt, + fmt_wally_psbt(tmpctx, psbt), - type_to_string(tmpctx, struct wally_psbt, + fmt_wally_psbt(tmpctx, tx_state->psbt)); } tal_wally_end(tx_state->psbt); @@ -1808,8 +1788,7 @@ static bool run_tx_interactive(struct state *state, if (!is_segwit_output(&tx->wtx->outputs[outpoint.n])) { open_abort(state, "Invalid tx sent. Not SegWit %s", - type_to_string(tmpctx, - struct bitcoin_tx, + fmt_bitcoin_tx(tmpctx, tx)); return false; } @@ -1827,8 +1806,7 @@ static bool run_tx_interactive(struct state *state, open_abort(state, "Unable to add input %s- " "already present", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &outpoint)); return false; } @@ -1845,8 +1823,7 @@ static bool run_tx_interactive(struct state *state, if (!in) { open_abort(state, "Unable to add input %s", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &outpoint)); return false; } @@ -1863,7 +1840,7 @@ static bool run_tx_interactive(struct state *state, /* FIXME: persist asset tags */ asset = amount_sat_to_asset(&amt, - chainparams->fee_asset_tag); + chainparams->fee_asset_tag); /* FIXME: persist nonces */ psbt_elements_input_set_asset(psbt, outpoint.n, @@ -2108,8 +2085,8 @@ static void revert_channel_state(struct state *state) /* We've already checked this */ if (!amount_sat_to_msat(&our_msats, state->our_role == TX_INITIATOR ? - tx_state->opener_funding : - tx_state->accepter_funding)) + tx_state->opener_funding : + tx_state->accepter_funding)) abort(); tal_free(state->channel); @@ -2123,8 +2100,8 @@ static void revert_channel_state(struct state *state) total, our_msats, take(new_fee_states( - NULL, opener, - &state->feerate_per_kw_commitment)), + NULL, opener, + &state->feerate_per_kw_commitment)), &tx_state->localconf, &tx_state->remoteconf, &state->our_points, @@ -2164,18 +2141,18 @@ static u8 *accepter_commits(struct state *state, scriptpubkey_p2wsh(tmpctx, wscript), &tx_state->funding.n)) { *err_reason = tal_fmt(tmpctx, "Expected output %s not" - " found on funding tx %s", - tal_hex(tmpctx, - scriptpubkey_p2wsh(tmpctx, wscript)), - type_to_string(tmpctx, struct wally_psbt, - tx_state->psbt)); + " found on funding tx %s", + tal_hex(tmpctx, + scriptpubkey_p2wsh(tmpctx, wscript)), + fmt_wally_psbt(tmpctx, + tx_state->psbt)); return NULL; } /* Check tx funds are sane */ *err_reason = check_balances(tmpctx, state, tx_state, - tx_state->psbt, - tx_state->feerate_per_kw_funding); + tx_state->psbt, + tx_state->feerate_per_kw_funding); if (*err_reason) return NULL; @@ -2198,8 +2175,8 @@ static u8 *accepter_commits(struct state *state, total, our_msats, take(new_fee_states( - NULL, REMOTE, - &state->feerate_per_kw_commitment)), + NULL, REMOTE, + &state->feerate_per_kw_commitment)), &tx_state->localconf, &tx_state->remoteconf, &state->our_points, @@ -2233,8 +2210,8 @@ static u8 *accepter_commits(struct state *state, state->upfront_shutdown_script[LOCAL], state->upfront_shutdown_script[REMOTE], state->requested_lease ? - *state->requested_lease : - AMOUNT_SAT(0), + *state->requested_lease : + AMOUNT_SAT(0), tx_state->blockheight, tx_state->lease_expiry, tx_state->lease_fee, @@ -2408,9 +2385,9 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) peer_failed_err(state->pps, &cid, "open_channel2 channel_id incorrect." " Expected %s, received %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &state->channel_id), - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); } /* BOLT #2: @@ -2472,8 +2449,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) */ if (!bitcoin_blkid_eq(&chain_hash, &chainparams->genesis_blockhash)) { negotiation_failed(state, "Unknown chain-hash %s", - type_to_string(tmpctx, - struct bitcoin_blkid, + fmt_bitcoin_blkid(tmpctx, &chain_hash)); return; } @@ -2491,8 +2467,8 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) chainparams->max_funding)) { negotiation_failed(state, "opener's funding_satoshis %s too large", - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, + tx_state->opener_funding)); return; } @@ -2543,10 +2519,9 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) tx_state->psbt->fallback_locktime = tx_state->tx_locktime; if (!psbt_set_version(tx_state->psbt, 2)) { status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Could not set PSBT version: %s", - type_to_string(tmpctx, - struct wally_psbt, - tx_state->psbt)); + "Could not set PSBT version: %s", + fmt_wally_psbt(tmpctx, + tx_state->psbt)); } } @@ -2598,12 +2573,10 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) negotiation_failed(state, "Unable to add accepter's funding" " and channel lease fee (%s + %s)", - type_to_string(tmpctx, - struct amount_sat, - &tx_state->accepter_funding), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->lease_fee)); + fmt_amount_sat(tmpctx, + tx_state->accepter_funding), + fmt_amount_sat(tmpctx, + tx_state->lease_fee)); return; } } @@ -2613,10 +2586,10 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) tx_state->accepter_funding)) { negotiation_failed(state, "Amount overflow. Local sats %s. Remote sats %s", - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, + tx_state->accepter_funding), + fmt_amount_sat(tmpctx, + tx_state->opener_funding)); return; } @@ -2632,8 +2605,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) OPT_LARGE_CHANNELS) && amount_sat_greater(total, chainparams->max_funding)) { negotiation_failed(state, "total funding_satoshis %s too large", - type_to_string(tmpctx, struct amount_sat, - &total)); + fmt_amount_sat(tmpctx, total)); return; } @@ -2688,7 +2660,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) * - if the `option_will_fund` tlv was sent in `open_channel2`: * - if they decide to accept the offer: * - MUST include a `will_fund` tlv - */ + */ if (open_tlv->request_funds && tx_state->rates) accept_tlv_add_offer(a_tlv, tx_state, tx_state->rates, state->our_funding_pubkey, @@ -2808,8 +2780,7 @@ static u8 *opener_commits(struct state *state, tal_hex(tmpctx, scriptpubkey_p2wsh(tmpctx, wscript)), - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, tx_state->psbt)); return NULL; } @@ -2820,8 +2791,7 @@ static u8 *opener_commits(struct state *state, if (error) { *err_reason = tal_fmt(tmpctx, "Insufficiently funded funding " "tx, %s. %s", error, - type_to_string(tmpctx, - struct wally_psbt, + fmt_wally_psbt(tmpctx, tx_state->psbt)); return NULL; } @@ -2830,8 +2800,7 @@ static u8 *opener_commits(struct state *state, status_failed(STATUS_FAIL_INTERNAL_ERROR, "Rounding error, can't convert opener_funding %s" " to msats", - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, tx_state->opener_funding)); return NULL; } @@ -2839,8 +2808,7 @@ static u8 *opener_commits(struct state *state, status_failed(STATUS_FAIL_INTERNAL_ERROR, "Overflow error, can't convert accepter_funding %s" " to msats", - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding)); + fmt_amount_sat(tmpctx, tx_state->accepter_funding)); return NULL; } @@ -2900,8 +2868,8 @@ static u8 *opener_commits(struct state *state, state->upfront_shutdown_script[LOCAL], state->upfront_shutdown_script[REMOTE], state->requested_lease ? - *state->requested_lease : - AMOUNT_SAT(0), + *state->requested_lease : + AMOUNT_SAT(0), tx_state->blockheight, tx_state->lease_expiry, tx_state->lease_fee, @@ -2996,8 +2964,8 @@ static void opener_start(struct state *state, u8 *msg) state->channel_type = ctype; } else { state->channel_type = default_channel_type(state, - state->our_features, - state->their_features); + state->our_features, + state->their_features); } open_tlv->channel_type = state->channel_type->features; @@ -3117,9 +3085,9 @@ static void opener_start(struct state *state, u8 *msg) peer_failed_err(state->pps, &cid, "accept_channel2 ids don't match: " "expected %s, got %s", - type_to_string(msg, struct channel_id, + fmt_channel_id(msg, &state->channel_id), - type_to_string(msg, struct channel_id, &cid)); + fmt_channel_id(msg, &cid)); } } @@ -3145,8 +3113,8 @@ static void opener_start(struct state *state, u8 *msg) tx_state->accepter_funding, state->require_confirmed_inputs[REMOTE], a_tlv->will_fund - ? &a_tlv->will_fund->lease_rates - : NULL); + ? &a_tlv->will_fund->lease_rates + : NULL); wire_sync_write(REQ_FD, take(msg)); @@ -3184,12 +3152,10 @@ static void opener_start(struct state *state, u8 *msg) "We requested %s, which is more" " than they've offered to provide" " (%s)", - type_to_string(tmpctx, - struct amount_sat, - state->requested_lease), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->accepter_funding)); + fmt_amount_sat(tmpctx, + *state->requested_lease), + fmt_amount_sat(tmpctx, + tx_state->accepter_funding)); return; } @@ -3261,12 +3227,10 @@ static void opener_start(struct state *state, u8 *msg) negotiation_failed(state, "Unable to add accepter's funding" " and channel lease fee (%s + %s)", - type_to_string(tmpctx, - struct amount_sat, - &tx_state->accepter_funding), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->lease_fee)); + fmt_amount_sat(tmpctx, + tx_state->accepter_funding), + fmt_amount_sat(tmpctx, + tx_state->lease_fee)); return; } @@ -3286,10 +3250,8 @@ static void opener_start(struct state *state, u8 *msg) tx_state->accepter_funding)) { negotiation_failed(state, "Amount overflow. Local sats %s. " "Remote sats %s", - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding)); + fmt_amount_sat(tmpctx, tx_state->opener_funding), + fmt_amount_sat(tmpctx, tx_state->accepter_funding)); return; } @@ -3306,8 +3268,7 @@ static void opener_start(struct state *state, u8 *msg) && amount_sat_greater(total, chainparams->max_funding)) { negotiation_failed(state, "total funding_satoshis %s too large", - type_to_string(tmpctx, struct amount_sat, - &total)); + fmt_amount_sat(tmpctx, total)); return; } @@ -3559,7 +3520,7 @@ static void rbf_local_start(struct state *state, u8 *msg) init_rbf_tlvs->funding_output_contribution = tal(init_rbf_tlvs, s64); *init_rbf_tlvs->funding_output_contribution - = (s64)tx_state->opener_funding.satoshis; /* Raw: wire conversion */ + = (s64)tx_state->opener_funding.satoshis; /* Raw: wire conversion */ /* We repeat whatever we used on initial open for requiring confirmed @@ -3599,10 +3560,10 @@ static void rbf_local_start(struct state *state, u8 *msg) if (!amount_sat_eq(state->tx_state->accepter_funding, tx_state->accepter_funding)) status_debug("RBF: accepter amt changed %s->%s", - type_to_string(tmpctx, struct amount_sat, - &state->tx_state->accepter_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding)); + fmt_amount_sat(tmpctx, + state->tx_state->accepter_funding), + fmt_amount_sat(tmpctx, + tx_state->accepter_funding)); } else tx_state->accepter_funding = state->tx_state->accepter_funding; @@ -3619,10 +3580,8 @@ static void rbf_local_start(struct state *state, u8 *msg) tx_state->accepter_funding)) { open_abort(state, "Amount overflow. Local sats %s." " Remote sats %s", - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, tx_state->accepter_funding), + fmt_amount_sat(tmpctx, tx_state->opener_funding)); return; } /* Check that total funding doesn't exceed allowed channel capacity */ @@ -3637,9 +3596,7 @@ static void rbf_local_start(struct state *state, u8 *msg) OPT_LARGE_CHANNELS) && amount_sat_greater(total, chainparams->max_funding)) { open_abort(state, "Total funding_satoshis %s too large", - type_to_string(tmpctx, - struct amount_sat, - &total)); + fmt_amount_sat(tmpctx, total)); return; } @@ -3652,12 +3609,10 @@ static void rbf_local_start(struct state *state, u8 *msg) "We requested %s, which is more" " than they've offered to provide" " (%s)", - type_to_string(tmpctx, - struct amount_sat, - state->requested_lease), - type_to_string(tmpctx, - struct amount_sat, - &tx_state->accepter_funding)); + fmt_amount_sat(tmpctx, + *state->requested_lease), + fmt_amount_sat(tmpctx, + tx_state->accepter_funding)); return; } @@ -3687,7 +3642,7 @@ static void rbf_local_start(struct state *state, u8 *msg) /* Notify lightningd about require_confirmed state */ msg = towire_dualopend_update_require_confirmed(NULL, - state->require_confirmed_inputs[REMOTE]); + state->require_confirmed_inputs[REMOTE]); wire_sync_write(REQ_FD, take(msg)); /* We merge with RBF's we've initiated now */ @@ -3745,10 +3700,10 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) if (!amount_sat_eq(tx_state->opener_funding, state->tx_state->opener_funding)) status_debug("RBF: opener amt changed %s->%s", - type_to_string(tmpctx, struct amount_sat, - &state->tx_state->opener_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, + state->tx_state->opener_funding), + fmt_amount_sat(tmpctx, + tx_state->opener_funding)); } else /* Otherwise we use the last known funding amount */ tx_state->opener_funding = state->tx_state->opener_funding; @@ -3810,10 +3765,10 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) tx_state->accepter_funding)) { open_abort(state, "Amount overflow. Local sats %s. Remote sats %s", - type_to_string(tmpctx, struct amount_sat, - &tx_state->accepter_funding), - type_to_string(tmpctx, struct amount_sat, - &tx_state->opener_funding)); + fmt_amount_sat(tmpctx, + tx_state->accepter_funding), + fmt_amount_sat(tmpctx, + tx_state->opener_funding)); goto free_rbf_ctx; } @@ -3849,8 +3804,7 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) OPT_LARGE_CHANNELS) && amount_sat_greater(total, chainparams->max_funding)) { open_abort(state, "Total funding_satoshis %s too large", - type_to_string(tmpctx, struct amount_sat, - &total)); + fmt_amount_sat(tmpctx, total)); goto free_rbf_ctx; } @@ -3858,7 +3812,7 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) ack_rbf_tlvs->funding_output_contribution = tal(ack_rbf_tlvs, s64); *ack_rbf_tlvs->funding_output_contribution - = (s64)tx_state->accepter_funding.satoshis; /* Raw: wire conversion */ + = (s64)tx_state->accepter_funding.satoshis; /* Raw: wire conversion */ /* We keep whatever we initially set at open for RBFs */ if (state->require_confirmed_inputs[LOCAL]) @@ -3906,7 +3860,7 @@ static void send_channel_ready(struct state *state) tlvs->short_channel_id = &state->local_alias; msg = towire_channel_ready(NULL, &state->channel_id, - &next_local_per_commit, tlvs); + &next_local_per_commit, tlvs); peer_write(state->pps, take(msg)); state->channel_ready[LOCAL] = true; @@ -4129,18 +4083,17 @@ static void do_reconnect_dance(struct state *state) peer_billboard(true, "Non-matching next_funding on reconnect. Aborting."); open_abort(state, "Sent next_funding_txid %s doesn't match ours %s", - type_to_string(tmpctx, struct bitcoin_txid, - tlvs->next_funding), - type_to_string(tmpctx, struct bitcoin_txid, - &tx_state->funding.txid)); + fmt_bitcoin_txid(tmpctx, + tlvs->next_funding), + fmt_bitcoin_txid(tmpctx, + &tx_state->funding.txid)); return; } } if (state->channel_ready[LOCAL]) { status_debug("Retransmitting channel_ready for channel %s", - type_to_string(tmpctx, - struct channel_id, + fmt_channel_id(tmpctx, &state->channel_id)); send_channel_ready(state); } @@ -4180,7 +4133,7 @@ static u8 *handle_master_in(struct state *state) handle_failure_fatal(state, msg); return NULL; - /* Handled inline */ + /* Handled inline */ case WIRE_DUALOPEND_INIT: case WIRE_DUALOPEND_REINIT: case WIRE_DUALOPEND_COMMIT_SEND_ACK: @@ -4192,7 +4145,7 @@ static u8 *handle_master_in(struct state *state) case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY: case WIRE_DUALOPEND_VALIDATE_INPUTS_REPLY: - /* Messages we send */ + /* Messages we send */ case WIRE_DUALOPEND_COMMIT_READY: case WIRE_DUALOPEND_GOT_OFFER: case WIRE_DUALOPEND_GOT_RBF_OFFER: @@ -4259,7 +4212,7 @@ static u8 *handle_peer_in(struct state *state) case WIRE_TX_ABORT: handle_tx_abort(state, msg); return NULL; - /* Otherwise we fall through */ + /* Otherwise we fall through */ case WIRE_INIT: case WIRE_ERROR: case WIRE_OPEN_CHANNEL: @@ -4485,14 +4438,14 @@ int main(int argc, char *argv[]) state->our_role = TX_INITIATOR; ok = amount_msat_to_sat(&state->tx_state->opener_funding, our_msat); ok &= amount_sat_sub(&state->tx_state->accepter_funding, - total_funding, - state->tx_state->opener_funding); + total_funding, + state->tx_state->opener_funding); } else { state->our_role = TX_ACCEPTER; ok = amount_msat_to_sat(&state->tx_state->accepter_funding, our_msat); ok &= amount_sat_sub(&state->tx_state->opener_funding, - total_funding, - state->tx_state->accepter_funding); + total_funding, + state->tx_state->accepter_funding); } assert(ok); diff --git a/openingd/openingd.c b/openingd/openingd.c index 8ebdeea38cc8..33803a13d15f 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -147,7 +147,7 @@ static void NORETURN negotiation_failed(struct state *state, static void set_reserve_absolute(struct state * state, const struct amount_sat dust_limit, struct amount_sat reserve_sat) { status_debug("Setting their reserve to %s", - type_to_string(tmpctx, struct amount_sat, &reserve_sat)); + fmt_amount_sat(tmpctx, reserve_sat)); if (state->allowdustreserve) { state->localconf.channel_reserve = reserve_sat; } else { @@ -161,10 +161,8 @@ static void set_reserve_absolute(struct state * state, const struct amount_sat d if (amount_sat_greater(dust_limit, reserve_sat)) { status_debug("Their reserve is too small, bumping to " "dust_limit: %s < %s", - type_to_string(tmpctx, struct amount_sat, - &reserve_sat), - type_to_string(tmpctx, struct amount_sat, - &dust_limit)); + fmt_amount_sat(tmpctx, reserve_sat), + fmt_amount_sat(tmpctx, dust_limit)); state->localconf.channel_reserve = dust_limit; } else { state->localconf.channel_reserve = reserve_sat; @@ -249,10 +247,8 @@ static bool setup_channel_funder(struct state *state) chainparams->max_funding)) { status_failed(STATUS_FAIL_MASTER_IO, "funding_satoshis must be < %s, not %s", - type_to_string(tmpctx, struct amount_sat, - &chainparams->max_funding), - type_to_string(tmpctx, struct amount_sat, - &state->funding_sats)); + fmt_amount_sat(tmpctx, chainparams->max_funding), + fmt_amount_sat(tmpctx, state->funding_sats)); return false; } @@ -441,12 +437,9 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags, status_debug( "accept_channel: max_htlc_value_in_flight=%s, channel_reserve=%s, " "htlc_minimum=%s, minimum_depth=%d", - type_to_string(tmpctx, struct amount_msat, - &state->remoteconf.max_htlc_value_in_flight), - type_to_string(tmpctx, struct amount_sat, - &state->remoteconf.channel_reserve), - type_to_string(tmpctx, struct amount_msat, - &state->remoteconf.htlc_minimum), + fmt_amount_msat(tmpctx, state->remoteconf.max_htlc_value_in_flight), + fmt_amount_sat(tmpctx, state->remoteconf.channel_reserve), + fmt_amount_msat(tmpctx, state->remoteconf.htlc_minimum), their_mindepth); /* BOLT #2: @@ -499,8 +492,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags, /* In this case we exit, since we don't know what's going on. */ 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, + fmt_channel_id(msg, &id_in), + fmt_channel_id(msg, &state->channel_id)); if (!state->allowdustreserve && @@ -509,10 +502,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags, negotiation_failed(state, "dust limit %s" " would be above our reserve %s", - type_to_string(tmpctx, struct amount_sat, - &state->remoteconf.dust_limit), - type_to_string(tmpctx, struct amount_sat, - &state->localconf.channel_reserve)); + fmt_amount_sat(tmpctx, state->remoteconf.dust_limit), + fmt_amount_sat(tmpctx, state->localconf.channel_reserve)); return NULL; } @@ -550,10 +541,9 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags, "Please increase the funding amount or reduce the " "max_accepted_htlcs to ensure at least one non-dust " "output.", - type_to_string(tmpctx, struct amount_sat, - &state->funding_sats), + fmt_amount_sat(tmpctx, state->funding_sats), maxhtlcs, - type_to_string(tmpctx, struct amount_sat, &mindust)); + fmt_amount_sat(tmpctx, mindust)); return NULL; } @@ -741,9 +731,9 @@ static bool funder_finalize_channel_setup(struct state *state, /* You can tell this has been a problem before, since there's a debug * message here: */ status_debug("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, + fmt_bitcoin_signature(tmpctx, sig), + fmt_bitcoin_tx(tmpctx, *tx), + fmt_pubkey(tmpctx, &state->our_funding_pubkey)); /* Now we give our peer the signature for their first commitment @@ -805,9 +795,9 @@ static bool funder_finalize_channel_setup(struct state *state, if (!channel_id_eq(&id_in, &state->channel_id)) peer_failed_err(state->pps, &id_in, "funding_signed ids don't match: expected %s got %s", - type_to_string(msg, struct channel_id, + fmt_channel_id(msg, &state->channel_id), - type_to_string(msg, struct channel_id, &id_in)); + fmt_channel_id(msg, &id_in)); /* BOLT #2: * @@ -831,10 +821,10 @@ static bool funder_finalize_channel_setup(struct state *state, if (!check_tx_sig(*tx, 0, NULL, wscript, &state->their_funding_pubkey, sig)) { peer_failed_err(state->pps, &state->channel_id, "Bad signature %s on tx %s using key %s (channel_type=%s)", - type_to_string(tmpctx, struct bitcoin_signature, + fmt_bitcoin_signature(tmpctx, sig), - type_to_string(tmpctx, struct bitcoin_tx, *tx), - type_to_string(tmpctx, struct pubkey, + fmt_bitcoin_tx(tmpctx, *tx), + fmt_pubkey(tmpctx, &state->their_funding_pubkey), fmt_featurebits(tmpctx, state->channel->type->features)); @@ -867,17 +857,15 @@ static u8 *funder_channel_complete(struct state *state) /* Update the billboard about what we're doing*/ peer_billboard(false, "Funding channel con't: continuing with funding_txid %s", - type_to_string(tmpctx, struct bitcoin_txid, &state->funding.txid)); + fmt_bitcoin_txid(tmpctx, &state->funding.txid)); /* We recalculate the local_msat from cached values; should * succeed because we checked it earlier */ if (!amount_sat_sub_msat(&local_msat, state->funding_sats, state->push_msat)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "push_msat %s > funding %s?", - type_to_string(tmpctx, struct amount_msat, - &state->push_msat), - type_to_string(tmpctx, struct amount_sat, - &state->funding_sats)); + fmt_amount_msat(tmpctx, state->push_msat), + fmt_amount_sat(tmpctx, state->funding_sats)); if (!funder_finalize_channel_setup(state, local_msat, &sig, &tx, &pbase)) @@ -997,9 +985,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) if (!bitcoin_blkid_eq(&chain_hash, &chainparams->genesis_blockhash)) { negotiation_failed(state, "Unknown chain-hash %s", - type_to_string(tmpctx, - struct bitcoin_blkid, - &chain_hash)); + fmt_bitcoin_blkid(tmpctx, &chain_hash)); return NULL; } @@ -1015,8 +1001,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) && amount_sat_greater(state->funding_sats, chainparams->max_funding)) { negotiation_failed(state, "funding_satoshis %s too large", - type_to_string(tmpctx, struct amount_sat, - &state->funding_sats)); + fmt_amount_sat(tmpctx, state->funding_sats)); return NULL; } @@ -1030,10 +1015,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) 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_sats)); + fmt_amount_msat(tmpctx, state->push_msat), + fmt_amount_sat(tmpctx, state->funding_sats)); return NULL; } @@ -1077,10 +1060,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) negotiation_failed(state, "Our channel reserve %s" " would be below their dust %s", - type_to_string(tmpctx, struct amount_sat, - &state->localconf.channel_reserve), - type_to_string(tmpctx, struct amount_sat, - &state->remoteconf.dust_limit)); + fmt_amount_sat(tmpctx, state->localconf.channel_reserve), + fmt_amount_sat(tmpctx, state->remoteconf.dust_limit)); return NULL; } @@ -1216,9 +1197,9 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) if (!channel_id_eq(&id_in, &state->channel_id)) peer_failed_err(state->pps, &id_in, "funding_created ids don't match: sent %s got %s", - type_to_string(msg, struct channel_id, + fmt_channel_id(msg, &state->channel_id), - type_to_string(msg, struct channel_id, &id_in)); + fmt_channel_id(msg, &id_in)); /* Backwards/cross compat hack */ if (intuit_scid_alias_type(state, channel_flags, @@ -1309,10 +1290,10 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) * longer read C code. */ peer_failed_err(state->pps, &state->channel_id, "Bad signature %s on tx %s using key %s", - type_to_string(tmpctx, struct bitcoin_signature, + fmt_bitcoin_signature(tmpctx, &theirsig), - type_to_string(tmpctx, struct bitcoin_tx, local_commit), - type_to_string(tmpctx, struct pubkey, + fmt_bitcoin_tx(tmpctx, local_commit), + fmt_pubkey(tmpctx, &their_funding_pubkey)); } diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c index 6cca96492ecf..43cd76b5783f 100644 --- a/plugins/bkpr/bookkeeper.c +++ b/plugins/bkpr/bookkeeper.c @@ -749,21 +749,15 @@ static char *msat_net(const tal_t *ctx, if (!amount_msat_sub(credit_net, credit, debit)) return tal_fmt(ctx, "unexpected fail, can't sub." " %s - %s", - type_to_string(ctx, struct amount_msat, - &credit), - type_to_string(ctx, struct amount_msat, - &debit)); + fmt_amount_msat(ctx, credit), + fmt_amount_msat(ctx, debit)); *debit_net = AMOUNT_MSAT(0); } else { if (!amount_msat_sub(debit_net, debit, credit)) { return tal_fmt(ctx, "unexpected fail, can't sub." " %s - %s", - type_to_string(ctx, - struct amount_msat, - &debit), - type_to_string(ctx, - struct amount_msat, - &credit)); + fmt_amount_msat(ctx, debit), + fmt_amount_msat(ctx, credit)); } *credit_net = AMOUNT_MSAT(0); } @@ -1005,8 +999,7 @@ static struct command_result *json_balance_snapshot(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "account %s has balance %s", acct_name, - type_to_string(tmpctx, struct amount_msat, - &snap_balance)); + fmt_amount_msat(tmpctx, snap_balance)); /* Find the account balances */ err = account_get_balance(cmd, db, acct_name, @@ -1086,12 +1079,9 @@ static struct command_result *json_balance_snapshot(struct command *cmd, "Snapshot balance does not equal ondisk" " reported %s, off by (+%s/-%s) (account %s)" " Logging journal entry.", - type_to_string(tmpctx, struct amount_msat, - &snap_balance), - type_to_string(tmpctx, struct amount_msat, - &debit_diff), - type_to_string(tmpctx, struct amount_msat, - &credit_diff), + fmt_amount_msat(tmpctx, snap_balance), + fmt_amount_msat(tmpctx, debit_diff), + fmt_amount_msat(tmpctx, credit_diff), acct_name); @@ -1151,8 +1141,7 @@ static char *fetch_out_desc_invstr(const tal_t *ctx, const char *buf, desc = tal_strdup(ctx, bolt11->description); else if (bolt11->description_hash) desc = tal_fmt(ctx, "%s", - type_to_string(ctx, - struct sha256, + fmt_sha256(ctx, bolt11->description_hash)); else desc = NULL; @@ -1732,8 +1721,8 @@ static struct command_result *json_coin_moved(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "coin_move %d (%s) %s -%s %s %"PRIu64, version, mvt_tag_str(tags[0]), - type_to_string(tmpctx, struct amount_msat, &credit), - type_to_string(tmpctx, struct amount_msat, &debit), + fmt_amount_msat(tmpctx, credit), + fmt_amount_msat(tmpctx, debit), mvt_type, timestamp); if (streq(mvt_type, CHAIN_MOVE)) diff --git a/plugins/bkpr/incomestmt.c b/plugins/bkpr/incomestmt.c index ee357997e0f7..ed6c49506236 100644 --- a/plugins/bkpr/incomestmt.c +++ b/plugins/bkpr/incomestmt.c @@ -628,14 +628,13 @@ static void koinly_entry(const tal_t *ctx, FILE *csvf, struct income_event *ev) /* TxHash */ if (ev->txid) fprintf(csvf, "%s", - type_to_string(ctx, struct bitcoin_txid, ev->txid)); + fmt_bitcoin_txid(ctx, ev->txid)); else if (ev->payment_id) fprintf(csvf, "%s", - type_to_string(ctx, struct sha256, ev->payment_id)); + fmt_sha256(ctx, ev->payment_id)); else if (ev->outpoint) fprintf(csvf, "%s", - type_to_string(ctx, struct bitcoin_outpoint, - ev->outpoint)); + fmt_bitcoin_outpoint(ctx, ev->outpoint)); } static void harmony_header(FILE *csvf) @@ -738,20 +737,19 @@ static void harmony_entry(const tal_t *ctx, FILE *csvf, struct income_event *ev) * We don't have a standard 'txid' for every event though */ if (ev->txid) fprintf(csvf, "%s", - type_to_string(ctx, struct bitcoin_txid, ev->txid)); + fmt_bitcoin_txid(ctx, ev->txid)); else if (ev->payment_id) fprintf(csvf, "%s", - type_to_string(ctx, struct sha256, ev->payment_id)); + fmt_sha256(ctx, ev->payment_id)); else if (ev->outpoint) fprintf(csvf, "%s", - type_to_string(ctx, struct bitcoin_outpoint, - ev->outpoint)); + fmt_bitcoin_outpoint(ctx, ev->outpoint)); fprintf(csvf, ","); /* ",Order ID" payment hash, if any */ if (ev->payment_id) fprintf(csvf, "%s", - type_to_string(ctx, struct sha256, ev->payment_id)); + fmt_sha256(ctx, ev->payment_id)); fprintf(csvf, ","); /* ",Account" */ @@ -761,8 +759,7 @@ static void harmony_entry(const tal_t *ctx, FILE *csvf, struct income_event *ev) /* ",Network ID" outpoint */ if (ev->outpoint) fprintf(csvf, "%s", - type_to_string(ctx, struct bitcoin_outpoint, - ev->outpoint)); + fmt_bitcoin_outpoint(ctx, ev->outpoint)); fprintf(csvf, ","); /* ",Note" description (may be NULL) */ diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c index 000a01f86d57..55c16789a1a2 100644 --- a/plugins/bkpr/recorder.c +++ b/plugins/bkpr/recorder.c @@ -885,10 +885,8 @@ char *account_get_balance(const tal_t *ctx, return tal_fmt(ctx, "%s channel balance is negative? %s - %s", bal->currency, - type_to_string(ctx, struct amount_msat, - &bal->credit), - type_to_string(ctx, struct amount_msat, - &bal->debit)); + fmt_amount_msat(ctx, bal->credit), + fmt_amount_msat(ctx, bal->debit)); } return NULL; @@ -1806,7 +1804,7 @@ char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db, events[i]->debit)) { err = tal_fmt(ctx, "Overflow adding withdrawal debits for" " txid: %s", - type_to_string(ctx, struct bitcoin_txid, + fmt_bitcoin_txid(ctx, txid)); goto finished; } @@ -1815,7 +1813,7 @@ char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db, events[i]->credit)) { err = tal_fmt(ctx, "Overflow adding deposit credits for" " txid: %s", - type_to_string(ctx, struct bitcoin_txid, + fmt_bitcoin_txid(ctx, txid)); goto finished; } @@ -1859,9 +1857,9 @@ char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db, if (!amount_msat_sub(&fees_msat, withdraw_msat, deposit_msat)) { err = tal_fmt(ctx, "Err subtracting withdraw %s from deposit %s" " for txid %s", - type_to_string(ctx, struct amount_msat, &withdraw_msat), - type_to_string(ctx, struct amount_msat, &deposit_msat), - type_to_string(ctx, struct bitcoin_txid, txid)); + fmt_amount_msat(ctx, withdraw_msat), + fmt_amount_msat(ctx, deposit_msat), + fmt_bitcoin_txid(ctx, txid)); goto finished; } diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c index e2410379a567..04ffe463f916 100644 --- a/plugins/bkpr/test/run-bkpr_db.c +++ b/plugins/bkpr/test/run-bkpr_db.c @@ -44,6 +44,9 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED, /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c index 62b6039dd607..73fcf54a88fd 100644 --- a/plugins/bkpr/test/run-recorder.c +++ b/plugins/bkpr/test/run-recorder.c @@ -50,6 +50,9 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED, /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } diff --git a/plugins/chanbackup.c b/plugins/chanbackup.c index ee9607bcb0d4..f63b5e672327 100644 --- a/plugins/chanbackup.c +++ b/plugins/chanbackup.c @@ -379,9 +379,8 @@ static struct command_result *peer_after_send_scb(struct command *cmd, cmd, tal_fmt(cmd, "chanbackup/peers/%s", - type_to_string(tmpctx, - struct node_id, - nodeid)), + fmt_node_id(tmpctx, + nodeid)), peer_after_listdatastore, nodeid); } @@ -590,7 +589,7 @@ static struct command_result *failed_peer_restore(struct command *cmd, char *reason) { plugin_log(cmd->plugin, LOG_DBG, "PeerStorageFailed!: %s: %s", - type_to_string(tmpctx, struct node_id, node_id), + fmt_node_id(tmpctx, node_id), reason); return command_hook_success(cmd); } @@ -641,9 +640,8 @@ static struct command_result *handle_your_peer_storage(struct command *cmd, cmd, tal_fmt(cmd, "chanbackup/peers/%s", - type_to_string(tmpctx, - struct node_id, - &node_id)), + fmt_node_id(tmpctx, + &node_id)), payload_deserialise, "create-or-replace", datastore_success, diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index b97573e13af0..133a1efebb28 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -496,8 +496,7 @@ static struct pubkey *path_to_node(const tal_t *ctx, for (size_t i = 0; i < tal_count(r); i++) { if (!pubkey_from_node_id(&nodes[i+1], &r[i].node_id)) { plugin_err(plugin, "Could not convert nodeid %s", - type_to_string(tmpctx, struct node_id, - &r[i].node_id)); + fmt_node_id(tmpctx, &r[i].node_id)); } } @@ -537,8 +536,7 @@ send_modern_message(struct command *cmd, if (!pubkey_from_privkey(&blinding_iter, &fwd_blinding)) return command_fail(cmd, LIGHTNINGD, "Could not convert blinding %s to pubkey!", - type_to_string(tmpctx, struct privkey, - &blinding_iter)); + fmt_privkey(tmpctx, &blinding_iter)); /* We overallocate: this node (0) doesn't have payload or alias */ payloads = tal_arr(cmd, struct tlv_onionmsg_tlv *, nhops); @@ -766,8 +764,7 @@ connect_direct(struct command *cmd, "Cannot find route, but" " fetchplugin-noconnect set:" " trying direct anyway to %s", - type_to_string(tmpctx, struct pubkey, - dst)); + fmt_pubkey(tmpctx, dst)); return cb(cmd, NULL, NULL, sent); } diff --git a/plugins/funder.c b/plugins/funder.c index fa1c6c35f21f..76ae3e6e8499 100644 --- a/plugins/funder.c +++ b/plugins/funder.c @@ -81,7 +81,7 @@ unreserve_done(struct command *cmd UNUSED, { plugin_log(open->p, LOG_DBG, "`unreserveinputs` for channel %s completed. %*.s", - type_to_string(tmpctx, struct channel_id, &open->channel_id), + fmt_channel_id(tmpctx, &open->channel_id), json_tok_full_len(result), json_tok_full(buf, result)); @@ -96,7 +96,7 @@ static void unreserve_psbt(struct pending_open *open) plugin_log(open->p, LOG_DBG, "Calling `unreserveinputs` for channel %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &open->channel_id)); req = jsonrpc_request_start(open->p, NULL, @@ -207,7 +207,7 @@ remember_channel_utxos(struct command *cmd, struct out_req *req; u8 *utxos_bin; char *chan_key = tal_fmt(cmd, "funder/%s", - type_to_string(cmd, struct channel_id, + fmt_channel_id(cmd, &open->channel_id)); req = jsonrpc_request_start(cmd->plugin, cmd, @@ -247,7 +247,7 @@ signpsbt_done(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "`signpsbt` done for channel %s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &open->channel_id)); err = json_scan(tmpctx, buf, result, "{signed_psbt:%}", @@ -299,20 +299,20 @@ json_openchannel2_sign_call(struct command *cmd, if (!open) { plugin_log(cmd->plugin, LOG_DBG, "nothing to sign for channel %s", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); return command_hook_cont_psbt(cmd, psbt); } if (!psbt_has_our_input(psbt)) { plugin_log(cmd->plugin, LOG_DBG, "no inputs to sign for channel %s", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); return command_hook_cont_psbt(cmd, psbt); } plugin_log(cmd->plugin, LOG_DBG, "openchannel_sign PSBT is %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); req = jsonrpc_request_start(cmd->plugin, cmd, "signpsbt", @@ -334,7 +334,7 @@ json_openchannel2_sign_call(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "calling `signpsbt` for channel %s for %zu input%s", - type_to_string(tmpctx, struct channel_id, + fmt_channel_id(tmpctx, &open->channel_id), count, count == 1 ? "" : "s"); return send_outreq(cmd->plugin, req); @@ -364,7 +364,7 @@ json_openchannel2_changed_call(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "openchannel_changed PSBT is %s", - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); /* FIXME: do we have any additions or updates to make based * on their changes? */ @@ -467,10 +467,8 @@ psbt_fund_failed(struct command *cmd, "Unable to secure %s from wallet," " continuing channel open to %s" " without our participation. err %.*s", - type_to_string(tmpctx, struct amount_sat, - &info->our_funding), - type_to_string(tmpctx, struct node_id, - &info->id), + fmt_amount_sat(tmpctx, info->our_funding), + fmt_node_id(tmpctx, &info->id), json_tok_full_len(error), json_tok_full(buf, error)); @@ -696,8 +694,7 @@ listfunds_success(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Policy %s returned funding amount of %s. %s", funder_policy_desc(tmpctx, current_policy), - type_to_string(tmpctx, struct amount_sat, - &info->our_funding), + fmt_amount_sat(tmpctx, info->our_funding), funding_err ? funding_err : ""); if (amount_sat_zero(info->our_funding)) @@ -705,11 +702,9 @@ listfunds_success(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Funding channel %s with %s (their input %s)", - type_to_string(tmpctx, struct channel_id, &info->cid), - type_to_string(tmpctx, struct amount_sat, - &info->our_funding), - type_to_string(tmpctx, struct amount_sat, - &info->their_funding)); + fmt_channel_id(tmpctx, &info->cid), + fmt_amount_sat(tmpctx, info->our_funding), + fmt_amount_sat(tmpctx, info->their_funding)); /* If there's prevouts, we compose a psbt with those first, * then add more funds for anything missing */ @@ -732,8 +727,7 @@ listfunds_success(struct command *cmd, json_add_bool(req->js, "nonwrapped", true); } json_add_string(req->js, "satoshi", - type_to_string(tmpctx, struct amount_sat, - &info->our_funding)); + fmt_amount_sat(tmpctx, info->our_funding)); json_add_string(req->js, "feerate", tal_fmt(tmpctx, "%"PRIu64"%s", info->funding_feerate_perkw, @@ -762,7 +756,7 @@ listfunds_failed(struct command *cmd, "Unable to fetch wallet funds info." " Continuing channel open to %s" " without our participation. err %.*s", - type_to_string(tmpctx, struct node_id, + fmt_node_id(tmpctx, &info->id), json_tok_full_len(error), json_tok_full(buf, error)); @@ -1068,7 +1062,7 @@ json_rbf_channel_call(struct command *cmd, &datastore_list_fail, info); chan_key = tal_fmt(cmd, "funder/%s", - type_to_string(cmd, struct channel_id, + fmt_channel_id(cmd, &info->cid)); json_add_string(req->js, "key", chan_key); return send_outreq(cmd->plugin, req); @@ -1093,7 +1087,7 @@ static struct command_result *json_disconnect(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Cleaning up inflights for peer id %s", - type_to_string(tmpctx, struct node_id, &id)); + fmt_node_id(tmpctx, &id)); cleanup_peer_pending_opens(&id); @@ -1117,7 +1111,7 @@ delete_channel_from_datastore(struct command *cmd, NULL); json_add_string(req->js, "key", tal_fmt(cmd, "funder/%s", - type_to_string(cmd, struct channel_id, cid))); + fmt_channel_id(cmd, cid))); return send_outreq(cmd->plugin, req); } @@ -1153,7 +1147,7 @@ static struct command_result *json_channel_state_changed(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Cleaning up datastore for channel_id %s", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); return delete_channel_from_datastore(cmd, &cid); } @@ -1179,7 +1173,7 @@ static struct command_result *json_channel_open_failed(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "Cleaning up inflight for channel_id %s", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); open = find_channel_pending_open(&cid); if (open) @@ -1460,7 +1454,7 @@ static void tell_lightningd_lease_rates(struct plugin *p, mval = amount_msat(rates->lease_fee_base_sat * 1000); json_out_addstr(jout, "lease_fee_base_msat", - type_to_string(tmpctx, struct amount_msat, &mval)); + fmt_amount_msat(tmpctx, mval)); json_out_add(jout, "lease_fee_basis", false, "%d", rates->lease_fee_basis); @@ -1469,7 +1463,7 @@ static void tell_lightningd_lease_rates(struct plugin *p, mval = amount_msat(rates->channel_fee_max_base_msat); json_out_addstr(jout, "channel_fee_max_base_msat", - type_to_string(tmpctx, struct amount_msat, &mval)); + fmt_amount_msat(tmpctx, mval)); json_out_add(jout, "channel_fee_max_proportional_thousandths", false, "%d", rates->channel_fee_max_proportional_thousandths); diff --git a/plugins/funder_policy.c b/plugins/funder_policy.c index 9ac79f40fba0..8a6196db8f68 100644 --- a/plugins/funder_policy.c +++ b/plugins/funder_policy.c @@ -43,7 +43,7 @@ const char *funder_policy_desc(const tal_t *ctx, struct amount_sat amt = amount_sat(policy->mod); return tal_fmt(ctx, "%s (%s)", funder_opt_name(policy->opt), - type_to_string(ctx, struct amount_sat, &amt)); + fmt_amount_sat(ctx, amt)); } else return tal_fmt(ctx, "%s (%"PRIu64"%%)", funder_opt_name(policy->opt), policy->mod); @@ -239,10 +239,8 @@ calculate_our_funding(struct funder_policy *policy, *our_funding = AMOUNT_SAT(0); return tal_fmt(tmpctx, "No space available in channel." " channel_max %s, their_funding %s", - type_to_string(tmpctx, struct amount_sat, - &channel_max), - type_to_string(tmpctx, struct amount_sat, - &their_funding)); + fmt_amount_sat(tmpctx, channel_max), + fmt_amount_sat(tmpctx, their_funding)); } /* Figure out actual available funds, given our requested @@ -253,10 +251,8 @@ calculate_our_funding(struct funder_policy *policy, *our_funding = AMOUNT_SAT(0); return tal_fmt(tmpctx, "Reserve tank too low." " available_funds %s, reserve_tank requires %s", - type_to_string(tmpctx, struct amount_sat, - &available_funds), - type_to_string(tmpctx, struct amount_sat, - &policy->reserve_tank)); + fmt_amount_sat(tmpctx, available_funds), + fmt_amount_sat(tmpctx, policy->reserve_tank)); } /* Are they funding enough ? */ @@ -265,10 +261,8 @@ calculate_our_funding(struct funder_policy *policy, return tal_fmt(tmpctx, "Peer's funding too little." " their_funding %s," " min_their_funding requires %s", - type_to_string(tmpctx, struct amount_sat, - &their_funding), - type_to_string(tmpctx, struct amount_sat, - &policy->min_their_funding)); + fmt_amount_sat(tmpctx, their_funding), + fmt_amount_sat(tmpctx, policy->min_their_funding)); } /* Are they funding too much ? */ @@ -277,10 +271,8 @@ calculate_our_funding(struct funder_policy *policy, return tal_fmt(tmpctx, "Peer's funding too much." " their_funding %s," " max_their_funding requires %s", - type_to_string(tmpctx, struct amount_sat, - &their_funding), - type_to_string(tmpctx, struct amount_sat, - &policy->max_their_funding)); + fmt_amount_sat(tmpctx, their_funding), + fmt_amount_sat(tmpctx, policy->max_their_funding)); } /* What's our amount, given our policy */ @@ -317,12 +309,10 @@ calculate_our_funding(struct funder_policy *policy, && amount_sat_less(*our_funding, requested_lease)) { return tal_fmt(tmpctx, "New amount (%s) is less than" " last (%s); peer requested a lease (%s)", - type_to_string(tmpctx, struct amount_sat, - our_funding), - type_to_string(tmpctx, struct amount_sat, - our_last_funding), - type_to_string(tmpctx, struct amount_sat, - &requested_lease)); + fmt_amount_sat(tmpctx, *our_funding), + fmt_amount_sat(tmpctx, + *our_last_funding), + fmt_amount_sat(tmpctx, requested_lease)); } } @@ -333,10 +323,8 @@ calculate_our_funding(struct funder_policy *policy, return tal_fmt(tmpctx, "Can't meet our min channel requirement." " our_funding %s," " per_channel_min requires %s", - type_to_string(tmpctx, struct amount_sat, - our_funding), - type_to_string(tmpctx, struct amount_sat, - &policy->per_channel_min)); + fmt_amount_sat(tmpctx, *our_funding), + fmt_amount_sat(tmpctx, policy->per_channel_min)); } return NULL; diff --git a/plugins/keysend.c b/plugins/keysend.c index 0a8683d1b972..1f0ef2cb7a32 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -555,8 +555,8 @@ static struct command_result *htlc_accepted_call(struct command *cmd, "payment_hash: SHA256(%s)=%s != %s. Ignoring keysend.", tal_hexstr(tmpctx, preimage_field->value, preimage_field->length), - type_to_string(tmpctx, struct sha256, &ki->payment_hash), - type_to_string(tmpctx, struct sha256, &payment_hash)); + fmt_sha256(tmpctx, &ki->payment_hash), + fmt_sha256(tmpctx, &payment_hash)); tal_free(ki); return htlc_accepted_continue(cmd, NULL); } @@ -573,7 +573,7 @@ static struct command_result *htlc_accepted_call(struct command *cmd, &htlc_accepted_invoice_failed, ki); - plugin_log(cmd->plugin, LOG_INFORM, "Inserting a new invoice for keysend with payment_hash %s", type_to_string(tmpctx, struct sha256, &payment_hash)); + plugin_log(cmd->plugin, LOG_INFORM, "Inserting a new invoice for keysend with payment_hash %s", fmt_sha256(tmpctx, &payment_hash)); json_add_string(req->js, "amount_msat", "any"); json_add_string(req->js, "label", ki->label); if (desc_field) { diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 3295018d573e..54a9bcbc4fd8 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -255,10 +255,8 @@ struct payment_tree_result payment_collect_result(struct payment *p) paymod_err( p, "Number overflow summing partial payments: %s + %s", - type_to_string(tmpctx, struct amount_msat, - &res.sent), - type_to_string(tmpctx, struct amount_msat, - &cres.sent)); + fmt_amount_msat(tmpctx, res.sent), + fmt_amount_msat(tmpctx, cres.sent)); /* Bubble up the first preimage we see. */ if (res.preimage == NULL && cres.preimage != NULL) @@ -387,13 +385,11 @@ static void channel_hints_update(struct payment *p, "Updated a channel hint for %s: " "enabled %s, " "estimated capacity %s", - type_to_string(tmpctx, - struct short_channel_id_dir, + fmt_short_channel_id_dir(tmpctx, &hint->scid), hint->enabled ? "true" : "false", - type_to_string(tmpctx, - struct amount_msat, - &hint->estimated_capacity)); + fmt_amount_msat(tmpctx, + hint->estimated_capacity)); return; } } @@ -416,10 +412,9 @@ static void channel_hints_update(struct payment *p, paymod_log( p, LOG_DBG, "Added a channel hint for %s: enabled %s, estimated capacity %s", - type_to_string(tmpctx, struct short_channel_id_dir, &newhint.scid), + fmt_short_channel_id_dir(tmpctx, &newhint.scid), newhint.enabled ? "true" : "false", - type_to_string(tmpctx, struct amount_msat, - &newhint.estimated_capacity)); + fmt_amount_msat(tmpctx, newhint.estimated_capacity)); } static void payment_exclude_most_expensive(struct payment *p) @@ -465,9 +460,8 @@ static struct amount_msat payment_route_fee(struct payment *p) LOG_BROKEN, "gossipd returned a route with a negative fee: sending %s " "to deliver %s", - type_to_string(tmpctx, struct amount_msat, - &p->route[0].amount), - type_to_string(tmpctx, struct amount_msat, &p->our_amount)); + fmt_amount_msat(tmpctx, p->route[0].amount), + fmt_amount_msat(tmpctx, p->our_amount)); abort(); } return fee; @@ -557,17 +551,14 @@ static bool payment_chanhints_apply_route(struct payment *p, bool remove) "Could not update the channel hint " "for %s. Could be a concurrent " "`getroute` call.", - type_to_string(tmpctx, - struct short_channel_id_dir, - &curhint->scid)); + fmt_short_channel_id_dir(tmpctx, + &curhint->scid)); paymod_log( p, LOG_DBG, "Capacity: estimated_capacity=%s, hop_amount=%s. " "local=%s%s", - type_to_string(tmpctx, struct amount_msat, - &curhint->estimated_capacity), - type_to_string(tmpctx, struct amount_msat, - &curhop->amount), + fmt_amount_msat(tmpctx, curhint->estimated_capacity), + fmt_amount_msat(tmpctx, curhop->amount), curhint->local ? "Y" : "N", curhint->local ? tal_fmt(tmpctx, " HTLC Budget: htlc_budget=%d", @@ -882,8 +873,7 @@ static struct command_result *payment_getroute(struct payment *p) put_gossmap(p); payment_fail( p, "Unknown destination %s", - type_to_string(tmpctx, struct node_id, - p->getroute->destination)); + fmt_node_id(tmpctx, p->getroute->destination)); /* Let payment_finished_ handle this, so we mark it as pending */ return command_still_pending(p->cmd); @@ -927,9 +917,8 @@ static struct command_result *payment_getroute(struct payment *p) p->route = tal_free(p->route); payment_fail( p, "Fee exceeds our fee budget: %s > %s, discarding route", - type_to_string(tmpctx, struct amount_msat, &fee), - type_to_string(tmpctx, struct amount_msat, - &p->constraints.fee_budget)); + fmt_amount_msat(tmpctx, fee), + fmt_amount_msat(tmpctx, p->constraints.fee_budget)); return command_still_pending(p->cmd); } @@ -1161,16 +1150,15 @@ static void report_tampering(struct payment *p, paymod_log(p, LOG_UNUSUAL, "Node #%zu (%s) claimed we sent them invalid %s", report_pos + 1, - type_to_string(tmpctx, struct node_id, id), + fmt_node_id(tmpctx, id), style); } else { paymod_log(p, LOG_UNUSUAL, "Node #%zu (%s) claimed #%zu (%s) sent them invalid %s", report_pos + 1, - type_to_string(tmpctx, struct node_id, id), + fmt_node_id(tmpctx, id), report_pos, - type_to_string(tmpctx, struct node_id, - &p->route[report_pos-1].node_id), + fmt_node_id(tmpctx, &p->route[report_pos-1].node_id), style); } } @@ -1244,7 +1232,7 @@ handle_final_failure(struct command *cmd, paymod_log(p, LOG_DBG, "Final node %s reported %04x (%s) on route %s", - type_to_string(tmpctx, struct node_id, final_id), + fmt_node_id(tmpctx, final_id), failcode, onion_wire_name(failcode), p->routetxt); @@ -1317,7 +1305,7 @@ handle_final_failure(struct command *cmd, strange_error: paymod_log(p, LOG_UNUSUAL, "Final node %s reported strange error code %04x (%s)", - type_to_string(tmpctx, struct node_id, final_id), + fmt_node_id(tmpctx, final_id), failcode, describe_failcode(tmpctx, failcode)); error: @@ -1343,10 +1331,9 @@ handle_intermediate_failure(struct command *cmd, paymod_log(p, LOG_DBG, "Intermediate node %s reported %04x (%s) at %s on route %s", - type_to_string(tmpctx, struct node_id, errnode), + fmt_node_id(tmpctx, errnode), failcode, onion_wire_name(failcode), - type_to_string(tmpctx, struct short_channel_id, - &errchan->scid), + fmt_short_channel_id(tmpctx, errchan->scid), p->routetxt); /* We use an exhaustive switch statement here so you get a compile @@ -1423,7 +1410,7 @@ handle_intermediate_failure(struct command *cmd, strange_error: paymod_log(p, LOG_UNUSUAL, "Intermediate node %s reported strange error code %04x (%s)", - type_to_string(tmpctx, struct node_id, errnode), + fmt_node_id(tmpctx, errnode), failcode, describe_failcode(tmpctx, failcode)); error: @@ -1817,8 +1804,7 @@ static void payment_compute_onion_payloads(struct payment *p) &p->route[i + 1], false, NULL, NULL); tal_append_fmt(&routetxt, "%s -> ", - type_to_string(tmpctx, struct short_channel_id, - &p->route[i].scid)); + fmt_short_channel_id(tmpctx, p->route[i].scid)); } /* If we're headed to a blinded path, connect that now. */ @@ -1829,8 +1815,8 @@ static void payment_compute_onion_payloads(struct payment *p) root->blindedfinalamount, root->blindedfinalcltv); tal_append_fmt(&routetxt, "%s -> blinded path (%zu hops)", - type_to_string(tmpctx, struct short_channel_id, - &p->route[hopcount-1].scid), + fmt_short_channel_id(tmpctx, + p->route[hopcount-1].scid), tal_count(root->blindedpath->path)); } else { /* Final hop */ @@ -1840,8 +1826,8 @@ static void payment_compute_onion_payloads(struct payment *p) root->payment_secret, root->payment_metadata); tal_append_fmt(&routetxt, "%s", - type_to_string(tmpctx, struct short_channel_id, - &p->route[hopcount - 1].scid)); + fmt_short_channel_id(tmpctx, + p->route[hopcount - 1].scid)); } paymod_log(p, LOG_DBG, @@ -2400,7 +2386,7 @@ static inline void retry_step_cb(struct retry_mod_data *rd, p, LOG_INFORM, "Payment deadline expired, not retrying (partial-)payment " "%s/%d", - type_to_string(tmpctx, struct sha256, p->payment_hash), + fmt_sha256(tmpctx, p->payment_hash), p->partid); root->abort = true; return payment_continue(p); @@ -2429,9 +2415,9 @@ static inline void retry_step_cb(struct retry_mod_data *rd, paymod_log( p, LOG_DBG, "Retrying %s/%d (%s), new partid %d. %d attempts left\n", - type_to_string(tmpctx, struct sha256, p->payment_hash), + fmt_sha256(tmpctx, p->payment_hash), p->partid, - type_to_string(tmpctx, struct amount_msat, &p->our_amount), + fmt_amount_msat(tmpctx, p->our_amount), subpayment->partid, rdata->retries - 1); } @@ -2585,14 +2571,14 @@ static struct route_info **filter_routehints(struct gossmap *map, "Removed routehint %zu because " "entrypoint %s is unknown. ", i, - type_to_string(tmpctx, struct node_id, - &hints[i][0].pubkey)); + fmt_node_id(tmpctx, + &hints[i][0].pubkey)); plugin_log(p->plugin, LOG_DBG, "Removed routehint %zu because " "entrypoint %s is unknown. ", i, - type_to_string(tmpctx, struct node_id, - &hints[i][0].pubkey)); + fmt_node_id(tmpctx, + &hints[i][0].pubkey)); tal_arr_remove(&hints, i); i--; continue; @@ -2609,14 +2595,14 @@ static struct route_info **filter_routehints(struct gossmap *map, "Removed routehint %zu because " "entrypoint %s is unreachable. ", i, - type_to_string(tmpctx, struct node_id, - &hints[i][0].pubkey)); + fmt_node_id(tmpctx, + &hints[i][0].pubkey)); plugin_log(p->plugin, LOG_DBG, "Removed routehint %zu because " "entrypoint %s is unreachable. ", i, - type_to_string(tmpctx, struct node_id, - &hints[i][0].pubkey)); + fmt_node_id(tmpctx, + &hints[i][0].pubkey)); tal_arr_remove(&hints, i); i--; } @@ -2810,10 +2796,9 @@ static void routehint_pre_getroute(struct routehints_data *d, struct payment *p) tal_count(d->current_routehint)); paymod_log( p, LOG_DBG, "Using routehint %s (%s) cltv_delta=%d", - type_to_string(tmpctx, struct node_id, - &d->current_routehint->pubkey), - type_to_string(tmpctx, struct short_channel_id, - &d->current_routehint->short_channel_id), + fmt_node_id(tmpctx, &d->current_routehint->pubkey), + fmt_short_channel_id(tmpctx, + d->current_routehint->short_channel_id), d->current_routehint->cltv_expiry_delta); /* Exclude the entrypoint to the routehint, so we don't end up @@ -2881,7 +2866,7 @@ static void routehint_check_reachable(struct payment *p) p, "Destination %s is not reachable directly and " "all routehints were unusable.", - type_to_string(tmpctx, struct node_id, p->destination)); + fmt_node_id(tmpctx, p->destination)); put_gossmap(p); return; } @@ -3072,8 +3057,8 @@ static void exemptfee_cb(struct exemptfee_data *d, struct payment *p) p, LOG_INFORM, "Payment fee constraint %s is below exemption threshold, " "allowing a maximum fee of %s", - type_to_string(tmpctx, struct amount_msat, &p->constraints.fee_budget), - type_to_string(tmpctx, struct amount_msat, &d->amount)); + fmt_amount_msat(tmpctx, p->constraints.fee_budget), + fmt_amount_msat(tmpctx, d->amount)); p->constraints.fee_budget = d->amount; p->start_constraints->fee_budget = d->amount; } @@ -3233,9 +3218,8 @@ static struct command_result *shadow_route_listchannels(struct command *cmd, p, LOG_DBG, "Adding shadow_route hop over channel %s: adding %s " "in fees and %d CLTV delta", - type_to_string(tmpctx, struct short_channel_id, - &best->short_channel_id), - type_to_string(tmpctx, struct amount_msat, &best_fee), + fmt_short_channel_id(tmpctx, best->short_channel_id), + fmt_amount_msat(tmpctx, best_fee), best->cltv_expiry_delta); d->destination = best->pubkey; @@ -3259,12 +3243,11 @@ static struct command_result *shadow_route_listchannels(struct command *cmd, "for shadow route extension. " "payment fee budget %s, modifier " "fee budget %s, shadow fee to add %s", - type_to_string(tmpctx, struct amount_msat, - &p->constraints.fee_budget), - type_to_string(tmpctx, struct amount_msat, - &d->constraints.fee_budget), - type_to_string(tmpctx, struct amount_msat, - &best_fee)); + fmt_amount_msat(tmpctx, + p->constraints.fee_budget), + fmt_amount_msat(tmpctx, + d->constraints.fee_budget), + fmt_amount_msat(tmpctx, best_fee)); } next: @@ -3341,8 +3324,7 @@ static void direct_pay_override(struct payment *p) { paymod_log(p, LOG_DBG, "Found a direct channel (%s) with sufficient " "capacity, skipping route computation.", - type_to_string(tmpctx, struct short_channel_id_dir, - &hint->scid)); + fmt_short_channel_id_dir(tmpctx, &hint->scid)); payment_set_step(p, PAYMENT_STEP_GOT_ROUTE); } @@ -3696,11 +3678,9 @@ static void adaptive_splitter_cb(struct adaptive_split_mod_data *d, struct payme "new partid %"PRIu32" (%s), " "new partid %"PRIu32" (%s)", a->partid, - type_to_string(tmpctx, struct amount_msat, - &a->our_amount), + fmt_amount_msat(tmpctx, a->our_amount), b->partid, - type_to_string(tmpctx, struct amount_msat, - &b->our_amount)); + fmt_amount_msat(tmpctx, b->our_amount)); /* Take note that we now have an additional split that * may end up using an HTLC. */ @@ -3709,10 +3689,9 @@ static void adaptive_splitter_cb(struct adaptive_split_mod_data *d, struct payme paymod_log(p, LOG_INFORM, "Lower limit of adaptive splitter reached " "(%s < %s), not splitting further.", - type_to_string(tmpctx, struct amount_msat, - &p->our_amount), - type_to_string(tmpctx, struct amount_msat, - &MPP_ADAPTIVE_LOWER_LIMIT)); + fmt_amount_msat(tmpctx, p->our_amount), + fmt_amount_msat(tmpctx, + MPP_ADAPTIVE_LOWER_LIMIT)); } } payment_continue(p); @@ -3787,7 +3766,7 @@ payee_incoming_limit_count(struct command *cmd, why = tal_fmt(tmpctx, "Destination %s has %zd channels, " "assuming %d HTLCs per channel", - type_to_string(tmpctx, struct node_id, + fmt_node_id(tmpctx, p->destination), num_channels, ASSUMED_MAX_HTLCS_PER_CHANNEL); diff --git a/plugins/offers_inv_hook.c b/plugins/offers_inv_hook.c index ebe43977ac1f..49b447f51da8 100644 --- a/plugins/offers_inv_hook.c +++ b/plugins/offers_inv_hook.c @@ -98,8 +98,8 @@ static struct command_result *pay_done(struct command *cmd, plugin_log(cmd->plugin, LOG_INFORM, "Payed out %s for invreq %s: %.*s", - type_to_string(tmpctx, struct amount_msat, &msat), - type_to_string(tmpctx, struct sha256, &inv->invreq_id), + fmt_amount_msat(tmpctx, msat), + fmt_sha256(tmpctx, &inv->invreq_id), json_tok_full_len(result), json_tok_full(buf, result)); return command_hook_success(cmd); @@ -145,7 +145,7 @@ static struct command_result *listinvreqs_done(struct command *cmd, /* Since the invreq_id hashes all fields < 160, we know it matches */ if (arr->size == 0) return fail_inv(cmd, inv, "Unknown invoice_request %s", - type_to_string(tmpctx, struct sha256, &inv->invreq_id)); + fmt_sha256(tmpctx, &inv->invreq_id)); activetok = json_get_member(buf, arr + 1, "active"); if (!activetok) { @@ -186,8 +186,8 @@ static struct command_result *listinvreqs_done(struct command *cmd, amt = amount_msat(*inv->inv->invoice_amount); plugin_log(cmd->plugin, LOG_INFORM, "Attempting payment of %s for invoice_request %s", - type_to_string(tmpctx, struct amount_msat, &amt), - type_to_string(tmpctx, struct sha256, &inv->invreq_id)); + fmt_amount_msat(tmpctx, amt), + fmt_sha256(tmpctx, &inv->invreq_id)); req = jsonrpc_request_start(cmd->plugin, cmd, "pay", pay_done, pay_error, inv); diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 1a52a3cdd1f7..f263fff1411e 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -140,8 +140,8 @@ static void json_add_label(struct json_stream *js, char *label; label = tal_fmt(tmpctx, "%s-%s-%u", - type_to_string(tmpctx, struct sha256, offer_id), - type_to_string(tmpctx, struct pubkey, payer_key), + fmt_sha256(tmpctx, offer_id), + fmt_pubkey(tmpctx, payer_key), counter); json_add_string(js, "label", label); } @@ -717,8 +717,8 @@ static struct command_result *handle_amount_and_recurrence(struct command *cmd, if (ir->invreq->offer_amount && ir->invreq->invreq_amount) { if (amount_msat_less(amount_msat(*ir->invreq->invreq_amount), base_inv_amount)) { return fail_invreq(cmd, ir, "Amount must be at least %s", - type_to_string(tmpctx, struct amount_msat, - &base_inv_amount)); + fmt_amount_msat(tmpctx, + base_inv_amount)); } /* BOLT-offers #12: * - MAY fail the request if `invreq_amount`.`msat` greatly exceeds @@ -728,8 +728,8 @@ static struct command_result *handle_amount_and_recurrence(struct command *cmd, if (amount_msat_greater(amount_msat_div(amount_msat(*ir->invreq->invreq_amount), 5), base_inv_amount)) { return fail_invreq(cmd, ir, "Amount vastly exceeds %s", - type_to_string(tmpctx, struct amount_msat, - &base_inv_amount)); + fmt_amount_msat(tmpctx, + base_inv_amount)); } base_inv_amount = amount_msat(*ir->invreq->invreq_amount); } diff --git a/plugins/pay.c b/plugins/pay.c index 8062bf650246..980c752f4e29 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -339,8 +339,8 @@ static void add_amount_sent(struct plugin *p, plugin_log(p, LOG_BROKEN, "Cannot add amount_sent_msat for %s: %s + %s", invstring, - type_to_string(tmpctx, struct amount_msat, &mpp->amount_sent), - type_to_string(tmpctx, struct amount_msat, &sent)); + fmt_amount_msat(tmpctx, mpp->amount_sent), + fmt_amount_msat(tmpctx, sent)); msattok = json_get_member(buf, t, "amount_msat"); @@ -366,8 +366,8 @@ static void add_amount_sent(struct plugin *p, plugin_log(p, LOG_BROKEN, "Cannot add amount_msat for %s: %s + %s", invstring, - type_to_string(tmpctx, struct amount_msat, mpp->amount), - type_to_string(tmpctx, struct amount_msat, &sent)); + fmt_amount_msat(tmpctx, *mpp->amount), + fmt_amount_msat(tmpctx, sent)); } static void add_new_entry(struct json_stream *ret, diff --git a/plugins/recover.c b/plugins/recover.c index f83895ec63d5..3ad20226a660 100644 --- a/plugins/recover.c +++ b/plugins/recover.c @@ -138,7 +138,8 @@ static void do_check_gossip (struct command *cmd) json_add_node_id(req->js, "id", &peer_id); - plugin_log(plugin, LOG_DBG, "Connecting to: %s", type_to_string(tmpctx, struct node_id, &peer_id)); + plugin_log(plugin, LOG_DBG, "Connecting to: %s", + fmt_node_id(tmpctx, &peer_id)); send_outreq(plugin, req); } diff --git a/plugins/renepay/flow.c b/plugins/renepay/flow.c index f138f4dc64ac..9fbfb5ae718b 100644 --- a/plugins/renepay/flow.c +++ b/plugins/renepay/flow.c @@ -23,7 +23,7 @@ static char *chan_extra_not_found_error(const tal_t *ctx, { return tal_fmt(ctx, "chan_extra for scid=%s not found in chan_extra_map", - type_to_string(ctx, struct short_channel_id, scid)); + fmt_short_channel_id(ctx, *scid)); } bool chan_extra_is_busy(const struct chan_extra *const ce) @@ -43,12 +43,12 @@ const char *fmt_chan_extra_map(const tal_t *ctx, ch=chan_extra_map_next(chan_extra_map,&it)) { const char *scid_str = - type_to_string(this_ctx,struct short_channel_id,&ch->scid); + fmt_short_channel_id(this_ctx, ch->scid); for(int dir=0;dir<2;++dir) { tal_append_fmt(&buff,"%s[%d]:(%s,%s)\n",scid_str,dir, - type_to_string(this_ctx,struct amount_msat,&ch->half[dir].known_min), - type_to_string(this_ctx,struct amount_msat,&ch->half[dir].known_max)); + fmt_amount_msat(this_ctx, ch->half[dir].known_min), + fmt_amount_msat(this_ctx, ch->half[dir].known_max)); } } tal_free(this_ctx); @@ -517,9 +517,8 @@ static bool chan_extra_adjust_half(const tal_t *ctx, struct chan_extra *ce, if(fail) *fail = tal_fmt( ctx, "cannot substract capacity=%s and known_min=%s", - type_to_string(ctx, struct amount_msat, &ce->capacity), - type_to_string(ctx, struct amount_msat, - &ce->half[!dir].known_min)); + fmt_amount_msat(ctx, ce->capacity), + fmt_amount_msat(ctx, ce->half[!dir].known_min)); goto function_fail; } if (!amount_msat_sub(&new_known_min, ce->capacity, @@ -527,9 +526,8 @@ static bool chan_extra_adjust_half(const tal_t *ctx, struct chan_extra *ce, if(fail) *fail = tal_fmt( ctx, "cannot substract capacity=%s and known_max=%s", - type_to_string(ctx, struct amount_msat, &ce->capacity), - type_to_string(ctx, struct amount_msat, - &ce->half[!dir].known_max)); + fmt_amount_msat(ctx, ce->capacity), + fmt_amount_msat(ctx, ce->half[!dir].known_max)); goto function_fail; } @@ -555,8 +553,8 @@ static bool chan_extra_can_send_(const tal_t *ctx, struct chan_extra *ce, ctx, "can send amount (%s) is larger than the " "channel's capacity (%s)", - type_to_string(ctx, struct amount_msat, &x), - type_to_string(ctx, struct amount_msat, &ce->capacity)); + fmt_amount_msat(ctx, x), + fmt_amount_msat(ctx, ce->capacity)); goto function_fail; } @@ -636,10 +634,8 @@ bool chan_extra_cannot_send(const tal_t *ctx, if(fail) *fail = tal_fmt( ctx, "htlc_total=%s is less than 0msats in channel %s", - type_to_string(this_ctx, struct amount_msat, - &ce->half[scidd->dir].htlc_total), - type_to_string(this_ctx, struct short_channel_id, - &scidd->scid)); + fmt_amount_msat(this_ctx, ce->half[scidd->dir].htlc_total), + fmt_short_channel_id(this_ctx, scidd->scid)); goto function_fail; } @@ -690,8 +686,8 @@ static bool chan_extra_set_liquidity_(const tal_t *ctx, struct chan_extra *ce, ctx, "tried to set liquidity (%s) to a value greater than " "channel's capacity (%s)", - type_to_string(this_ctx, struct amount_msat, &x), - type_to_string(this_ctx, struct amount_msat, &ce->capacity)); + fmt_amount_msat(this_ctx, x), + fmt_amount_msat(this_ctx, ce->capacity)); goto function_fail; } @@ -775,8 +771,8 @@ bool chan_extra_sent_success(const tal_t *ctx, ctx, "sent success (%s) is larger than the " "channel's capacity (%s)", - type_to_string(this_ctx, struct amount_msat, &x), - type_to_string(this_ctx, struct amount_msat, &ce->capacity)); + fmt_amount_msat(this_ctx, x), + fmt_amount_msat(this_ctx, ce->capacity)); goto function_fail; } @@ -1019,8 +1015,8 @@ static double edge_probability(const tal_t *ctx, struct amount_msat min, if(fail) *fail = tal_fmt(ctx, "in_flight=%s cannot be greater than known_max+1=%s", - type_to_string(this_ctx, struct amount_msat, &in_flight), - type_to_string(this_ctx, struct amount_msat, &B) + fmt_amount_msat(this_ctx, in_flight), + fmt_amount_msat(this_ctx, B) ); goto function_fail; } @@ -1036,8 +1032,8 @@ static double edge_probability(const tal_t *ctx, struct amount_msat min, { if(fail) *fail = tal_fmt(ctx,"known_max+1=%s must be greater than known_min=%s", - type_to_string(this_ctx, struct amount_msat, &B), - type_to_string(this_ctx, struct amount_msat, &A)); + fmt_amount_msat(this_ctx, B), + fmt_amount_msat(this_ctx, A)); goto function_fail; } struct amount_msat numerator; // MAX(0,B-f) @@ -1078,11 +1074,9 @@ bool remove_completed_flow(const tal_t *ctx, const struct gossmap *gossmap, "could not substract HTLC amounts, " "total htlc amount = %s, " "flow->amounts[%zu] = %s.", - type_to_string(this_ctx, struct amount_msat, - &h->htlc_total), + fmt_amount_msat(this_ctx, h->htlc_total), i, - type_to_string(this_ctx, struct amount_msat, - &flow->amounts[i])); + fmt_amount_msat(this_ctx, flow->amounts[i])); goto function_fail; } if (h->num_htlcs == 0) @@ -1142,8 +1136,7 @@ bool commit_flow(const tal_t *ctx, const struct gossmap *gossmap, "could not add HTLC amounts, " "flow->amounts[%zu] = %s.", i, - type_to_string(this_ctx, struct amount_msat, - &flow->amounts[i])); + fmt_amount_msat(this_ctx, flow->amounts[i])); goto function_fail; } h->num_htlcs++; diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index f4320d63ce5f..0811b7253ad2 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -386,8 +386,8 @@ const char *try_paying(const tal_t *ctx, "%s (line %d) could not substract maxspend=%s and amount=%s.", __PRETTY_FUNCTION__, __LINE__, - type_to_string(tmpctx, struct amount_msat, &payment->maxspend), - type_to_string(tmpctx, struct amount_msat, &payment->amount)); + fmt_amount_msat(tmpctx, payment->maxspend), + fmt_amount_msat(tmpctx, payment->amount)); } /* Fees spent so far */ @@ -397,8 +397,8 @@ const char *try_paying(const tal_t *ctx, "%s (line %d) could not substract total_sent=%s and total_delivering=%s.", __PRETTY_FUNCTION__, __LINE__, - type_to_string(tmpctx, struct amount_msat, &payment->total_sent), - type_to_string(tmpctx, struct amount_msat, &payment->total_delivering)); + fmt_amount_msat(tmpctx, payment->total_sent), + fmt_amount_msat(tmpctx, payment->total_delivering)); } /* Remaining fee budget. */ @@ -408,8 +408,8 @@ const char *try_paying(const tal_t *ctx, "%s (line %d) could not substract feebudget=%s and fees_spent=%s.", __PRETTY_FUNCTION__, __LINE__, - type_to_string(tmpctx, struct amount_msat, &feebudget), - type_to_string(tmpctx, struct amount_msat, &fees_spent)); + fmt_amount_msat(tmpctx, feebudget), + fmt_amount_msat(tmpctx, fees_spent)); } /* How much are we still trying to send? */ @@ -419,8 +419,8 @@ const char *try_paying(const tal_t *ctx, "%s (line %d) could not substract amount=%s and total_delivering=%s.", __PRETTY_FUNCTION__, __LINE__, - type_to_string(tmpctx, struct amount_msat, &payment->amount), - type_to_string(tmpctx, struct amount_msat, &payment->total_delivering)); + fmt_amount_msat(tmpctx, payment->amount), + fmt_amount_msat(tmpctx, payment->total_delivering)); } // plugin_log(pay_plugin->plugin,LOG_DBG,fmt_chan_extra_map(tmpctx,pay_plugin->chan_extra_map)); @@ -739,7 +739,7 @@ payment_listsendpays_previous( plugin_log(pay_plugin->plugin,LOG_DBG, "this part is complete then " "complete_msat = %s", - type_to_string(tmpctx,struct amount_msat,&complete_msat)); + fmt_amount_msat(tmpctx, complete_msat)); } else if (streq(status, "pending")) { /* If we have more than one pending group, something went wrong! */ if (pending_group_id != INVALID_ID @@ -792,7 +792,7 @@ payment_listsendpays_previous( "delivering = %s, " "last_partid = %"PRIu64, pending_group_id, - type_to_string(tmpctx,struct amount_msat,&payment->total_delivering), + fmt_amount_msat(tmpctx, payment->total_delivering), max_pending_partid); if(amount_msat_greater_eq(payment->total_delivering,payment->amount)) @@ -1234,8 +1234,8 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf, "Failure to forward amount %s in channel %s, " "state change %s -> %s", fmt_amount_msat(tmpctx, pf->amounts[erridx]), - type_to_string(tmpctx, struct short_channel_id_dir, - &pf->path_scidds[erridx]), + fmt_short_channel_id_dir(tmpctx, + &pf->path_scidds[erridx]), old_state, fmt_chan_extra_details(tmpctx, pay_plugin->chan_extra_map, diff --git a/plugins/renepay/pay_flow.c b/plugins/renepay/pay_flow.c index d7d519dc65ca..f8b67503122f 100644 --- a/plugins/renepay/pay_flow.c +++ b/plugins/renepay/pay_flow.c @@ -60,9 +60,9 @@ static void remove_htlc_payflow( "half total htlc amount = %s, " "pf->amounts[%lld] = %s.", __PRETTY_FUNCTION__, - type_to_string(tmpctx, struct amount_msat, &h->htlc_total), + fmt_amount_msat(tmpctx, h->htlc_total), i, - type_to_string(tmpctx, struct amount_msat, &pf->amounts[i])); + fmt_amount_msat(tmpctx, pf->amounts[i])); } if (h->num_htlcs == 0) { @@ -95,7 +95,7 @@ static void commit_htlc_payflow( "pf->amounts[%lld] = %s.", __PRETTY_FUNCTION__, i, - type_to_string(tmpctx, struct amount_msat, &pf->amounts[i])); + fmt_amount_msat(tmpctx, pf->amounts[i])); } h->num_htlcs++; } @@ -154,9 +154,8 @@ static u32 shadow_one_flow(const struct gossmap *gossmap, if (!amount_msat_sub(shadow_fee, amount, f->amounts[numpath-1])) plugin_err(pay_plugin->plugin, "Failed to calc shadow fee: %s - %s", - type_to_string(tmpctx, struct amount_msat, &amount), - type_to_string(tmpctx, struct amount_msat, - &f->amounts[numpath-1])); + fmt_amount_msat(tmpctx, amount), + fmt_amount_msat(tmpctx, f->amounts[numpath-1])); return shadow_delay; } @@ -245,17 +244,14 @@ static u32 *shadow_additions(const tal_t *ctx, "No shadow fee for flow %zu/%zu:" " fee would add %s to %s, exceeding budget %s.", i, tal_count(flows), - type_to_string(tmpctx, struct amount_msat, - &shadow_fee), - type_to_string(tmpctx, struct amount_msat, - &flows[i]->amounts[0]), - type_to_string(tmpctx, struct amount_msat, - &p->maxspend)); + fmt_amount_msat(tmpctx, shadow_fee), + fmt_amount_msat(tmpctx, + flows[i]->amounts[0]), + fmt_amount_msat(tmpctx, p->maxspend)); } else { payment_note(p, LOG_DBG, "No MPP, so added %s shadow fee", - type_to_string(tmpctx, struct amount_msat, - &shadow_fee)); + fmt_amount_msat(tmpctx, shadow_fee)); } } @@ -279,9 +275,8 @@ static const char *flow_path_annotated(const tal_t *ctx, char *s = tal_strdup(ctx, ""); for (size_t i = 0; i < tal_count(flow->path_scidds); i++) { tal_append_fmt(&s, "-%s%s->", - type_to_string(tmpctx, - struct short_channel_id_dir, - &flow->path_scidds[i]), + fmt_short_channel_id_dir(tmpctx, + &flow->path_scidds[i]), fmt_chan_extra_details(tmpctx, pay_plugin->chan_extra_map, &flow->path_scidds[i])); @@ -493,8 +488,7 @@ const char *add_payflows(const tal_t *ctx, struct payment *p, fail = tal_fmt( ctx, "minflow couldn't find a feasible flow for %s, %s", - type_to_string(tmpctx, struct amount_msat, - &amount_to_deliver), + fmt_amount_msat(tmpctx, amount_to_deliver), errmsg); goto function_fail; } @@ -533,7 +527,7 @@ const char *add_payflows(const tal_t *ctx, struct payment *p, "we have computed a set of %ld flows with " "probability %.3lf, fees %s and delay %ld", tal_count(flows), prob, - type_to_string(tmpctx, struct amount_msat, &fee), + fmt_amount_msat(tmpctx, fee), delay); if (amount_msat_greater(fee, feebudget)) { @@ -542,9 +536,8 @@ const char *add_payflows(const tal_t *ctx, struct payment *p, ctx, "Fee exceeds our fee budget, " "fee = %s (maxfee = %s)", - type_to_string(tmpctx, struct amount_msat, &fee), - type_to_string(tmpctx, struct amount_msat, - &feebudget)); + fmt_amount_msat(tmpctx, fee), + fmt_amount_msat(tmpctx, feebudget)); goto function_fail; } if (delay > p->maxdelay) { @@ -635,8 +628,8 @@ const char *flow_path_to_str(const tal_t *ctx, const struct pay_flow *flow) char *s = tal_strdup(ctx, ""); for (size_t i = 0; i < tal_count(flow->path_scidds); i++) { tal_append_fmt(&s, "-%s->", - type_to_string(tmpctx, struct short_channel_id, - &flow->path_scidds[i].scid)); + fmt_short_channel_id(tmpctx, + flow->path_scidds[i].scid)); } return s; } diff --git a/plugins/renepay/pay_flow.h b/plugins/renepay/pay_flow.h index c17e00dcf3d7..2b54dc0e2254 100644 --- a/plugins/renepay/pay_flow.h +++ b/plugins/renepay/pay_flow.h @@ -75,7 +75,7 @@ static inline const char* fmt_payflow_key( ctx, "key: groupid=%"PRIu64", partid=%"PRIu64", payment_hash=%s", k->groupid,k->partid, - type_to_string(ctx,struct sha256,&k->payment_hash)); + fmt_sha256(ctx, &k->payment_hash)); return str; } diff --git a/plugins/renepay/payment.c b/plugins/renepay/payment.c index 0fcb558a9b08..1ec331f4d8f0 100644 --- a/plugins/renepay/payment.c +++ b/plugins/renepay/payment.c @@ -96,7 +96,7 @@ void payflow_disable_chan(struct pay_flow *pf, str = tal_vfmt(tmpctx, fmt, ap); va_end(ap); payflow_note(pf, lvl, "disabling %s: %s", - type_to_string(tmpctx, struct short_channel_id, &scid), + fmt_short_channel_id(tmpctx, scid), str); tal_arr_expand(&pf->payment->disabled_scids, scid); } @@ -113,7 +113,7 @@ void payment_disable_chan(struct payment *p, str = tal_vfmt(tmpctx, fmt, ap); va_end(ap); payment_note(p, lvl, "disabling %s: %s", - type_to_string(tmpctx, struct short_channel_id, &scid), + fmt_short_channel_id(tmpctx, scid), str); tal_arr_expand(&p->disabled_scids, scid); } @@ -139,8 +139,8 @@ struct amount_msat payment_fees(const struct payment *p) if(!amount_msat_sub(&fees,sent,delivered)) plugin_err(pay_plugin->plugin, "Strange, sent amount (%s) is less than delivered (%s), aborting.", - type_to_string(tmpctx,struct amount_msat,&sent), - type_to_string(tmpctx,struct amount_msat,&delivered)); + fmt_amount_msat(tmpctx, sent), + fmt_amount_msat(tmpctx, delivered)); return fees; } @@ -184,8 +184,8 @@ void payment_assert_delivering_incomplete(const struct payment *p) { plugin_err(pay_plugin->plugin, "Strange, delivering (%s) is not smaller than amount (%s)", - type_to_string(tmpctx,struct amount_msat,&p->total_delivering), - type_to_string(tmpctx,struct amount_msat,&p->amount)); + fmt_amount_msat(tmpctx, p->total_delivering), + fmt_amount_msat(tmpctx, p->amount)); } } void payment_assert_delivering_all(const struct payment *p) @@ -194,8 +194,8 @@ void payment_assert_delivering_all(const struct payment *p) { plugin_err(pay_plugin->plugin, "Strange, delivering (%s) is less than amount (%s)", - type_to_string(tmpctx,struct amount_msat,&p->total_delivering), - type_to_string(tmpctx,struct amount_msat,&p->amount)); + fmt_amount_msat(tmpctx, p->total_delivering), + fmt_amount_msat(tmpctx, p->amount)); } } @@ -297,15 +297,12 @@ void payment_reconsider(struct payment *payment) i->payment_preimage)) { plugin_err(pay_plugin->plugin, "Impossible preimage clash for %s: %s and %s?", - type_to_string(tmpctx, - struct sha256, - &payment->payment_hash), - type_to_string(tmpctx, - struct preimage, - payment->preimage), - type_to_string(tmpctx, - struct preimage, - i->payment_preimage)); + fmt_sha256(tmpctx, + &payment->payment_hash), + fmt_preimage(tmpctx, + payment->preimage), + fmt_preimage(tmpctx, + i->payment_preimage)); } } else { payment->preimage = tal_dup(payment, struct preimage, @@ -337,13 +334,9 @@ void payment_reconsider(struct payment *payment) plugin_log(pay_plugin->plugin, LOG_BROKEN, "Destination %s succeeded payment %s" " (preimage %s) after previous final failure?", - type_to_string(tmpctx, struct node_id, - &payment->destination), - type_to_string(tmpctx, struct sha256, - &payment->payment_hash), - type_to_string(tmpctx, - struct preimage, - payment->preimage)); + fmt_node_id(tmpctx, &payment->destination), + fmt_sha256(tmpctx, &payment->payment_hash), + fmt_preimage(tmpctx, payment->preimage)); break; } @@ -370,9 +363,9 @@ void payment_reconsider(struct payment *payment) plugin_log(pay_plugin->plugin, LOG_BROKEN, "Destination %s failed payment %s with %u/%s" " after previous success?", - type_to_string(tmpctx, struct node_id, + fmt_node_id(tmpctx, &payment->destination), - type_to_string(tmpctx, struct sha256, + fmt_sha256(tmpctx, &payment->payment_hash), final_error, final_msg); break; @@ -401,7 +394,7 @@ void payment_reconsider(struct payment *payment) if (have_state[PAY_FLOW_FAILED_GOSSIP_PENDING]) { plugin_log(pay_plugin->plugin, LOG_DBG, "%s waiting on addgossip return", - type_to_string(tmpctx, struct sha256, + fmt_sha256(tmpctx, &payment->payment_hash)); return; } diff --git a/plugins/renepay/test/run-mcf-diamond.c b/plugins/renepay/test/run-mcf-diamond.c index a93347f8bafb..ee368894536d 100644 --- a/plugins/renepay/test/run-mcf-diamond.c +++ b/plugins/renepay/test/run-mcf-diamond.c @@ -58,7 +58,7 @@ static const char* print_flows( = gossmap_chan_scid(gossmap, flows[i]->path[j]); tal_append_fmt(&buff,"%s%s", j ? "->" : "", - type_to_string(this_ctx, struct short_channel_id, &scid)); + fmt_short_channel_id(this_ctx, scid)); } delivered = flows[i]->amounts[tal_count(flows[i]->amounts)-1]; if (!amount_msat_sub(&fee, flows[i]->amounts[0], delivered)) @@ -67,8 +67,8 @@ static const char* print_flows( } tal_append_fmt(&buff," prob %.2f, %s delivered with fee %s\n", flows[i]->success_prob, - type_to_string(this_ctx, struct amount_msat, &delivered), - type_to_string(this_ctx, struct amount_msat, &fee)); + fmt_amount_msat(this_ctx, delivered), + fmt_amount_msat(this_ctx, fee)); } tal_free(this_ctx); diff --git a/plugins/renepay/test/run-mcf.c b/plugins/renepay/test/run-mcf.c index 959eb3cdd130..1d5feb4ca223 100644 --- a/plugins/renepay/test/run-mcf.c +++ b/plugins/renepay/test/run-mcf.c @@ -307,15 +307,15 @@ static const char *print_flows( = gossmap_chan_scid(gossmap, flows[i]->path[j]); tal_append_fmt(&buff,"%s%s", j ? "->" : "", - type_to_string(this_ctx, struct short_channel_id, &scid)); + fmt_short_channel_id(this_ctx, scid)); } delivered = flows[i]->amounts[tal_count(flows[i]->amounts)-1]; if (!amount_msat_sub(&fee, flows[i]->amounts[0], delivered)) abort(); tal_append_fmt(&buff," prob %.2f, %s delivered with fee %s\n", flows[i]->success_prob, - type_to_string(this_ctx, struct amount_msat, &delivered), - type_to_string(this_ctx, struct amount_msat, &fee)); + fmt_amount_msat(this_ctx, delivered), + fmt_amount_msat(this_ctx, fee)); } tal_free(this_ctx); return buff; diff --git a/plugins/renepay/uncertainty_network.c b/plugins/renepay/uncertainty_network.c index 7dba292dac8f..a41470af4786 100644 --- a/plugins/renepay/uncertainty_network.c +++ b/plugins/renepay/uncertainty_network.c @@ -207,8 +207,8 @@ void uncertainty_network_flow_success( "Success forwarding amount %s in channel %s, " "state change %s -> %s", fmt_amount_msat(tmpctx, pf->amounts[i]), - type_to_string(tmpctx, struct short_channel_id_dir, - &pf->path_scidds[i]), + fmt_short_channel_id_dir(tmpctx, + &pf->path_scidds[i]), old_state, fmt_chan_extra_details(tmpctx, pay_plugin->chan_extra_map, @@ -263,8 +263,7 @@ void uncertainty_network_update_from_listpeerchannels(struct payment *p, tmpctx, "Failed to update channel from listpeerchannels " "scid=%s, missing total_msat", - type_to_string(tmpctx, struct short_channel_id, - &scidd->scid)); + fmt_short_channel_id(tmpctx, scidd->scid)); goto error; } if (!json_to_msat(buf, totaltok, &capacity)) { @@ -272,8 +271,7 @@ void uncertainty_network_update_from_listpeerchannels(struct payment *p, tmpctx, "Failed to update channel from listpeerchannels " "scid=%s, cannot parse total_msat", - type_to_string(tmpctx, struct short_channel_id, - &scidd->scid)); + fmt_short_channel_id(tmpctx, scidd->scid)); goto error; } @@ -312,9 +310,7 @@ void uncertainty_network_relax_fraction(struct chan_extra_map *chan_extra_map, plugin_err(pay_plugin->plugin, "chan_extra_relax_fraction failed for " "channel %s: %s", - type_to_string(tmpctx, - struct short_channel_id, - &ce->scid), + fmt_short_channel_id(tmpctx, ce->scid), fail); } } diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 6563bc68e5d0..d405c138e9e9 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -585,15 +585,14 @@ after_signpsbt(struct command *cmd, /* It should be well-formed? */ plugin_err(mfc->cmd->plugin, "mfc: could not set PSBT version: %s", - type_to_string(tmpctx, struct wally_psbt, - mfc->psbt)); + fmt_wally_psbt(tmpctx, mfc->psbt)); } if (!psbt_finalize(psbt)) plugin_err(mfc->cmd->plugin, "mfc %"PRIu64": Signed PSBT won't finalize" "%s", mfc->id, - type_to_string(tmpctx, struct wally_psbt, psbt)); + fmt_wally_psbt(tmpctx, psbt)); /* Replace the PSBT. */ @@ -860,8 +859,7 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc) /* It should be well-formed? */ plugin_err(mfc->cmd->plugin, "mfc: could not set PSBT version: %s", - type_to_string(tmpctx, struct wally_psbt, - mfc->psbt)); + fmt_wally_psbt(tmpctx, mfc->psbt)); } /* Construct a deck of destinations. */ @@ -906,11 +904,8 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc) if (v2_dest_count == 0) dest->outnum = outnum; tal_append_fmt(&content, "%s: %s", - type_to_string(tmpctx, struct node_id, - &dest->id), - type_to_string(tmpctx, - struct amount_sat, - &dest->amount)); + fmt_node_id(tmpctx, &dest->id), + fmt_amount_sat(tmpctx, dest->amount)); } if (v2_dest_count > 0) { @@ -938,16 +933,14 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc) plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64": funding tx %s: %s", mfc->id, - type_to_string(tmpctx, struct bitcoin_txid, - mfc->txid), + fmt_bitcoin_txid(tmpctx, mfc->txid), content); if (!psbt_set_version(mfc->psbt, psbt_version)) { /* It should be well-formed? */ plugin_err(mfc->cmd->plugin, "mfc: could not set PSBT version: %s", - type_to_string(tmpctx, struct wally_psbt, - mfc->psbt)); + fmt_wally_psbt(tmpctx, mfc->psbt)); } /* Now we can feed the TXID and outnums to the peer. */ @@ -1150,7 +1143,7 @@ fundchannel_start_dest(struct multifundchannel_destination *dest) if (dest->reserve) json_add_string( req->js, "reserve", - type_to_string(tmpctx, struct amount_sat, dest->reserve)); + fmt_amount_sat(tmpctx, *dest->reserve)); send_outreq(cmd->plugin, req); } @@ -1164,7 +1157,7 @@ perform_channel_start(struct multifundchannel_command *mfc) "mfc %"PRIu64": fundchannel_start parallel " "with PSBT %s", mfc->id, - type_to_string(tmpctx, struct wally_psbt, mfc->psbt)); + fmt_wally_psbt(tmpctx, mfc->psbt)); mfc->pending = tal_count(mfc->destinations); @@ -1396,8 +1389,7 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate) } } json_add_string(req->js, "satoshi", - type_to_string(tmpctx, struct amount_sat, - &sum)); + fmt_amount_sat(tmpctx, sum)); } json_add_string(req->js, "feerate", tal_fmt(tmpctx, "%uperkw", feerate)); diff --git a/plugins/spender/multiwithdraw.c b/plugins/spender/multiwithdraw.c index a47954fb1a58..0d7dc81d3737 100644 --- a/plugins/spender/multiwithdraw.c +++ b/plugins/spender/multiwithdraw.c @@ -194,9 +194,8 @@ json_multiwithdraw(struct command *cmd, return command_fail(cmd, FUND_OUTPUT_IS_DUST, "Output %s would be " "dust.", - type_to_string(tmpctx, - struct amount_sat, - &mw->outputs[i].amount)); + fmt_amount_sat(tmpctx, + mw->outputs[i].amount)); /* Begin. */ return start_mw(mw); @@ -380,8 +379,7 @@ static struct command_result *start_mw(struct multiwithdraw_command *mw) FUND_CANNOT_AFFORD, "Overflow in amount sum."); json_add_string(req->js, "satoshi", - type_to_string(tmpctx, struct amount_sat, - &sum)); + fmt_amount_sat(tmpctx, sum)); } json_add_string(req->js, "feerate", mw->feerate); json_add_u64(req->js, "startweight", startweight); @@ -468,9 +466,7 @@ mw_after_fundpsbt(struct command *cmd, if (amount_sat_less(excess_sat, chainparams->dust_limit)) return mw_fail(mw, FUND_OUTPUT_IS_DUST, "Output 'all' %s would be dust.", - type_to_string(tmpctx, - struct amount_sat, - &excess_sat)); + fmt_amount_sat(tmpctx, excess_sat)); /* Transfer the excess to the 'all' output. */ mw->outputs[all_index].amount = excess_sat; diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index fc0044675d69..9bc62228f8d7 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -442,8 +442,8 @@ openchannel_signed_dest(struct multifundchannel_destination *dest) "mfc %"PRIu64", dest %u: `openchannel_signed` %s " "psbt %s", mfc->id, dest->index, - type_to_string(tmpctx, struct channel_id, &dest->channel_id), - type_to_string(tmpctx, struct wally_psbt, dest->psbt)); + fmt_channel_id(tmpctx, &dest->channel_id), + fmt_wally_psbt(tmpctx, dest->psbt)); req = jsonrpc_request_start(cmd->plugin, cmd, @@ -564,7 +564,7 @@ static struct command_result *json_peer_sigs(struct command *cmd, plugin_log(cmd->plugin, LOG_DBG, "mfc ??: `openchannel_peer_sigs` no " "pending dest found for channel_id %s", - type_to_string(tmpctx, struct channel_id, &cid)); + fmt_channel_id(tmpctx, &cid)); return notification_handled(cmd); } @@ -582,9 +582,8 @@ static struct command_result *json_peer_sigs(struct command *cmd, "mfc %"PRIu64": Unable to combine signed " "PSBT with roll-up. " "Signed %s, prev %s", dest->mfc->id, - type_to_string(tmpctx, struct wally_psbt, psbt), - type_to_string(tmpctx, struct wally_psbt, - dest->mfc->psbt)); + fmt_wally_psbt(tmpctx, psbt), + fmt_wally_psbt(tmpctx, dest->mfc->psbt)); tal_wally_end(dest->mfc->psbt); @@ -634,8 +633,7 @@ funding_transaction_established(struct multifundchannel_command *mfc) plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64": funding tx %s", mfc->id, - type_to_string(tmpctx, struct bitcoin_txid, - mfc->txid)); + fmt_bitcoin_txid(tmpctx, mfc->txid)); /* If all we've got is v2 destinations, we're just waiting * for all of our peers to send us their sigs. @@ -795,7 +793,7 @@ openchannel_update_dest(struct multifundchannel_destination *dest) "with psbt %s", mfc->id, dest->index, fmt_node_id(tmpctx, &dest->id), - type_to_string(tmpctx, struct wally_psbt, dest->psbt)); + fmt_wally_psbt(tmpctx, dest->psbt)); req = jsonrpc_request_start(cmd->plugin, cmd, @@ -1022,8 +1020,7 @@ openchannel_init_dest(struct multifundchannel_destination *dest) "Using openchannel for %s open, " "ignoring `push_msat` of %s", fmt_node_id(tmpctx, &dest->id), - type_to_string(tmpctx, struct amount_msat, - &dest->push_msat)); + fmt_amount_msat(tmpctx, dest->push_msat)); /* Request some sats from the peer! */ if (!amount_sat_zero(dest->request_amt)) { diff --git a/plugins/sql.c b/plugins/sql.c index 7379fb714158..41bf6ef232cf 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -849,7 +849,7 @@ static struct command_result *channels_refresh(struct command *cmd, } plugin_log(cmd->plugin, LOG_DBG, "Refreshing channel: %s", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); /* FIXME: sqlite 3.24.0 (2018-06-04) added UPSERT, but * we don't require it. */ delete_channel_from_db(cmd, scid); @@ -866,7 +866,7 @@ static struct command_result *channels_refresh(struct command *cmd, break; } plugin_log(cmd->plugin, LOG_DBG, "Deleting channel: %s", - type_to_string(tmpctx, struct short_channel_id, &scid)); + fmt_short_channel_id(tmpctx, scid)); delete_channel_from_db(cmd, scid); } } diff --git a/plugins/test/run-funder_policy.c b/plugins/test/run-funder_policy.c index a9a96eaf14d8..8db20983fa15 100644 --- a/plugins/test/run-funder_policy.c +++ b/plugins/test/run-funder_policy.c @@ -523,10 +523,8 @@ int main(int argc, const char *argv[]) if (!amount_sat_eq(cases[i].exp_our_funds, our_funds)) { fprintf(stderr, "FAIL policy: %s. expected %s, got %s\n", funder_policy_desc(NULL, &cases[i].policy), - type_to_string(NULL, struct amount_sat, - &cases[i].exp_our_funds), - type_to_string(NULL, struct amount_sat, - &our_funds)); + fmt_amount_sat(NULL, cases[i].exp_our_funds), + fmt_amount_sat(NULL, our_funds)); ok = false; } if (cases[i].expect_err != (err != NULL)) { diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 679f2f6a4f3b..2b28bf8af6df 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -407,8 +407,8 @@ int main(int argc, char *argv[]) AMOUNT_MSAT(1000000 * 1000), 0, 0, 0); SUPERVERBOSE("Joining %s to %s, fee %u\n", - type_to_string(tmpctx, struct node_id, &ids[i-1]), - type_to_string(tmpctx, struct node_id, &ids[i]), + fmt_node_id(tmpctx, &ids[i-1]), + fmt_node_id(tmpctx, &ids[i]), 0); if (i <= 2) @@ -420,8 +420,8 @@ int main(int argc, char *argv[]) AMOUNT_MSAT(1000000 * 1000), 1 << i, 0, 0); SUPERVERBOSE("Joining %s to %s, fee %u\n", - type_to_string(tmpctx, struct node_id, &ids[1]), - type_to_string(tmpctx, struct node_id, &ids[i]), + fmt_node_id(tmpctx, &ids[1]), + fmt_node_id(tmpctx, &ids[i]), 1 << i); } @@ -431,8 +431,8 @@ int main(int argc, char *argv[]) struct route_hop *r; const char *errmsg; SUPERVERBOSE("%s -> %s:\n", - type_to_string(tmpctx, struct node_id, &ids[0]), - type_to_string(tmpctx, struct node_id, &ids[NUM_NODES-1])); + fmt_node_id(tmpctx, &ids[0]), + fmt_node_id(tmpctx, &ids[NUM_NODES-1])); src = gossmap_find_node(global_gossmap, &ids[0]); dst = gossmap_find_node(global_gossmap, &ids[NUM_NODES-1]); diff --git a/plugins/topology.c b/plugins/topology.c index 85f2ab1261f8..d4bf6c397d2a 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -110,13 +110,13 @@ static struct command_result *try_route(struct command *cmd, if (!src) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "%s: unknown source node_id (no public channels?)", - type_to_string(tmpctx, struct node_id, info->source)); + fmt_node_id(tmpctx, info->source)); dst = gossmap_find_node(gossmap, info->destination); if (!dst) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "%s: unknown destination node_id (no public channels?)", - type_to_string(tmpctx, struct node_id, info->destination)); + fmt_node_id(tmpctx, info->destination)); dij = dijkstra(tmpctx, gossmap, dst, *info->msat, *info->riskfactor_millionths / 1000000.0, @@ -511,8 +511,7 @@ static void json_add_node(struct json_stream *js, plugin_log(plugin, LOG_BROKEN, "Cannot parse stored node_announcement" " for %s at %u: %s", - type_to_string(tmpctx, struct node_id, - &node_id), + fmt_node_id(tmpctx, &node_id), n->nann_off, tal_hex(tmpctx, nannounce)); goto out; diff --git a/plugins/txprepare.c b/plugins/txprepare.c index 148c3f226ca9..4cf3d2427631 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -166,8 +166,7 @@ static struct command_result *signpsbt_done(struct command *cmd, "Signed tx changed txid? Had '%s' now '%s'", tal_hex(tmpctx, linearize_wtx(tmpctx, utx->tx)), - type_to_string(tmpctx, struct wally_psbt, - utx->psbt)); + fmt_wally_psbt(tmpctx, utx->psbt)); } req = jsonrpc_request_start(cmd->plugin, cmd, "sendpsbt", @@ -194,9 +193,8 @@ static struct command_result *finish_txprepare(struct command *cmd, "Invalid output %zi (%s:%s)", i, tal_hex(tmpctx, txp->outputs[i].script), - type_to_string(tmpctx, - struct amount_sat, - &txp->outputs[i].amount)); + fmt_amount_sat(tmpctx, + txp->outputs[i].amount)); psbt_add_output(txp->psbt, out, i); if (txp->outputs[i].is_to_external) @@ -396,7 +394,7 @@ static struct command_result *param_unreleased_txid(struct command *cmd, return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "not an unreleased txid '%s'", - type_to_string(tmpctx, struct bitcoin_txid, txid)); + fmt_bitcoin_txid(tmpctx, txid)); } static struct command_result *json_txdiscard(struct command *cmd, diff --git a/tools/hsmtool.c b/tools/hsmtool.c index e9a4c7a24dd3..87e48458571c 100644 --- a/tools/hsmtool.c +++ b/tools/hsmtool.c @@ -371,7 +371,7 @@ static int dump_commitments_infos(struct node_id *node_id, u64 channel_id, get_channel_seed(&channel_seed, node_id, channel_id, &hsm_secret); derive_shaseed(&channel_seed, &shaseed); - printf("shaseed: %s\n", type_to_string(tmpctx, struct sha256, &shaseed)); + printf("shaseed: %s\n", fmt_sha256(tmpctx, &shaseed)); for (u64 i = 0; i < depth; i++) { if (!per_commit_secret(&shaseed, &per_commitment_secret, i)) errx(ERROR_KEYDERIV, "Could not derive secret #%"PRIu64, i); @@ -381,7 +381,7 @@ static int dump_commitments_infos(struct node_id *node_id, u64 channel_id, if (!per_commit_point(&shaseed, &per_commitment_point, i)) errx(ERROR_KEYDERIV, "Could not derive point #%"PRIu64, i); printf("commit point #%"PRIu64": %s\n", - i, type_to_string(tmpctx, struct pubkey, &per_commitment_point)); + i, fmt_pubkey(tmpctx, &per_commitment_point)); } return 0; @@ -433,8 +433,7 @@ static int guess_to_remote(const char *address, struct node_id *node_id, &basepoint, &basepoint_secret)) errx(ERROR_KEYDERIV, "Could not derive basepoints for dbid %"PRIu64 " and channel seed %s.", dbid, - type_to_string(tmpctx, - struct secret, &channel_seed)); + fmt_secret(tmpctx, &channel_seed)); pubkey_to_hash160(&basepoint, &pubkeyhash); if (memcmp(pubkeyhash.u.u8, goal_pubkeyhash, 20) == 0) { @@ -442,9 +441,9 @@ static int guess_to_remote(const char *address, struct node_id *node_id, printf("pubkey hash : %s\n", tal_hexstr(tmpctx, pubkeyhash.u.u8, 20)); printf("pubkey : %s \n", - type_to_string(tmpctx, struct pubkey, &basepoint)); + fmt_pubkey(tmpctx, &basepoint)); printf("privkey : %s \n", - type_to_string(tmpctx, struct secret, &basepoint_secret)); + fmt_secret(tmpctx, &basepoint_secret)); return 0; } } diff --git a/wallet/reservation.c b/wallet/reservation.c index 28b0772f28bc..f334b2da2e7a 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -69,9 +69,8 @@ static void reserve_and_report(struct json_stream *response, current_height, reserve)) { fatal("Unable to reserve %s!", - type_to_string(tmpctx, - struct bitcoin_outpoint, - &utxos[i]->outpoint)); + fmt_bitcoin_outpoint(tmpctx, + &utxos[i]->outpoint)); } json_add_reservestatus(response, utxos[i], oldstatus, old_res, current_height); @@ -102,9 +101,7 @@ static struct command_result *json_reserveinputs(struct command *cmd, if (!psbt_set_version(psbt, 2)) { return command_fail(cmd, LIGHTNINGD, "Failed to set version for PSBT: %s", - type_to_string(tmpctx, - struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); } current_height = get_block_height(cmd->ld->topology); @@ -119,16 +116,14 @@ static struct command_result *json_reserveinputs(struct command *cmd, if (*exclusive && utxo_is_reserved(utxo, current_height)) { return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "%s already reserved", - type_to_string(tmpctx, - struct bitcoin_outpoint, - &utxo->outpoint)); + fmt_bitcoin_outpoint(tmpctx, + &utxo->outpoint)); } if (utxo->status == OUTPUT_STATE_SPENT) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "%s already spent", - type_to_string(tmpctx, - struct bitcoin_outpoint, - &utxo->outpoint)); + fmt_bitcoin_outpoint(tmpctx, + &utxo->outpoint)); tal_arr_expand(&utxos, utxo); } @@ -169,8 +164,7 @@ static struct command_result *json_unreserveinputs(struct command *cmd, if (!psbt_set_version(psbt, 2)) { log_broken(cmd->ld->log, "Unable to set version for PSBT: %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); } /* We should also add the utxo info for these inputs! @@ -191,8 +185,7 @@ static struct command_result *json_unreserveinputs(struct command *cmd, } else log_broken(cmd->ld->log, "No transaction found for UTXO %s", - type_to_string(tmpctx, struct bitcoin_txid, - &txid)); + fmt_bitcoin_txid(tmpctx, &txid)); } if (command_check_only(cmd)) @@ -596,14 +589,10 @@ static struct command_result *json_fundpsbt(struct command *cmd, return command_fail(cmd, FUND_CANNOT_AFFORD, "Could not afford %s using all %zu available UTXOs: %s short", all ? "all" - : type_to_string(tmpctx, - struct amount_sat, - amount), + : fmt_amount_sat(tmpctx, *amount), tal_count(utxos), all ? "all" - : type_to_string(tmpctx, - struct amount_sat, - &diff)); + : fmt_amount_sat(tmpctx, diff)); } tal_free(excluded); @@ -704,9 +693,8 @@ static struct command_result *json_addpsbtoutput(struct command *cmd, if (amount_sat_less(*amount, chainparams->dust_limit)) return command_fail(cmd, FUND_OUTPUT_IS_DUST, "Receive amount is below dust limit (%s)", - type_to_string(tmpctx, - struct amount_sat, - &chainparams->dust_limit)); + fmt_amount_sat(tmpctx, + chainparams->dust_limit)); if (command_check_only(cmd)) return command_check_done(cmd); @@ -794,15 +782,13 @@ static struct command_result *param_txout(struct command *cmd, if (!utxo) { return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unknown UTXO %s", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &outpoint)); } if (utxo->status == OUTPUT_STATE_SPENT) { return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Already spent UTXO %s", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &outpoint)); } @@ -862,14 +848,12 @@ static struct command_result *json_utxopsbt(struct command *cmd, if (!*reserved_ok && utxo_is_reserved(utxo, current_height)) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "UTXO %s already reserved", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &utxo->outpoint)); if (utxo_is_csv_locked(utxo, current_height)) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "UTXO %s is csv locked (%u)", - type_to_string(tmpctx, - struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &utxo->outpoint), utxo->close_info->csv); @@ -891,9 +875,7 @@ static struct command_result *json_utxopsbt(struct command *cmd, || amount_sat_less(excess, chainparams->dust_limit)) { return command_fail(cmd, FUND_CANNOT_AFFORD, "Could not afford anything using UTXOs totalling %s with weight %u at feerate %u", - type_to_string(tmpctx, - struct amount_sat, - &input), + fmt_amount_sat(tmpctx, input), *weight, *feerate_per_kw); } *excess_as_change = false; @@ -902,12 +884,8 @@ static struct command_result *json_utxopsbt(struct command *cmd, *feerate_per_kw, *weight, &excess)) { return command_fail(cmd, FUND_CANNOT_AFFORD, "Could not afford %s using UTXOs totalling %s with weight %u at feerate %u", - type_to_string(tmpctx, - struct amount_sat, - amount), - type_to_string(tmpctx, - struct amount_sat, - &input), + fmt_amount_sat(tmpctx, *amount), + fmt_amount_sat(tmpctx, input), *weight, *feerate_per_kw); } } diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index 50fa0e6917a8..04253603b147 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -58,6 +58,9 @@ void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED) /* Generated stub for find_peer_by_dbid */ struct peer *find_peer_by_dbid(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED) { fprintf(stderr, "find_peer_by_dbid called!\n"); abort(); } +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for forward_index_created */ u64 forward_index_created(struct lightningd *ld UNNEEDED, enum forward_status status UNNEEDED, diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 73c51bd37988..13de882007c3 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -229,6 +229,9 @@ void fatal(const char *fmt UNNEEDED, ...) /* Generated stub for fatal_vfmt */ void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED) { fprintf(stderr, "fatal_vfmt called!\n"); abort(); } +/* Generated stub for fmt_channel_id */ +char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for force_peer_disconnect */ void force_peer_disconnect(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED, diff --git a/wallet/wallet.c b/wallet/wallet.c index ea639aad47b5..e1e382ac9966 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -559,7 +559,7 @@ void wallet_unreserve_utxo(struct wallet *w, struct utxo *utxo, { if (utxo->status != OUTPUT_STATE_RESERVED) fatal("UTXO %s is not reserved", - type_to_string(tmpctx, struct bitcoin_outpoint, + fmt_bitcoin_outpoint(tmpctx, &utxo->outpoint)); if (utxo->reserved_til <= current_height + unreserve) { @@ -1676,7 +1676,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm last_tx = db_col_psbt_to_tx(tmpctx, stmt, "last_tx"); if (!last_tx) db_fatal(w->db, "Failed to decode channel %s psbt %s", - type_to_string(tmpctx, struct channel_id, &cid), + fmt_channel_id(tmpctx, &cid), tal_hex(tmpctx, db_col_arr(tmpctx, stmt, "last_tx", u8))); last_sig = tal(tmpctx, struct bitcoin_signature); @@ -2543,7 +2543,7 @@ struct state_change_entry *wallet_state_change_get(struct wallet *w, static void wallet_peer_save(struct wallet *w, struct peer *peer) { const char *addr = - type_to_string(tmpctx, struct wireaddr_internal, &peer->addr); + fmt_wireaddr_internal(tmpctx, &peer->addr); struct db_stmt *stmt = db_prepare_v2(w->db, SQL("SELECT id FROM peers WHERE node_id = ?")); @@ -2762,11 +2762,9 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, utxo->scriptPubkey = tal_dup_arr(utxo, u8, txout->script, txout->script_len, 0); log_debug(w->log, "Owning output %zu %s (%s) txid %s%s%s", i, - type_to_string(tmpctx, struct amount_sat, - &utxo->amount), + fmt_amount_sat(tmpctx, utxo->amount), utxo->is_p2sh ? "P2SH" : "SEGWIT", - type_to_string(tmpctx, struct bitcoin_txid, - &utxo->outpoint.txid), + fmt_bitcoin_txid(tmpctx, &utxo->outpoint.txid), blockheight ? " CONFIRMED" : "", is_coinbase ? " COINBASE" : ""); @@ -2801,9 +2799,8 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, if (total && !amount_sat_add(total, *total, utxo->amount)) fatal("Cannot add utxo output %zu/%zu %s + %s", i, wtx->num_outputs, - type_to_string(tmpctx, struct amount_sat, total), - type_to_string(tmpctx, struct amount_sat, - &utxo->amount)); + fmt_amount_sat(tmpctx, *total), + fmt_amount_sat(tmpctx, utxo->amount)); wallet_annotate_txout(w, &utxo->outpoint, TX_WALLET_DEPOSIT, 0); tal_free(utxo); @@ -3154,8 +3151,8 @@ static void fixup_hin(struct wallet *wallet, struct htlc_in *hin) " is missing a resolution:" " subsituting temporary node failure", hin->key.id, htlc_state_name(hin->hstate), - type_to_string(tmpctx, struct amount_msat, &hin->msat), - type_to_string(tmpctx, struct node_id, + fmt_amount_msat(tmpctx, hin->msat), + fmt_node_id(tmpctx, &hin->key.channel->peer->id)); #endif } @@ -4185,9 +4182,9 @@ bool wallet_sanity_check(struct wallet *w) "!= %s. " "Are you on the right network? " "(--network={one of %s})", - type_to_string(w, struct bitcoin_blkid, + fmt_bitcoin_blkid(w, &chainhash), - type_to_string(w, struct bitcoin_blkid, + fmt_bitcoin_blkid(w, &chainparams->genesis_blockhash), chainparams_get_network_names(tmpctx)); return false; @@ -4216,8 +4213,8 @@ bool wallet_sanity_check(struct wallet *w) "match HSM: %s " "!= %s. " "Did your hsm_secret change?", - type_to_string(tmpctx, struct node_id, &id), - type_to_string(tmpctx, struct node_id, + fmt_node_id(tmpctx, &id), + fmt_node_id(tmpctx, &w->ld->id)); return false; } @@ -4974,8 +4971,8 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w) deleted = amount_msat(db_get_intvar(w->db, "deleted_forward_fees", 0)); if (!amount_msat_add(&total, total, deleted)) db_fatal(w->db, "Adding forward fees %s + %s overflowed", - type_to_string(tmpctx, struct amount_msat, &total), - type_to_string(tmpctx, struct amount_msat, &deleted)); + fmt_amount_msat(tmpctx, total), + fmt_amount_msat(tmpctx, deleted)); return total; } @@ -5139,10 +5136,8 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, cur->msat_out = db_col_amount_msat(stmt, "out_msatoshi"); if (!amount_msat_sub(&cur->fee, cur->msat_in, cur->msat_out)) { log_broken(w->log, "Forwarded in %s less than out %s!", - type_to_string(tmpctx, struct amount_msat, - &cur->msat_in), - type_to_string(tmpctx, struct amount_msat, - &cur->msat_out)); + fmt_amount_msat(tmpctx, cur->msat_in), + fmt_amount_msat(tmpctx, cur->msat_out)); cur->fee = AMOUNT_MSAT(0); } } @@ -5548,7 +5543,7 @@ void wallet_offer_mark_used(struct db *db, const struct sha256 *offer_id) if (!db_step(stmt)) fatal("%s: unknown offer_id %s", __func__, - type_to_string(tmpctx, struct sha256, offer_id)); + fmt_sha256(tmpctx, offer_id)); status = offer_status_in_db(db_col_int(stmt, "status")); tal_free(stmt); @@ -5556,7 +5551,7 @@ void wallet_offer_mark_used(struct db *db, const struct sha256 *offer_id) if (!offer_status_active(status)) fatal("%s: offer_id %s not active: status %i", __func__, - type_to_string(tmpctx, struct sha256, offer_id), + fmt_sha256(tmpctx, offer_id), status); if (!offer_status_used(status)) { @@ -5715,7 +5710,7 @@ void wallet_invoice_request_mark_used(struct db *db, const struct sha256 *invreq if (!db_step(stmt)) fatal("%s: unknown invreq_id %s", __func__, - type_to_string(tmpctx, struct sha256, invreq_id)); + fmt_sha256(tmpctx, invreq_id)); status = offer_status_in_db(db_col_int(stmt, "status")); tal_free(stmt); @@ -5723,7 +5718,7 @@ void wallet_invoice_request_mark_used(struct db *db, const struct sha256 *invreq if (!offer_status_active(status)) fatal("%s: invreq_id %s not active: status %i", __func__, - type_to_string(tmpctx, struct sha256, invreq_id), + fmt_sha256(tmpctx, invreq_id), status); if (!offer_status_used(status)) { diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 974f51dedabd..3e31c6a53115 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -282,9 +282,8 @@ static void json_add_utxo(struct json_stream *response, if (!out) log_broken(wallet->log, "Could not encode utxo %s%s!", - type_to_string(tmpctx, - struct bitcoin_outpoint, - &utxo->outpoint), + fmt_bitcoin_outpoint(tmpctx, + &utxo->outpoint), utxo->close_info ? " (has close_info)" : ""); else json_add_string(response, "address", out); @@ -612,8 +611,8 @@ static struct command_result *match_psbt_inputs_to_utxos(struct command *cmd, if (only_inputs) return command_fail(cmd, LIGHTNINGD, "Aborting PSBT signing. UTXO %s is unknown (and specified by signonly)", - type_to_string(tmpctx, struct bitcoin_outpoint, - &outpoint)); + fmt_bitcoin_outpoint(tmpctx, + &outpoint)); continue; } @@ -621,8 +620,8 @@ static struct command_result *match_psbt_inputs_to_utxos(struct command *cmd, if (!utxo_is_reserved(utxo, get_block_height(cmd->ld->topology))) return command_fail(cmd, LIGHTNINGD, "Aborting PSBT signing. UTXO %s is not reserved", - type_to_string(tmpctx, struct bitcoin_outpoint, - &utxo->outpoint)); + fmt_bitcoin_outpoint(tmpctx, + &utxo->outpoint)); /* If the psbt doesn't have the UTXO info yet, add it. * We only add the witness_utxo for this */ @@ -729,8 +728,7 @@ static struct command_result *json_signpsbt(struct command *cmd, if (!psbt_set_version(psbt, 2)) { return command_fail(cmd, LIGHTNINGD, "Could not set PSBT version: %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); } /* Sanity check! */ @@ -785,15 +783,13 @@ static struct command_result *json_signpsbt(struct command *cmd, if (!combined_psbt) { return command_fail(cmd, LIGHTNINGD, "Unable to combine signed psbt: %s", - type_to_string(tmpctx, struct wally_psbt, - signed_psbt)); + fmt_wally_psbt(tmpctx, signed_psbt)); } if (!psbt_set_version(combined_psbt, psbt_version)) { return command_fail(cmd, LIGHTNINGD, "Signed PSBT unable to have version set: %s", - type_to_string(tmpctx, struct wally_psbt, - combined_psbt)); + fmt_wally_psbt(tmpctx, combined_psbt)); } response = json_stream_success(cmd); @@ -916,8 +912,7 @@ static void sendpsbt_done(struct bitcoind *bitcoind UNUSED, "Error broadcasting transaction: %s." " Unsent tx discarded %s", msg, - type_to_string(tmpctx, struct wally_tx, - sending->wtx))); + fmt_wally_tx(tmpctx, sending->wtx))); return; } @@ -973,8 +968,7 @@ static struct command_result *json_sendpsbt(struct command *cmd, if (!sending->wtx) return command_fail(cmd, LIGHTNINGD, "PSBT not finalizeable %s", - type_to_string(tmpctx, struct wally_psbt, - psbt)); + fmt_wally_psbt(tmpctx, psbt)); /* We have to find/locate the utxos that are ours on this PSBT, * so that we know who to mark as used.