topo: Tell chain_topology about the min and max block height

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-06-04 15:00:05 +02:00
parent 5c9c682cf7
commit bdb87aa994
No known key found for this signature in database
GPG Key ID: 1416D83DC4F0E86D
4 changed files with 17 additions and 21 deletions

View File

@ -745,14 +745,14 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log)
void setup_topology(struct chain_topology *topo,
struct timers *timers,
u32 first_blocknum)
u32 min_blockheight, u32 max_blockheight)
{
memset(&topo->feerate, 0, sizeof(topo->feerate));
topo->timers = timers;
/* FIXME(cdecker) Actually load this from DB */
topo->min_blockheight = first_blocknum;
topo->max_blockheight = first_blocknum;
topo->min_blockheight = min_blockheight;
topo->max_blockheight = max_blockheight;
/* Make sure bitcoind is started, and ready */
wait_for_bitcoind(topo->bitcoind);

View File

@ -150,9 +150,8 @@ void broadcast_tx(struct chain_topology *topo,
const char *err));
struct chain_topology *new_topology(struct lightningd *ld, struct log *log);
void setup_topology(struct chain_topology *topology,
struct timers *timers,
u32 first_channel_block);
void setup_topology(struct chain_topology *topology, struct timers *timers,
u32 min_blockheight, u32 max_blockheight);
void begin_topology(struct chain_topology *topo);

View File

@ -306,7 +306,7 @@ void notify_new_block(struct lightningd *ld,
int main(int argc, char *argv[])
{
struct lightningd *ld;
u32 blockheight, first_block;
u32 min_blockheight, max_blockheight;
setup_locale();
daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
@ -388,24 +388,22 @@ int main(int argc, char *argv[])
/* Get the blockheight we are currently at, UINT32_MAX is used to signal
* an unitialized wallet and that we should start off of bitcoind's
* current height */
wallet_blocks_heights(ld->wallet, UINT32_MAX, &first_block, &blockheight);
wallet_blocks_heights(ld->wallet, UINT32_MAX, &min_blockheight, &max_blockheight);
/* If we were asked to rescan from an absolute height (--rescan < 0)
* then just go there. Otherwise take compute the diff to our current
* height, lowerbounded by 0. */
* then just go there. Otherwise compute the diff to our current height,
* lowerbounded by 0. */
if (ld->config.rescan < 0)
blockheight = -ld->config.rescan;
else if (blockheight < (u32)ld->config.rescan)
blockheight = 0;
else if (blockheight != UINT32_MAX)
blockheight -= ld->config.rescan;
max_blockheight = -ld->config.rescan;
else if (max_blockheight < (u32)ld->config.rescan)
max_blockheight = 0;
else if (max_blockheight != UINT32_MAX)
max_blockheight -= ld->config.rescan;
db_commit_transaction(ld->wallet->db);
/* Initialize block topology (does its own transaction) */
setup_topology(ld->topology,
&ld->timers,
blockheight);
setup_topology(ld->topology, &ld->timers, min_blockheight, max_blockheight);
/* Create RPC socket (if any) */
setup_jsonrpc(ld, ld->rpc_filename);

View File

@ -101,9 +101,8 @@ void setup_color_and_alias(struct lightningd *ld UNNEEDED)
void setup_jsonrpc(struct lightningd *ld UNNEEDED, const char *rpc_filename UNNEEDED)
{ fprintf(stderr, "setup_jsonrpc called!\n"); abort(); }
/* Generated stub for setup_topology */
void setup_topology(struct chain_topology *topology UNNEEDED,
struct timers *timers UNNEEDED,
u32 first_channel_block UNNEEDED)
void setup_topology(struct chain_topology *topology UNNEEDED, struct timers *timers UNNEEDED,
u32 min_blockheight UNNEEDED, u32 max_blockheight UNNEEDED)
{ fprintf(stderr, "setup_topology called!\n"); abort(); }
/* Generated stub for subd_shutdown */
void subd_shutdown(struct subd *subd UNNEEDED, unsigned int seconds UNNEEDED)