bcli: replace magic numbers with constants
What changed, and why it matters
This commit is a simple code cleanup: it replaces three hard-coded numbers in the bitcoin-cli plugin with named constants. The actual behavior of the program does not change at all. There is no security fix here.
No security action needed. Treat as normal maintainability refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces three #define constants in plugins/bcli.c and substitutes them for previously literal values: RPC_TRANSACTION_ALREADY_IN_CHAIN (-27), BLOCK_HASH_HEX_LEN (64), and BITCOIND_VERSION_GETBLOCKFROMPEER (230000). The diff is purely cosmetic/refactoring; no logic, comparisons, or control flow are altered.
Changed components
plugins/bcli.cInspect captured patch +9 / −2
diff --git a/plugins/bcli.c b/plugins/bcli.c
index c9ca1ec8..67271bb0 100644
--- a/plugins/bcli.c
+++ b/plugins/bcli.c
@@ -13,8 +13,15 @@
#include <plugins/libplugin.h>
#include <unistd.h>
+/* Bitcoin Core RPC error code for duplicate transaction */
#define RPC_TRANSACTION_ALREADY_IN_CHAIN -27
+/* Hex-encoded SHA256 block hash length (32 bytes = 64 hex chars) */
+#define BLOCK_HASH_HEX_LEN 64
+
+/* Bitcoin Core version 23.0.0 introduced getblockfrompeer RPC */
+#define BITCOIND_VERSION_GETBLOCKFROMPEER 230000
+
struct bitcoind {
/* eg. "bitcoin-cli" */
char *cli;
@@ -362,7 +369,7 @@ static struct command_result *getrawblockbyheight(struct command *cmd,
}
strip_trailing_whitespace(res->output, res->output_len);
- if (strlen(res->output) != 64)
+ if (strlen(res->output) != BLOCK_HASH_HEX_LEN)
return command_err(cmd, res, "bad JSON: bad blockhash");
block_hash = tal_strdup(cmd, res->output);
@@ -396,7 +403,7 @@ static struct command_result *getrawblockbyheight(struct command *cmd,
}
/* Try fetching from peers if bitcoind >= 23.0.0 */
- if (bitcoind->version >= 230000) {
+ if (bitcoind->version >= BITCOIND_VERSION_GETBLOCKFROMPEER) {
if (!peers)
peers = get_fullnode_peers(cmd, cmd);
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.