rpc: getprivatebroadcastinfo and abortprivatebroadcast throw if -privatebroadcast is disabled

This commit is contained in:
Pol Espinasa
2026-05-13 21:03:46 +02:00
parent 47da4f9b71
commit 7b821ef9b7
3 changed files with 15 additions and 3 deletions

View File

@@ -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,
};
}

View File

@@ -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

View File

@@ -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()) {