bwatch: add blockdepth watch RPCs
What changed, and why it matters
This commit adds two new internal plugin commands, addblockdepthwatch and delblockdepthwatch, to the bwatch plugin in Core Lightning. They let another part of the node ask bwatch to track how many blocks have passed since a chosen starting block height. There is no indication in the commit that this fixes a bug or addresses a security issue; it appears to be a normal feature addition.
No security action required; review as part of normal code review. If these RPCs become externally exposed in future changes, ensure they are guarded by appropriate authorization and input validation.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch registers two new JSON-RPC command handlers in plugins/bwatch/bwatch.c and implements them in plugins/bwatch/bwatch_interface.c. addblockdepthwatch creates a WATCH_BLOCKDEPTH keyed by (owner, start_block), and delblockdepthwatch removes an owner from that watch. A debug log line is also added to bwatch_send_blockdepth_found. The change is additive (+59 lines, no deletions) and does not alter existing authentication, authorization, or resource-limit logic.
Changed components
plugins/bwatch/bwatch.cplugins/bwatch/bwatch_interface.cplugins/bwatch/bwatch_interface.hInspect captured patch +59 / −0
diff --git a/plugins/bwatch/bwatch.c b/plugins/bwatch/bwatch.c
index fdb8fe76..7f37212a 100644
--- a/plugins/bwatch/bwatch.c
+++ b/plugins/bwatch/bwatch.c
@@ -291,9 +291,11 @@ static const struct plugin_command commands[] = {
{ "addscriptpubkeywatch", json_bwatch_add_scriptpubkey },
{ "addoutpointwatch", json_bwatch_add_outpoint },
{ "addscidwatch", json_bwatch_add_scid },
+ { "addblockdepthwatch", json_bwatch_add_blockdepth },
{ "delscriptpubkeywatch", json_bwatch_del_scriptpubkey },
{ "deloutpointwatch", json_bwatch_del_outpoint },
{ "delscidwatch", json_bwatch_del_scid },
+ { "delblockdepthwatch", json_bwatch_del_blockdepth },
};
int main(int argc, char *argv[])
diff --git a/plugins/bwatch/bwatch_interface.c b/plugins/bwatch/bwatch_interface.c
index ce8da769..72b9823e 100644
--- a/plugins/bwatch/bwatch_interface.c
+++ b/plugins/bwatch/bwatch_interface.c
@@ -79,6 +79,10 @@ void bwatch_send_blockdepth_found(struct command *cmd,
json_add_string(req->js, NULL, w->owners[i]);
json_array_end(req->js);
+ plugin_log(cmd->plugin, LOG_DBG,
+ "watch_found at block %u (blockdepth depth=%u)",
+ blockheight, depth);
+
send_outreq(req);
}
@@ -458,3 +462,48 @@ struct command_result *json_bwatch_del_scid(struct command *cmd,
NULL, NULL, scid, NULL, owner);
return command_success(cmd, json_out_obj(cmd, "removed", "true"));
}
+
+/* Register a blockdepth watch for `owner` anchored at `start_block`.
+ * Each new block fires a watch_found with depth = tip - start_block + 1. */
+struct command_result *json_bwatch_add_blockdepth(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params)
+{
+ struct bwatch *bwatch = bwatch_of(cmd->plugin);
+ const char *owner;
+ u32 *start_block;
+
+ if (!param(cmd, buffer, params,
+ p_req("owner", param_string, &owner),
+ p_req("start_block", param_u32, &start_block),
+ NULL))
+ return command_param_failed();
+
+ /* start_block doubles as the watch key (confirm_height) and
+ * the anchor for depth = tip - start_block + 1. */
+ bwatch_add_watch(cmd, bwatch, WATCH_BLOCKDEPTH,
+ NULL, NULL, NULL, start_block,
+ *start_block, owner);
+ return command_success(cmd, json_out_obj(cmd, NULL, NULL));
+}
+
+/* Drop one owner from a blockdepth watch; the watch itself goes away
+ * once the last owner is removed. */
+struct command_result *json_bwatch_del_blockdepth(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params)
+{
+ struct bwatch *bwatch = bwatch_of(cmd->plugin);
+ const char *owner;
+ u32 *start_block;
+
+ if (!param(cmd, buffer, params,
+ p_req("owner", param_string, &owner),
+ p_req("start_block", param_u32, &start_block),
+ NULL))
+ return command_param_failed();
+
+ bwatch_del_watch(cmd, bwatch, WATCH_BLOCKDEPTH,
+ NULL, NULL, NULL, start_block, owner);
+ return command_success(cmd, json_out_obj(cmd, "removed", "true"));
+}
diff --git a/plugins/bwatch/bwatch_interface.h b/plugins/bwatch/bwatch_interface.h
index edd5085f..5e5ec0c6 100644
--- a/plugins/bwatch/bwatch_interface.h
+++ b/plugins/bwatch/bwatch_interface.h
@@ -53,6 +53,14 @@ struct command_result *json_bwatch_del_scid(struct command *cmd,
const char *buffer,
const jsmntok_t *params);
+/* RPC handlers: add / remove a blockdepth watch. */
+struct command_result *json_bwatch_add_blockdepth(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params);
+struct command_result *json_bwatch_del_blockdepth(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params);
+
/* Send a block_processed RPC to watchman after a new block has been
* persisted. The next poll is started from the ack callback so we don't
* race ahead of watchman's view of the chain. Chains on the same poll
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.