mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 02:39:28 +01:00
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>
This commit is contained in:
parent
93c589efe8
commit
7b735e5de8
3 changed files with 14 additions and 9 deletions
|
@ -467,13 +467,11 @@ static void get_init_block(struct bitcoind *bitcoind,
|
|||
static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
|
||||
struct chain_topology *topo)
|
||||
{
|
||||
/* Start back before any reasonable forks. */
|
||||
if (blockcount < 100)
|
||||
topo->first_blocknum = 0;
|
||||
else if (!topo->first_blocknum || blockcount - 100 < topo->first_blocknum)
|
||||
topo->first_blocknum = blockcount - 100;
|
||||
/* This happens if first_blocknum is UINTMAX-1 */
|
||||
if (blockcount < topo->first_blocknum)
|
||||
topo->first_blocknum = blockcount;
|
||||
|
||||
/* Start topology from 100 blocks back. */
|
||||
/* Get up to speed with topology. */
|
||||
bitcoind_getblockhash(bitcoind, topo->first_blocknum,
|
||||
get_init_block, topo);
|
||||
}
|
||||
|
@ -716,7 +714,9 @@ void setup_topology(struct chain_topology *topo,
|
|||
memset(&topo->feerate, 0, sizeof(topo->feerate));
|
||||
topo->timers = timers;
|
||||
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 */
|
||||
wait_for_bitcoind(topo->bitcoind);
|
||||
|
|
|
@ -210,6 +210,7 @@ int main(int argc, char *argv[])
|
|||
struct log_book *log_book;
|
||||
struct lightningd *ld;
|
||||
bool newdir;
|
||||
u32 peer_first_blocknum;
|
||||
|
||||
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))
|
||||
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);
|
||||
|
||||
/* Initialize block topology (does its own transaction) */
|
||||
setup_topology(ld->topology,
|
||||
&ld->timers,
|
||||
ld->config.poll_time,
|
||||
/* FIXME: Load from peers. */
|
||||
0);
|
||||
peer_first_blocknum);
|
||||
|
||||
/* Create RPC socket (if any) */
|
||||
setup_jsonrpc(ld, ld->rpc_filename);
|
||||
|
|
|
@ -87,6 +87,9 @@ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)
|
|||
/* Generated stub for version */
|
||||
const char *version(void)
|
||||
{ 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 */
|
||||
bool wallet_channels_load_active(struct wallet *w UNNEEDED, struct list_head *peers UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue