topology: Track blockchain changes in the DB

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-02-19 15:20:51 +01:00
parent 9440b23852
commit 1aa21498c3
3 changed files with 11 additions and 1 deletions

View File

@ -360,6 +360,7 @@ static void add_tip(struct chain_topology *topo, struct block *b)
b->prev = topo->tip;
topo->tip->next = b;
topo->tip = b;
wallet_block_add(topo->wallet, b);
}
static struct block *new_block(struct chain_topology *topo,
@ -403,6 +404,7 @@ static void remove_tip(struct chain_topology *topo)
for (i = 0; i < n; i++)
txwatch_fire(topo, b->txs[i], 0);
wallet_block_remove(topo->wallet, b);
tal_free(b);
}
@ -471,6 +473,10 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
else
topo->first_blocknum -= 100;
/* Rollback to the given blockheight, so we start track
* correctly again */
wallet_blocks_rollback(topo->wallet, topo->first_blocknum - 1);
/* Get up to speed with topology. */
bitcoind_getblockhash(bitcoind, topo->first_blocknum,
get_init_block, topo);
@ -666,7 +672,7 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log)
topo->default_fee_rate = 40000;
topo->override_fee_rate = NULL;
topo->bitcoind = new_bitcoind(topo, ld, log);
topo->wallet = ld->wallet;
return topo;
}

View File

@ -86,6 +86,9 @@ struct chain_topology {
u32 feerate[NUM_FEERATES];
bool startup;
/* Where to store blockchain info. */
struct wallet *wallet;
/* Where to log things. */
struct log *log;

View File

@ -321,6 +321,7 @@ int main(int argc, char *argv[])
/* Initialize wallet, now that we are in the correct directory */
ld->wallet = wallet_new(ld, ld->log, &ld->timers);
ld->owned_txfilter = txfilter_new(ld);
ld->topology->wallet = ld->wallet;
/* Set up HSM. */
hsm_init(ld, newdir);