From 0e569209ecbb90f5212a5f83bbefb39470f1ab4e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 26 Sep 2017 14:27:31 +0930 Subject: [PATCH] onchaind: immediately broadcast proposals which don't need to wait. This removes an extra call and simplifies handling of "immediate" txs. Signed-off-by: Rusty Russell --- onchaind/onchain.c | 47 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 1e5b1e172..a59772b30 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -294,6 +294,26 @@ static void ignore_output(struct tracked_output *out) out->resolved->tx_type = SELF; } +static void proposal_meets_depth(struct tracked_output *out) +{ + /* If we simply wanted to ignore it after some depth */ + if (!out->proposal->tx) { + ignore_output(out); + return; + } + + status_trace("Broadcasting %s (%s) to resolve %s/%s", + tx_type_name(out->proposal->tx_type), + type_to_string(trc, struct bitcoin_tx, out->proposal->tx), + tx_type_name(out->tx_type), + output_type_name(out->output_type)); + + wire_sync_write(REQ_FD, + take(towire_onchain_broadcast_tx(NULL, + out->proposal->tx))); + /* We will get a callback when it's in a block. */ +} + static void propose_resolution(struct tracked_output *out, const struct bitcoin_tx *tx, unsigned int depth_required, @@ -310,6 +330,9 @@ static void propose_resolution(struct tracked_output *out, out->proposal->tx = tal_steal(out->proposal, tx); out->proposal->depth_required = depth_required; out->proposal->tx_type = tx_type; + + if (depth_required == 0) + proposal_meets_depth(out); } static void propose_resolution_at_block(struct tracked_output *out, @@ -465,26 +488,6 @@ static bool all_irrevocably_resolved(struct tracked_output **outs) return true; } -static void proposal_meets_depth(struct tracked_output *out) -{ - /* If we simply wanted to ignore it after some depth */ - if (!out->proposal->tx) { - ignore_output(out); - return; - } - - status_trace("Broadcasting %s (%s) to resolve %s/%s", - tx_type_name(out->proposal->tx_type), - type_to_string(trc, struct bitcoin_tx, out->proposal->tx), - tx_type_name(out->tx_type), - output_type_name(out->output_type)); - - wire_sync_write(REQ_FD, - take(towire_onchain_broadcast_tx(NULL, - out->proposal->tx))); - /* We will get a callback when it's in a block. */ -} - static void unwatch_tx(const struct bitcoin_tx *tx) { u8 *msg; @@ -795,10 +798,6 @@ static void handle_preimage(struct tracked_output **outs, propose_resolution(outs[i], tx, 0, THEIR_HTLC_FULFILL_TO_US); } - - /* Broadcast immediately. */ - proposal_meets_depth(outs[i]); - break; } }