lightningd: don't print zero blockheight while we're syncing.

In v0.11 (71f736678f) we changed lightningd to wait for gossipd to
acknowledge blocks before updating blockheight: this resolved a problem
which lnprototest had where it wanted to know when we'd fully digested
a block.

However, it broke the syncing case: until then we don't even tell
gossipd, so this stayed at zero.  We should use the current blockheight
for that corner case!

Fixes: #5894
Changelog-Fixed: JSON-RPC: `getinfo` `blockheight` no longer sits on 0 while we sync with bitcoind the first time.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-02-06 22:41:47 +10:30
committed by Alex Myers
parent e29fd2a8e2
commit 7b9f1b72c6
4 changed files with 13 additions and 4 deletions

View File

@@ -201,7 +201,7 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,
} }
/* Now, finally update getinfo's blockheight */ /* Now, finally update getinfo's blockheight */
gossipd->ld->blockheight = ptr2int(blockheight); gossipd->ld->gossip_blockheight = ptr2int(blockheight);
} }
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight) void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)

View File

@@ -244,7 +244,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
/*~ This is detailed in chaintopology.c */ /*~ This is detailed in chaintopology.c */
ld->topology = new_topology(ld, ld->log); ld->topology = new_topology(ld, ld->log);
ld->blockheight = 0; ld->gossip_blockheight = 0;
ld->daemon_parent_fd = -1; ld->daemon_parent_fd = -1;
ld->proxyaddr = NULL; ld->proxyaddr = NULL;
ld->always_use_proxy = false; ld->always_use_proxy = false;

View File

@@ -198,7 +198,7 @@ struct lightningd {
struct chain_topology *topology; struct chain_topology *topology;
/* Blockheight (as acknowledged by gossipd) */ /* Blockheight (as acknowledged by gossipd) */
u32 blockheight; u32 gossip_blockheight;
/* HTLCs in flight. */ /* HTLCs in flight. */
struct htlc_in_map *htlcs_in; struct htlc_in_map *htlcs_in;

View File

@@ -2418,7 +2418,16 @@ static struct command_result *json_getinfo(struct command *cmd,
json_array_end(response); json_array_end(response);
json_add_string(response, "version", version()); json_add_string(response, "version", version());
json_add_num(response, "blockheight", cmd->ld->blockheight); /* If we're still syncing, put the height we're up to here, so
* they can see progress! Otherwise use the height gossipd knows
* about, so tests work properly. */
if (!topology_synced(cmd->ld->topology)) {
json_add_num(response, "blockheight",
get_block_height(cmd->ld->topology));
} else {
json_add_num(response, "blockheight",
cmd->ld->gossip_blockheight);
}
json_add_string(response, "network", chainparams->network_name); json_add_string(response, "network", chainparams->network_name);
json_add_amount_msat_compat(response, json_add_amount_msat_compat(response,
wallet_total_forward_fees(cmd->ld->wallet), wallet_total_forward_fees(cmd->ld->wallet),