Skip to content

Commit

Permalink
chaintopology: only do callbacks once chain has settled.
Browse files Browse the repository at this point in the history
This is only important for testing, where we add 100 blocks at once
and time out under valgrind.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Dec 21, 2017
1 parent 887e9dc commit 6debacc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
35 changes: 23 additions & 12 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,26 @@ static void next_updatefee_timer(struct chain_topology *topo)
start_fee_estimate, topo));
}

/* Once we're run out of new blocks to add, call this. */
static void updates_complete(struct chain_topology *topo)
{
if (topo->tip != topo->prev_tip) {
/* Tell lightningd about new block. */
notify_new_block(topo->bitcoind->ld, topo->tip->height);

/* Tell watch code to re-evaluate all txs. */
watch_topology_changed(topo);

/* Maybe need to rebroadcast. */
rebroadcast_txs(topo, NULL);

topo->prev_tip = topo->tip;
}

/* Try again soon. */
next_topology_timer(topo);
}

static void add_tip(struct chain_topology *topo, struct block *b)
{
/* Only keep the transactions we care about. */
Expand All @@ -348,15 +368,6 @@ static void add_tip(struct chain_topology *topo, struct block *b)
b->prev = topo->tip;
topo->tip->next = b;
topo->tip = b;

/* Tell lightningd about new block. */
notify_new_block(topo->bitcoind->ld, b->height);

/* Tell watch code to re-evaluate all txs. */
watch_topology_changed(topo);

/* Maybe need to rebroadcast. */
rebroadcast_txs(topo, NULL);
}

static struct block *new_block(struct chain_topology *topo,
Expand Down Expand Up @@ -422,8 +433,8 @@ static void get_new_block(struct bitcoind *bitcoind,
struct chain_topology *topo)
{
if (!blkid) {
/* No such block, poll. */
next_topology_timer(topo);
/* No such block, we're done. */
updates_complete(topo);
return;
}
bitcoind_getrawblock(bitcoind, blkid, have_new_block, topo);
Expand All @@ -441,7 +452,7 @@ static void init_topo(struct bitcoind *bitcoind,
{
topo->root = new_block(topo, blk, topo->first_blocknum);
block_map_add(&topo->block_map, topo->root);
topo->tip = topo->root;
topo->tip = topo->prev_tip = topo->root;

try_extend_tip(topo);
}
Expand Down
2 changes: 1 addition & 1 deletion lightningd/chaintopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ HTABLE_DEFINE_TYPE(struct block, keyof_block_map, hash_sha, block_eq, block_map)

struct chain_topology {
struct block *root;
struct block *tip;
struct block *prev_tip, *tip;
struct block_map block_map;
u32 feerate[NUM_FEERATES];
bool startup;
Expand Down

0 comments on commit 6debacc

Please sign in to comment.