bwatch: add outpoint watch RPCs
What changed, and why it matters
This commit adds two new internal plugin commands, addoutpointwatch and deloutpointwatch, to the bwatch plugin in Core Lightning. They let the lightning node start or stop watching a specific transaction output (a txid plus output number) on behalf of a named owner. There is no indication in the commit that this is a security fix or that it addresses any vulnerability; it reads as ordinary feature work.
No security action required. Review as normal feature code if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch registers two new JSON-RPC handlers in plugins/bwatch/bwatch.c and implements them in plugins/bwatch/bwatch_interface.c. Both reuse existing watch-management helpers (bwatch_add_watch / bwatch_del_watch) with WATCH_OUTPOINT. Required parameters are owner, outpoint, and start_block for add; owner and outpoint for del. No authentication, authorization, input validation, or memory-handling changes beyond the existing param() framework are visible. The diff is additive only and does not modify existing behavior.
Changed components
plugins/bwatch/bwatch.cplugins/bwatch/bwatch_interface.cplugins/bwatch/bwatch_interface.hInspect captured patch +57 / −0
diff --git a/plugins/bwatch/bwatch.c b/plugins/bwatch/bwatch.c
index 6b8cb25e..d0512474 100644
--- a/plugins/bwatch/bwatch.c
+++ b/plugins/bwatch/bwatch.c
@@ -289,7 +289,9 @@ static const char *init(struct command *cmd,
static const struct plugin_command commands[] = {
{ "addscriptpubkeywatch", json_bwatch_add_scriptpubkey },
+ { "addoutpointwatch", json_bwatch_add_outpoint },
{ "delscriptpubkeywatch", json_bwatch_del_scriptpubkey },
+ { "deloutpointwatch", json_bwatch_del_outpoint },
};
int main(int argc, char *argv[])
diff --git a/plugins/bwatch/bwatch_interface.c b/plugins/bwatch/bwatch_interface.c
index 178f3e81..c6a1e106 100644
--- a/plugins/bwatch/bwatch_interface.c
+++ b/plugins/bwatch/bwatch_interface.c
@@ -363,3 +363,50 @@ struct command_result *json_bwatch_del_scriptpubkey(struct command *cmd,
NULL, scriptpubkey, NULL, NULL, owner);
return command_success(cmd, json_out_obj(cmd, "removed", "true"));
}
+
+/* Register an outpoint (txid + outnum) watch for `owner` from
+ * `start_block` onwards. */
+struct command_result *json_bwatch_add_outpoint(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params)
+{
+ struct bwatch *bwatch = bwatch_of(cmd->plugin);
+ const char *owner;
+ struct bitcoin_outpoint *outpoint;
+ u32 *start_block;
+
+ if (!param(cmd, buffer, params,
+ p_req("owner", param_string, &owner),
+ p_req("outpoint", param_outpoint, &outpoint),
+ p_req("start_block", param_u32, &start_block),
+ NULL))
+ return command_param_failed();
+
+ /* New owner is appended to the watch's owner list; same owner
+ * re-adding lowers start_block if needed (rescan handled later). */
+ bwatch_add_watch(cmd, bwatch, WATCH_OUTPOINT,
+ outpoint, NULL, NULL, NULL,
+ *start_block, owner);
+ return command_success(cmd, json_out_obj(cmd, NULL, NULL));
+}
+
+/* Drop one owner from an outpoint watch; the watch itself goes away
+ * once the last owner is removed. */
+struct command_result *json_bwatch_del_outpoint(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params)
+{
+ struct bwatch *bwatch = bwatch_of(cmd->plugin);
+ const char *owner;
+ struct bitcoin_outpoint *outpoint;
+
+ if (!param(cmd, buffer, params,
+ p_req("owner", param_string, &owner),
+ p_req("outpoint", param_outpoint, &outpoint),
+ NULL))
+ return command_param_failed();
+
+ bwatch_del_watch(cmd, bwatch, WATCH_OUTPOINT,
+ outpoint, NULL, NULL, NULL, 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 8d705312..c9477413 100644
--- a/plugins/bwatch/bwatch_interface.h
+++ b/plugins/bwatch/bwatch_interface.h
@@ -37,6 +37,14 @@ struct command_result *json_bwatch_del_scriptpubkey(struct command *cmd,
const char *buffer,
const jsmntok_t *params);
+/* RPC handlers: add / remove an outpoint watch. */
+struct command_result *json_bwatch_add_outpoint(struct command *cmd,
+ const char *buffer,
+ const jsmntok_t *params);
+struct command_result *json_bwatch_del_outpoint(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.