Skip to content

Commit

Permalink
optimise UTXO cache to avoid keeping unspendable transactions forever
Browse files Browse the repository at this point in the history
[ Slight edit to use is_unspendable(), and to measure:
  As of block 391263, this cuts the number of UTXOs from 8815881 to 8313410.
  -- RR ]
  • Loading branch information
ajtowns authored and rustyrussell committed Jan 4, 2016
1 parent 5da0c2b commit c81c603
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,21 @@ static void add_utxo(const tal_t *tal_ctx,
{
struct utxo *utxo;
unsigned int i;
unsigned int spend_count = 0;

for (i = 0; i < t->output_count; i++)
if (!is_unspendable(&t->output[i]))
spend_count++;

if (spend_count == 0)
return;

utxo = tal_alloc_(tal_ctx, sizeof(*utxo) + (sizeof(utxo->amount[0]) + 1)
* t->output_count, false, TAL_LABEL(struct utxo, ""));

memcpy(utxo->tx, t->sha256, sizeof(utxo->tx));
utxo->num_outputs = utxo->unspent_outputs = t->output_count;
utxo->num_outputs = t->output_count;
utxo->unspent_outputs = spend_count;
utxo->height = b->height;
utxo->timestamp = b->b->timestamp;
for (i = 0; i < utxo->num_outputs; i++)
Expand Down

0 comments on commit c81c603

Please sign in to comment.