Skip to content

Commit dec1da5

Browse files
committed
add getextrapoolinfo rpc
1 parent 271fd20 commit dec1da5

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/net_processing.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ class PeerManagerImpl final : public PeerManager
522522
ServiceFlags GetDesirableServiceFlags(ServiceFlags services) const override;
523523
int GetNumberOfPeersWithValidatedDownloads() const override EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
524524

525+
size_t ExtraTxnForCompactCount() const override EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
526+
size_t ExtraTxnForCompactBytes() const override EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
527+
525528
private:
526529
/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
527530
void ConsiderEviction(CNode& pto, Peer& peer, std::chrono::seconds time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_msgproc_mutex);
@@ -1063,6 +1066,19 @@ CNodeState* PeerManagerImpl::State(NodeId pnode)
10631066
return const_cast<CNodeState*>(std::as_const(*this).State(pnode));
10641067
}
10651068

1069+
size_t PeerManagerImpl::ExtraTxnForCompactCount() const {
1070+
AssertLockHeld(::cs_main);
1071+
size_t count = 0;
1072+
for (const auto& tx : vExtraTxnForCompact) {
1073+
if (tx) count++;
1074+
}
1075+
return count;
1076+
}
1077+
size_t PeerManagerImpl::ExtraTxnForCompactBytes() const {
1078+
AssertLockHeld(::cs_main);
1079+
return blockreconstructionextratxn_memusage;
1080+
}
1081+
10661082
/**
10671083
* Whether the peer supports the address. For example, a peer that does not
10681084
* implement BIP155 cannot receive Tor v3 addresses because it requires

src/net_processing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
113113
/** Get peer manager info. */
114114
virtual PeerManagerInfo GetInfo() const = 0;
115115

116+
virtual size_t ExtraTxnForCompactCount() const = 0;
117+
virtual size_t ExtraTxnForCompactBytes() const = 0;
118+
116119
/** Relay transaction to all peers. */
117120
virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0;
118121

src/rpc/mempool.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,36 @@ static RPCHelpMan getmempoolinfo()
10641064
};
10651065
}
10661066

1067+
static RPCHelpMan getextrapoolinfo()
1068+
{
1069+
return RPCHelpMan{"getextrapoolinfo",
1070+
"Returns details about the extra tx pool used for compact block reconstruction.\n",
1071+
{},
1072+
RPCResult{
1073+
RPCResult::Type::OBJ, "", "",
1074+
{
1075+
{RPCResult::Type::NUM, "count", "Number of transactions in the extra pool"},
1076+
{RPCResult::Type::NUM, "bytes", "Sum of virtual transaction size for all transactions in the extra pool"},
1077+
}},
1078+
RPCExamples{
1079+
HelpExampleCli("getextrapoolinfo", "") +
1080+
HelpExampleRpc("getextrapoolinfo", "")
1081+
},
1082+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1083+
{
1084+
const NodeContext& node = EnsureAnyNodeContext(request.context);
1085+
PeerManager& peerman = EnsurePeerman(node);
1086+
1087+
LOCK(::cs_main);
1088+
1089+
UniValue ret(UniValue::VOBJ);
1090+
ret.pushKV("count", (uint64_t)peerman.ExtraTxnForCompactCount());
1091+
ret.pushKV("bytes", (uint64_t)peerman.ExtraTxnForCompactBytes());
1092+
return ret;
1093+
},
1094+
};
1095+
}
1096+
10671097
static RPCHelpMan importmempool()
10681098
{
10691099
return RPCHelpMan{
@@ -1480,6 +1510,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
14801510
{"blockchain", &getmempoolentry},
14811511
{"blockchain", &gettxspendingprevout},
14821512
{"blockchain", &getmempoolinfo},
1513+
{"blockchain", &getextrapoolinfo},
14831514
{"blockchain", &getrawmempool},
14841515
{"blockchain", &importmempool},
14851516
{"blockchain", &savemempool},

0 commit comments

Comments
 (0)