rpc: getprivatebroadcastinfo and abortprivatebroadcast throw if -privatebroadcast is disabled
What changed, and why it matters
This commit makes two Bitcoin Core RPC commands—getprivatebroadcastinfo and abortprivatebroadcast—return a clear 'method not available' error when the optional -privatebroadcast feature is turned off. Previously these methods may have been callable even though the underlying feature was inactive, which could have led to confusing or misleading results rather than any direct loss of funds.
No urgent action required. Treat as a minor hardening/UX improvement. Operators using these RPCs should ensure -privatebroadcast=1 is set if they need the functionality.
Security signals we found
RPC method behavior hardened to reject calls when dependent feature is disabled
New runtime guard added before accessing private-broadcast state
No memory safety, cryptographic, or consensus changes observed
Evidence from the diff
The patch exposes the private_broadcast option value through PeerManagerInfo and then checks it at the start of getprivatebroadcastinfo and abortprivatebroadcast. If -privatebroadcast is disabled, the RPC now throws RPC_METHOD_NOT_FOUND with a descriptive message. This is a hardening/UX fix: it prevents RPC consumers from invoking private-broadcast-related methods when the subsystem is inactive.
Changed components
src/net_processing.cppsrc/net_processing.hsrc/rpc/mempool.cppRPC interface: getprivatebroadcastinfoRPC interface: abortprivatebroadcastInspect captured patch +15 / −3
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 50ea62ff..0ca56e70 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1852,6 +1852,7 @@ PeerManagerInfo PeerManagerImpl::GetInfo() const
return PeerManagerInfo{
.median_outbound_time_offset = m_outbound_time_offsets.Median(),
.ignores_incoming_txs = m_opts.ignore_incoming_txs,
+ .private_broadcast = m_opts.private_broadcast,
};
}
diff --git a/src/net_processing.h b/src/net_processing.h
index 4ae48f84..630656e2 100644
--- a/src/net_processing.h
+++ b/src/net_processing.h
@@ -71,6 +71,7 @@ struct CNodeStateStats {
struct PeerManagerInfo {
std::chrono::seconds median_outbound_time_offset{0s};
bool ignores_incoming_txs{false};
+ bool private_broadcast{DEFAULT_PRIVATE_BROADCAST};
};
class PeerManager : public CValidationInterface, public NetEventsInterface
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index 98450b90..0358aeae 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -143,7 +143,8 @@ static RPCMethod getprivatebroadcastinfo()
{
return RPCMethod{
"getprivatebroadcastinfo",
- "Returns information about transactions that are currently being privately broadcast.\n",
+ "Returns information about transactions that are currently being privately broadcast.\n"
+ "This method is only available when running with -privatebroadcast enabled.\n",
{},
RPCResult{
RPCResult::Type::OBJ, "", "",
@@ -176,6 +177,10 @@ static RPCMethod getprivatebroadcastinfo()
{
const NodeContext& node{EnsureAnyNodeContext(request.context)};
const PeerManager& peerman{EnsurePeerman(node)};
+ if (!peerman.GetInfo().private_broadcast) {
+ throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Private broadcast is not enabled. Ensure you're running Bitcoin Core with -privatebroadcast=1.");
+ }
+
const auto txs{peerman.GetPrivateBroadcastInfo()};
UniValue transactions(UniValue::VARR);
@@ -211,7 +216,8 @@ static RPCMethod abortprivatebroadcast()
return RPCMethod{
"abortprivatebroadcast",
"Abort private broadcast attempts for a transaction currently being privately broadcast.\n"
- "The transaction will be removed from the private broadcast queue.\n",
+ "The transaction will be removed from the private broadcast queue.\n"
+ "This method is only available when running with -privatebroadcast enabled.\n",
{
{"id", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A transaction identifier to abort. It will be matched against both txid and wtxid for all transactions in the private broadcast queue.\n"
"If the provided id matches a txid that corresponds to multiple transactions with different wtxids, multiple transactions will be removed and returned."},
@@ -236,10 +242,14 @@ static RPCMethod abortprivatebroadcast()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const uint256 id{ParseHashV(self.Arg<UniValue>("id"), "id")};
const NodeContext& node{EnsureAnyNodeContext(request.context)};
PeerManager& peerman{EnsurePeerman(node)};
+ if (!peerman.GetInfo().private_broadcast) {
+ throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Private broadcast is not enabled. Ensure you're running Bitcoin Core with -privatebroadcast=1.");
+ }
+
+ const uint256 id{ParseHashV(self.Arg<UniValue>("id"), "id")};
const auto removed_txs{peerman.AbortPrivateBroadcast(id)};
if (removed_txs.empty()) {
Why this scored 19/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.