mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
chaintopology: only do callbacks once chain has settled.
This is only important for testing, where we add 100 blocks at once and time out under valgrind. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
887e9dcc44
commit
6debaccfd5
2 changed files with 24 additions and 13 deletions
|
@ -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. */
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue