MCPcopy Create free account
hub / github.com/ElementsProject/lightning / getchaininfo_done

Function getchaininfo_done

plugins/bwatch/bwatch.c:253–294  ·  view source on GitHub ↗

getchaininfo response: pick the next block to fetch (or just reschedule). */

Source from the content-addressed store, hash-verified

251
252/* getchaininfo response: pick the next block to fetch (or just reschedule). */
253static struct command_result *getchaininfo_done(struct command *cmd,
254 const char *method UNUSED,
255 const char *buf,
256 const jsmntok_t *result,
257 void *unused UNUSED)
258{
259 struct bwatch *bwatch = bwatch_of(cmd->plugin);
260 u32 blockheight;
261 const char *err;
262
263 err = json_scan(tmpctx, buf, result,
264 "{blockcount:%}",
265 JSON_SCAN(json_to_number, &blockheight));
266 if (err) {
267 plugin_log(cmd->plugin, LOG_BROKEN,
268 "getchaininfo parse failed: %s", err);
269 return poll_finished(cmd);
270 }
271
272 if (blockheight > bwatch->current_height) {
273 u32 target_height;
274
275 /* On first init we jump straight to the chain tip; afterwards
276 * we catch up one block at a time so handle_block can validate
277 * each parent hash (added in a later commit). */
278 if (bwatch->current_height == 0) {
279 plugin_log(cmd->plugin, LOG_DBG,
280 "First poll: init at block %u",
281 blockheight);
282 target_height = blockheight;
283 } else {
284 target_height = bwatch->current_height + 1;
285 }
286
287 return fetch_block_handle(cmd, target_height);
288 }
289
290 plugin_log(cmd->plugin, LOG_DBG,
291 "No block change, current_height remains %u",
292 bwatch->current_height);
293 return poll_finished(cmd);
294}
295
296/* Non-fatal: bcli may not have come up yet — log and retry on the next poll. */
297static struct command_result *getchaininfo_failed(struct command *cmd,

Callers

nothing calls this directly

Calls 5

bwatch_ofFunction · 0.85
poll_finishedFunction · 0.85
fetch_block_handleFunction · 0.85
json_scanFunction · 0.50
plugin_logFunction · 0.50

Tested by

no test coverage detected