rpc: Add abortprivatebroadcast
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
This commit is contained in:
4 files changed
+91
No files matched your search
@@ -543,6 +543,7 @@ public:
|
|||||||
std::vector<node::TxOrphanage::OrphanInfo> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
|
std::vector<node::TxOrphanage::OrphanInfo> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
|
||||||
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
|
std::vector<CTransactionRef> AbortPrivateBroadcast(const uint256& id) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
void InitiateTxBroadcastToAll(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
void InitiateTxBroadcastToAll(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
void InitiateTxBroadcastPrivate(const CTransactionRef& tx) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
void InitiateTxBroadcastPrivate(const CTransactionRef& tx) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
@@ -1861,6 +1862,26 @@ std::vector<PrivateBroadcast::TxBroadcastInfo> PeerManagerImpl::GetPrivateBroadc
|
|||||||
return m_tx_for_private_broadcast.GetBroadcastInfo();
|
return m_tx_for_private_broadcast.GetBroadcastInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CTransactionRef> PeerManagerImpl::AbortPrivateBroadcast(const uint256& id)
|
||||||
|
{
|
||||||
|
const auto snapshot{m_tx_for_private_broadcast.GetBroadcastInfo()};
|
||||||
|
std::vector<CTransactionRef> removed_txs;
|
||||||
|
|
||||||
|
size_t connections_cancelled{0};
|
||||||
|
for (const auto& [tx, _] : snapshot) {
|
||||||
|
if (tx->GetHash().ToUint256() != id && tx->GetWitnessHash().ToUint256() != id) continue;
|
||||||
|
if (const auto peer_acks{m_tx_for_private_broadcast.Remove(tx)}) {
|
||||||
|
removed_txs.push_back(tx);
|
||||||
|
if (NUM_PRIVATE_BROADCAST_PER_TX > *peer_acks) {
|
||||||
|
connections_cancelled += (NUM_PRIVATE_BROADCAST_PER_TX - *peer_acks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_connman.m_private_broadcast.NumToOpenSub(connections_cancelled);
|
||||||
|
|
||||||
|
return removed_txs;
|
||||||
|
}
|
||||||
|
|
||||||
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
||||||
{
|
{
|
||||||
if (m_opts.max_extra_txs <= 0)
|
if (m_opts.max_extra_txs <= 0)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <private_broadcast.h>
|
#include <private_broadcast.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <threadsafety.h>
|
#include <threadsafety.h>
|
||||||
|
#include <uint256.h>
|
||||||
#include <util/expected.h>
|
#include <util/expected.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
@@ -122,6 +123,18 @@ public:
|
|||||||
/** Get info about transactions currently being privately broadcast. */
|
/** Get info about transactions currently being privately broadcast. */
|
||||||
virtual std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const = 0;
|
virtual std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abort private broadcast attempts for transactions currently being privately broadcast.
|
||||||
|
*
|
||||||
|
* @param[in] id A transaction identifier. It will be matched against both txid and wtxid for
|
||||||
|
* all transactions in the private broadcast queue.
|
||||||
|
*
|
||||||
|
* @return Transactions removed from the private broadcast queue. If the provided id matches a
|
||||||
|
* txid that corresponds to multiple transactions with different wtxids, multiple
|
||||||
|
* transactions may be returned.
|
||||||
|
*/
|
||||||
|
virtual std::vector<CTransactionRef> AbortPrivateBroadcast(const uint256& id) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate a transaction broadcast to eligible peers.
|
* Initiate a transaction broadcast to eligible peers.
|
||||||
* Queue the witness transaction id to `Peer::TxRelay::m_tx_inventory_to_send`
|
* Queue the witness transaction id to `Peer::TxRelay::m_tx_inventory_to_send`
|
||||||
|
|||||||
@@ -202,6 +202,61 @@ static RPCHelpMan getprivatebroadcastinfo()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RPCHelpMan abortprivatebroadcast()
|
||||||
|
{
|
||||||
|
return RPCHelpMan{
|
||||||
|
"abortprivatebroadcast",
|
||||||
|
"Abort private broadcast attempts for a transaction currently being privately broadcast.\n"
|
||||||
|
"The transaction will be removed from the private broadcast queue.\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."},
|
||||||
|
},
|
||||||
|
RPCResult{
|
||||||
|
RPCResult::Type::OBJ, "", "",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::ARR, "removed_transactions", "Transactions removed from the private broadcast queue",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::OBJ, "", "",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
|
||||||
|
{RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
|
||||||
|
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded transaction data"},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
RPCExamples{
|
||||||
|
HelpExampleCli("abortprivatebroadcast", "\"id\"")
|
||||||
|
+ HelpExampleRpc("abortprivatebroadcast", "\"id\"")
|
||||||
|
},
|
||||||
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
const uint256 id{ParseHashV(self.Arg<UniValue>("id"), "id")};
|
||||||
|
|
||||||
|
const NodeContext& node{EnsureAnyNodeContext(request.context)};
|
||||||
|
PeerManager& peerman{EnsurePeerman(node)};
|
||||||
|
|
||||||
|
const auto removed_txs{peerman.AbortPrivateBroadcast(id)};
|
||||||
|
if (removed_txs.empty()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in private broadcast queue. Check getprivatebroadcastinfo.");
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue removed_transactions(UniValue::VARR);
|
||||||
|
for (const auto& tx : removed_txs) {
|
||||||
|
UniValue o(UniValue::VOBJ);
|
||||||
|
o.pushKV("txid", tx->GetHash().ToString());
|
||||||
|
o.pushKV("wtxid", tx->GetWitnessHash().ToString());
|
||||||
|
o.pushKV("hex", EncodeHexTx(*tx));
|
||||||
|
removed_transactions.push_back(std::move(o));
|
||||||
|
}
|
||||||
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
ret.pushKV("removed_transactions", std::move(removed_transactions));
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan testmempoolaccept()
|
static RPCHelpMan testmempoolaccept()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{
|
return RPCHelpMan{
|
||||||
@@ -1395,6 +1450,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
|
|||||||
static const CRPCCommand commands[]{
|
static const CRPCCommand commands[]{
|
||||||
{"rawtransactions", &sendrawtransaction},
|
{"rawtransactions", &sendrawtransaction},
|
||||||
{"rawtransactions", &getprivatebroadcastinfo},
|
{"rawtransactions", &getprivatebroadcastinfo},
|
||||||
|
{"rawtransactions", &abortprivatebroadcast},
|
||||||
{"rawtransactions", &testmempoolaccept},
|
{"rawtransactions", &testmempoolaccept},
|
||||||
{"blockchain", &getmempoolancestors},
|
{"blockchain", &getmempoolancestors},
|
||||||
{"blockchain", &getmempooldescendants},
|
{"blockchain", &getmempooldescendants},
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
|
|||||||
|
|
||||||
// RPC commands which are safe for fuzzing.
|
// RPC commands which are safe for fuzzing.
|
||||||
const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
||||||
|
"abortprivatebroadcast",
|
||||||
"analyzepsbt",
|
"analyzepsbt",
|
||||||
"clearbanned",
|
"clearbanned",
|
||||||
"combinepsbt",
|
"combinepsbt",
|
||||||
|
|||||||
Reference in new issue
Block a user