Bitcoin ABC 0.34.5
P2P Digital Currency
Loading...
Searching...
No Matches
mempool.cpp
Go to the documentation of this file.
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
8
9#include <chainparams.h>
10#include <core_io.h>
11#include <net_processing.h>
12#include <node/context.h>
14#include <node/types.h>
15#include <policy/settings.h>
17#include <rpc/server.h>
18#include <rpc/server_util.h>
19#include <rpc/util.h>
20#include <txmempool.h>
21#include <txorphanage.h>
22#include <univalue.h>
23#include <util/fs.h>
24#include <util/moneystr.h>
25#include <util/strencodings.h>
26#include <util/time.h>
27#include <util/vector.h>
28#include <validation.h>
29#include <validationinterface.h>
30
32
37using util::ToString;
38
40 return RPCHelpMan{
41 "sendrawtransaction",
42 "Submits raw transaction (serialized, hex-encoded) to local node and "
43 "network.\n"
44 "\nAlso see createrawtransaction and "
45 "signrawtransactionwithkey calls.\n",
46 {
48 "The hex string of the raw transaction"},
49 {"maxfeerate", RPCArg::Type::AMOUNT,
51 FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
52 "Reject transactions whose fee rate is higher than the specified "
53 "value, expressed in " +
55 "/kB\nSet to 0 to accept any fee rate.\n"},
56 },
57 RPCResult{RPCResult::Type::STR_HEX, "", "The transaction hash in hex"},
59 "\nCreate a transaction\n" +
61 "createrawtransaction",
62 "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
63 "\"{\\\"myaddress\\\":10000}\"") +
64 "Sign the transaction, and get back the hex\n" +
65 HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
66 "\nSend the transaction (signed hex)\n" +
67 HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
68 "\nAs a JSON-RPC call\n" +
69 HelpExampleRpc("sendrawtransaction", "\"signedhex\"")},
70 [&](const RPCHelpMan &self, const Config &config,
71 const JSONRPCRequest &request) -> UniValue {
72 // parse hex string from parameter
74 if (!DecodeHexTx(mtx, request.params[0].get_str())) {
76 "TX decode failed");
77 }
78
79 CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
80
81 const CFeeRate max_raw_tx_fee_rate =
82 request.params[1].isNull()
83 ? DEFAULT_MAX_RAW_TX_FEE_RATE
84 : CFeeRate(AmountFromValue(request.params[1]));
85
86 int64_t virtual_size = GetVirtualTransactionSize(*tx);
87 Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
88
89 std::string err_string;
91 NodeContext &node = EnsureAnyNodeContext(request.context);
92 const TransactionError err = BroadcastTransaction(
93 node, tx, err_string, max_raw_tx_fee, /*relay*/ true,
94 /*wait_callback*/ true);
95 if (err != TransactionError::OK) {
96 throw JSONRPCTransactionError(err, err_string);
97 }
98
99 // Block to make sure wallet/indexers sync before returning
100 CHECK_NONFATAL(node.validation_signals)
101 ->SyncWithValidationInterfaceQueue();
102
103 return tx->GetHash().GetHex();
104 },
105 };
106}
107
109 const auto ticker = Currency::getTicker();
110 return RPCHelpMan{
111 "testmempoolaccept",
112 "\nReturns result of mempool acceptance tests indicating if raw "
113 "transaction(s) (serialized, hex-encoded) would be accepted by "
114 "mempool.\n"
115 "\nIf multiple transactions are passed in, parents must come before "
116 "children and package policies apply: the transactions cannot conflict "
117 "with any mempool transactions or each other.\n"
118 "\nIf one transaction fails, other transactions may not be fully "
119 "validated (the 'allowed' key will be blank).\n"
120 "\nThe maximum number of transactions allowed is " +
121 ToString(MAX_PACKAGE_COUNT) +
122 ".\n"
123 "\nThis checks if transactions violate the consensus or policy "
124 "rules.\n"
125 "\nSee sendrawtransaction call.\n",
126 {
127 {
128 "rawtxs",
131 "An array of hex strings of raw transactions.",
132 {
134 ""},
135 },
136 },
137 {"maxfeerate", RPCArg::Type::AMOUNT,
139 FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
140 "Reject transactions whose fee rate is higher than the specified "
141 "value, expressed in " +
142 ticker + "/kB\n"},
143 },
144 RPCResult{
146 "",
147 "The result of the mempool acceptance test for each raw "
148 "transaction in the input array.\n"
149 "Returns results for each transaction in the same order they were "
150 "passed in.\n"
151 "Transactions that cannot be fully validated due to failures in "
152 "other transactions will not contain an 'allowed' result.\n",
153 {
155 "",
156 "",
157 {
159 "The transaction hash in hex"},
160 {RPCResult::Type::STR, "package-error",
161 "Package validation error, if any (only possible if "
162 "rawtxs had more than 1 transaction)."},
163 {RPCResult::Type::BOOL, "allowed",
164 "Whether this tx would be accepted to the mempool and "
165 "pass client-specified maxfeerate. "
166 "If not present, the tx was not fully validated due to a "
167 "failure in another tx in the list."},
168 {RPCResult::Type::NUM, "size", "The transaction size"},
170 "fees",
171 "Transaction fees (only present if 'allowed' is true)",
172 {
174 "transaction fee in " + ticker},
175 {RPCResult::Type::STR_AMOUNT, "effective-feerate",
176 "the effective feerate in " + ticker +
177 " per KvB. May differ from the base feerate if, "
178 "for example, there are modified fees from "
179 "prioritisetransaction or a package feerate was "
180 "used."},
182 "effective-includes",
183 "transactions whose fees and vsizes are included in "
184 "effective-feerate.",
185 {
187 "transaction txid in hex"},
188 }},
189 }},
190 {RPCResult::Type::STR, "reject-reason", /*optional=*/true,
191 "Rejection string (only present when 'allowed' is "
192 "false)"},
193 {RPCResult::Type::STR, "reject-details", /*optional=*/true,
194 "Rejection details (only present when 'allowed' is false "
195 "and rejection details exist)"},
196
197 }},
198 }},
200 "\nCreate a transaction\n" +
202 "createrawtransaction",
203 "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
204 "\"{\\\"myaddress\\\":10000}\"") +
205 "Sign the transaction, and get back the hex\n" +
206 HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
207 "\nTest acceptance of the transaction (signed hex)\n" +
208 HelpExampleCli("testmempoolaccept", R"('["signedhex"]')") +
209 "\nAs a JSON-RPC call\n" +
210 HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")},
211 [&](const RPCHelpMan &self, const Config &config,
212 const JSONRPCRequest &request) -> UniValue {
213 const UniValue raw_transactions = request.params[0].get_array();
214 if (raw_transactions.size() < 1 ||
215 raw_transactions.size() > MAX_PACKAGE_COUNT) {
217 "Array must contain between 1 and " +
218 ToString(MAX_PACKAGE_COUNT) +
219 " transactions.");
220 }
221
222 const CFeeRate max_raw_tx_fee_rate =
223 request.params[1].isNull()
224 ? DEFAULT_MAX_RAW_TX_FEE_RATE
225 : CFeeRate(AmountFromValue(request.params[1]));
226
227 std::vector<CTransactionRef> txns;
228 txns.reserve(raw_transactions.size());
229 for (const auto &rawtx : raw_transactions.getValues()) {
231 if (!DecodeHexTx(mtx, rawtx.get_str())) {
233 "TX decode failed: " + rawtx.get_str());
234 }
235 txns.emplace_back(MakeTransactionRef(std::move(mtx)));
236 }
237
238 NodeContext &node = EnsureAnyNodeContext(request.context);
239 CTxMemPool &mempool = EnsureMemPool(node);
241 Chainstate &chainstate = chainman.ActiveChainstate();
242 const PackageMempoolAcceptResult package_result = [&] {
244 if (txns.size() > 1) {
245 return ProcessNewPackage(chainstate, mempool, txns,
246 /* test_accept */ true);
247 }
249 txns[0]->GetId(),
250 chainman.ProcessTransaction(txns[0],
251 /* test_accept*/ true));
252 }();
253
254 UniValue rpc_result(UniValue::VARR);
255 // We will check transaction fees while we iterate through txns in
256 // order. If any transaction fee exceeds maxfeerate, we will leave
257 // the rest of the validation results blank, because it doesn't make
258 // sense to return a validation result for a transaction if its
259 // ancestor(s) would not be submitted.
260 bool exit_early{false};
261 for (const auto &tx : txns) {
262 UniValue result_inner(UniValue::VOBJ);
263 result_inner.pushKV("txid", tx->GetId().GetHex());
264 if (package_result.m_state.GetResult() ==
266 result_inner.pushKV(
267 "package-error",
268 package_result.m_state.GetRejectReason());
269 }
270 auto it = package_result.m_tx_results.find(tx->GetId());
271 if (exit_early || it == package_result.m_tx_results.end()) {
272 // Validation unfinished. Just return the txid.
273 rpc_result.push_back(std::move(result_inner));
274 continue;
275 }
276 const auto &tx_result = it->second;
277 // Package testmempoolaccept doesn't allow transactions to
278 // already be in the mempool.
279 CHECK_NONFATAL(tx_result.m_result_type !=
281 if (tx_result.m_result_type ==
283 const Amount fee = tx_result.m_base_fees.value();
284 // Check that fee does not exceed maximum fee
285 const int64_t virtual_size = tx_result.m_vsize.value();
286 const Amount max_raw_tx_fee =
287 max_raw_tx_fee_rate.GetFee(virtual_size);
288 if (max_raw_tx_fee != Amount::zero() &&
289 fee > max_raw_tx_fee) {
290 result_inner.pushKV("allowed", false);
291 result_inner.pushKV("reject-reason",
292 "max-fee-exceeded");
293 exit_early = true;
294 } else {
295 // Only return the fee and size if the transaction
296 // would pass ATMP.
297 // These can be used to calculate the feerate.
298 result_inner.pushKV("allowed", true);
299 result_inner.pushKV("size", virtual_size);
301 fees.pushKV("base", fee);
302 fees.pushKV(
303 "effective-feerate",
304 tx_result.m_effective_feerate.value().GetFeePerK());
305 UniValue effective_includes_res(UniValue::VARR);
306 for (const auto &txid :
307 tx_result.m_txids_fee_calculations.value()) {
308 effective_includes_res.push_back(txid.ToString());
309 }
310 fees.pushKV("effective-includes",
311 std::move(effective_includes_res));
312 result_inner.pushKV("fees", std::move(fees));
313 }
314 } else {
315 result_inner.pushKV("allowed", false);
316 const TxValidationState state = tx_result.m_state;
317 if (state.GetResult() ==
319 result_inner.pushKV("reject-reason", "missing-inputs");
320 } else {
321 result_inner.pushKV("reject-reason",
322 state.GetRejectReason());
323 result_inner.pushKV("reject-details", state.ToString());
324 }
325 }
326 rpc_result.push_back(std::move(result_inner));
327 }
328 return rpc_result;
329 },
330 };
331}
332
333static std::vector<RPCResult> MempoolEntryDescription() {
334 const auto ticker = Currency::getTicker();
335 return {
336 RPCResult{RPCResult::Type::NUM, "size", "transaction size."},
338 "local time transaction entered pool in seconds since 1 Jan "
339 "1970 GMT"},
341 "block height when transaction entered pool"},
343 "fees",
344 "",
345 {{
347 "transaction fee in " + ticker},
349 "transaction fee with fee deltas used for "
350 "mining priority in " +
351 ticker},
352 }}},
353 RPCResult{
355 "depends",
356 "unconfirmed transactions used as inputs for this transaction",
357 {RPCResult{RPCResult::Type::STR_HEX, "transactionid",
358 "parent transaction id"}}},
359 RPCResult{
361 "spentby",
362 "unconfirmed transactions spending outputs from this transaction",
363 {RPCResult{RPCResult::Type::STR_HEX, "transactionid",
364 "child transaction id"}}},
365 RPCResult{RPCResult::Type::BOOL, "unbroadcast",
366 "Whether this transaction is currently unbroadcast (initial "
367 "broadcast not yet acknowledged by any peers)"},
368 };
369}
370
371static void entryToJSON(const CTxMemPool &pool, UniValue &info,
372 const CTxMemPoolEntryRef &e)
373 EXCLUSIVE_LOCKS_REQUIRED(pool.cs) {
374 AssertLockHeld(pool.cs);
375
377 fees.pushKV("base", e->GetFee());
378 fees.pushKV("modified", e->GetModifiedFee());
379 info.pushKV("fees", fees);
380
381 info.pushKV("size", (int)e->GetTxSize());
382 info.pushKV("time", count_seconds(e->GetTime()));
383 info.pushKV("height", (int)e->GetHeight());
384 const CTransaction &tx = e->GetTx();
385 std::set<std::string> setDepends;
386 for (const CTxIn &txin : tx.vin) {
387 if (pool.exists(txin.prevout.GetTxId())) {
388 setDepends.insert(txin.prevout.GetTxId().ToString());
389 }
390 }
391
392 UniValue depends(UniValue::VARR);
393 for (const std::string &dep : setDepends) {
394 depends.push_back(dep);
395 }
396
397 info.pushKV("depends", std::move(depends));
398
400 for (const auto &child : e->GetMemPoolChildrenConst()) {
401 spent.push_back(child.get()->GetTx().GetId().ToString());
402 }
403
404 info.pushKV("spentby", std::move(spent));
405 info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetId()));
406}
407
408UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose,
409 bool include_mempool_sequence) {
410 if (verbose) {
411 if (include_mempool_sequence) {
412 throw JSONRPCError(
414 "Verbose results cannot contain mempool sequence values.");
415 }
416 LOCK(pool.cs);
418 for (const CTxMemPoolEntryRef &e : pool.mapTx) {
419 const TxId &txid = e->GetTx().GetId();
421 entryToJSON(pool, info, e);
422 // Mempool has unique entries so there is no advantage in using
423 // UniValue::pushKV, which checks if the key already exists in O(N).
424 // UniValue::pushKVEnd is used instead which currently is O(1).
425 o.pushKVEnd(txid.ToString(), std::move(info));
426 }
427 return o;
428 } else {
429 uint64_t mempool_sequence;
430 std::vector<TxId> vtxids;
431 {
432 LOCK(pool.cs);
433 pool.getAllTxIds(vtxids);
434 mempool_sequence = pool.GetSequence();
435 }
437 for (const TxId &txid : vtxids) {
438 a.push_back(txid.ToString());
439 }
440
441 if (!include_mempool_sequence) {
442 return a;
443 } else {
445 o.pushKV("txids", std::move(a));
446 o.pushKV("mempool_sequence", mempool_sequence);
447 return o;
448 }
449 }
450}
451
453 return RPCHelpMan{
454 "getrawmempool",
455 "Returns all transaction ids in memory pool as a json array of "
456 "string transaction ids.\n"
457 "\nHint: use getmempoolentry to fetch a specific transaction from the "
458 "mempool.\n",
459 {
460 {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false},
461 "True for a json object, false for array of transaction ids"},
462 {"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false},
463 "If verbose=false, returns a json object with transaction list "
464 "and mempool sequence number attached."},
465 },
466 {
467 RPCResult{"for verbose = false",
469 "",
470 "",
471 {
472 {RPCResult::Type::STR_HEX, "", "The transaction id"},
473 }},
474 RPCResult{"for verbose = true",
476 "",
477 "",
478 {
479 {RPCResult::Type::OBJ, "transactionid", "",
481 }},
482 RPCResult{
483 "for verbose = false and mempool_sequence = true",
485 "",
486 "",
487 {
489 "txids",
490 "",
491 {
492 {RPCResult::Type::STR_HEX, "", "The transaction id"},
493 }},
494 {RPCResult::Type::NUM, "mempool_sequence",
495 "The mempool sequence value."},
496 }},
497 },
498 RPCExamples{HelpExampleCli("getrawmempool", "true") +
499 HelpExampleRpc("getrawmempool", "true")},
500 [&](const RPCHelpMan &self, const Config &config,
501 const JSONRPCRequest &request) -> UniValue {
502 bool fVerbose = false;
503 if (!request.params[0].isNull()) {
504 fVerbose = request.params[0].get_bool();
505 }
506
507 bool include_mempool_sequence = false;
508 if (!request.params[1].isNull()) {
509 include_mempool_sequence = request.params[1].get_bool();
510 }
511
512 return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose,
513 include_mempool_sequence);
514 },
515 };
516}
517
519 return RPCHelpMan{
520 "getmempoolancestors",
521 "If txid is in the mempool, returns all in-mempool ancestors.\n",
522 {
524 "The transaction id (must be in mempool)"},
525 {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false},
526 "True for a json object, false for array of transaction ids"},
527 },
528 {
529 RPCResult{
530 "for verbose = false",
532 "",
533 "",
535 "The transaction id of an in-mempool ancestor transaction"}}},
536 RPCResult{"for verbose = true",
538 "",
539 "",
540 {
541 {RPCResult::Type::OBJ, "transactionid", "",
543 }},
544 },
545 RPCExamples{HelpExampleCli("getmempoolancestors", "\"mytxid\"") +
546 HelpExampleRpc("getmempoolancestors", "\"mytxid\"")},
547 [&](const RPCHelpMan &self, const Config &config,
548 const JSONRPCRequest &request) -> UniValue {
549 bool fVerbose = false;
550 if (!request.params[1].isNull()) {
551 fVerbose = request.params[1].get_bool();
552 }
553
554 TxId txid(ParseHashV(request.params[0], "parameter 1"));
555
556 const CTxMemPool &mempool = EnsureAnyMemPool(request.context);
557 LOCK(mempool.cs);
558
559 CTxMemPool::txiter it = mempool.mapTx.find(txid);
560 if (it == mempool.mapTx.end()) {
562 "Transaction not in mempool");
563 }
564
565 CTxMemPool::setEntries setAncestors;
566 mempool.CalculateMemPoolAncestors(*it, setAncestors);
567
568 if (!fVerbose) {
570 for (CTxMemPool::txiter ancestorIt : setAncestors) {
571 o.push_back((*ancestorIt)->GetTx().GetId().ToString());
572 }
573 return o;
574 } else {
576 for (CTxMemPool::txiter ancestorIt : setAncestors) {
577 const CTxMemPoolEntryRef &e = *ancestorIt;
578 const TxId &_txid = e->GetTx().GetId();
580 entryToJSON(mempool, info, e);
581 o.pushKV(_txid.ToString(), std::move(info));
582 }
583 return o;
584 }
585 },
586 };
587}
588
590 return RPCHelpMan{
591 "getmempooldescendants",
592 "If txid is in the mempool, returns all in-mempool descendants.\n",
593 {
595 "The transaction id (must be in mempool)"},
596 {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false},
597 "True for a json object, false for array of transaction ids"},
598 },
599 {
600 RPCResult{"for verbose = false",
602 "",
603 "",
605 "The transaction id of an in-mempool descendant "
606 "transaction"}}},
607 RPCResult{"for verbose = true",
609 "",
610 "",
611 {
612 {RPCResult::Type::OBJ, "transactionid", "",
614 }},
615 },
616 RPCExamples{HelpExampleCli("getmempooldescendants", "\"mytxid\"") +
617 HelpExampleRpc("getmempooldescendants", "\"mytxid\"")},
618 [&](const RPCHelpMan &self, const Config &config,
619 const JSONRPCRequest &request) -> UniValue {
620 bool fVerbose = false;
621 if (!request.params[1].isNull()) {
622 fVerbose = request.params[1].get_bool();
623 }
624
625 TxId txid(ParseHashV(request.params[0], "parameter 1"));
626
627 const CTxMemPool &mempool = EnsureAnyMemPool(request.context);
628 LOCK(mempool.cs);
629
630 CTxMemPool::txiter it = mempool.mapTx.find(txid);
631 if (it == mempool.mapTx.end()) {
633 "Transaction not in mempool");
634 }
635
636 CTxMemPool::setEntries setDescendants;
637 mempool.CalculateDescendants(it, setDescendants);
638 // CTxMemPool::CalculateDescendants will include the given tx
639 setDescendants.erase(it);
640
641 if (!fVerbose) {
643 for (CTxMemPool::txiter descendantIt : setDescendants) {
644 o.push_back((*descendantIt)->GetTx().GetId().ToString());
645 }
646
647 return o;
648 } else {
650 for (CTxMemPool::txiter descendantIt : setDescendants) {
651 const CTxMemPoolEntryRef &e = *descendantIt;
652 const TxId &_txid = e->GetTx().GetId();
654 entryToJSON(mempool, info, e);
655 o.pushKV(_txid.ToString(), std::move(info));
656 }
657 return o;
658 }
659 },
660 };
661}
662
664 return RPCHelpMan{
665 "getmempoolentry",
666 "Returns mempool data for given transaction\n",
667 {
669 "The transaction id (must be in mempool)"},
670 },
672 RPCExamples{HelpExampleCli("getmempoolentry", "\"mytxid\"") +
673 HelpExampleRpc("getmempoolentry", "\"mytxid\"")},
674 [&](const RPCHelpMan &self, const Config &config,
675 const JSONRPCRequest &request) -> UniValue {
676 TxId txid(ParseHashV(request.params[0], "parameter 1"));
677
678 const CTxMemPool &mempool = EnsureAnyMemPool(request.context);
679 LOCK(mempool.cs);
680
681 CTxMemPool::txiter it = mempool.mapTx.find(txid);
682 if (it == mempool.mapTx.end()) {
684 "Transaction not in mempool");
685 }
686
688 entryToJSON(mempool, info, *it);
689 return info;
690 },
691 };
692}
693
695 // Make sure this call is atomic in the pool.
696 LOCK(pool.cs);
698 ret.pushKV("loaded", pool.GetLoadTried());
699 ret.pushKV("size", (int64_t)pool.size());
700 ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize());
701 ret.pushKV("finalized_txs_size", (int64_t)pool.GetFinalizedTxCount());
702 ret.pushKV("finalized_txs_bytes", (int64_t)pool.GetTotalFinalizedTxSize());
703 ret.pushKV("finalized_txs_sigchecks",
704 (int64_t)pool.GetTotalFinalizedTxSigchecks());
705 ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage());
706 ret.pushKV("total_fee", pool.GetTotalFee());
707 ret.pushKV("maxmempool", pool.m_opts.max_size_bytes);
708 ret.pushKV(
709 "mempoolminfee",
710 std::max(pool.GetMinFee(), pool.m_opts.min_relay_feerate).GetFeePerK());
711 ret.pushKV("minrelaytxfee", pool.m_opts.min_relay_feerate.GetFeePerK());
712 ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()});
713 return ret;
714}
715
717 const auto ticker = Currency::getTicker();
718 return RPCHelpMan{
719 "getmempoolinfo",
720 "Returns details on the active state of the TX memory pool.\n",
721 {},
722 RPCResult{
724 "",
725 "",
726 {
727 {RPCResult::Type::BOOL, "loaded",
728 "True if the initial load attempt of the persisted mempool "
729 "finished"},
730 {RPCResult::Type::NUM, "size", "Current tx count"},
731 {RPCResult::Type::NUM, "bytes", "Sum of all transaction sizes"},
732 {RPCResult::Type::NUM, "finalized_txs_size",
733 "Current finalized tx count"},
734 {RPCResult::Type::NUM, "finalized_txs_bytes",
735 "Sum of all finalized transaction sizes"},
736 {RPCResult::Type::NUM, "finalized_txs_sigchecks",
737 "Sum of all finalized transaction sigchecks"},
738 {RPCResult::Type::NUM, "usage",
739 "Total memory usage for the mempool"},
740 {RPCResult::Type::NUM, "maxmempool",
741 "Maximum memory usage for the mempool"},
742 {RPCResult::Type::STR_AMOUNT, "total_fee",
743 "Total fees for the mempool in " + ticker +
744 ", ignoring modified fees through prioritisetransaction"},
745 {RPCResult::Type::STR_AMOUNT, "mempoolminfee",
746 "Minimum fee rate in " + ticker +
747 "/kB for tx to be accepted. Is the maximum of "
748 "minrelaytxfee and minimum mempool fee"},
749 {RPCResult::Type::STR_AMOUNT, "minrelaytxfee",
750 "Current minimum relay fee for transactions"},
751 {RPCResult::Type::NUM, "unbroadcastcount",
752 "Current number of transactions that haven't passed initial "
753 "broadcast yet"},
754 }},
755 RPCExamples{HelpExampleCli("getmempoolinfo", "") +
756 HelpExampleRpc("getmempoolinfo", "")},
757 [&](const RPCHelpMan &self, const Config &config,
758 const JSONRPCRequest &request) -> UniValue {
759 return MempoolInfoToJSON(EnsureAnyMemPool(request.context));
760 },
761 };
762}
763
765 return RPCHelpMan{
766 "importmempool",
767 "Import a mempool.dat file and attempt to add its contents to the "
768 "mempool.\n"
769 "Warning: Importing untrusted files is dangerous, especially if "
770 "metadata from the file is taken over.",
771 {
773 "The mempool file"},
774 {"options",
777 "",
778 {
779 {"use_current_time", RPCArg::Type::BOOL, RPCArg::Default{true},
780 "Whether to use the current system time or use the entry "
781 "time metadata from the mempool file.\n"
782 "Warning: Importing untrusted metadata may lead to "
783 "unexpected issues and undesirable behavior."},
784 {"apply_fee_delta_priority", RPCArg::Type::BOOL,
785 RPCArg::Default{false},
786 "Whether to apply the fee delta metadata from the mempool "
787 "file.\n"
788 "It will be added to any existing fee deltas.\n"
789 "The fee delta can be set by the prioritisetransaction RPC.\n"
790 "Warning: Importing untrusted metadata may lead to "
791 "unexpected issues and undesirable behavior.\n"
792 "Only set this bool if you understand what it does."},
793 {"apply_unbroadcast_set", RPCArg::Type::BOOL,
794 RPCArg::Default{false},
795 "Whether to apply the unbroadcast set metadata from the "
796 "mempool file.\n"
797 "Warning: Importing untrusted metadata may lead to "
798 "unexpected issues and undesirable behavior."},
799 },
800 RPCArgOptions{.oneline_description = "\"options\""}},
801 },
802 RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
803 RPCExamples{HelpExampleCli("importmempool", "/path/to/mempool.dat") +
804 HelpExampleRpc("importmempool", "/path/to/mempool.dat")},
805 [&](const RPCHelpMan &self, const Config &config,
806 const JSONRPCRequest &request) -> UniValue {
807 const NodeContext &node{EnsureAnyNodeContext(request.context)};
808
809 CTxMemPool &mempool{EnsureMemPool(node)};
811 Chainstate &chainstate = chainman.ActiveChainstate();
812
813 if (chainman.IsInitialBlockDownload()) {
815 "Can only import the mempool after the "
816 "block download and sync is done.");
817 }
818
819 const fs::path load_path{fs::u8path(request.params[0].get_str())};
820 const UniValue &use_current_time{
821 request.params[1]["use_current_time"]};
822 const UniValue &apply_fee_delta{
823 request.params[1]["apply_fee_delta_priority"]};
824 const UniValue &apply_unbroadcast{
825 request.params[1]["apply_unbroadcast_set"]};
827 .use_current_time = use_current_time.isNull()
828 ? true
829 : use_current_time.get_bool(),
830 .apply_fee_delta_priority = apply_fee_delta.isNull()
831 ? false
832 : apply_fee_delta.get_bool(),
833 .apply_unbroadcast_set = apply_unbroadcast.isNull()
834 ? false
835 : apply_unbroadcast.get_bool(),
836 };
837
838 if (!kernel::LoadMempool(mempool, load_path, chainstate,
839 std::move(opts))) {
841 "Unable to import mempool file, see "
842 "debug.log for details.");
843 }
844
846 return ret;
847 },
848 };
849}
850
852 return RPCHelpMan{
853 "savemempool",
854 "Dumps the mempool to disk. It will fail until the previous dump is "
855 "fully loaded.\n",
856 {},
858 "",
859 "",
860 {
861 {RPCResult::Type::STR, "filename",
862 "the directory and file where the mempool was saved"},
863 }},
864 RPCExamples{HelpExampleCli("savemempool", "") +
865 HelpExampleRpc("savemempool", "")},
866 [&](const RPCHelpMan &self, const Config &config,
867 const JSONRPCRequest &request) -> UniValue {
868 const ArgsManager &args{EnsureAnyArgsman(request.context)};
869 const CTxMemPool &mempool = EnsureAnyMemPool(request.context);
870
871 if (!mempool.GetLoadTried()) {
873 "The mempool was not loaded yet");
874 }
875
876 const fs::path &dump_path = MempoolPath(args);
877
878 if (!DumpMempool(mempool, dump_path)) {
880 "Unable to dump mempool to disk");
881 }
882
884 ret.pushKV("filename", dump_path.u8string());
885
886 return ret;
887 },
888 };
889}
890
891static std::vector<RPCResult> OrphanDescription() {
892 return {
894 "The transaction hash in hex"},
896 "The serialized transaction size in bytes"},
898 "The entry time into the orphanage expressed in " +
901 "The orphan expiration time expressed in " + UNIX_EPOCH_TIME},
903 "from",
904 "",
905 {
906 RPCResult{RPCResult::Type::NUM, "peer_id", "Peer ID"},
907 }},
908 };
909}
910
913 o.pushKV("txid", orphan.tx->GetId().ToString());
914 o.pushKV("bytes", orphan.tx->GetTotalSize());
915 o.pushKV("entry", int64_t{TicksSinceEpoch<std::chrono::seconds>(
917 o.pushKV("expiration", int64_t{TicksSinceEpoch<std::chrono::seconds>(
918 orphan.nTimeExpire)});
920 for (const auto fromPeer : orphan.announcers) {
921 from.push_back(fromPeer);
922 }
923 o.pushKV("from", from);
924 return o;
925}
926
928 return RPCHelpMan{
929 "getorphantxs",
930 "\nShows transactions in the tx orphanage.\n"
931 "\nEXPERIMENTAL warning: this call may be changed in future "
932 "releases.\n",
933 {
934 {"verbosity", RPCArg::Type::NUM, RPCArg::Default{0},
935 "0 for an array of txids (may contain duplicates), 1 for an "
936 "array of objects with tx details, and 2 for details from (1) and "
937 "tx hex",
939 },
940 {
941 RPCResult{"for verbose = 0",
943 "",
944 "",
945 {
947 "The transaction hash in hex"},
948 }},
949 RPCResult{"for verbose = 1",
951 "",
952 "",
953 {
955 }},
956 RPCResult{"for verbose = 2",
958 "",
959 "",
960 {
961 {RPCResult::Type::OBJ, "", "",
962 Cat<std::vector<RPCResult>>(
965 "The serialized, hex-encoded transaction "
966 "data"}})},
967 }},
968 },
969 RPCExamples{HelpExampleCli("getorphantxs", "2") +
970 HelpExampleRpc("getorphantxs", "2")},
971 [&](const RPCHelpMan &self, const Config &config,
972 const JSONRPCRequest &request) -> UniValue {
973 const NodeContext &node = EnsureAnyNodeContext(request.context);
974 PeerManager &peerman = EnsurePeerman(node);
975 std::vector<TxOrphanage::PoolTx> orphanage =
976 peerman.GetOrphanTransactions();
977
978 int verbosity{ParseVerbosity(request.params[0],
979 /*default_verbosity=*/0,
980 /*allow_bool=*/false)};
981
983
984 if (verbosity == 0) {
985 for (const auto &orphan : orphanage) {
986 ret.push_back(orphan.tx->GetId().ToString());
987 }
988 } else if (verbosity == 1) {
989 for (const auto &orphan : orphanage) {
990 ret.push_back(OrphanToJSON(orphan));
991 }
992 } else if (verbosity == 2) {
993 for (const auto &orphan : orphanage) {
994 UniValue o{OrphanToJSON(orphan)};
995 o.pushKV("hex", EncodeHexTx(*orphan.tx));
996 ret.push_back(o);
997 }
998 } else {
1000 "Invalid verbosity value " +
1001 ToString(verbosity));
1002 }
1003
1004 return ret;
1005 },
1006 };
1007}
1008
1010 const auto ticker = Currency::getTicker();
1011 return RPCHelpMan{
1012 "submitpackage",
1013 "Submit a package of raw transactions (serialized, hex-encoded) to "
1014 "local node.\n"
1015 "The package must consist of a child with its parents, and none of the "
1016 "parents may depend on one another.\n"
1017 "The package will be validated according to consensus and mempool "
1018 "policy rules. If any transaction passes, it will be accepted to "
1019 "mempool.\n"
1020 "This RPC is experimental and the interface may be unstable. Refer to "
1021 "doc/policy/packages.md for documentation on package policies.\n"
1022 "Warning: successful submission does not mean the transactions will "
1023 "propagate throughout the network.\n",
1024 {
1025 {
1026 "package",
1029 "An array of raw transactions.",
1030 {
1032 ""},
1033 },
1034 },
1035 },
1036 RPCResult{
1038 "",
1039 "",
1040 {
1041 {RPCResult::Type::STR, "package_msg",
1042 "The transaction package result message. \"success\" "
1043 "indicates all transactions were accepted into or are already "
1044 "in the mempool."},
1046 "tx-results",
1047 "transaction results keyed by txid",
1049 "txid",
1050 "transaction txid",
1051 {
1052 {RPCResult::Type::NUM, "vsize", /*optional=*/true,
1053 "Virtual transaction size."},
1055 "fees",
1056 /*optional=*/true,
1057 "Transaction fees",
1058 {
1060 "transaction fee in " + ticker},
1061 {RPCResult::Type::STR_AMOUNT, "effective-feerate",
1062 "the effective feerate in " + ticker +
1063 " per KvB. May differ from the base feerate "
1064 "if, for example, there are modified fees "
1065 "from prioritisetransaction or a package "
1066 "feerate was used."},
1068 "effective-includes",
1069 "transactions whose fees and vsizes are included "
1070 "in effective-feerate.",
1071 {
1073 "transaction txid in hex"},
1074 }},
1075 }},
1076 {RPCResult::Type::STR, "error", /*optional=*/true,
1077 "The transaction error string, if it was rejected by "
1078 "the mempool"},
1079 }}}},
1080 },
1081 },
1082 RPCExamples{HelpExampleCli("testmempoolaccept", "[rawtx1, rawtx2]") +
1083 HelpExampleCli("submitpackage", "[rawtx1, rawtx2]")},
1084 [&](const RPCHelpMan &self, const Config &config,
1085 const JSONRPCRequest &request) -> UniValue {
1086 const UniValue &raw_transactions = request.params[0].get_array();
1087 if (raw_transactions.size() < 1 ||
1088 raw_transactions.size() > MAX_PACKAGE_COUNT) {
1090 "Array must contain between 1 and " +
1091 ToString(MAX_PACKAGE_COUNT) +
1092 " transactions.");
1093 }
1094
1095 std::vector<CTransactionRef> txns;
1096 txns.reserve(raw_transactions.size());
1097 for (const auto &rawtx : raw_transactions.getValues()) {
1099 if (!DecodeHexTx(mtx, rawtx.get_str())) {
1100 throw JSONRPCError(
1102 "TX decode failed: " + rawtx.get_str() +
1103 " Make sure the tx has at least one input.");
1104 }
1105 txns.emplace_back(MakeTransactionRef(std::move(mtx)));
1106 }
1107 if (!IsChildWithParentsTree(txns)) {
1109 TransactionError::INVALID_PACKAGE,
1110 "package topology disallowed. not child-with-parents or "
1111 "parents depend on each other.");
1112 }
1113
1114 NodeContext &node = EnsureAnyNodeContext(request.context);
1115 CTxMemPool &mempool = EnsureMemPool(node);
1117 const auto package_result = WITH_LOCK(
1118 ::cs_main, return ProcessNewPackage(chainstate, mempool, txns,
1119 /*test_accept=*/false));
1120
1121 std::string package_msg = "success";
1122
1123 // First catch package-wide errors, continue if we can
1124 switch (package_result.m_state.GetResult()) {
1126 // Belt-and-suspenders check; everything should be
1127 // successful here
1128 CHECK_NONFATAL(package_result.m_tx_results.size() ==
1129 txns.size());
1130 for (const auto &tx : txns) {
1131 CHECK_NONFATAL(mempool.exists(tx->GetId()));
1132 }
1133 break;
1134 }
1136 // This only happens with internal bug; user should stop and
1137 // report
1139 TransactionError::MEMPOOL_ERROR,
1140 package_result.m_state.GetRejectReason());
1141 }
1144 // Package-wide error we want to return, but we also want to
1145 // return individual responses
1146 package_msg = package_result.m_state.GetRejectReason();
1147 CHECK_NONFATAL(package_result.m_tx_results.size() ==
1148 txns.size() ||
1149 package_result.m_tx_results.empty());
1150 break;
1151 }
1152 }
1153 size_t num_broadcast{0};
1154 for (const auto &tx : txns) {
1155 // We don't want to re-submit the txn for validation in
1156 // BroadcastTransaction
1157 if (!mempool.exists(tx->GetId())) {
1158 continue;
1159 }
1160
1161 // We do not expect an error here; we are only broadcasting
1162 // things already/still in mempool
1163 std::string err_string;
1164 const auto err = BroadcastTransaction(
1165 node, tx, err_string, /*max_tx_fee=*/Amount::zero(),
1166 /*relay=*/true, /*wait_callback=*/true);
1167 if (err != TransactionError::OK) {
1169 err,
1170 strprintf("transaction broadcast failed: %s (%d "
1171 "transactions were broadcast successfully)",
1172 err_string, num_broadcast));
1173 }
1174 num_broadcast++;
1175 }
1176
1177 UniValue rpc_result{UniValue::VOBJ};
1178 rpc_result.pushKV("package_msg", package_msg);
1179 UniValue tx_result_map{UniValue::VOBJ};
1180 for (const auto &tx : txns) {
1181 UniValue result_inner{UniValue::VOBJ};
1182 auto it = package_result.m_tx_results.find(tx->GetId());
1183 if (it == package_result.m_tx_results.end()) {
1184 // No results, report error and continue
1185 result_inner.pushKV("error", "unevaluated");
1186 continue;
1187 }
1188 const auto &tx_result = it->second;
1189 switch (it->second.m_result_type) {
1191 result_inner.pushKV("error",
1192 it->second.m_state.ToString());
1193 break;
1196 result_inner.pushKV(
1197 "vsize", int64_t{it->second.m_vsize.value()});
1199 fees.pushKV("base", it->second.m_base_fees.value());
1200 if (tx_result.m_result_type ==
1202 // Effective feerate is not provided for
1203 // MEMPOOL_ENTRY (already in mempool) transactions
1204 // even though modified fees is known, because it is
1205 // unknown whether package feerate was used when it
1206 // was originally submitted.
1207 fees.pushKV("effective-feerate",
1208 tx_result.m_effective_feerate.value()
1209 .GetFeePerK());
1210 UniValue effective_includes_res(UniValue::VARR);
1211 for (const auto &txid :
1212 tx_result.m_txids_fee_calculations.value()) {
1213 effective_includes_res.push_back(
1214 txid.ToString());
1215 }
1216 fees.pushKV("effective-includes",
1217 std::move(effective_includes_res));
1218 }
1219 result_inner.pushKV("fees", std::move(fees));
1220 break;
1221 }
1222 tx_result_map.pushKV(tx->GetId().GetHex(),
1223 std::move(result_inner));
1224 }
1225 rpc_result.pushKV("tx-results", std::move(tx_result_map));
1226
1227 return rpc_result;
1228 },
1229 };
1230}
1231
1233 static const CRPCCommand commands[]{
1234 // category actor (function)
1235 // -------- ----------------
1236 {"rawtransactions", sendrawtransaction},
1237 {"rawtransactions", testmempoolaccept},
1238 {"blockchain", getmempoolancestors},
1239 {"blockchain", getmempooldescendants},
1240 {"blockchain", getmempoolentry},
1241 {"blockchain", getmempoolinfo},
1242 {"blockchain", getrawmempool},
1243 {"blockchain", importmempool},
1244 {"blockchain", savemempool},
1245 {"hidden", getorphantxs},
1246 {"rawtransactions", submitpackage},
1247 };
1248 for (const auto &c : commands) {
1249 t.appendCommand(c.name, &c);
1250 }
1251}
#define CHECK_NONFATAL(condition)
Identity function.
Definition check.h:83
Fee rate in satoshis per virtualbyte: Amount / vB the feerate is represented internally as FeeFrac.
Definition feerate.h:24
Amount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given size in bytes.
Definition feerate.cpp:23
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition feerate.h:55
A mutable version of CTransaction.
RPC command dispatcher.
Definition server.h:194
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition server.cpp:330
The basic transaction that is broadcasted on the network and contained in blocks.
TxId GetId() const
const std::vector< CTxIn > vin
An input of a transaction.
Definition transaction.h:59
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:222
std::set< txiter, CompareIteratorById > setEntries
Definition txmempool.h:320
bool GetLoadTried() const
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Definition txmempool.h:460
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition txmempool.h:316
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:527
uint64_t GetTotalFinalizedTxSigchecks() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:518
void getAllTxIds(std::vector< TxId > &vtxid) const
size_t DynamicMemoryUsage() const
const Options m_opts
Definition txmempool.h:356
bool exists(const TxId &txid) const
Definition txmempool.h:532
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition txmempool.h:572
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:588
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition txmempool.h:319
uint64_t GetFinalizedTxCount() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:507
void CalculateMemPoolAncestors(const CTxMemPoolEntryRef &entry, setEntries &setAncestors, bool unfinalizedOnly=false) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Calculate all in-mempool ancestors of entry.
Definition txmempool.cpp:61
uint64_t GetTotalFinalizedTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:512
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
unsigned long size() const
Definition txmempool.h:497
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition txmempool.h:502
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition validation.h:725
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(Chainstate ActiveChainstate)() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
virtual std::vector< TxOrphanage::PoolTx > GetOrphanTransactions()=0
Definition rcu.h:85
void push_back(UniValue val)
Definition univalue.cpp:96
size_t size() const
Definition univalue.h:92
const std::vector< UniValue > & getValues() const
void pushKVEnd(std::string key, UniValue val)
Definition univalue.cpp:108
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
Definition univalue.cpp:115
bool get_bool() const
std::string GetRejectReason() const
Definition validation.h:123
Result GetResult() const
Definition validation.h:122
std::string ToString() const
Definition validation.h:125
std::string ToString() const
Definition uint256.h:117
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition fs.h:30
std::string u8string() const
Definition fs.h:72
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
std::string EncodeHexTx(const CTransaction &tx)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:7
static RPCHelpMan getmempoolinfo()
Definition mempool.cpp:716
static RPCHelpMan sendrawtransaction()
Definition mempool.cpp:39
static std::vector< RPCResult > OrphanDescription()
Definition mempool.cpp:891
static RPCHelpMan importmempool()
Definition mempool.cpp:764
static UniValue OrphanToJSON(const TxOrphanage::PoolTx &orphan)
Definition mempool.cpp:911
void RegisterMempoolRPCCommands(CRPCTable &t)
Register mempool RPC commands.
Definition mempool.cpp:1232
static RPCHelpMan getrawmempool()
Definition mempool.cpp:452
static RPCHelpMan getmempoolentry()
Definition mempool.cpp:663
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition mempool.cpp:694
static std::vector< RPCResult > MempoolEntryDescription()
Definition mempool.cpp:333
static RPCHelpMan submitpackage()
Definition mempool.cpp:1009
static RPCHelpMan getorphantxs()
Definition mempool.cpp:927
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition mempool.cpp:408
static void entryToJSON(const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntryRef &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
Definition mempool.cpp:371
static RPCHelpMan testmempoolaccept()
Definition mempool.cpp:108
static RPCHelpMan getmempooldescendants()
Definition mempool.cpp:589
static RPCHelpMan getmempoolancestors()
Definition mempool.cpp:518
static RPCHelpMan savemempool()
Definition mempool.cpp:851
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
Definition moneystr.cpp:13
static path u8path(const std::string &utf8_str)
Definition fs.h:90
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, ImportMempoolOptions &&opts)
Import the file and attempt to add its contents to the mempool.
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
TransactionError
Definition types.h:17
fs::path MempoolPath(const ArgsManager &argsman)
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
Definition transaction.h:33
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition string.h:156
is a home for public enum and struct type definitions that are used by internally by node code,...
bool IsChildWithParentsTree(const Package &package)
Context-free check that a package IsChildWithParents() and none of the parents depend on each other (...
Definition packages.cpp:109
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition packages.h:15
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
@ PCKG_RESULT_UNSET
Initial value. The package has not yet been rejected.
@ PCKG_MEMPOOL_ERROR
Mempool logic error.
@ PCKG_TX
At least one tx is invalid.
int64_t GetVirtualTransactionSize(int64_t nSize, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
Compute the virtual transaction size (size, or more if sigChecks are too dense).
Definition policy.cpp:167
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
UniValue JSONRPCError(int code, const std::string &message)
Definition request.cpp:58
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
Definition protocol.h:38
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition protocol.h:46
@ RPC_CLIENT_IN_INITIAL_DOWNLOAD
Still downloading initial blocks.
Definition protocol.h:71
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
Definition protocol.h:50
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
Definition protocol.h:42
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition util.cpp:182
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition util.cpp:375
Amount AmountFromValue(const UniValue &value)
Definition util.cpp:69
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition util.cpp:199
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
Definition util.cpp:36
int ParseVerbosity(const UniValue &arg, int default_verbosity, bool allow_bool)
Parses verbosity from provided UniValue.
Definition util.cpp:126
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
Definition util.cpp:87
NodeContext & EnsureAnyNodeContext(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
PeerManager & EnsurePeerman(const NodeContext &node)
ChainstateManager & EnsureChainman(const NodeContext &node)
CTxMemPool & EnsureAnyMemPool(const std::any &context)
ArgsManager & EnsureAnyArgsman(const std::any &context)
static constexpr Amount zero() noexcept
Definition amount.h:36
static std::string getTicker()
Definition amount.h:163
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
Validation result for package mempool acceptance.
Definition validation.h:297
PackageValidationState m_state
Definition validation.h:298
std::map< TxId, MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition validation.h:306
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ NO
Required arg.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
Definition util.h:162
bool skip_type_check
Definition util.h:159
@ NUM_TIME
Special numeric to denote unix epoch time.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
A TxId is the identifier of a transaction.
Definition txid.h:14
Allows providing pool transaction information externally.
Definition txpool.h:95
NodeSeconds nTimeExpire
Definition txpool.h:99
CTransactionRef tx
Definition txpool.h:96
std::set< NodeId > announcers
Peers added with AddTx or AddAnnouncer.
Definition txpool.h:98
CFeeRate min_relay_feerate
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
NodeContext struct containing references to chain state and connection state.
Definition context.h:50
#define AssertLockNotHeld(cs)
Definition sync.h:163
#define LOCK(cs)
Definition sync.h:295
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition sync.h:343
#define AssertLockHeld(cs)
Definition sync.h:146
#define EXCLUSIVE_LOCKS_REQUIRED(...)
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition time.h:85
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
static constexpr auto ORPHAN_TX_EXPIRE_TIME
Expiration time for orphan transactions.
Definition txorphanage.h:12
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Validate (and maybe submit) a package to the mempool.