diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index ebf633da0..4dbd05c38 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -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; } diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 512ed50ba..a6fc84196 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -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; diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 31db45c43..fd8cf3ec8 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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);