Branch data Line data Source code
1 : : // Copyright (c) 2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-2022 The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : #include <rpc/blockchain.h>
7 : :
8 : : #include <node/mempool_persist.h>
9 : :
10 : : #include <chainparams.h>
11 : : #include <consensus/validation.h>
12 : : #include <core_io.h>
13 : : #include <kernel/mempool_entry.h>
14 : : #include <net_processing.h>
15 : : #include <node/mempool_persist_args.h>
16 : : #include <node/types.h>
17 : : #include <policy/rbf.h>
18 : : #include <policy/settings.h>
19 : : #include <primitives/transaction.h>
20 : : #include <rpc/server.h>
21 : : #include <rpc/server_util.h>
22 : : #include <rpc/util.h>
23 : : #include <txmempool.h>
24 : : #include <univalue.h>
25 : : #include <util/fs.h>
26 : : #include <util/moneystr.h>
27 : : #include <util/strencodings.h>
28 : : #include <util/time.h>
29 : : #include <util/vector.h>
30 : :
31 : : #include <string_view>
32 : : #include <utility>
33 : :
34 : : using node::DumpMempool;
35 : :
36 : : using node::DEFAULT_MAX_BURN_AMOUNT;
37 : : using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
38 : : using node::MempoolPath;
39 : : using node::NodeContext;
40 : : using node::TransactionError;
41 : : using util::ToString;
42 : :
43 : 91 : static RPCHelpMan sendrawtransaction()
44 : : {
45 : 91 : return RPCHelpMan{
46 : 91 : "sendrawtransaction",
47 [ + - ]: 182 : "Submit a raw transaction (serialized, hex-encoded) to local node and network.\n"
48 : : "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
49 : : "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
50 : : "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
51 : : "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_UTXO_SET, may throw if the transaction cannot be added to the mempool.\n"
52 : : "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
53 : : {
54 [ + - + - ]: 182 : {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
55 [ + - + - : 182 : {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
+ - ]
56 [ + - ]: 182 : "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
57 : 91 : "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
58 [ + - + - : 182 : {"maxburnamount", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_BURN_AMOUNT)},
+ - ]
59 [ + - ]: 182 : "Reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value, expressed in " + CURRENCY_UNIT + ".\n"
60 : : "If burning funds through unspendable outputs is desired, increase this value.\n"
61 : 91 : "This check is based on heuristics and does not guarantee spendability of outputs.\n"},
62 : : },
63 [ + - ]: 182 : RPCResult{
64 [ + - + - ]: 182 : RPCResult::Type::STR_HEX, "", "The transaction hash in hex"
65 [ + - ]: 182 : },
66 : 91 : RPCExamples{
67 : : "\nCreate a transaction\n"
68 [ + - + - : 182 : + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
+ - + - ]
69 : 91 : "Sign the transaction, and get back the hex\n"
70 [ + - + - : 364 : + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
+ - + - ]
71 : 91 : "\nSend the transaction (signed hex)\n"
72 [ + - + - : 364 : + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
+ - + - ]
73 : 91 : "\nAs a JSON-RPC call\n"
74 [ + - + - : 364 : + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
+ - + - ]
75 [ + - ]: 91 : },
76 : 91 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
77 : : {
78 [ - + ]: 2 : const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
79 : :
80 : 2 : CMutableTransaction mtx;
81 [ + - + - : 2 : if (!DecodeHexTx(mtx, request.params[0].get_str())) {
+ - + - ]
82 [ + - + - ]: 4 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
83 : : }
84 : :
85 [ # # ]: 0 : for (const auto& out : mtx.vout) {
86 [ # # # # : 0 : if((out.scriptPubKey.IsUnspendable() || !out.scriptPubKey.HasValidOps()) && out.nValue > max_burn_amount) {
# # # # ]
87 [ # # # # ]: 0 : throw JSONRPCTransactionError(TransactionError::MAX_BURN_EXCEEDED);
88 : : }
89 : : }
90 : :
91 [ # # ]: 0 : CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
92 : :
93 [ # # # # ]: 0 : const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
94 : :
95 [ # # ]: 0 : int64_t virtual_size = GetVirtualTransactionSize(*tx);
96 [ # # ]: 0 : CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
97 : :
98 [ # # ]: 0 : std::string err_string;
99 : 0 : AssertLockNotHeld(cs_main);
100 [ # # ]: 0 : NodeContext& node = EnsureAnyNodeContext(request.context);
101 [ # # # # : 0 : const TransactionError err = BroadcastTransaction(node, tx, err_string, max_raw_tx_fee, /*relay=*/true, /*wait_callback=*/true);
# # ]
102 [ # # ]: 0 : if (TransactionError::OK != err) {
103 [ # # ]: 0 : throw JSONRPCTransactionError(err, err_string);
104 : : }
105 : :
106 [ # # # # ]: 0 : return tx->GetHash().GetHex();
107 [ # # ]: 0 : },
108 [ + - + - : 637 : };
+ + - - ]
109 [ + - + - : 546 : }
+ - - - ]
110 : :
111 : 88 : static RPCHelpMan testmempoolaccept()
112 : : {
113 : 88 : return RPCHelpMan{
114 : 88 : "testmempoolaccept",
115 : : "Returns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n"
116 : : "\nIf multiple transactions are passed in, parents must come before children and package policies apply: the transactions cannot conflict with any mempool transactions or each other.\n"
117 : : "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n"
118 [ + - + - ]: 176 : "\nThe maximum number of transactions allowed is " + ToString(MAX_PACKAGE_COUNT) + ".\n"
119 : : "\nThis checks if transactions violate the consensus or policy rules.\n"
120 : 88 : "\nSee sendrawtransaction call.\n",
121 : : {
122 [ + - + - ]: 176 : {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of hex strings of raw transactions.",
123 : : {
124 [ + - + - ]: 176 : {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
125 : : },
126 : : },
127 [ + - + - : 176 : {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
+ - ]
128 [ + - ]: 176 : "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
129 : 88 : "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
130 : : },
131 [ + - ]: 176 : RPCResult{
132 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n"
133 : : "Returns results for each transaction in the same order they were passed in.\n"
134 : : "Transactions that cannot be fully validated due to failures in other transactions will not contain an 'allowed' result.\n",
135 : : {
136 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "", "",
137 : : {
138 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
139 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
140 [ + - + - ]: 176 : {RPCResult::Type::STR, "package-error", /*optional=*/true, "Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
141 [ + - + - ]: 176 : {RPCResult::Type::BOOL, "allowed", /*optional=*/true, "Whether this tx would be accepted to the mempool and pass client-specified maxfeerate. "
142 : : "If not present, the tx was not fully validated due to a failure in another tx in the list."},
143 [ + - + - ]: 176 : {RPCResult::Type::NUM, "vsize", /*optional=*/true, "Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted (only present when 'allowed' is true)"},
144 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "fees", /*optional=*/true, "Transaction fees (only present if 'allowed' is true)",
145 : : {
146 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
147 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "effective-feerate", /*optional=*/false, "the effective feerate in " + CURRENCY_UNIT + " per KvB. May differ from the base feerate if, for example, there are modified fees from prioritisetransaction or a package feerate was used."},
148 [ + - + - ]: 176 : {RPCResult::Type::ARR, "effective-includes", /*optional=*/false, "transactions whose fees and vsizes are included in effective-feerate.",
149 [ + - + - ]: 176 : {RPCResult{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
150 : : }},
151 : : }},
152 [ + - + - ]: 176 : {RPCResult::Type::STR, "reject-reason", /*optional=*/true, "Rejection reason (only present when 'allowed' is false)"},
153 [ + - + - ]: 176 : {RPCResult::Type::STR, "reject-details", /*optional=*/true, "Rejection details (only present when 'allowed' is false and rejection details exist)"},
154 : : }},
155 : : }
156 [ + - + - : 2376 : },
+ - + - +
- + + + +
+ + + + -
- - - - -
- - ]
157 : 88 : RPCExamples{
158 : : "\nCreate a transaction\n"
159 [ + - + - : 176 : + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
+ - + - ]
160 : 88 : "Sign the transaction, and get back the hex\n"
161 [ + - + - : 352 : + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
+ - + - ]
162 : 88 : "\nTest acceptance of the transaction (signed hex)\n"
163 [ + - + - : 352 : + HelpExampleCli("testmempoolaccept", R"('["signedhex"]')") +
+ - + - ]
164 : 88 : "\nAs a JSON-RPC call\n"
165 [ + - + - : 352 : + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
+ - + - ]
166 [ + - ]: 88 : },
167 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
168 : : {
169 : 0 : const UniValue raw_transactions = request.params[0].get_array();
170 [ # # # # : 0 : if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
# # ]
171 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER,
172 [ # # # # : 0 : "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
# # ]
173 : : }
174 : :
175 [ # # # # ]: 0 : const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
176 : :
177 : 0 : std::vector<CTransactionRef> txns;
178 [ # # # # ]: 0 : txns.reserve(raw_transactions.size());
179 [ # # # # ]: 0 : for (const auto& rawtx : raw_transactions.getValues()) {
180 [ # # ]: 0 : CMutableTransaction mtx;
181 [ # # # # : 0 : if (!DecodeHexTx(mtx, rawtx.get_str())) {
# # ]
182 : 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
183 [ # # # # : 0 : "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
# # ]
184 : : }
185 [ # # # # ]: 0 : txns.emplace_back(MakeTransactionRef(std::move(mtx)));
186 : 0 : }
187 : :
188 [ # # ]: 0 : NodeContext& node = EnsureAnyNodeContext(request.context);
189 [ # # ]: 0 : CTxMemPool& mempool = EnsureMemPool(node);
190 [ # # ]: 0 : ChainstateManager& chainman = EnsureChainman(node);
191 [ # # ]: 0 : Chainstate& chainstate = chainman.ActiveChainstate();
192 : 0 : const PackageMempoolAcceptResult package_result = [&] {
193 : 0 : LOCK(::cs_main);
194 [ # # # # : 0 : if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/true, /*client_maxfeerate=*/{});
# # ]
195 [ # # ]: 0 : return PackageMempoolAcceptResult(txns[0]->GetWitnessHash(),
196 [ # # # # ]: 0 : chainman.ProcessTransaction(txns[0], /*test_accept=*/true));
197 [ # # ]: 0 : }();
198 : :
199 : 0 : UniValue rpc_result(UniValue::VARR);
200 : : // We will check transaction fees while we iterate through txns in order. If any transaction fee
201 : : // exceeds maxfeerate, we will leave the rest of the validation results blank, because it
202 : : // doesn't make sense to return a validation result for a transaction if its ancestor(s) would
203 : : // not be submitted.
204 : 0 : bool exit_early{false};
205 [ # # ]: 0 : for (const auto& tx : txns) {
206 : 0 : UniValue result_inner(UniValue::VOBJ);
207 [ # # # # : 0 : result_inner.pushKV("txid", tx->GetHash().GetHex());
# # # # ]
208 [ # # # # : 0 : result_inner.pushKV("wtxid", tx->GetWitnessHash().GetHex());
# # # # ]
209 [ # # ]: 0 : if (package_result.m_state.GetResult() == PackageValidationResult::PCKG_POLICY) {
210 [ # # # # : 0 : result_inner.pushKV("package-error", package_result.m_state.ToString());
# # # # ]
211 : : }
212 : 0 : auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
213 [ # # # # ]: 0 : if (exit_early || it == package_result.m_tx_results.end()) {
214 : : // Validation unfinished. Just return the txid and wtxid.
215 [ # # ]: 0 : rpc_result.push_back(std::move(result_inner));
216 : 0 : continue;
217 : : }
218 [ # # ]: 0 : const auto& tx_result = it->second;
219 : : // Package testmempoolaccept doesn't allow transactions to already be in the mempool.
220 [ # # ]: 0 : CHECK_NONFATAL(tx_result.m_result_type != MempoolAcceptResult::ResultType::MEMPOOL_ENTRY);
221 [ # # ]: 0 : if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
222 [ # # ]: 0 : const CAmount fee = tx_result.m_base_fees.value();
223 : : // Check that fee does not exceed maximum fee
224 [ # # ]: 0 : const int64_t virtual_size = tx_result.m_vsize.value();
225 [ # # ]: 0 : const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
226 [ # # ]: 0 : if (max_raw_tx_fee && fee > max_raw_tx_fee) {
227 [ # # # # : 0 : result_inner.pushKV("allowed", false);
# # ]
228 [ # # # # : 0 : result_inner.pushKV("reject-reason", "max-fee-exceeded");
# # ]
229 : 0 : exit_early = true;
230 : : } else {
231 : : // Only return the fee and vsize if the transaction would pass ATMP.
232 : : // These can be used to calculate the feerate.
233 [ # # # # : 0 : result_inner.pushKV("allowed", true);
# # ]
234 [ # # # # : 0 : result_inner.pushKV("vsize", virtual_size);
# # ]
235 : 0 : UniValue fees(UniValue::VOBJ);
236 [ # # # # : 0 : fees.pushKV("base", ValueFromAmount(fee));
# # ]
237 [ # # # # : 0 : fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
# # # # ]
238 : 0 : UniValue effective_includes_res(UniValue::VARR);
239 [ # # # # ]: 0 : for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
240 [ # # # # : 0 : effective_includes_res.push_back(wtxid.ToString());
# # ]
241 : : }
242 [ # # # # ]: 0 : fees.pushKV("effective-includes", std::move(effective_includes_res));
243 [ # # # # ]: 0 : result_inner.pushKV("fees", std::move(fees));
244 : 0 : }
245 : : } else {
246 [ # # # # : 0 : result_inner.pushKV("allowed", false);
# # ]
247 [ # # ]: 0 : const TxValidationState state = tx_result.m_state;
248 [ # # ]: 0 : if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
249 [ # # # # : 0 : result_inner.pushKV("reject-reason", "missing-inputs");
# # ]
250 : : } else {
251 [ # # # # : 0 : result_inner.pushKV("reject-reason", state.GetRejectReason());
# # # # ]
252 [ # # # # : 0 : result_inner.pushKV("reject-details", state.ToString());
# # # # ]
253 : : }
254 : 0 : }
255 [ # # ]: 0 : rpc_result.push_back(std::move(result_inner));
256 : 0 : }
257 : 0 : return rpc_result;
258 : 0 : },
259 [ + - + - : 792 : };
+ - + + +
+ - - -
- ]
260 [ + - + - : 1672 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - - -
- - - - ]
261 : :
262 : 352 : static std::vector<RPCResult> MempoolEntryDescription()
263 : : {
264 : 352 : return {
265 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "vsize", "virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
266 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "weight", "transaction weight as defined in BIP 141."},
267 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM_TIME, "time", "local time transaction entered pool in seconds since 1 Jan 1970 GMT"},
268 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "height", "block height when transaction entered pool"},
269 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "descendantcount", "number of in-mempool descendant transactions (including this one)"},
270 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "descendantsize", "virtual transaction size of in-mempool descendants (including this one)"},
271 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
272 [ + - + - ]: 704 : RPCResult{RPCResult::Type::NUM, "ancestorsize", "virtual transaction size of in-mempool ancestors (including this one)"},
273 [ + - + - ]: 704 : RPCResult{RPCResult::Type::STR_HEX, "wtxid", "hash of serialized transaction, including witness data"},
274 [ + - + - ]: 704 : RPCResult{RPCResult::Type::OBJ, "fees", "",
275 : : {
276 [ + - + - ]: 704 : RPCResult{RPCResult::Type::STR_AMOUNT, "base", "transaction fee, denominated in " + CURRENCY_UNIT},
277 [ + - + - ]: 704 : RPCResult{RPCResult::Type::STR_AMOUNT, "modified", "transaction fee with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
278 [ + - + - ]: 704 : RPCResult{RPCResult::Type::STR_AMOUNT, "ancestor", "transaction fees of in-mempool ancestors (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
279 [ + - + - ]: 704 : RPCResult{RPCResult::Type::STR_AMOUNT, "descendant", "transaction fees of in-mempool descendants (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
280 [ + - + + : 2112 : }},
- - ]
281 [ + - + - ]: 704 : RPCResult{RPCResult::Type::ARR, "depends", "unconfirmed transactions used as inputs for this transaction",
282 [ + - + - : 1408 : {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "parent transaction id"}}},
+ - + + -
- ]
283 [ + - + - ]: 704 : RPCResult{RPCResult::Type::ARR, "spentby", "unconfirmed transactions spending outputs from this transaction",
284 [ + - + - : 1408 : {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "child transaction id"}}},
+ - + + -
- ]
285 [ + - + - ]: 704 : RPCResult{RPCResult::Type::BOOL, "bip125-replaceable", "Whether this transaction signals BIP125 replaceability or has an unconfirmed ancestor signaling BIP125 replaceability. (DEPRECATED)\n"},
286 [ + - + - ]: 704 : RPCResult{RPCResult::Type::BOOL, "unbroadcast", "Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)"},
287 [ + - + + : 5984 : };
- - ]
288 [ + - + - : 7040 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- - - -
- ]
289 : :
290 : 0 : static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
291 : : {
292 : 0 : AssertLockHeld(pool.cs);
293 : :
294 [ # # # # ]: 0 : info.pushKV("vsize", (int)e.GetTxSize());
295 [ # # # # ]: 0 : info.pushKV("weight", (int)e.GetTxWeight());
296 [ # # # # ]: 0 : info.pushKV("time", count_seconds(e.GetTime()));
297 [ # # # # ]: 0 : info.pushKV("height", (int)e.GetHeight());
298 [ # # # # ]: 0 : info.pushKV("descendantcount", e.GetCountWithDescendants());
299 [ # # # # ]: 0 : info.pushKV("descendantsize", e.GetSizeWithDescendants());
300 [ # # # # ]: 0 : info.pushKV("ancestorcount", e.GetCountWithAncestors());
301 [ # # # # ]: 0 : info.pushKV("ancestorsize", e.GetSizeWithAncestors());
302 [ # # # # : 0 : info.pushKV("wtxid", e.GetTx().GetWitnessHash().ToString());
# # ]
303 : :
304 : 0 : UniValue fees(UniValue::VOBJ);
305 [ # # # # : 0 : fees.pushKV("base", ValueFromAmount(e.GetFee()));
# # ]
306 [ # # # # : 0 : fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee()));
# # ]
307 [ # # # # : 0 : fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors()));
# # ]
308 [ # # # # : 0 : fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants()));
# # ]
309 [ # # # # ]: 0 : info.pushKV("fees", std::move(fees));
310 : :
311 : 0 : const CTransaction& tx = e.GetTx();
312 : 0 : std::set<std::string> setDepends;
313 [ # # ]: 0 : for (const CTxIn& txin : tx.vin)
314 : : {
315 [ # # # # ]: 0 : if (pool.exists(txin.prevout.hash))
316 [ # # # # ]: 0 : setDepends.insert(txin.prevout.hash.ToString());
317 : : }
318 : :
319 : 0 : UniValue depends(UniValue::VARR);
320 [ # # ]: 0 : for (const std::string& dep : setDepends)
321 : : {
322 [ # # # # ]: 0 : depends.push_back(dep);
323 : : }
324 : :
325 [ # # # # ]: 0 : info.pushKV("depends", std::move(depends));
326 : :
327 : 0 : UniValue spent(UniValue::VARR);
328 [ # # # # ]: 0 : for (const CTxMemPoolEntry& child : e.GetMemPoolChildrenConst()) {
329 [ # # # # : 0 : spent.push_back(child.GetTx().GetHash().ToString());
# # ]
330 : : }
331 : :
332 [ # # # # ]: 0 : info.pushKV("spentby", std::move(spent));
333 : :
334 : : // Add opt-in RBF status
335 : 0 : bool rbfStatus = false;
336 [ # # ]: 0 : RBFTransactionState rbfState = IsRBFOptIn(tx, pool);
337 [ # # ]: 0 : if (rbfState == RBFTransactionState::UNKNOWN) {
338 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not in mempool");
339 [ # # ]: 0 : } else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125) {
340 : 0 : rbfStatus = true;
341 : : }
342 : :
343 [ # # # # : 0 : info.pushKV("bip125-replaceable", rbfStatus);
# # ]
344 [ # # # # : 0 : info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetHash()));
# # ]
345 : 0 : }
346 : :
347 : 0 : UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
348 : : {
349 [ # # ]: 0 : if (verbose) {
350 [ # # ]: 0 : if (include_mempool_sequence) {
351 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbose results cannot contain mempool sequence values.");
352 : : }
353 : 0 : LOCK(pool.cs);
354 : 0 : UniValue o(UniValue::VOBJ);
355 [ # # # # ]: 0 : for (const CTxMemPoolEntry& e : pool.entryAll()) {
356 : 0 : UniValue info(UniValue::VOBJ);
357 [ # # ]: 0 : entryToJSON(pool, info, e);
358 : : // Mempool has unique entries so there is no advantage in using
359 : : // UniValue::pushKV, which checks if the key already exists in O(N).
360 : : // UniValue::pushKVEnd is used instead which currently is O(1).
361 [ # # # # ]: 0 : o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info));
362 : 0 : }
363 [ # # ]: 0 : return o;
364 : 0 : } else {
365 : 0 : UniValue a(UniValue::VARR);
366 : 0 : uint64_t mempool_sequence;
367 : 0 : {
368 [ # # ]: 0 : LOCK(pool.cs);
369 [ # # # # : 0 : for (const CTxMemPoolEntry& e : pool.entryAll()) {
# # ]
370 [ # # # # : 0 : a.push_back(e.GetTx().GetHash().ToString());
# # ]
371 : : }
372 [ # # ]: 0 : mempool_sequence = pool.GetSequence();
373 : 0 : }
374 [ # # ]: 0 : if (!include_mempool_sequence) {
375 : 0 : return a;
376 : : } else {
377 : 0 : UniValue o(UniValue::VOBJ);
378 [ # # # # ]: 0 : o.pushKV("txids", std::move(a));
379 [ # # # # : 0 : o.pushKV("mempool_sequence", mempool_sequence);
# # ]
380 : 0 : return o;
381 : 0 : }
382 : 0 : }
383 : : }
384 : :
385 : 88 : static RPCHelpMan getrawmempool()
386 : : {
387 : 88 : return RPCHelpMan{
388 : 88 : "getrawmempool",
389 [ + - ]: 176 : "Returns all transaction ids in memory pool as a json array of string transaction ids.\n"
390 : : "\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
391 : : {
392 [ + - + - : 264 : {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
+ - ]
393 [ + - + - : 264 : {"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false}, "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
+ - ]
394 : : },
395 : : {
396 [ + - ]: 88 : RPCResult{"for verbose = false",
397 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
398 : : {
399 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "", "The transaction id"},
400 [ + - + + : 264 : }},
- - ]
401 [ + - ]: 176 : RPCResult{"for verbose = true",
402 [ + - + - ]: 176 : RPCResult::Type::OBJ_DYN, "", "",
403 : : {
404 [ + - + - : 176 : {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
+ - ]
405 [ + - + + : 264 : }},
- - ]
406 [ + - ]: 176 : RPCResult{"for verbose = false and mempool_sequence = true",
407 [ + - + - ]: 176 : RPCResult::Type::OBJ, "", "",
408 : : {
409 [ + - + - ]: 176 : {RPCResult::Type::ARR, "txids", "",
410 : : {
411 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "", "The transaction id"},
412 : : }},
413 [ + - + - ]: 176 : {RPCResult::Type::NUM, "mempool_sequence", "The mempool sequence value."},
414 [ + - + - : 616 : }},
+ + + + -
- - - ]
415 : : },
416 : 88 : RPCExamples{
417 [ + - + - : 176 : HelpExampleCli("getrawmempool", "true")
+ - ]
418 [ + - + - : 352 : + HelpExampleRpc("getrawmempool", "true")
+ - ]
419 [ + - ]: 88 : },
420 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
421 : : {
422 : 0 : bool fVerbose = false;
423 [ # # ]: 0 : if (!request.params[0].isNull())
424 : 0 : fVerbose = request.params[0].get_bool();
425 : :
426 : 0 : bool include_mempool_sequence = false;
427 [ # # ]: 0 : if (!request.params[1].isNull()) {
428 : 0 : include_mempool_sequence = request.params[1].get_bool();
429 : : }
430 : :
431 : 0 : return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
432 : : },
433 [ + - + - : 1056 : };
+ - + - +
+ + + - -
- - ]
434 [ + - + - : 1056 : }
+ - + - +
- + - + -
+ - + - +
- - - - -
- - ]
435 : :
436 : 88 : static RPCHelpMan getmempoolancestors()
437 : : {
438 : 88 : return RPCHelpMan{
439 : 88 : "getmempoolancestors",
440 [ + - ]: 176 : "If txid is in the mempool, returns all in-mempool ancestors.\n",
441 : : {
442 [ + - + - ]: 176 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
443 [ + - + - : 264 : {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
+ - ]
444 : : },
445 : : {
446 [ + - ]: 88 : RPCResult{"for verbose = false",
447 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
448 [ + - + - : 352 : {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}},
+ - + + -
- ]
449 [ + - ]: 176 : RPCResult{"for verbose = true",
450 [ + - + - ]: 176 : RPCResult::Type::OBJ_DYN, "", "",
451 : : {
452 [ + - + - : 176 : {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
+ - ]
453 [ + - + + : 264 : }},
- - ]
454 : : },
455 : 88 : RPCExamples{
456 [ + - + - : 176 : HelpExampleCli("getmempoolancestors", "\"mytxid\"")
+ - ]
457 [ + - + - : 352 : + HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
+ - ]
458 [ + - ]: 88 : },
459 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
460 : : {
461 : 0 : bool fVerbose = false;
462 [ # # ]: 0 : if (!request.params[1].isNull())
463 : 0 : fVerbose = request.params[1].get_bool();
464 : :
465 : 0 : auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
466 : :
467 : 0 : const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
468 : 0 : LOCK(mempool.cs);
469 : :
470 [ # # ]: 0 : const auto entry{mempool.GetEntry(txid)};
471 [ # # ]: 0 : if (entry == nullptr) {
472 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
473 : : }
474 : :
475 [ # # # # ]: 0 : auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *entry, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
476 : :
477 [ # # ]: 0 : if (!fVerbose) {
478 : 0 : UniValue o(UniValue::VARR);
479 [ # # ]: 0 : for (CTxMemPool::txiter ancestorIt : ancestors) {
480 [ # # # # : 0 : o.push_back(ancestorIt->GetTx().GetHash().ToString());
# # ]
481 : : }
482 : : return o;
483 : 0 : } else {
484 : 0 : UniValue o(UniValue::VOBJ);
485 [ # # ]: 0 : for (CTxMemPool::txiter ancestorIt : ancestors) {
486 : 0 : const CTxMemPoolEntry &e = *ancestorIt;
487 : 0 : UniValue info(UniValue::VOBJ);
488 [ # # ]: 0 : entryToJSON(mempool, info, e);
489 [ # # # # ]: 0 : o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
490 : 0 : }
491 : 0 : return o;
492 : 0 : }
493 [ # # ]: 0 : },
494 [ + - + - : 968 : };
+ - + - +
+ + + - -
- - ]
495 [ + - + - : 704 : }
+ - + - +
- + - - -
- - ]
496 : :
497 : 88 : static RPCHelpMan getmempooldescendants()
498 : : {
499 : 88 : return RPCHelpMan{
500 : 88 : "getmempooldescendants",
501 [ + - ]: 176 : "If txid is in the mempool, returns all in-mempool descendants.\n",
502 : : {
503 [ + - + - ]: 176 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
504 [ + - + - : 264 : {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
+ - ]
505 : : },
506 : : {
507 [ + - ]: 88 : RPCResult{"for verbose = false",
508 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
509 [ + - + - : 352 : {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool descendant transaction"}}},
+ - + + -
- ]
510 [ + - ]: 176 : RPCResult{"for verbose = true",
511 [ + - + - ]: 176 : RPCResult::Type::OBJ_DYN, "", "",
512 : : {
513 [ + - + - : 176 : {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
+ - ]
514 [ + - + + : 264 : }},
- - ]
515 : : },
516 : 88 : RPCExamples{
517 [ + - + - : 176 : HelpExampleCli("getmempooldescendants", "\"mytxid\"")
+ - ]
518 [ + - + - : 352 : + HelpExampleRpc("getmempooldescendants", "\"mytxid\"")
+ - ]
519 [ + - ]: 88 : },
520 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
521 : : {
522 : 0 : bool fVerbose = false;
523 [ # # ]: 0 : if (!request.params[1].isNull())
524 : 0 : fVerbose = request.params[1].get_bool();
525 : :
526 : 0 : auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
527 : :
528 : 0 : const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
529 : 0 : LOCK(mempool.cs);
530 : :
531 [ # # ]: 0 : const auto it{mempool.GetIter(txid)};
532 [ # # ]: 0 : if (!it) {
533 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
534 : : }
535 : :
536 [ # # ]: 0 : CTxMemPool::setEntries setDescendants;
537 [ # # ]: 0 : mempool.CalculateDescendants(*it, setDescendants);
538 : : // CTxMemPool::CalculateDescendants will include the given tx
539 : 0 : setDescendants.erase(*it);
540 : :
541 [ # # ]: 0 : if (!fVerbose) {
542 : 0 : UniValue o(UniValue::VARR);
543 [ # # ]: 0 : for (CTxMemPool::txiter descendantIt : setDescendants) {
544 [ # # # # : 0 : o.push_back(descendantIt->GetTx().GetHash().ToString());
# # ]
545 : : }
546 : :
547 : : return o;
548 : 0 : } else {
549 : 0 : UniValue o(UniValue::VOBJ);
550 [ # # ]: 0 : for (CTxMemPool::txiter descendantIt : setDescendants) {
551 : 0 : const CTxMemPoolEntry &e = *descendantIt;
552 : 0 : UniValue info(UniValue::VOBJ);
553 [ # # ]: 0 : entryToJSON(mempool, info, e);
554 [ # # # # ]: 0 : o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
555 : 0 : }
556 : 0 : return o;
557 : 0 : }
558 [ # # ]: 0 : },
559 [ + - + - : 968 : };
+ - + - +
+ + + - -
- - ]
560 [ + - + - : 704 : }
+ - + - +
- + - - -
- - ]
561 : :
562 : 88 : static RPCHelpMan getmempoolentry()
563 : : {
564 : 88 : return RPCHelpMan{
565 : 88 : "getmempoolentry",
566 [ + - ]: 176 : "Returns mempool data for given transaction\n",
567 : : {
568 [ + - + - ]: 176 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
569 : : },
570 [ + - ]: 176 : RPCResult{
571 [ + - + - : 176 : RPCResult::Type::OBJ, "", "", MempoolEntryDescription()},
+ - + - ]
572 : 88 : RPCExamples{
573 [ + - + - : 176 : HelpExampleCli("getmempoolentry", "\"mytxid\"")
+ - ]
574 [ + - + - : 352 : + HelpExampleRpc("getmempoolentry", "\"mytxid\"")
+ - + - ]
575 [ + - ]: 88 : },
576 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
577 : : {
578 : 0 : auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
579 : :
580 : 0 : const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
581 : 0 : LOCK(mempool.cs);
582 : :
583 [ # # ]: 0 : const auto entry{mempool.GetEntry(txid)};
584 [ # # ]: 0 : if (entry == nullptr) {
585 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
586 : : }
587 : :
588 : 0 : UniValue info(UniValue::VOBJ);
589 [ # # ]: 0 : entryToJSON(mempool, info, *entry);
590 [ # # ]: 0 : return info;
591 : 0 : },
592 [ + - + - : 440 : };
+ + - - ]
593 [ + - ]: 176 : }
594 : :
595 : 88 : static RPCHelpMan gettxspendingprevout()
596 : : {
597 : 88 : return RPCHelpMan{"gettxspendingprevout",
598 [ + - ]: 176 : "Scans the mempool to find transactions spending any of the given outputs",
599 : : {
600 [ + - + - ]: 176 : {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",
601 : : {
602 [ + - + - ]: 176 : {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
603 : : {
604 [ + - + - ]: 176 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
605 [ + - + - ]: 176 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
606 : : },
607 : : },
608 : : },
609 : : },
610 : : },
611 [ + - ]: 176 : RPCResult{
612 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
613 : : {
614 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "", "",
615 : : {
616 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "txid", "the transaction id of the checked output"},
617 [ + - + - ]: 176 : {RPCResult::Type::NUM, "vout", "the vout value of the checked output"},
618 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},
619 : : }},
620 : : }
621 [ + - + - : 792 : },
+ - + + +
+ - - -
- ]
622 : 88 : RPCExamples{
623 [ + - + - : 176 : HelpExampleCli("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
+ - ]
624 [ + - + - : 352 : + HelpExampleRpc("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
+ - + - ]
625 [ + - ]: 88 : },
626 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
627 : : {
628 : 0 : const UniValue& output_params = request.params[0].get_array();
629 [ # # # # ]: 0 : if (output_params.empty()) {
630 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, outputs are missing");
631 : : }
632 : :
633 : 0 : std::vector<COutPoint> prevouts;
634 [ # # ]: 0 : prevouts.reserve(output_params.size());
635 : :
636 [ # # # # ]: 0 : for (unsigned int idx = 0; idx < output_params.size(); idx++) {
637 [ # # # # ]: 0 : const UniValue& o = output_params[idx].get_obj();
638 : :
639 [ # # # # : 0 : RPCTypeCheckObj(o,
# # ]
640 : : {
641 [ # # ]: 0 : {"txid", UniValueType(UniValue::VSTR)},
642 [ # # ]: 0 : {"vout", UniValueType(UniValue::VNUM)},
643 : : }, /*fAllowNull=*/false, /*fStrict=*/true);
644 : :
645 [ # # ]: 0 : const Txid txid = Txid::FromUint256(ParseHashO(o, "txid"));
646 [ # # # # ]: 0 : const int nOutput{o.find_value("vout").getInt<int>()};
647 [ # # ]: 0 : if (nOutput < 0) {
648 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
649 : : }
650 : :
651 [ # # ]: 0 : prevouts.emplace_back(txid, nOutput);
652 : : }
653 : :
654 [ # # ]: 0 : const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
655 [ # # ]: 0 : LOCK(mempool.cs);
656 : :
657 : 0 : UniValue result{UniValue::VARR};
658 : :
659 [ # # ]: 0 : for (const COutPoint& prevout : prevouts) {
660 : 0 : UniValue o(UniValue::VOBJ);
661 [ # # # # : 0 : o.pushKV("txid", prevout.hash.ToString());
# # # # ]
662 [ # # # # : 0 : o.pushKV("vout", (uint64_t)prevout.n);
# # ]
663 : :
664 [ # # ]: 0 : const CTransaction* spendingTx = mempool.GetConflictTx(prevout);
665 [ # # ]: 0 : if (spendingTx != nullptr) {
666 [ # # # # : 0 : o.pushKV("spendingtxid", spendingTx->GetHash().ToString());
# # # # ]
667 : : }
668 : :
669 [ # # ]: 0 : result.push_back(std::move(o));
670 : 0 : }
671 : :
672 [ # # ]: 0 : return result;
673 [ # # # # : 0 : },
# # # # ]
674 [ + - + - : 1056 : };
+ - + - +
+ + + + +
- - - - -
- ]
675 [ + - + - : 1056 : }
+ - + - +
- + - + -
+ - - - -
- ]
676 : :
677 : 0 : UniValue MempoolInfoToJSON(const CTxMemPool& pool)
678 : : {
679 : : // Make sure this call is atomic in the pool.
680 : 0 : LOCK(pool.cs);
681 : 0 : UniValue ret(UniValue::VOBJ);
682 [ # # # # : 0 : ret.pushKV("loaded", pool.GetLoadTried());
# # # # ]
683 [ # # # # : 0 : ret.pushKV("size", (int64_t)pool.size());
# # # # ]
684 [ # # # # : 0 : ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize());
# # ]
685 [ # # # # : 0 : ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage());
# # # # ]
686 [ # # # # : 0 : ret.pushKV("total_fee", ValueFromAmount(pool.GetTotalFee()));
# # ]
687 [ # # # # : 0 : ret.pushKV("maxmempool", pool.m_opts.max_size_bytes);
# # ]
688 [ # # # # : 0 : ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(), pool.m_opts.min_relay_feerate).GetFeePerK()));
# # # # ]
689 [ # # # # : 0 : ret.pushKV("minrelaytxfee", ValueFromAmount(pool.m_opts.min_relay_feerate.GetFeePerK()));
# # ]
690 [ # # # # : 0 : ret.pushKV("incrementalrelayfee", ValueFromAmount(pool.m_opts.incremental_relay_feerate.GetFeePerK()));
# # ]
691 [ # # # # : 0 : ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()});
# # # # ]
692 [ # # # # : 0 : ret.pushKV("fullrbf", true);
# # ]
693 [ # # # # : 0 : ret.pushKV("permitbaremultisig", pool.m_opts.permit_bare_multisig);
# # ]
694 [ # # # # : 0 : ret.pushKV("maxdatacarriersize", pool.m_opts.max_datacarrier_bytes.value_or(0));
# # # # ]
695 [ # # ]: 0 : return ret;
696 : 0 : }
697 : :
698 : 88 : static RPCHelpMan getmempoolinfo()
699 : : {
700 : 88 : return RPCHelpMan{"getmempoolinfo",
701 [ + - ]: 176 : "Returns details on the active state of the TX memory pool.",
702 : : {},
703 [ + - ]: 176 : RPCResult{
704 [ + - ]: 176 : RPCResult::Type::OBJ, "", "",
705 : : {
706 [ + - + - ]: 176 : {RPCResult::Type::BOOL, "loaded", "True if the initial load attempt of the persisted mempool finished"},
707 [ + - + - ]: 176 : {RPCResult::Type::NUM, "size", "Current tx count"},
708 [ + - + - ]: 176 : {RPCResult::Type::NUM, "bytes", "Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted"},
709 [ + - + - ]: 176 : {RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
710 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "total_fee", "Total fees for the mempool in " + CURRENCY_UNIT + ", ignoring modified fees through prioritisetransaction"},
711 [ + - + - ]: 176 : {RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
712 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "mempoolminfee", "Minimum fee rate in " + CURRENCY_UNIT + "/kvB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee"},
713 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
714 [ + - + - ]: 176 : {RPCResult::Type::NUM, "incrementalrelayfee", "minimum fee rate increment for mempool limiting or replacement in " + CURRENCY_UNIT + "/kvB"},
715 [ + - + - ]: 176 : {RPCResult::Type::NUM, "unbroadcastcount", "Current number of transactions that haven't passed initial broadcast yet"},
716 [ + - + - ]: 176 : {RPCResult::Type::BOOL, "fullrbf", "True if the mempool accepts RBF without replaceability signaling inspection (DEPRECATED)"},
717 [ + - + - ]: 176 : {RPCResult::Type::BOOL, "permitbaremultisig", "True if the mempool accepts transactions with bare multisig outputs"},
718 [ + - + - ]: 176 : {RPCResult::Type::NUM, "maxdatacarriersize", "Maximum number of bytes that can be used by OP_RETURN outputs in the mempool"},
719 [ + - + - : 2376 : }},
+ + - - ]
720 : 88 : RPCExamples{
721 [ + - + - : 176 : HelpExampleCli("getmempoolinfo", "")
+ - ]
722 [ + - + - : 352 : + HelpExampleRpc("getmempoolinfo", "")
+ - + - ]
723 [ + - ]: 88 : },
724 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
725 : : {
726 : 0 : return MempoolInfoToJSON(EnsureAnyMemPool(request.context));
727 : : },
728 [ + - + - ]: 352 : };
729 [ + - + - : 1144 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - - - ]
730 : :
731 : 88 : static RPCHelpMan importmempool()
732 : : {
733 : 88 : return RPCHelpMan{
734 : 88 : "importmempool",
735 [ + - ]: 176 : "Import a mempool.dat file and attempt to add its contents to the mempool.\n"
736 : : "Warning: Importing untrusted files is dangerous, especially if metadata from the file is taken over.",
737 : : {
738 [ + - + - ]: 176 : {"filepath", RPCArg::Type::STR, RPCArg::Optional::NO, "The mempool file"},
739 [ + - ]: 176 : {"options",
740 : : RPCArg::Type::OBJ_NAMED_PARAMS,
741 : 88 : RPCArg::Optional::OMITTED,
742 [ + - ]: 176 : "",
743 : : {
744 [ + - + - ]: 176 : {"use_current_time", RPCArg::Type::BOOL, RPCArg::Default{true},
745 [ + - ]: 176 : "Whether to use the current system time or use the entry time metadata from the mempool file.\n"
746 : : "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
747 [ + - + - ]: 176 : {"apply_fee_delta_priority", RPCArg::Type::BOOL, RPCArg::Default{false},
748 [ + - ]: 176 : "Whether to apply the fee delta metadata from the mempool file.\n"
749 : : "It will be added to any existing fee deltas.\n"
750 : : "The fee delta can be set by the prioritisetransaction RPC.\n"
751 : : "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior.\n"
752 : : "Only set this bool if you understand what it does."},
753 [ + - + - ]: 176 : {"apply_unbroadcast_set", RPCArg::Type::BOOL, RPCArg::Default{false},
754 [ + - ]: 176 : "Whether to apply the unbroadcast set metadata from the mempool file.\n"
755 : : "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
756 : : },
757 [ + - ]: 88 : RPCArgOptions{.oneline_description = "options"}},
758 : : },
759 [ + - + - : 176 : RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
+ - + - ]
760 [ + - + - : 264 : RPCExamples{HelpExampleCli("importmempool", "/path/to/mempool.dat") + HelpExampleRpc("importmempool", "/path/to/mempool.dat")},
+ - + - +
- + - + -
+ - ]
761 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
762 : 0 : const NodeContext& node{EnsureAnyNodeContext(request.context)};
763 : :
764 : 0 : CTxMemPool& mempool{EnsureMemPool(node)};
765 : 0 : ChainstateManager& chainman = EnsureChainman(node);
766 : 0 : Chainstate& chainstate = chainman.ActiveChainstate();
767 : :
768 [ # # ]: 0 : if (chainman.IsInitialBlockDownload()) {
769 [ # # # # ]: 0 : throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Can only import the mempool after the block download and sync is done.");
770 : : }
771 : :
772 : 0 : const fs::path load_path{fs::u8path(self.Arg<std::string_view>("filepath"))};
773 [ # # # # : 0 : const UniValue& use_current_time{request.params[1]["use_current_time"]};
# # ]
774 [ # # # # : 0 : const UniValue& apply_fee_delta{request.params[1]["apply_fee_delta_priority"]};
# # ]
775 [ # # # # : 0 : const UniValue& apply_unbroadcast{request.params[1]["apply_unbroadcast_set"]};
# # ]
776 [ # # ]: 0 : node::ImportMempoolOptions opts{
777 [ # # # # ]: 0 : .use_current_time = use_current_time.isNull() ? true : use_current_time.get_bool(),
778 [ # # # # ]: 0 : .apply_fee_delta_priority = apply_fee_delta.isNull() ? false : apply_fee_delta.get_bool(),
779 [ # # # # ]: 0 : .apply_unbroadcast_set = apply_unbroadcast.isNull() ? false : apply_unbroadcast.get_bool(),
780 [ # # # # : 0 : };
# # ]
781 : :
782 [ # # # # ]: 0 : if (!node::LoadMempool(mempool, load_path, chainstate, std::move(opts))) {
783 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "Unable to import mempool file, see debug.log for details.");
784 : : }
785 : :
786 : 0 : UniValue ret{UniValue::VOBJ};
787 : 0 : return ret;
788 : 0 : },
789 [ + - + - : 968 : };
+ - + + +
+ - - -
- ]
790 [ + - + - : 792 : }
+ - + - +
- - - -
- ]
791 : :
792 : 88 : static RPCHelpMan savemempool()
793 : : {
794 : 88 : return RPCHelpMan{
795 : 88 : "savemempool",
796 [ + - ]: 176 : "Dumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
797 : : {},
798 [ + - ]: 176 : RPCResult{
799 [ + - ]: 176 : RPCResult::Type::OBJ, "", "",
800 : : {
801 [ + - + - ]: 176 : {RPCResult::Type::STR, "filename", "the directory and file where the mempool was saved"},
802 [ + - + - : 264 : }},
+ + - - ]
803 : 88 : RPCExamples{
804 [ + - + - : 176 : HelpExampleCli("savemempool", "")
+ - ]
805 [ + - + - : 352 : + HelpExampleRpc("savemempool", "")
+ - + - ]
806 [ + - ]: 88 : },
807 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
808 : : {
809 : 0 : const ArgsManager& args{EnsureAnyArgsman(request.context)};
810 : 0 : const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
811 : :
812 [ # # ]: 0 : if (!mempool.GetLoadTried()) {
813 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
814 : : }
815 : :
816 : 0 : const fs::path& dump_path = MempoolPath(args);
817 : :
818 [ # # # # ]: 0 : if (!DumpMempool(mempool, dump_path)) {
819 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
820 : : }
821 : :
822 : 0 : UniValue ret(UniValue::VOBJ);
823 [ # # # # : 0 : ret.pushKV("filename", dump_path.utf8string());
# # # # ]
824 : :
825 : 0 : return ret;
826 : 0 : },
827 [ + - + - ]: 352 : };
828 [ + - ]: 88 : }
829 : :
830 : 176 : static std::vector<RPCResult> OrphanDescription()
831 : : {
832 : 176 : return {
833 [ + - + - ]: 352 : RPCResult{RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
834 [ + - + - ]: 352 : RPCResult{RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
835 [ + - + - ]: 352 : RPCResult{RPCResult::Type::NUM, "bytes", "The serialized transaction size in bytes"},
836 [ + - + - ]: 352 : RPCResult{RPCResult::Type::NUM, "vsize", "The virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
837 [ + - + - ]: 352 : RPCResult{RPCResult::Type::NUM, "weight", "The transaction weight as defined in BIP 141."},
838 [ + - + - ]: 352 : RPCResult{RPCResult::Type::ARR, "from", "",
839 : : {
840 [ + - + - ]: 352 : RPCResult{RPCResult::Type::NUM, "peer_id", "Peer ID"},
841 [ + - + + : 528 : }},
- - ]
842 [ + - + + : 1584 : };
- - ]
843 [ + - + - : 1232 : }
+ - + - +
- + - + -
- - ]
844 : :
845 : 0 : static UniValue OrphanToJSON(const node::TxOrphanage::OrphanInfo& orphan)
846 : : {
847 : 0 : UniValue o(UniValue::VOBJ);
848 [ # # # # : 0 : o.pushKV("txid", orphan.tx->GetHash().ToString());
# # # # ]
849 [ # # # # : 0 : o.pushKV("wtxid", orphan.tx->GetWitnessHash().ToString());
# # # # ]
850 [ # # # # : 0 : o.pushKV("bytes", orphan.tx->GetTotalSize());
# # # # ]
851 [ # # # # : 0 : o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx));
# # # # ]
852 [ # # # # : 0 : o.pushKV("weight", GetTransactionWeight(*orphan.tx));
# # ]
853 : 0 : UniValue from(UniValue::VARR);
854 [ # # ]: 0 : for (const auto fromPeer: orphan.announcers) {
855 [ # # # # ]: 0 : from.push_back(fromPeer);
856 : : }
857 [ # # # # : 0 : o.pushKV("from", from);
# # ]
858 : 0 : return o;
859 : 0 : }
860 : :
861 : 88 : static RPCHelpMan getorphantxs()
862 : : {
863 : 88 : return RPCHelpMan{
864 : 88 : "getorphantxs",
865 [ + - ]: 176 : "Shows transactions in the tx orphanage.\n"
866 : : "\nEXPERIMENTAL warning: this call may be changed in future releases.\n",
867 : : {
868 [ + - + - : 264 : {"verbosity", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for an array of txids (may contain duplicates), 1 for an array of objects with tx details, and 2 for details from (1) and tx hex",
+ - ]
869 [ + - ]: 176 : RPCArgOptions{.skip_type_check = true}},
870 : : },
871 : : {
872 [ + - ]: 88 : RPCResult{"for verbose = 0",
873 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
874 : : {
875 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
876 [ + - + + : 264 : }},
- - ]
877 [ + - ]: 176 : RPCResult{"for verbose = 1",
878 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
879 : : {
880 [ + - + - : 176 : {RPCResult::Type::OBJ, "", "", OrphanDescription()},
+ - ]
881 [ + - + + : 264 : }},
- - ]
882 [ + - ]: 176 : RPCResult{"for verbose = 2",
883 [ + - + - ]: 176 : RPCResult::Type::ARR, "", "",
884 : : {
885 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "", "",
886 [ + - + - : 440 : Cat<std::vector<RPCResult>>(
+ + - - ]
887 [ + - ]: 176 : OrphanDescription(),
888 [ + - + - ]: 176 : {{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded transaction data"}}
889 : : )
890 : : },
891 [ + - + + : 264 : }},
- - ]
892 : : },
893 : 88 : RPCExamples{
894 [ + - + - : 176 : HelpExampleCli("getorphantxs", "2")
+ - ]
895 [ + - + - : 528 : + HelpExampleRpc("getorphantxs", "2")
+ - ]
896 [ + - ]: 88 : },
897 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
898 : : {
899 : 0 : const NodeContext& node = EnsureAnyNodeContext(request.context);
900 : 0 : PeerManager& peerman = EnsurePeerman(node);
901 : 0 : std::vector<node::TxOrphanage::OrphanInfo> orphanage = peerman.GetOrphanTransactions();
902 : :
903 [ # # # # ]: 0 : int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)};
904 : :
905 : 0 : UniValue ret(UniValue::VARR);
906 : :
907 [ # # ]: 0 : if (verbosity == 0) {
908 [ # # ]: 0 : for (auto const& orphan : orphanage) {
909 [ # # # # : 0 : ret.push_back(orphan.tx->GetHash().ToString());
# # ]
910 : : }
911 [ # # ]: 0 : } else if (verbosity == 1) {
912 [ # # ]: 0 : for (auto const& orphan : orphanage) {
913 [ # # # # ]: 0 : ret.push_back(OrphanToJSON(orphan));
914 : : }
915 [ # # ]: 0 : } else if (verbosity == 2) {
916 [ # # ]: 0 : for (auto const& orphan : orphanage) {
917 [ # # ]: 0 : UniValue o{OrphanToJSON(orphan)};
918 [ # # # # : 0 : o.pushKV("hex", EncodeHexTx(*orphan.tx));
# # # # ]
919 [ # # # # ]: 0 : ret.push_back(o);
920 : 0 : }
921 : : } else {
922 [ # # # # : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid verbosity value " + ToString(verbosity));
# # ]
923 : : }
924 : :
925 : 0 : return ret;
926 : 0 : },
927 [ + - + - : 968 : };
+ - + - +
+ + + - -
- - ]
928 [ + - + - : 704 : }
+ - + - +
- + - + -
+ - - - ]
929 : :
930 : 88 : static RPCHelpMan submitpackage()
931 : : {
932 : 88 : return RPCHelpMan{"submitpackage",
933 [ + - ]: 176 : "Submit a package of raw transactions (serialized, hex-encoded) to local node.\n"
934 : : "The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.\n"
935 : : "This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n"
936 : : "Warning: successful submission does not mean the transactions will propagate throughout the network.\n"
937 : : ,
938 : : {
939 [ + - + - ]: 176 : {"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.\n"
940 : : "The package must consist of a transaction with (some, all, or none of) its unconfirmed parents. A single transaction is permitted.\n"
941 : : "None of the parents may depend on each other. Parents that are already in mempool do not need to be present in the package.\n"
942 : : "The package must be topologically sorted, with the child being the last element in the array if there are multiple elements.",
943 : : {
944 [ + - + - ]: 176 : {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
945 : : },
946 : : },
947 [ + - + - : 176 : {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
+ - ]
948 [ + - ]: 176 : "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
949 : 88 : "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
950 [ + - + - : 176 : {"maxburnamount", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_BURN_AMOUNT)},
+ - ]
951 [ + - ]: 176 : "Reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value, expressed in " + CURRENCY_UNIT + ".\n"
952 : : "If burning funds through unspendable outputs is desired, increase this value.\n"
953 : 88 : "This check is based on heuristics and does not guarantee spendability of outputs.\n"
954 : : },
955 : : },
956 [ + - ]: 176 : RPCResult{
957 [ + - + - ]: 176 : RPCResult::Type::OBJ, "", "",
958 : : {
959 [ + - + - ]: 176 : {RPCResult::Type::STR, "package_msg", "The transaction package result message. \"success\" indicates all transactions were accepted into or are already in the mempool."},
960 [ + - + - ]: 176 : {RPCResult::Type::OBJ_DYN, "tx-results", "The transaction results keyed by wtxid. An entry is returned for every submitted wtxid.",
961 : : {
962 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "wtxid", "transaction wtxid", {
963 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
964 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "other-wtxid", /*optional=*/true, "The wtxid of a different transaction with the same txid but different witness found in the mempool. This means the submitted transaction was ignored."},
965 [ + - + - ]: 176 : {RPCResult::Type::NUM, "vsize", /*optional=*/true, "Sigops-adjusted virtual transaction size."},
966 [ + - + - ]: 176 : {RPCResult::Type::OBJ, "fees", /*optional=*/true, "Transaction fees", {
967 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
968 [ + - + - ]: 176 : {RPCResult::Type::STR_AMOUNT, "effective-feerate", /*optional=*/true, "if the transaction was not already in the mempool, the effective feerate in " + CURRENCY_UNIT + " per KvB. For example, the package feerate and/or feerate with modified fees from prioritisetransaction."},
969 [ + - + - ]: 176 : {RPCResult::Type::ARR, "effective-includes", /*optional=*/true, "if effective-feerate is provided, the wtxids of the transactions whose fees and vsizes are included in effective-feerate.",
970 [ + - + - ]: 176 : {{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
971 : : }},
972 : : }},
973 [ + - + - ]: 176 : {RPCResult::Type::STR, "error", /*optional=*/true, "Error string if rejected from mempool, or \"package-not-validated\" when the package aborts before any per-tx processing."},
974 : : }}
975 : : }},
976 [ + - + - ]: 176 : {RPCResult::Type::ARR, "replaced-transactions", /*optional=*/true, "List of txids of replaced transactions",
977 : : {
978 [ + - + - ]: 176 : {RPCResult::Type::STR_HEX, "", "The transaction id"},
979 : : }},
980 : : },
981 [ + - + - : 2552 : },
+ - + - +
- + - + -
+ + + + +
+ + + + +
+ + - - -
- - - - -
- - - - ]
982 : 88 : RPCExamples{
983 [ + - + - : 176 : HelpExampleRpc("submitpackage", R"(["raw-parent-tx-1", "raw-parent-tx-2", "raw-child-tx"])") +
+ - ]
984 [ + - + - : 264 : HelpExampleCli("submitpackage", R"('["raw-tx-without-unconfirmed-parents"]')")
+ - + - ]
985 [ + - ]: 88 : },
986 : 88 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
987 : : {
988 : 0 : const UniValue raw_transactions = request.params[0].get_array();
989 [ # # # # : 0 : if (raw_transactions.empty() || raw_transactions.size() > MAX_PACKAGE_COUNT) {
# # ]
990 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER,
991 [ # # # # : 0 : "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
# # ]
992 : : }
993 : :
994 : : // Fee check needs to be run with chainstate and package context
995 [ # # # # ]: 0 : const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
996 [ # # ]: 0 : std::optional<CFeeRate> client_maxfeerate{max_raw_tx_fee_rate};
997 : : // 0-value is special; it's mapped to no sanity check
998 [ # # ]: 0 : if (max_raw_tx_fee_rate == CFeeRate(0)) {
999 : 0 : client_maxfeerate = std::nullopt;
1000 : : }
1001 : :
1002 : : // Burn sanity check is run with no context
1003 [ # # # # : 0 : const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
# # # # ]
1004 : :
1005 : 0 : std::vector<CTransactionRef> txns;
1006 [ # # # # ]: 0 : txns.reserve(raw_transactions.size());
1007 [ # # # # ]: 0 : for (const auto& rawtx : raw_transactions.getValues()) {
1008 [ # # ]: 0 : CMutableTransaction mtx;
1009 [ # # # # : 0 : if (!DecodeHexTx(mtx, rawtx.get_str())) {
# # ]
1010 : 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
1011 [ # # # # : 0 : "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
# # ]
1012 : : }
1013 : :
1014 [ # # ]: 0 : for (const auto& out : mtx.vout) {
1015 [ # # # # : 0 : if((out.scriptPubKey.IsUnspendable() || !out.scriptPubKey.HasValidOps()) && out.nValue > max_burn_amount) {
# # # # ]
1016 [ # # # # ]: 0 : throw JSONRPCTransactionError(TransactionError::MAX_BURN_EXCEEDED);
1017 : : }
1018 : : }
1019 : :
1020 [ # # # # ]: 0 : txns.emplace_back(MakeTransactionRef(std::move(mtx)));
1021 : 0 : }
1022 [ # # ]: 0 : CHECK_NONFATAL(!txns.empty());
1023 [ # # # # : 0 : if (txns.size() > 1 && !IsChildWithParentsTree(txns)) {
# # # # ]
1024 [ # # # # ]: 0 : throw JSONRPCTransactionError(TransactionError::INVALID_PACKAGE, "package topology disallowed. not child-with-parents or parents depend on each other.");
1025 : : }
1026 : :
1027 [ # # ]: 0 : NodeContext& node = EnsureAnyNodeContext(request.context);
1028 [ # # ]: 0 : CTxMemPool& mempool = EnsureMemPool(node);
1029 [ # # # # ]: 0 : Chainstate& chainstate = EnsureChainman(node).ActiveChainstate();
1030 [ # # # # ]: 0 : const auto package_result = WITH_LOCK(::cs_main, return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/ false, client_maxfeerate));
1031 : :
1032 [ # # ]: 0 : std::string package_msg = "success";
1033 : :
1034 : : // First catch package-wide errors, continue if we can
1035 [ # # # # ]: 0 : switch(package_result.m_state.GetResult()) {
1036 : 0 : case PackageValidationResult::PCKG_RESULT_UNSET:
1037 : 0 : {
1038 : : // Belt-and-suspenders check; everything should be successful here
1039 [ # # # # ]: 0 : CHECK_NONFATAL(package_result.m_tx_results.size() == txns.size());
1040 [ # # ]: 0 : for (const auto& tx : txns) {
1041 [ # # # # ]: 0 : CHECK_NONFATAL(mempool.exists(tx->GetHash()));
1042 : : }
1043 : : break;
1044 : : }
1045 : 0 : case PackageValidationResult::PCKG_MEMPOOL_ERROR:
1046 : 0 : {
1047 : : // This only happens with internal bug; user should stop and report
1048 : 0 : throw JSONRPCTransactionError(TransactionError::MEMPOOL_ERROR,
1049 [ # # # # ]: 0 : package_result.m_state.GetRejectReason());
1050 : : }
1051 : 0 : case PackageValidationResult::PCKG_POLICY:
1052 : 0 : case PackageValidationResult::PCKG_TX:
1053 : 0 : {
1054 : : // Package-wide error we want to return, but we also want to return individual responses
1055 [ # # ]: 0 : package_msg = package_result.m_state.ToString();
1056 [ # # # # : 0 : CHECK_NONFATAL(package_result.m_tx_results.size() == txns.size() ||
# # # # ]
1057 : : package_result.m_tx_results.empty());
1058 : : break;
1059 : : }
1060 : : }
1061 : :
1062 : 0 : size_t num_broadcast{0};
1063 [ # # ]: 0 : for (const auto& tx : txns) {
1064 : : // We don't want to re-submit the txn for validation in BroadcastTransaction
1065 [ # # # # ]: 0 : if (!mempool.exists(tx->GetHash())) {
1066 : 0 : continue;
1067 : : }
1068 : :
1069 : : // We do not expect an error here; we are only broadcasting things already/still in mempool
1070 [ # # ]: 0 : std::string err_string;
1071 [ # # # # : 0 : const auto err = BroadcastTransaction(node, tx, err_string, /*max_tx_fee=*/0, /*relay=*/true, /*wait_callback=*/true);
# # ]
1072 [ # # ]: 0 : if (err != TransactionError::OK) {
1073 : 0 : throw JSONRPCTransactionError(err,
1074 [ # # ]: 0 : strprintf("transaction broadcast failed: %s (%d transactions were broadcast successfully)",
1075 [ # # ]: 0 : err_string, num_broadcast));
1076 : : }
1077 : 0 : num_broadcast++;
1078 : 0 : }
1079 : :
1080 : 0 : UniValue rpc_result{UniValue::VOBJ};
1081 [ # # # # : 0 : rpc_result.pushKV("package_msg", package_msg);
# # ]
1082 : 0 : UniValue tx_result_map{UniValue::VOBJ};
1083 : 0 : std::set<Txid> replaced_txids;
1084 [ # # ]: 0 : for (const auto& tx : txns) {
1085 : 0 : UniValue result_inner{UniValue::VOBJ};
1086 [ # # # # : 0 : result_inner.pushKV("txid", tx->GetHash().GetHex());
# # # # ]
1087 [ # # ]: 0 : const auto wtxid_hex = tx->GetWitnessHash().GetHex();
1088 : 0 : auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
1089 [ # # ]: 0 : if (it == package_result.m_tx_results.end()) {
1090 : : // No per-tx result for this wtxid
1091 : : // Current invariant: per-tx results are all-or-none (every member or empty on package abort).
1092 : : // If any exist yet this one is missing, it's an unexpected partial map.
1093 [ # # ]: 0 : CHECK_NONFATAL(package_result.m_tx_results.empty());
1094 [ # # # # : 0 : result_inner.pushKV("error", "package-not-validated");
# # ]
1095 [ # # # # ]: 0 : tx_result_map.pushKV(wtxid_hex, std::move(result_inner));
1096 : 0 : continue;
1097 : : }
1098 [ # # # # ]: 0 : const auto& tx_result = it->second;
1099 [ # # # # ]: 0 : switch(it->second.m_result_type) {
1100 : 0 : case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS:
1101 [ # # # # : 0 : result_inner.pushKV("other-wtxid", it->second.m_other_wtxid.value().GetHex());
# # # # #
# ]
1102 : 0 : break;
1103 : 0 : case MempoolAcceptResult::ResultType::INVALID:
1104 [ # # # # : 0 : result_inner.pushKV("error", it->second.m_state.ToString());
# # # # ]
1105 : 0 : break;
1106 : 0 : case MempoolAcceptResult::ResultType::VALID:
1107 : 0 : case MempoolAcceptResult::ResultType::MEMPOOL_ENTRY:
1108 [ # # # # : 0 : result_inner.pushKV("vsize", int64_t{it->second.m_vsize.value()});
# # # # ]
1109 : 0 : UniValue fees(UniValue::VOBJ);
1110 [ # # # # : 0 : fees.pushKV("base", ValueFromAmount(it->second.m_base_fees.value()));
# # # # ]
1111 [ # # ]: 0 : if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
1112 : : // Effective feerate is not provided for MEMPOOL_ENTRY transactions even
1113 : : // though modified fees is known, because it is unknown whether package
1114 : : // feerate was used when it was originally submitted.
1115 [ # # # # : 0 : fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
# # # # ]
1116 : 0 : UniValue effective_includes_res(UniValue::VARR);
1117 [ # # # # ]: 0 : for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
1118 [ # # # # : 0 : effective_includes_res.push_back(wtxid.ToString());
# # ]
1119 : : }
1120 [ # # # # ]: 0 : fees.pushKV("effective-includes", std::move(effective_includes_res));
1121 : 0 : }
1122 [ # # # # ]: 0 : result_inner.pushKV("fees", std::move(fees));
1123 [ # # ]: 0 : for (const auto& ptx : it->second.m_replaced_transactions) {
1124 [ # # ]: 0 : replaced_txids.insert(ptx->GetHash());
1125 : : }
1126 : 0 : break;
1127 : : }
1128 [ # # # # ]: 0 : tx_result_map.pushKV(wtxid_hex, std::move(result_inner));
1129 : 0 : }
1130 [ # # # # ]: 0 : rpc_result.pushKV("tx-results", std::move(tx_result_map));
1131 : 0 : UniValue replaced_list(UniValue::VARR);
1132 [ # # # # : 0 : for (const auto& txid : replaced_txids) replaced_list.push_back(txid.ToString());
# # # # ]
1133 [ # # # # ]: 0 : rpc_result.pushKV("replaced-transactions", std::move(replaced_list));
1134 : 0 : return rpc_result;
1135 : 0 : },
1136 [ + - + - : 880 : };
+ - + + +
+ - - -
- ]
1137 [ + - + - : 1936 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - - - -
- - - -
- ]
1138 : :
1139 : 176 : void RegisterMempoolRPCCommands(CRPCTable& t)
1140 : : {
1141 : 176 : static const CRPCCommand commands[]{
1142 [ + - ]: 88 : {"rawtransactions", &sendrawtransaction},
1143 [ + - ]: 88 : {"rawtransactions", &testmempoolaccept},
1144 [ + - ]: 88 : {"blockchain", &getmempoolancestors},
1145 [ + - ]: 88 : {"blockchain", &getmempooldescendants},
1146 [ + - ]: 88 : {"blockchain", &getmempoolentry},
1147 [ + - ]: 88 : {"blockchain", &gettxspendingprevout},
1148 [ + - ]: 88 : {"blockchain", &getmempoolinfo},
1149 [ + - ]: 88 : {"blockchain", &getrawmempool},
1150 [ + - ]: 88 : {"blockchain", &importmempool},
1151 [ + - ]: 88 : {"blockchain", &savemempool},
1152 [ + - ]: 88 : {"hidden", &getorphantxs},
1153 [ + - ]: 88 : {"rawtransactions", &submitpackage},
1154 [ + + + - : 704 : };
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
- ]
1155 [ + + ]: 2288 : for (const auto& c : commands) {
1156 : 2112 : t.appendCommand(c.name, &c);
1157 : : }
1158 : 176 : }
|