From 7e0f2c4d268fe78a685644f078240dc02a6c1953 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 23 Feb 2018 16:23:47 +1030 Subject: [PATCH] onchaind: two small changes. I generally tried not to alter internal logic to add billboards (to avoid breakage), but these two make things neater. 1. Free ->proposal if it's not longer valid. That way we don't get confused by reporting old proposals. 2. Change all_irrevocably_resolved() to num_not_irrevocably_resolved() so we can report that number to the billboard. Signed-off-by: Rusty Russell --- onchaind/onchain.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 707621de4..d28a33ffb 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -380,6 +380,8 @@ static bool resolved_by_proposal(struct tracked_output *out, /* Not the same as what we proposed? */ if (!structeq(&out->resolved->txid, txid)) { out->resolved = tal_free(out->resolved); + /* Don't need proposal any more */ + out->proposal = tal_free(out->proposal); return false; } @@ -391,6 +393,9 @@ static bool resolved_by_proposal(struct tracked_output *out, out->resolved->depth = 0; out->resolved->tx_type = out->proposal->tx_type; + + /* Don't need proposal any more */ + out->proposal = tal_free(out->proposal); return true; } @@ -493,15 +498,15 @@ static bool is_local_commitment(const struct bitcoin_txid *txid, * once their *resolving* transaction is included in a block at least 100 * deep on the most-work blockchain. */ -static bool all_irrevocably_resolved(struct tracked_output **outs) +static size_t num_not_irrevocably_resolved(struct tracked_output **outs) { - size_t i; + size_t i, num = 0; for (i = 0; i < tal_count(outs); i++) { if (!outs[i]->resolved || outs[i]->resolved->depth < 100) - return false; + num++; } - return true; + return num; } static void unwatch_tx(const struct bitcoin_tx *tx) @@ -947,7 +952,7 @@ static void handle_preimage(struct tracked_output **outs, */ static void wait_for_resolved(struct tracked_output **outs) { - while (!all_irrevocably_resolved(outs)) { + while (num_not_irrevocably_resolved(outs) != 0) { u8 *msg = wire_sync_read(outs, REQ_FD); struct bitcoin_txid txid; struct bitcoin_tx *tx;