rpc: Add getprivatebroadcastinfo
Co-authored-by: Vasil Dimov <vd@freebsd.org>
This commit is contained in:
1 parent
5e64982541
commit
996f20c18a
4 files changed
+77
No files matched your search
@@ -542,6 +542,7 @@ public:
|
|||||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||||
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);
|
||||||
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);
|
||||||
@@ -1855,6 +1856,11 @@ PeerManagerInfo PeerManagerImpl::GetInfo() const
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<PrivateBroadcast::TxBroadcastInfo> PeerManagerImpl::GetPrivateBroadcastInfo() const
|
||||||
|
{
|
||||||
|
return m_tx_for_private_broadcast.GetBroadcastInfo();
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <node/txorphanage.h>
|
#include <node/txorphanage.h>
|
||||||
|
#include <private_broadcast.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <threadsafety.h>
|
#include <threadsafety.h>
|
||||||
#include <util/expected.h>
|
#include <util/expected.h>
|
||||||
@@ -118,6 +119,9 @@ public:
|
|||||||
/** Get peer manager info. */
|
/** Get peer manager info. */
|
||||||
virtual PeerManagerInfo GetInfo() const = 0;
|
virtual PeerManagerInfo GetInfo() const = 0;
|
||||||
|
|
||||||
|
/** Get info about transactions currently being privately broadcast. */
|
||||||
|
virtual std::vector<PrivateBroadcast::TxBroadcastInfo> GetPrivateBroadcastInfo() const = 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`
|
||||||
|
|||||||
@@ -137,6 +137,71 @@ static RPCHelpMan sendrawtransaction()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RPCHelpMan getprivatebroadcastinfo()
|
||||||
|
{
|
||||||
|
return RPCHelpMan{
|
||||||
|
"getprivatebroadcastinfo",
|
||||||
|
"Returns information about transactions that are currently being privately broadcast.\n",
|
||||||
|
{},
|
||||||
|
RPCResult{
|
||||||
|
RPCResult::Type::OBJ, "", "",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::ARR, "transactions", "",
|
||||||
|
{
|
||||||
|
{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"},
|
||||||
|
{RPCResult::Type::ARR, "peers", "Per-peer send and acknowledgment information for this transaction",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::OBJ, "", "",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::STR, "address", "The address of the peer to which the transaction was sent"},
|
||||||
|
{RPCResult::Type::NUM_TIME, "sent", "The time this transaction was picked for sending to this peer via private broadcast (seconds since epoch)"},
|
||||||
|
{RPCResult::Type::NUM_TIME, "received", /*optional=*/true, "The time this peer acknowledged reception of the transaction (seconds since epoch)"},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
RPCExamples{
|
||||||
|
HelpExampleCli("getprivatebroadcastinfo", "")
|
||||||
|
+ HelpExampleRpc("getprivatebroadcastinfo", "")
|
||||||
|
},
|
||||||
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
const NodeContext& node{EnsureAnyNodeContext(request.context)};
|
||||||
|
const PeerManager& peerman{EnsurePeerman(node)};
|
||||||
|
const auto txs{peerman.GetPrivateBroadcastInfo()};
|
||||||
|
|
||||||
|
UniValue transactions(UniValue::VARR);
|
||||||
|
for (const auto& tx_info : txs) {
|
||||||
|
UniValue o(UniValue::VOBJ);
|
||||||
|
o.pushKV("txid", tx_info.tx->GetHash().ToString());
|
||||||
|
o.pushKV("wtxid", tx_info.tx->GetWitnessHash().ToString());
|
||||||
|
o.pushKV("hex", EncodeHexTx(*tx_info.tx));
|
||||||
|
UniValue peers(UniValue::VARR);
|
||||||
|
for (const auto& peer : tx_info.peers) {
|
||||||
|
UniValue p(UniValue::VOBJ);
|
||||||
|
p.pushKV("address", peer.address.ToStringAddrPort());
|
||||||
|
p.pushKV("sent", TicksSinceEpoch<std::chrono::seconds>(peer.sent));
|
||||||
|
if (peer.received.has_value()) {
|
||||||
|
p.pushKV("received", TicksSinceEpoch<std::chrono::seconds>(*peer.received));
|
||||||
|
}
|
||||||
|
peers.push_back(std::move(p));
|
||||||
|
}
|
||||||
|
o.pushKV("peers", std::move(peers));
|
||||||
|
transactions.push_back(std::move(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
ret.pushKV("transactions", std::move(transactions));
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan testmempoolaccept()
|
static RPCHelpMan testmempoolaccept()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{
|
return RPCHelpMan{
|
||||||
@@ -1329,6 +1394,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
|
|||||||
{
|
{
|
||||||
static const CRPCCommand commands[]{
|
static const CRPCCommand commands[]{
|
||||||
{"rawtransactions", &sendrawtransaction},
|
{"rawtransactions", &sendrawtransaction},
|
||||||
|
{"rawtransactions", &getprivatebroadcastinfo},
|
||||||
{"rawtransactions", &testmempoolaccept},
|
{"rawtransactions", &testmempoolaccept},
|
||||||
{"blockchain", &getmempoolancestors},
|
{"blockchain", &getmempoolancestors},
|
||||||
{"blockchain", &getmempooldescendants},
|
{"blockchain", &getmempooldescendants},
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
|||||||
"getorphantxs",
|
"getorphantxs",
|
||||||
"getpeerinfo",
|
"getpeerinfo",
|
||||||
"getprioritisedtransactions",
|
"getprioritisedtransactions",
|
||||||
|
"getprivatebroadcastinfo",
|
||||||
"getrawaddrman",
|
"getrawaddrman",
|
||||||
"getrawmempool",
|
"getrawmempool",
|
||||||
"getrawtransaction",
|
"getrawtransaction",
|
||||||
|
|||||||
Reference in new issue
Block a user