Browse Source

onchaind: simplify reasonable-depth code a little.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
f3025ce147
  1. 28
      onchaind/onchain.c

28
onchaind/onchain.c

@ -750,30 +750,34 @@ static void output_spent(struct tracked_output ***outs,
static void update_resolution_depth(struct tracked_output *out, u32 depth) static void update_resolution_depth(struct tracked_output *out, u32 depth)
{ {
bool reached_reasonable_depth;
status_trace("%s/%s->%s depth %u", status_trace("%s/%s->%s depth %u",
tx_type_name(out->tx_type), tx_type_name(out->tx_type),
output_type_name(out->output_type), output_type_name(out->output_type),
tx_type_name(out->resolved->tx_type), tx_type_name(out->resolved->tx_type),
depth); depth);
/* We only set this once. */
reached_reasonable_depth = (out->resolved->depth < reasonable_depth
&& depth >= reasonable_depth);
/* BOLT #5: /* BOLT #5:
* *
* If the HTLC output has *timed out* and not been *resolved*, * If the HTLC output has *timed out* and not been *resolved*,
* the node MUST *resolve* the output and MUST fail the * the node MUST *resolve* the output and MUST fail the
* corresponding incoming HTLC (if any) once the resolving * corresponding incoming HTLC (if any) once the resolving
* transaction has reached reasonable depth. */ * transaction has reached reasonable depth. */
if (out->resolved->tx_type == OUR_HTLC_TIMEOUT_TX if ((out->resolved->tx_type == OUR_HTLC_TIMEOUT_TX
|| out->resolved->tx_type == OUR_HTLC_TIMEOUT_TO_US) { || out->resolved->tx_type == OUR_HTLC_TIMEOUT_TO_US)
if (out->resolved->depth < reasonable_depth && reached_reasonable_depth) {
&& depth >= reasonable_depth) { u8 *msg;
u8 *msg; status_trace("%s/%s reached reasonable depth %u",
status_trace("%s/%s reached reasonable depth %u", tx_type_name(out->tx_type),
tx_type_name(out->tx_type), output_type_name(out->output_type),
output_type_name(out->output_type), depth);
depth); msg = towire_onchain_htlc_timeout(out, out->htlc);
msg = towire_onchain_htlc_timeout(out, out->htlc); wire_sync_write(REQ_FD, take(msg));
wire_sync_write(REQ_FD, take(msg));
}
} }
out->resolved->depth = depth; out->resolved->depth = depth;
} }

Loading…
Cancel
Save