From abe934ce79af8c0a6ca3fb4b09b8baa958159a3d Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Fri, 17 May 2024 13:30:13 +0100 Subject: [PATCH] net: define NodeId as an int64_t This should make occurrences of NodeId wrapping essentially impossible for real-world usage. Backport of https://github.com/bitcoin/bitcoin/pull/10176 [zcashd] I have checked that zcashd has no current uses of NodeId that depend on it being an `int`. All accesses to the global `nLastNodeId` are under lock. `NodeId` *is* required to be a signed integral type, because `-1` is used as a sentinel value. It is also formatted using the `%d` tinyformat specifier, but unlike the C format specifier it is inspired by, this correctly handles integral types of arbitrary width. There are `NodeId` fields in `CNodeStats`, `NodeEvictionCandidate`, and (test-only) `COrphanTx`, but those types are not serializable, and there is no other ad-hoc serialization of `NodeId` values apart from its use in the "id" field of the output from the `getpeerinfo` RPC. `UniValue` has an override of `pushKV` for `int64_t`, and so that use will correctly handle values up to the [maximum safe JSON/JavaScript integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER), i.e. $2^{53} - 1$. As upstream did, we argue that it is not feasible to cause that value to be exceeded. Co-authored-by: Cory Fields Signed-off-by: Daira-Emma Hopwood --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index 51b902202a3..23c70c3e6ac 100644 --- a/src/net.h +++ b/src/net.h @@ -103,7 +103,7 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler); bool StopNode(); void SocketSendData(CNode *pnode); -typedef int NodeId; +typedef int64_t NodeId; struct CombinerAll {