diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 50ea62ff05c..0ca56e70419 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 4ae48f84e4b..630656e2af6 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 98450b90789..0358aeae938 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("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("id"), "id")}; const auto removed_txs{peerman.AbortPrivateBroadcast(id)}; if (removed_txs.empty()) {