Browse Source

lightningd: scan blockchain from first possible block.

Eventually we want to save blockchain in db to avoid this scan, but
for the moment, we need to reload as far back as we may be interested in.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
7b735e5de8
  1. 14
      lightningd/chaintopology.c
  2. 6
      lightningd/lightningd.c
  3. 3
      lightningd/test/run-find_my_path.c

14
lightningd/chaintopology.c

@ -467,13 +467,11 @@ static void get_init_block(struct bitcoind *bitcoind,
static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount, static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
struct chain_topology *topo) struct chain_topology *topo)
{ {
/* Start back before any reasonable forks. */ /* This happens if first_blocknum is UINTMAX-1 */
if (blockcount < 100) if (blockcount < topo->first_blocknum)
topo->first_blocknum = 0; topo->first_blocknum = blockcount;
else if (!topo->first_blocknum || blockcount - 100 < topo->first_blocknum)
topo->first_blocknum = blockcount - 100;
/* Start topology from 100 blocks back. */ /* Get up to speed with topology. */
bitcoind_getblockhash(bitcoind, topo->first_blocknum, bitcoind_getblockhash(bitcoind, topo->first_blocknum,
get_init_block, topo); get_init_block, topo);
} }
@ -716,7 +714,9 @@ void setup_topology(struct chain_topology *topo,
memset(&topo->feerate, 0, sizeof(topo->feerate)); memset(&topo->feerate, 0, sizeof(topo->feerate));
topo->timers = timers; topo->timers = timers;
topo->poll_time = poll_time; topo->poll_time = poll_time;
topo->first_blocknum = first_peer_block; /* Start one before the block we are interested in (as we won't
* get notifications on txs in that block). */
topo->first_blocknum = first_peer_block - 1;
/* Make sure bitcoind is started, and ready */ /* Make sure bitcoind is started, and ready */
wait_for_bitcoind(topo->bitcoind); wait_for_bitcoind(topo->bitcoind);

6
lightningd/lightningd.c

@ -210,6 +210,7 @@ int main(int argc, char *argv[])
struct log_book *log_book; struct log_book *log_book;
struct lightningd *ld; struct lightningd *ld;
bool newdir; bool newdir;
u32 peer_first_blocknum;
err_set_progname(argv[0]); err_set_progname(argv[0]);
@ -291,14 +292,15 @@ int main(int argc, char *argv[])
if (!wallet_htlcs_reconnect(ld->wallet, &ld->htlcs_in, &ld->htlcs_out)) if (!wallet_htlcs_reconnect(ld->wallet, &ld->htlcs_in, &ld->htlcs_out))
fatal("could not reconnect htlcs loaded from wallet, wallet may be inconsistent."); fatal("could not reconnect htlcs loaded from wallet, wallet may be inconsistent.");
peer_first_blocknum = wallet_channels_first_blocknum(ld->wallet);
db_commit_transaction(ld->wallet->db); db_commit_transaction(ld->wallet->db);
/* Initialize block topology (does its own transaction) */ /* Initialize block topology (does its own transaction) */
setup_topology(ld->topology, setup_topology(ld->topology,
&ld->timers, &ld->timers,
ld->config.poll_time, ld->config.poll_time,
/* FIXME: Load from peers. */ peer_first_blocknum);
0);
/* Create RPC socket (if any) */ /* Create RPC socket (if any) */
setup_jsonrpc(ld, ld->rpc_filename); setup_jsonrpc(ld, ld->rpc_filename);

3
lightningd/test/run-find_my_path.c

@ -87,6 +87,9 @@ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)
/* Generated stub for version */ /* Generated stub for version */
const char *version(void) const char *version(void)
{ fprintf(stderr, "version called!\n"); abort(); } { fprintf(stderr, "version called!\n"); abort(); }
/* Generated stub for wallet_channels_first_blocknum */
u32 wallet_channels_first_blocknum(struct wallet *w UNNEEDED)
{ fprintf(stderr, "wallet_channels_first_blocknum called!\n"); abort(); }
/* Generated stub for wallet_channels_load_active */ /* Generated stub for wallet_channels_load_active */
bool wallet_channels_load_active(struct wallet *w UNNEEDED, struct list_head *peers UNNEEDED) bool wallet_channels_load_active(struct wallet *w UNNEEDED, struct list_head *peers UNNEEDED)
{ fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); } { fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); }

Loading…
Cancel
Save