forked from bitcoin/bitcoin
-
Couldn't load subscription status.
- Fork 129
rpc: Add getextrapoolinfo RPC
#221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
1440000bytes
wants to merge
2
commits into
bitcoinknots:29.x-knots
Choose a base branch
from
1440000bytes:getextrapoolinfo-rpc
base: 29.x-knots
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1064,6 +1064,39 @@ static RPCHelpMan getmempoolinfo() | |
| }; | ||
| } | ||
|
|
||
| static RPCHelpMan getextrapoolinfo() | ||
| { | ||
| return RPCHelpMan{"getextrapoolinfo", | ||
| "Returns details about the extra pool used for compact block reconstruction.\n" | ||
| "This pool stores recent transactions to help reconstruct compact blocks without requesting missing transactions from peers.\n", | ||
| {}, | ||
| RPCResult{ | ||
| RPCResult::Type::OBJ, "", "", | ||
| { | ||
| {RPCResult::Type::NUM, "size", "Number of transactions in the extra pool"}, | ||
| {RPCResult::Type::NUM, "bytes", "Sum of virtual transaction size for all transactions in the extra pool"}, | ||
| {RPCResult::Type::NUM, "usage", "Total memory usage in bytes for the extra pool"}, | ||
| }}, | ||
| RPCExamples{ | ||
| HelpExampleCli("getextrapoolinfo", "") + | ||
| HelpExampleRpc("getextrapoolinfo", "") | ||
| }, | ||
| [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue | ||
| { | ||
| const NodeContext& node = EnsureAnyNodeContext(request.context); | ||
| PeerManager& peerman = EnsurePeerman(node); | ||
| LOCK(::cs_main); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Holding |
||
|
|
||
| UniValue ret(UniValue::VOBJ); | ||
| ret.pushKV("size", (int64_t)peerman.ExtraTxnForCompactCount()); | ||
| ret.pushKV("bytes", (int64_t)peerman.ExtraTxnForCompactBytes()); | ||
| ret.pushKV("usage", (int64_t)peerman.ExtraTxnForCompactMemoryUsage()); | ||
|
|
||
| return ret; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| static RPCHelpMan importmempool() | ||
| { | ||
| return RPCHelpMan{ | ||
|
|
@@ -1480,6 +1513,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t) | |
| {"blockchain", &getmempoolentry}, | ||
| {"blockchain", &gettxspendingprevout}, | ||
| {"blockchain", &getmempoolinfo}, | ||
| {"blockchain", &getextrapoolinfo}, | ||
| {"blockchain", &getrawmempool}, | ||
| {"blockchain", &importmempool}, | ||
| {"blockchain", &savemempool}, | ||
|
|
@@ -1491,4 +1525,4 @@ void RegisterMempoolRPCCommands(CRPCTable& t) | |
| for (const auto& c : commands) { | ||
| t.appendCommand(c.name, &c); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2025 Luke Dashjr | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| """Test the getextrapoolinfo RPC command.""" | ||
|
|
||
| from test_framework.test_framework import BitcoinTestFramework | ||
| from test_framework.util import assert_equal | ||
| from test_framework.wallet import MiniWallet | ||
| from test_framework.messages import msg_tx, tx_from_hex | ||
| from test_framework.p2p import P2PInterface | ||
| from test_framework.script import CScript, OP_TRUE | ||
| from test_framework.messages import CTxOut | ||
|
|
||
|
|
||
| class TestP2PConn(P2PInterface): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class RPCExtraPoolInfoTest(BitcoinTestFramework): | ||
| def set_test_params(self): | ||
| self.num_nodes = 2 | ||
|
|
||
| def run_test(self): | ||
| self.wallet0 = MiniWallet(self.nodes[0]) | ||
|
|
||
| self.connect_nodes(0, 1) | ||
|
|
||
| self.p2p_conn = self.nodes[1].add_p2p_connection(TestP2PConn()) | ||
|
|
||
| info = self.nodes[1].getextrapoolinfo() | ||
| assert_equal(info['count'], 0) | ||
| assert_equal(info['bytes'], 0) | ||
| assert_equal(info['memory_usage'], 0) | ||
|
|
||
| dust_tx = self.wallet0.create_self_transfer() | ||
| dust_amount = 100 # Below dust threshold | ||
| dust_script = CScript([OP_TRUE]) | ||
| dust_tx['tx'].vout.append(CTxOut(dust_amount, dust_script)) | ||
| dust_tx['tx'].vout[0].nValue -= dust_amount | ||
| dust_tx['tx'].rehash() | ||
|
|
||
| tx_obj = tx_from_hex(dust_tx['tx'].serialize().hex()) | ||
| self.p2p_conn.send_message(msg_tx(tx_obj)) | ||
| self.p2p_conn.sync_with_ping() | ||
|
|
||
| info = self.nodes[1].getextrapoolinfo() | ||
| print(info) | ||
| assert_equal(info['count'] > 0, True) | ||
| assert_equal(info['bytes'] > 0, True) | ||
| assert_equal(info['memory_usage'] > 0, True) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| RPCExtraPoolInfoTest(__file__).main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.