diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index f1c57b9e8..0b7235086 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1178,6 +1178,9 @@ static void new_blockheight(struct daemon *daemon, const u8 *msg) tal_arr_remove(&daemon->deferred_txouts, i); i--; } + + daemon_conn_send(daemon->master, + take(towire_gossipd_new_blockheight_reply(NULL))); } #if DEVELOPER @@ -1499,6 +1502,7 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY: case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US: case WIRE_GOSSIPD_ADDGOSSIP_REPLY: + case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY: break; } diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index 8f49421d0..6525397b8 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -74,6 +74,9 @@ msgdata,gossipd_dev_compact_store_reply,success,bool, msgtype,gossipd_new_blockheight,3026 msgdata,gossipd_new_blockheight,blockheight,u32, +# gossipd: got it! +msgtype,gossipd_new_blockheight_reply,3126 + msgtype,gossipd_got_onionmsg_to_us,3145 msgdata,gossipd_got_onionmsg_to_us,obs2,bool, msgdata,gossipd_got_onionmsg_to_us,node_alias,pubkey, diff --git a/gossipd/test/run-onion_message.c b/gossipd/test/run-onion_message.c index 1a4cfd59e..b306112c4 100644 --- a/gossipd/test/run-onion_message.c +++ b/gossipd/test/run-onion_message.c @@ -338,6 +338,9 @@ u8 *towire_gossipd_got_onionmsg_to_us(const tal_t *ctx UNNEEDED, bool obs2 UNNEE /* Generated stub for towire_gossipd_init_reply */ u8 *towire_gossipd_init_reply(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_gossipd_init_reply called!\n"); abort(); } +/* Generated stub for towire_gossipd_new_blockheight_reply */ +u8 *towire_gossipd_new_blockheight_reply(const tal_t *ctx UNNEEDED) +{ fprintf(stderr, "towire_gossipd_new_blockheight_reply called!\n"); abort(); } /* Generated stub for towire_gossipd_new_peer_reply */ u8 *towire_gossipd_new_peer_reply(const tal_t *ctx UNNEEDED, bool success UNNEEDED, const struct gossip_state *gs UNNEEDED) { fprintf(stderr, "towire_gossipd_new_peer_reply called!\n"); abort(); } diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index d64575220..2acf5d15a 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include #include #include @@ -132,6 +133,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY: case WIRE_GOSSIPD_GET_STRIPPED_CUPDATE_REPLY: case WIRE_GOSSIPD_ADDGOSSIP_REPLY: + case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY: break; case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US: @@ -144,14 +146,32 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) return 0; } +static void gossipd_new_blockheight_reply(struct subd *gossipd, + const u8 *reply, + const int *fds UNUSED, + void *blockheight) +{ + if (!fromwire_gossipd_new_blockheight_reply(reply)) { + /* Shouldn't happen! */ + log_broken(gossipd->ld->log, + "Invalid new_blockheight_reply from gossipd: %s", + tal_hex(tmpctx, reply)); + return; + } + + /* Now, finally update getinfo's blockheight */ + gossipd->ld->blockheight = ptr2int(blockheight); +} + void gossip_notify_new_block(struct lightningd *ld, u32 blockheight) { /* Only notify gossipd once we're synced. */ if (!topology_synced(ld->topology)) return; - subd_send_msg(ld->gossip, - take(towire_gossipd_new_blockheight(NULL, blockheight))); + subd_req(ld->gossip, ld->gossip, + take(towire_gossipd_new_blockheight(NULL, blockheight)), + -1, 0, gossipd_new_blockheight_reply, int2ptr(blockheight)); } static void gossip_topology_synced(struct chain_topology *topo, void *unused) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index b0ce617a3..1824838c4 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -215,6 +215,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) /*~ This is detailed in chaintopology.c */ ld->topology = new_topology(ld, ld->log); + ld->blockheight = 0; ld->daemon_parent_fd = -1; ld->proxyaddr = NULL; ld->always_use_proxy = false; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 884b2f921..8f870dbf7 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -167,6 +167,9 @@ struct lightningd { /* Our chain topology. */ struct chain_topology *topology; + /* Blockheight (as acknowledged by gossipd) */ + u32 blockheight; + /* HTLCs in flight. */ struct htlc_in_map htlcs_in; struct htlc_out_map htlcs_out; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index fc81ee52b..1df75a738 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1749,7 +1749,7 @@ static struct command_result *json_getinfo(struct command *cmd, json_array_end(response); } json_add_string(response, "version", version()); - json_add_num(response, "blockheight", get_block_height(cmd->ld->topology)); + json_add_num(response, "blockheight", cmd->ld->blockheight); json_add_string(response, "network", chainparams->network_name); json_add_amount_msat_compat(response, wallet_total_forward_fees(cmd->ld->wallet),