chainreg: use GetNetworkInfo for version check
What changed, and why it matters
This commit is a straightforward code cleanup in LND's Bitcoin backend health check. It replaces a manual raw JSON-RPC call and hand-written JSON parsing with a typed library call that does the same thing. There is no security issue visible in the change.
No security action needed. Treat as normal refactoring/cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors getBitcoindHealthCheckCmd in chainreg/chainregistry.go to use rpcclient.Client.GetNetworkInfo() instead of client.RawRequest(‘getnetworkinfo’, nil) followed by a local json.Unmarshal into an anonymous struct. The returned Version field is now uint32 from the typed call, so the two return sites cast it to int64. Behavior (query bitcoind version, choose ‘uptime’ if >= 150000 else ‘getblockchaininfo’) is unchanged.
Changed components
chainreg/chainregistry.gogetBitcoindHealthCheckCmdInspect captured patch +3 / −11
diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go
index 71e9c04..ee23885 100644
--- a/chainreg/chainregistry.go
+++ b/chainreg/chainregistry.go
@@ -802,19 +802,11 @@ func NewChainControl(walletConfig lnwallet.Config,
// getblockchaininfo.
func getBitcoindHealthCheckCmd(client *rpcclient.Client) (string, int64, error) {
// Query bitcoind to get our current version.
- resp, err := client.RawRequest("getnetworkinfo", nil)
+ info, err := client.GetNetworkInfo()
if err != nil {
return "", 0, err
}
- // Parse the response to retrieve bitcoind's version.
- info := struct {
- Version int64 `json:"version"`
- }{}
- if err := json.Unmarshal(resp, &info); err != nil {
- return "", 0, err
- }
-
// Bitcoind returns a single value representing the semantic version:
// 1000000 * CLIENT_VERSION_MAJOR + 10000 * CLIENT_VERSION_MINOR
// + 100 * CLIENT_VERSION_REVISION + 1 * CLIENT_VERSION_BUILD
@@ -822,10 +814,10 @@ func getBitcoindHealthCheckCmd(client *rpcclient.Client) (string, int64, error)
// The uptime call was added in version 0.15.0, so we return it for
// any version value >= 150000, as per the above calculation.
if info.Version >= 150000 {
- return "uptime", info.Version, nil
+ return "uptime", int64(info.Version), nil
}
- return "getblockchaininfo", info.Version, nil
+ return "getblockchaininfo", int64(info.Version), nil
}
var (
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.