Browse Source

channeld: clean up watchtower code.

1. Use status_debug() instead of status_unusual() for when we can't make a
   penalty tx (this happens easily the time if we fund a channel).
2. Use status_failed() (which exits) instead of status_broken() (which doesn't!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
nifty/pset-pre
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
e9cd84f490
  1. 26
      channeld/watchtower.c

26
channeld/watchtower.c

@ -43,23 +43,25 @@ penalty_tx_create(const tal_t *ctx,
if (to_them_outnum == -1 || if (to_them_outnum == -1 ||
amount_sat_less_eq(to_them_sats, dust_limit)) { amount_sat_less_eq(to_them_sats, dust_limit)) {
status_unusual( status_debug(
"Cannot create penalty transaction because there " "Cannot create penalty transaction because there "
"is no non-dust to_them output in the commitment."); "is no non-dust to_them output in the commitment.");
return NULL; return NULL;
} }
if (!pubkey_from_secret(&remote_per_commitment_secret, &remote_per_commitment_point)) if (!pubkey_from_secret(&remote_per_commitment_secret, &remote_per_commitment_point))
status_broken("Failed derive from per_commitment_secret %s", status_failed(STATUS_FAIL_INTERNAL_ERROR,
type_to_string(tmpctx, struct secret, "Failed derive from per_commitment_secret %s",
&remote_per_commitment_secret)); type_to_string(tmpctx, struct secret,
&remote_per_commitment_secret));
if (!derive_keyset(&remote_per_commitment_point, if (!derive_keyset(&remote_per_commitment_point,
&basepoints[REMOTE], &basepoints[REMOTE],
&basepoints[LOCAL], &basepoints[LOCAL],
option_static_remotekey, option_static_remotekey,
&keyset)) &keyset))
abort(); /* TODO(cdecker) Handle a bit more gracefully */ status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Failed deriving keyset");
wscript = bitcoin_wscript_to_local(tmpctx, remote_to_self_delay, wscript = bitcoin_wscript_to_local(tmpctx, remote_to_self_delay,
&keyset.self_revocation_key, &keyset.self_revocation_key,
@ -77,7 +79,7 @@ penalty_tx_create(const tal_t *ctx,
fee = amount_tx_fee(penalty_feerate, weight); fee = amount_tx_fee(penalty_feerate, weight);
if (!amount_sat_add(&min_out, dust_limit, fee)) if (!amount_sat_add(&min_out, dust_limit, fee))
status_broken( status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Cannot add dust_limit %s and fee %s", "Cannot add dust_limit %s and fee %s",
type_to_string(tmpctx, struct amount_sat, &dust_limit), type_to_string(tmpctx, struct amount_sat, &dust_limit),
type_to_string(tmpctx, struct amount_sat, &fee)); type_to_string(tmpctx, struct amount_sat, &fee));
@ -91,7 +93,7 @@ penalty_tx_create(const tal_t *ctx,
* happen! */ * happen! */
if (!amount_sat_sub(&amt, to_them_sats, fee)) { if (!amount_sat_sub(&amt, to_them_sats, fee)) {
amt = dust_limit; amt = dust_limit;
status_broken( status_failed(STATUS_FAIL_INTERNAL_ERROR,
"TX can't afford minimal feerate" "TX can't afford minimal feerate"
"; setting output to %s", "; setting output to %s",
type_to_string(tmpctx, struct amount_sat, &amt)); type_to_string(tmpctx, struct amount_sat, &amt));
@ -104,13 +106,13 @@ penalty_tx_create(const tal_t *ctx,
wscript, *tx->input_amounts[0]); wscript, *tx->input_amounts[0]);
if (!wire_sync_write(HSM_FD, take(hsm_sign_msg))) if (!wire_sync_write(HSM_FD, take(hsm_sign_msg)))
status_broken("Writing sign request to hsm"); status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Writing sign request to hsm");
msg = wire_sync_read(tmpctx, HSM_FD); msg = wire_sync_read(tmpctx, HSM_FD);
if (!msg || !fromwire_hsm_sign_tx_reply(msg, &sig)) { if (!msg || !fromwire_hsm_sign_tx_reply(msg, &sig))
status_broken("Reading sign_tx_reply: %s", tal_hex(tmpctx, msg)); status_failed(STATUS_FAIL_INTERNAL_ERROR,
abort(); "Reading sign_tx_reply: %s", tal_hex(tmpctx, msg));
}
witness = bitcoin_witness_sig_and_element(tx, &sig, &ONE, sizeof(ONE), witness = bitcoin_witness_sig_and_element(tx, &sig, &ONE, sizeof(ONE),
wscript); wscript);

Loading…
Cancel
Save