Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
7e0f2c4d26
  1. 15
      onchaind/onchain.c

15
onchaind/onchain.c

@ -380,6 +380,8 @@ static bool resolved_by_proposal(struct tracked_output *out,
/* Not the same as what we proposed? */ /* Not the same as what we proposed? */
if (!structeq(&out->resolved->txid, txid)) { if (!structeq(&out->resolved->txid, txid)) {
out->resolved = tal_free(out->resolved); out->resolved = tal_free(out->resolved);
/* Don't need proposal any more */
out->proposal = tal_free(out->proposal);
return false; return false;
} }
@ -391,6 +393,9 @@ static bool resolved_by_proposal(struct tracked_output *out,
out->resolved->depth = 0; out->resolved->depth = 0;
out->resolved->tx_type = out->proposal->tx_type; out->resolved->tx_type = out->proposal->tx_type;
/* Don't need proposal any more */
out->proposal = tal_free(out->proposal);
return true; 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 * once their *resolving* transaction is included in a block at least 100
* deep on the most-work blockchain. * 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++) { for (i = 0; i < tal_count(outs); i++) {
if (!outs[i]->resolved || outs[i]->resolved->depth < 100) 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) 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) 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); u8 *msg = wire_sync_read(outs, REQ_FD);
struct bitcoin_txid txid; struct bitcoin_txid txid;
struct bitcoin_tx *tx; struct bitcoin_tx *tx;

Loading…
Cancel
Save