Bitcoin Core  25.99.0
P2P Digital Currency
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 
6 #include <rpc/blockchain.h>
7 
9 
10 #include <chainparams.h>
11 #include <core_io.h>
12 #include <kernel/mempool_entry.h>
14 #include <policy/rbf.h>
15 #include <policy/settings.h>
16 #include <primitives/transaction.h>
17 #include <rpc/server.h>
18 #include <rpc/server_util.h>
19 #include <rpc/util.h>
20 #include <script/standard.h>
21 #include <txmempool.h>
22 #include <univalue.h>
23 #include <util/fs.h>
24 #include <util/moneystr.h>
25 #include <util/time.h>
26 
27 #include <utility>
28 
30 
32 using node::MempoolPath;
33 using node::NodeContext;
34 
36 {
37  return RPCHelpMan{"sendrawtransaction",
38  "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n"
39  "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
40  "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
41  "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
42  "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n"
43  "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
44  {
45  {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
47  "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
48  "/kvB.\nSet to 0 to accept any fee rate."},
49  {"maxburnamount", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(0)},
50  "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"
51  "If burning funds through unspendable outputs is desired, increase this value.\n"
52  "This check is based on heuristics and does not guarantee spendability of outputs.\n"},
53  },
54  RPCResult{
55  RPCResult::Type::STR_HEX, "", "The transaction hash in hex"
56  },
58  "\nCreate a transaction\n"
59  + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
60  "Sign the transaction, and get back the hex\n"
61  + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
62  "\nSend the transaction (signed hex)\n"
63  + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
64  "\nAs a JSON-RPC call\n"
65  + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
66  },
67  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
68  {
69  const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
70 
72  if (!DecodeHexTx(mtx, request.params[0].get_str())) {
73  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
74  }
75 
76  for (const auto& out : mtx.vout) {
77  if((out.scriptPubKey.IsUnspendable() || !out.scriptPubKey.HasValidOps()) && out.nValue > max_burn_amount) {
79  }
80  }
81 
82  CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
83 
84  const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
86  CFeeRate(AmountFromValue(request.params[1]));
87 
88  int64_t virtual_size = GetVirtualTransactionSize(*tx);
89  CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
90 
91  std::string err_string;
93  NodeContext& node = EnsureAnyNodeContext(request.context);
94  const TransactionError err = BroadcastTransaction(node, tx, err_string, max_raw_tx_fee, /*relay=*/true, /*wait_callback=*/true);
95  if (TransactionError::OK != err) {
96  throw JSONRPCTransactionError(err, err_string);
97  }
98 
99  return tx->GetHash().GetHex();
100  },
101  };
102 }
103 
105 {
106  return RPCHelpMan{"testmempoolaccept",
107  "\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n"
108  "\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"
109  "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n"
110  "\nThe maximum number of transactions allowed is " + ToString(MAX_PACKAGE_COUNT) + ".\n"
111  "\nThis checks if transactions violate the consensus or policy rules.\n"
112  "\nSee sendrawtransaction call.\n",
113  {
114  {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of hex strings of raw transactions.",
115  {
117  },
118  },
120  "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kvB\n"},
121  },
122  RPCResult{
123  RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n"
124  "Returns results for each transaction in the same order they were passed in.\n"
125  "Transactions that cannot be fully validated due to failures in other transactions will not contain an 'allowed' result.\n",
126  {
127  {RPCResult::Type::OBJ, "", "",
128  {
129  {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
130  {RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
131  {RPCResult::Type::STR, "package-error", /*optional=*/true, "Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
132  {RPCResult::Type::BOOL, "allowed", /*optional=*/true, "Whether this tx would be accepted to the mempool and pass client-specified maxfeerate. "
133  "If not present, the tx was not fully validated due to a failure in another tx in the list."},
134  {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)"},
135  {RPCResult::Type::OBJ, "fees", /*optional=*/true, "Transaction fees (only present if 'allowed' is true)",
136  {
137  {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
138  {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."},
139  {RPCResult::Type::ARR, "effective-includes", /*optional=*/false, "transactions whose fees and vsizes are included in effective-feerate.",
140  {RPCResult{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
141  }},
142  }},
143  {RPCResult::Type::STR, "reject-reason", /*optional=*/true, "Rejection string (only present when 'allowed' is false)"},
144  }},
145  }
146  },
147  RPCExamples{
148  "\nCreate a transaction\n"
149  + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
150  "Sign the transaction, and get back the hex\n"
151  + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
152  "\nTest acceptance of the transaction (signed hex)\n"
153  + HelpExampleCli("testmempoolaccept", R"('["signedhex"]')") +
154  "\nAs a JSON-RPC call\n"
155  + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
156  },
157  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
158  {
159  const UniValue raw_transactions = request.params[0].get_array();
160  if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
162  "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
163  }
164 
165  const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
167  CFeeRate(AmountFromValue(request.params[1]));
168 
169  std::vector<CTransactionRef> txns;
170  txns.reserve(raw_transactions.size());
171  for (const auto& rawtx : raw_transactions.getValues()) {
173  if (!DecodeHexTx(mtx, rawtx.get_str())) {
175  "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
176  }
177  txns.emplace_back(MakeTransactionRef(std::move(mtx)));
178  }
179 
180  NodeContext& node = EnsureAnyNodeContext(request.context);
181  CTxMemPool& mempool = EnsureMemPool(node);
183  Chainstate& chainstate = chainman.ActiveChainstate();
184  const PackageMempoolAcceptResult package_result = [&] {
185  LOCK(::cs_main);
186  if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/true);
187  return PackageMempoolAcceptResult(txns[0]->GetWitnessHash(),
188  chainman.ProcessTransaction(txns[0], /*test_accept=*/true));
189  }();
190 
191  UniValue rpc_result(UniValue::VARR);
192  // We will check transaction fees while we iterate through txns in order. If any transaction fee
193  // exceeds maxfeerate, we will leave the rest of the validation results blank, because it
194  // doesn't make sense to return a validation result for a transaction if its ancestor(s) would
195  // not be submitted.
196  bool exit_early{false};
197  for (const auto& tx : txns) {
198  UniValue result_inner(UniValue::VOBJ);
199  result_inner.pushKV("txid", tx->GetHash().GetHex());
200  result_inner.pushKV("wtxid", tx->GetWitnessHash().GetHex());
201  if (package_result.m_state.GetResult() == PackageValidationResult::PCKG_POLICY) {
202  result_inner.pushKV("package-error", package_result.m_state.GetRejectReason());
203  }
204  auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
205  if (exit_early || it == package_result.m_tx_results.end()) {
206  // Validation unfinished. Just return the txid and wtxid.
207  rpc_result.push_back(result_inner);
208  continue;
209  }
210  const auto& tx_result = it->second;
211  // Package testmempoolaccept doesn't allow transactions to already be in the mempool.
213  if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
214  const CAmount fee = tx_result.m_base_fees.value();
215  // Check that fee does not exceed maximum fee
216  const int64_t virtual_size = tx_result.m_vsize.value();
217  const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
218  if (max_raw_tx_fee && fee > max_raw_tx_fee) {
219  result_inner.pushKV("allowed", false);
220  result_inner.pushKV("reject-reason", "max-fee-exceeded");
221  exit_early = true;
222  } else {
223  // Only return the fee and vsize if the transaction would pass ATMP.
224  // These can be used to calculate the feerate.
225  result_inner.pushKV("allowed", true);
226  result_inner.pushKV("vsize", virtual_size);
227  UniValue fees(UniValue::VOBJ);
228  fees.pushKV("base", ValueFromAmount(fee));
229  fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
230  UniValue effective_includes_res(UniValue::VARR);
231  for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
232  effective_includes_res.push_back(wtxid.ToString());
233  }
234  fees.pushKV("effective-includes", effective_includes_res);
235  result_inner.pushKV("fees", fees);
236  }
237  } else {
238  result_inner.pushKV("allowed", false);
239  const TxValidationState state = tx_result.m_state;
241  result_inner.pushKV("reject-reason", "missing-inputs");
242  } else {
243  result_inner.pushKV("reject-reason", state.GetRejectReason());
244  }
245  }
246  rpc_result.push_back(result_inner);
247  }
248  return rpc_result;
249  },
250  };
251 }
252 
253 static std::vector<RPCResult> MempoolEntryDescription()
254 {
255  return {
256  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."},
257  RPCResult{RPCResult::Type::NUM, "weight", "transaction weight as defined in BIP 141."},
258  RPCResult{RPCResult::Type::NUM_TIME, "time", "local time transaction entered pool in seconds since 1 Jan 1970 GMT"},
259  RPCResult{RPCResult::Type::NUM, "height", "block height when transaction entered pool"},
260  RPCResult{RPCResult::Type::NUM, "descendantcount", "number of in-mempool descendant transactions (including this one)"},
261  RPCResult{RPCResult::Type::NUM, "descendantsize", "virtual transaction size of in-mempool descendants (including this one)"},
262  RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
263  RPCResult{RPCResult::Type::NUM, "ancestorsize", "virtual transaction size of in-mempool ancestors (including this one)"},
264  RPCResult{RPCResult::Type::STR_HEX, "wtxid", "hash of serialized transaction, including witness data"},
265  RPCResult{RPCResult::Type::OBJ, "fees", "",
266  {
267  RPCResult{RPCResult::Type::STR_AMOUNT, "base", "transaction fee, denominated in " + CURRENCY_UNIT},
268  RPCResult{RPCResult::Type::STR_AMOUNT, "modified", "transaction fee with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
269  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},
270  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},
271  }},
272  RPCResult{RPCResult::Type::ARR, "depends", "unconfirmed transactions used as inputs for this transaction",
273  {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "parent transaction id"}}},
274  RPCResult{RPCResult::Type::ARR, "spentby", "unconfirmed transactions spending outputs from this transaction",
275  {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "child transaction id"}}},
276  RPCResult{RPCResult::Type::BOOL, "bip125-replaceable", "Whether this transaction signals BIP125 replaceability or has an unconfirmed ancestor signaling BIP125 replaceability.\n"},
277  RPCResult{RPCResult::Type::BOOL, "unbroadcast", "Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)"},
278  };
279 }
280 
281 static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
282 {
283  AssertLockHeld(pool.cs);
284 
285  info.pushKV("vsize", (int)e.GetTxSize());
286  info.pushKV("weight", (int)e.GetTxWeight());
287  info.pushKV("time", count_seconds(e.GetTime()));
288  info.pushKV("height", (int)e.GetHeight());
289  info.pushKV("descendantcount", e.GetCountWithDescendants());
290  info.pushKV("descendantsize", e.GetSizeWithDescendants());
291  info.pushKV("ancestorcount", e.GetCountWithAncestors());
292  info.pushKV("ancestorsize", e.GetSizeWithAncestors());
293  info.pushKV("wtxid", pool.vTxHashes[e.vTxHashesIdx].first.ToString());
294 
295  UniValue fees(UniValue::VOBJ);
296  fees.pushKV("base", ValueFromAmount(e.GetFee()));
297  fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee()));
298  fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors()));
299  fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants()));
300  info.pushKV("fees", fees);
301 
302  const CTransaction& tx = e.GetTx();
303  std::set<std::string> setDepends;
304  for (const CTxIn& txin : tx.vin)
305  {
306  if (pool.exists(GenTxid::Txid(txin.prevout.hash)))
307  setDepends.insert(txin.prevout.hash.ToString());
308  }
309 
310  UniValue depends(UniValue::VARR);
311  for (const std::string& dep : setDepends)
312  {
313  depends.push_back(dep);
314  }
315 
316  info.pushKV("depends", depends);
317 
318  UniValue spent(UniValue::VARR);
319  const CTxMemPool::txiter& it = pool.mapTx.find(tx.GetHash());
320  const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
321  for (const CTxMemPoolEntry& child : children) {
322  spent.push_back(child.GetTx().GetHash().ToString());
323  }
324 
325  info.pushKV("spentby", spent);
326 
327  // Add opt-in RBF status
328  bool rbfStatus = false;
329  RBFTransactionState rbfState = IsRBFOptIn(tx, pool);
330  if (rbfState == RBFTransactionState::UNKNOWN) {
331  throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not in mempool");
332  } else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125) {
333  rbfStatus = true;
334  }
335 
336  info.pushKV("bip125-replaceable", rbfStatus);
337  info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetHash()));
338 }
339 
340 UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
341 {
342  if (verbose) {
343  if (include_mempool_sequence) {
344  throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbose results cannot contain mempool sequence values.");
345  }
346  LOCK(pool.cs);
348  for (const CTxMemPoolEntry& e : pool.mapTx) {
349  const uint256& hash = e.GetTx().GetHash();
350  UniValue info(UniValue::VOBJ);
351  entryToJSON(pool, info, e);
352  // Mempool has unique entries so there is no advantage in using
353  // UniValue::pushKV, which checks if the key already exists in O(N).
354  // UniValue::__pushKV is used instead which currently is O(1).
355  o.__pushKV(hash.ToString(), info);
356  }
357  return o;
358  } else {
359  uint64_t mempool_sequence;
360  std::vector<uint256> vtxid;
361  {
362  LOCK(pool.cs);
363  pool.queryHashes(vtxid);
364  mempool_sequence = pool.GetSequence();
365  }
367  for (const uint256& hash : vtxid)
368  a.push_back(hash.ToString());
369 
370  if (!include_mempool_sequence) {
371  return a;
372  } else {
374  o.pushKV("txids", a);
375  o.pushKV("mempool_sequence", mempool_sequence);
376  return o;
377  }
378  }
379 }
380 
382 {
383  return RPCHelpMan{"getrawmempool",
384  "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
385  "\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
386  {
387  {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
388  {"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false}, "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
389  },
390  {
391  RPCResult{"for verbose = false",
392  RPCResult::Type::ARR, "", "",
393  {
394  {RPCResult::Type::STR_HEX, "", "The transaction id"},
395  }},
396  RPCResult{"for verbose = true",
397  RPCResult::Type::OBJ_DYN, "", "",
398  {
399  {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
400  }},
401  RPCResult{"for verbose = false and mempool_sequence = true",
402  RPCResult::Type::OBJ, "", "",
403  {
404  {RPCResult::Type::ARR, "txids", "",
405  {
406  {RPCResult::Type::STR_HEX, "", "The transaction id"},
407  }},
408  {RPCResult::Type::NUM, "mempool_sequence", "The mempool sequence value."},
409  }},
410  },
411  RPCExamples{
412  HelpExampleCli("getrawmempool", "true")
413  + HelpExampleRpc("getrawmempool", "true")
414  },
415  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
416 {
417  bool fVerbose = false;
418  if (!request.params[0].isNull())
419  fVerbose = request.params[0].get_bool();
420 
421  bool include_mempool_sequence = false;
422  if (!request.params[1].isNull()) {
423  include_mempool_sequence = request.params[1].get_bool();
424  }
425 
426  return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
427 },
428  };
429 }
430 
432 {
433  return RPCHelpMan{"getmempoolancestors",
434  "\nIf txid is in the mempool, returns all in-mempool ancestors.\n",
435  {
436  {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
437  {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
438  },
439  {
440  RPCResult{"for verbose = false",
441  RPCResult::Type::ARR, "", "",
442  {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}},
443  RPCResult{"for verbose = true",
444  RPCResult::Type::OBJ_DYN, "", "",
445  {
446  {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
447  }},
448  },
449  RPCExamples{
450  HelpExampleCli("getmempoolancestors", "\"mytxid\"")
451  + HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
452  },
453  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
454 {
455  bool fVerbose = false;
456  if (!request.params[1].isNull())
457  fVerbose = request.params[1].get_bool();
458 
459  uint256 hash = ParseHashV(request.params[0], "parameter 1");
460 
461  const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
462  LOCK(mempool.cs);
463 
464  CTxMemPool::txiter it = mempool.mapTx.find(hash);
465  if (it == mempool.mapTx.end()) {
466  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
467  }
468 
469  auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
470 
471  if (!fVerbose) {
473  for (CTxMemPool::txiter ancestorIt : ancestors) {
474  o.push_back(ancestorIt->GetTx().GetHash().ToString());
475  }
476  return o;
477  } else {
479  for (CTxMemPool::txiter ancestorIt : ancestors) {
480  const CTxMemPoolEntry &e = *ancestorIt;
481  const uint256& _hash = e.GetTx().GetHash();
482  UniValue info(UniValue::VOBJ);
483  entryToJSON(mempool, info, e);
484  o.pushKV(_hash.ToString(), info);
485  }
486  return o;
487  }
488 },
489  };
490 }
491 
493 {
494  return RPCHelpMan{"getmempooldescendants",
495  "\nIf txid is in the mempool, returns all in-mempool descendants.\n",
496  {
497  {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
498  {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
499  },
500  {
501  RPCResult{"for verbose = false",
502  RPCResult::Type::ARR, "", "",
503  {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool descendant transaction"}}},
504  RPCResult{"for verbose = true",
505  RPCResult::Type::OBJ_DYN, "", "",
506  {
507  {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
508  }},
509  },
510  RPCExamples{
511  HelpExampleCli("getmempooldescendants", "\"mytxid\"")
512  + HelpExampleRpc("getmempooldescendants", "\"mytxid\"")
513  },
514  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
515 {
516  bool fVerbose = false;
517  if (!request.params[1].isNull())
518  fVerbose = request.params[1].get_bool();
519 
520  uint256 hash = ParseHashV(request.params[0], "parameter 1");
521 
522  const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
523  LOCK(mempool.cs);
524 
525  CTxMemPool::txiter it = mempool.mapTx.find(hash);
526  if (it == mempool.mapTx.end()) {
527  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
528  }
529 
530  CTxMemPool::setEntries setDescendants;
531  mempool.CalculateDescendants(it, setDescendants);
532  // CTxMemPool::CalculateDescendants will include the given tx
533  setDescendants.erase(it);
534 
535  if (!fVerbose) {
537  for (CTxMemPool::txiter descendantIt : setDescendants) {
538  o.push_back(descendantIt->GetTx().GetHash().ToString());
539  }
540 
541  return o;
542  } else {
544  for (CTxMemPool::txiter descendantIt : setDescendants) {
545  const CTxMemPoolEntry &e = *descendantIt;
546  const uint256& _hash = e.GetTx().GetHash();
547  UniValue info(UniValue::VOBJ);
548  entryToJSON(mempool, info, e);
549  o.pushKV(_hash.ToString(), info);
550  }
551  return o;
552  }
553 },
554  };
555 }
556 
558 {
559  return RPCHelpMan{"getmempoolentry",
560  "\nReturns mempool data for given transaction\n",
561  {
562  {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
563  },
564  RPCResult{
566  RPCExamples{
567  HelpExampleCli("getmempoolentry", "\"mytxid\"")
568  + HelpExampleRpc("getmempoolentry", "\"mytxid\"")
569  },
570  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
571 {
572  uint256 hash = ParseHashV(request.params[0], "parameter 1");
573 
574  const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
575  LOCK(mempool.cs);
576 
577  CTxMemPool::txiter it = mempool.mapTx.find(hash);
578  if (it == mempool.mapTx.end()) {
579  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
580  }
581 
582  const CTxMemPoolEntry &e = *it;
583  UniValue info(UniValue::VOBJ);
584  entryToJSON(mempool, info, e);
585  return info;
586 },
587  };
588 }
589 
591 {
592  return RPCHelpMan{"gettxspendingprevout",
593  "Scans the mempool to find transactions spending any of the given outputs",
594  {
595  {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",
596  {
598  {
599  {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
600  {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
601  },
602  },
603  },
604  },
605  },
606  RPCResult{
607  RPCResult::Type::ARR, "", "",
608  {
609  {RPCResult::Type::OBJ, "", "",
610  {
611  {RPCResult::Type::STR_HEX, "txid", "the transaction id of the checked output"},
612  {RPCResult::Type::NUM, "vout", "the vout value of the checked output"},
613  {RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},
614  }},
615  }
616  },
617  RPCExamples{
618  HelpExampleCli("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
619  + HelpExampleRpc("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
620  },
621  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
622  {
623  const UniValue& output_params = request.params[0].get_array();
624  if (output_params.empty()) {
625  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, outputs are missing");
626  }
627 
628  std::vector<COutPoint> prevouts;
629  prevouts.reserve(output_params.size());
630 
631  for (unsigned int idx = 0; idx < output_params.size(); idx++) {
632  const UniValue& o = output_params[idx].get_obj();
633 
634  RPCTypeCheckObj(o,
635  {
636  {"txid", UniValueType(UniValue::VSTR)},
637  {"vout", UniValueType(UniValue::VNUM)},
638  }, /*fAllowNull=*/false, /*fStrict=*/true);
639 
640  const uint256 txid(ParseHashO(o, "txid"));
641  const int nOutput{o.find_value("vout").getInt<int>()};
642  if (nOutput < 0) {
643  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
644  }
645 
646  prevouts.emplace_back(txid, nOutput);
647  }
648 
649  const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
650  LOCK(mempool.cs);
651 
652  UniValue result{UniValue::VARR};
653 
654  for (const COutPoint& prevout : prevouts) {
656  o.pushKV("txid", prevout.hash.ToString());
657  o.pushKV("vout", (uint64_t)prevout.n);
658 
659  const CTransaction* spendingTx = mempool.GetConflictTx(prevout);
660  if (spendingTx != nullptr) {
661  o.pushKV("spendingtxid", spendingTx->GetHash().ToString());
662  }
663 
664  result.push_back(o);
665  }
666 
667  return result;
668  },
669  };
670 }
671 
673 {
674  // Make sure this call is atomic in the pool.
675  LOCK(pool.cs);
677  ret.pushKV("loaded", pool.GetLoadTried());
678  ret.pushKV("size", (int64_t)pool.size());
679  ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize());
680  ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage());
681  ret.pushKV("total_fee", ValueFromAmount(pool.GetTotalFee()));
682  ret.pushKV("maxmempool", pool.m_max_size_bytes);
683  ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(), pool.m_min_relay_feerate).GetFeePerK()));
684  ret.pushKV("minrelaytxfee", ValueFromAmount(pool.m_min_relay_feerate.GetFeePerK()));
685  ret.pushKV("incrementalrelayfee", ValueFromAmount(pool.m_incremental_relay_feerate.GetFeePerK()));
686  ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()});
687  ret.pushKV("fullrbf", pool.m_full_rbf);
688  return ret;
689 }
690 
692 {
693  return RPCHelpMan{"getmempoolinfo",
694  "Returns details on the active state of the TX memory pool.",
695  {},
696  RPCResult{
697  RPCResult::Type::OBJ, "", "",
698  {
699  {RPCResult::Type::BOOL, "loaded", "True if the mempool is fully loaded"},
700  {RPCResult::Type::NUM, "size", "Current tx count"},
701  {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"},
702  {RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
703  {RPCResult::Type::STR_AMOUNT, "total_fee", "Total fees for the mempool in " + CURRENCY_UNIT + ", ignoring modified fees through prioritisetransaction"},
704  {RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
705  {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"},
706  {RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
707  {RPCResult::Type::NUM, "incrementalrelayfee", "minimum fee rate increment for mempool limiting or replacement in " + CURRENCY_UNIT + "/kvB"},
708  {RPCResult::Type::NUM, "unbroadcastcount", "Current number of transactions that haven't passed initial broadcast yet"},
709  {RPCResult::Type::BOOL, "fullrbf", "True if the mempool accepts RBF without replaceability signaling inspection"},
710  }},
711  RPCExamples{
712  HelpExampleCli("getmempoolinfo", "")
713  + HelpExampleRpc("getmempoolinfo", "")
714  },
715  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
716 {
717  return MempoolInfoToJSON(EnsureAnyMemPool(request.context));
718 },
719  };
720 }
721 
723 {
724  return RPCHelpMan{"savemempool",
725  "\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
726  {},
727  RPCResult{
728  RPCResult::Type::OBJ, "", "",
729  {
730  {RPCResult::Type::STR, "filename", "the directory and file where the mempool was saved"},
731  }},
732  RPCExamples{
733  HelpExampleCli("savemempool", "")
734  + HelpExampleRpc("savemempool", "")
735  },
736  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
737 {
738  const ArgsManager& args{EnsureAnyArgsman(request.context)};
739  const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
740 
741  if (!mempool.GetLoadTried()) {
742  throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
743  }
744 
745  const fs::path& dump_path = MempoolPath(args);
746 
747  if (!DumpMempool(mempool, dump_path)) {
748  throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
749  }
750 
752  ret.pushKV("filename", dump_path.u8string());
753 
754  return ret;
755 },
756  };
757 }
758 
760 {
761  return RPCHelpMan{"submitpackage",
762  "Submit a package of raw transactions (serialized, hex-encoded) to local node (-regtest only).\n"
763  "The package will be validated according to consensus and mempool policy rules. If all transactions pass, they will be accepted to mempool.\n"
764  "This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n"
765  "Warning: until package relay is in use, successful submission does not mean the transaction will propagate to other nodes on the network.\n"
766  "Currently, each transaction is broadcasted individually after submission, which means they must meet other nodes' feerate requirements alone.\n"
767  ,
768  {
769  {"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.",
770  {
772  },
773  },
774  },
775  RPCResult{
776  RPCResult::Type::OBJ, "", "",
777  {
778  {RPCResult::Type::OBJ_DYN, "tx-results", "transaction results keyed by wtxid",
779  {
780  {RPCResult::Type::OBJ, "wtxid", "transaction wtxid", {
781  {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
782  {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."},
783  {RPCResult::Type::NUM, "vsize", "Virtual transaction size as defined in BIP 141."},
784  {RPCResult::Type::OBJ, "fees", "Transaction fees", {
785  {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
786  {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."},
787  {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.",
788  {{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
789  }},
790  }},
791  }}
792  }},
793  {RPCResult::Type::ARR, "replaced-transactions", /*optional=*/true, "List of txids of replaced transactions",
794  {
795  {RPCResult::Type::STR_HEX, "", "The transaction id"},
796  }},
797  },
798  },
799  RPCExamples{
800  HelpExampleCli("testmempoolaccept", "[rawtx1, rawtx2]") +
801  HelpExampleCli("submitpackage", "[rawtx1, rawtx2]")
802  },
803  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
804  {
805  if (!Params().IsMockableChain()) {
806  throw std::runtime_error("submitpackage is for regression testing (-regtest mode) only");
807  }
808  const UniValue raw_transactions = request.params[0].get_array();
809  if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
811  "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
812  }
813 
814  std::vector<CTransactionRef> txns;
815  txns.reserve(raw_transactions.size());
816  for (const auto& rawtx : raw_transactions.getValues()) {
818  if (!DecodeHexTx(mtx, rawtx.get_str())) {
820  "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
821  }
822  txns.emplace_back(MakeTransactionRef(std::move(mtx)));
823  }
824 
825  NodeContext& node = EnsureAnyNodeContext(request.context);
826  CTxMemPool& mempool = EnsureMemPool(node);
827  Chainstate& chainstate = EnsureChainman(node).ActiveChainstate();
828  const auto package_result = WITH_LOCK(::cs_main, return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/ false));
829 
830  // First catch any errors.
831  switch(package_result.m_state.GetResult()) {
834  {
836  package_result.m_state.GetRejectReason());
837  }
839  {
841  package_result.m_state.GetRejectReason());
842  }
844  {
845  for (const auto& tx : txns) {
846  auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
847  if (it != package_result.m_tx_results.end() && it->second.m_state.IsInvalid()) {
849  strprintf("%s failed: %s", tx->GetHash().ToString(), it->second.m_state.GetRejectReason()));
850  }
851  }
852  // If a PCKG_TX error was returned, there must have been an invalid transaction.
854  }
855  }
856  size_t num_broadcast{0};
857  for (const auto& tx : txns) {
858  std::string err_string;
859  const auto err = BroadcastTransaction(node, tx, err_string, /*max_tx_fee=*/0, /*relay=*/true, /*wait_callback=*/true);
860  if (err != TransactionError::OK) {
861  throw JSONRPCTransactionError(err,
862  strprintf("transaction broadcast failed: %s (all transactions were submitted, %d transactions were broadcast successfully)",
863  err_string, num_broadcast));
864  }
865  num_broadcast++;
866  }
867  UniValue rpc_result{UniValue::VOBJ};
868  UniValue tx_result_map{UniValue::VOBJ};
869  std::set<uint256> replaced_txids;
870  for (const auto& tx : txns) {
871  auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
872  CHECK_NONFATAL(it != package_result.m_tx_results.end());
873  UniValue result_inner{UniValue::VOBJ};
874  result_inner.pushKV("txid", tx->GetHash().GetHex());
875  const auto& tx_result = it->second;
876  if (it->second.m_result_type == MempoolAcceptResult::ResultType::DIFFERENT_WITNESS) {
877  result_inner.pushKV("other-wtxid", it->second.m_other_wtxid.value().GetHex());
878  }
879  if (it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
880  it->second.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY) {
881  result_inner.pushKV("vsize", int64_t{it->second.m_vsize.value()});
882  UniValue fees(UniValue::VOBJ);
883  fees.pushKV("base", ValueFromAmount(it->second.m_base_fees.value()));
884  if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
885  // Effective feerate is not provided for MEMPOOL_ENTRY transactions even
886  // though modified fees is known, because it is unknown whether package
887  // feerate was used when it was originally submitted.
888  fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
889  UniValue effective_includes_res(UniValue::VARR);
890  for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
891  effective_includes_res.push_back(wtxid.ToString());
892  }
893  fees.pushKV("effective-includes", effective_includes_res);
894  }
895  result_inner.pushKV("fees", fees);
896  if (it->second.m_replaced_transactions.has_value()) {
897  for (const auto& ptx : it->second.m_replaced_transactions.value()) {
898  replaced_txids.insert(ptx->GetHash());
899  }
900  }
901  }
902  tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), result_inner);
903  }
904  rpc_result.pushKV("tx-results", tx_result_map);
905  UniValue replaced_list(UniValue::VARR);
906  for (const uint256& hash : replaced_txids) replaced_list.push_back(hash.ToString());
907  rpc_result.pushKV("replaced-transactions", replaced_list);
908  return rpc_result;
909  },
910  };
911 }
912 
914 {
915  static const CRPCCommand commands[]{
916  {"rawtransactions", &sendrawtransaction},
917  {"rawtransactions", &testmempoolaccept},
918  {"blockchain", &getmempoolancestors},
919  {"blockchain", &getmempooldescendants},
920  {"blockchain", &getmempoolentry},
921  {"blockchain", &gettxspendingprevout},
922  {"blockchain", &getmempoolinfo},
923  {"blockchain", &getrawmempool},
924  {"blockchain", &savemempool},
925  {"hidden", &submitpackage},
926  };
927  for (const auto& c : commands) {
928  t.appendCommand(c.name, &c);
929  }
930 }
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
int ret
static CAmount AmountFromValue(const UniValue &value)
Definition: bitcoin-tx.cpp:553
const CChainParams & Params()
Return the currently selected parameters.
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:46
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
Definition: check.h:90
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:110
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:23
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:65
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
uint256 hash
Definition: transaction.h:38
RPC command dispatcher.
Definition: server.h:135
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:295
const uint256 & GetHash() const
Definition: transaction.h:337
const std::vector< CTxIn > vin
Definition: transaction.h:305
An input of a transaction.
Definition: transaction.h:75
COutPoint prevout
Definition: transaction.h:77
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: mempool_entry.h:66
const CTransaction & GetTx() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
Definition: mempool_entry.h:71
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:316
setEntries AssumeCalculateMemPoolAncestors(std::string_view calling_fn_name, const CTxMemPoolEntry &entry, const Limits &limits, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Same as CalculateMemPoolAncestors, but always returns a (non-optional) setEntries.
Definition: txmempool.cpp:260
bool GetLoadTried() const
Definition: txmempool.cpp:1152
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:405
CFeeRate GetMinFee(size_t sizelimit) const
Definition: txmempool.cpp:1043
const bool m_full_rbf
Definition: txmempool.h:462
const int64_t m_max_size_bytes
Definition: txmempool.h:454
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:975
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:411
std::set< uint256 > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:712
void queryHashes(std::vector< uint256 > &vtxid) const
Definition: txmempool.cpp:807
const CFeeRate m_min_relay_feerate
Definition: txmempool.h:457
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:730
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:408
const CFeeRate m_incremental_relay_feerate
Definition: txmempool.h:456
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:899
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:529
unsigned long size() const
Definition: txmempool.h:661
CAmount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:673
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:667
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:459
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:870
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.
static GenTxid Txid(const uint256 &hash)
Definition: transaction.h:432
void push_back(UniValue val)
Definition: univalue.cpp:104
const UniValue & find_value(std::string_view key) const
Definition: univalue.cpp:233
@ VOBJ
Definition: univalue.h:21
@ VSTR
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
@ VNUM
Definition: univalue.h:21
bool isNull() const
Definition: univalue.h:76
const UniValue & get_obj() const
void __pushKV(std::string key, UniValue val)
Definition: univalue.cpp:118
size_t size() const
Definition: univalue.h:68
const std::vector< UniValue > & getValues() const
bool empty() const
Definition: univalue.h:66
Int getInt() const
Definition: univalue.h:137
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
bool get_bool() const
std::string GetRejectReason() const
Definition: validation.h:125
Result GetResult() const
Definition: validation.h:124
std::string ToString() const
Definition: uint256.cpp:55
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
std::string u8string() const
Definition: fs.h:55
256-bit opaque blob.
Definition: uint256.h:105
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
UniValue ValueFromAmount(const CAmount amount)
Definition: core_write.cpp:26
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
Definition: core_read.cpp:195
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
TransactionError
Definition: error.h:22
const std::string CURRENCY_UNIT
Definition: feerate.h:17
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:16
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
Definition: init.h:25
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
Definition: transaction.cpp:33
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:27
ArgsManager args
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition: packages.h:17
@ 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.
RBFTransactionState IsRBFOptIn(const CTransaction &tx, const CTxMemPool &pool)
Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This inv...
Definition: rbf.cpp:21
RBFTransactionState
The rbf state of unconfirmed transactions.
Definition: rbf.h:27
@ UNKNOWN
Unconfirmed tx that does not signal rbf and is not in the mempool.
@ REPLACEABLE_BIP125
Either this tx or a mempool ancestor signals rbf.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:295
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:422
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
static RPCHelpMan getmempoolinfo()
Definition: mempool.cpp:691
static RPCHelpMan sendrawtransaction()
Definition: mempool.cpp:35
static void entryToJSON(const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
Definition: mempool.cpp:281
static std::vector< RPCResult > MempoolEntryDescription()
Definition: mempool.cpp:253
void RegisterMempoolRPCCommands(CRPCTable &t)
Definition: mempool.cpp:913
static RPCHelpMan getrawmempool()
Definition: mempool.cpp:381
static RPCHelpMan getmempoolentry()
Definition: mempool.cpp:557
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: mempool.cpp:672
static RPCHelpMan gettxspendingprevout()
Definition: mempool.cpp:590
static RPCHelpMan submitpackage()
Definition: mempool.cpp:759
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition: mempool.cpp:340
static RPCHelpMan testmempoolaccept()
Definition: mempool.cpp:104
static RPCHelpMan getmempooldescendants()
Definition: mempool.cpp:492
static RPCHelpMan getmempoolancestors()
Definition: mempool.cpp:431
static RPCHelpMan savemempool()
Definition: mempool.cpp:722
@ RPC_MISC_ERROR
General application defined errors.
Definition: protocol.h:39
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition: protocol.h:43
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
Definition: protocol.h:45
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
Definition: protocol.h:41
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:139
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition: util.cpp:342
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:157
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: util.cpp:82
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:73
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
Definition: util.cpp:34
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition: server_util.cpp:65
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: server_util.cpp:38
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:21
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: server_util.cpp:30
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: server_util.cpp:70
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:109
A mutable version of CTransaction.
Definition: transaction.h:380
std::vector< CTxOut > vout
Definition: transaction.h:382
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
Validation result for package mempool acceptance.
Definition: validation.h:211
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
Definition: validation.h:219
const PackageValidationState m_state
Definition: validation.h:212
@ 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)
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ NO
Required arg.
@ 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.
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
Definition: util.h:58
static constexpr MemPoolLimits NoLimits()
NodeContext struct containing references to chain state and connection state.
Definition: context.h:45
#define AssertLockNotHeld(cs)
Definition: sync.h:148
#define LOCK(cs)
Definition: sync.h:258
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:302
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition: time.h:56
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Validate (and maybe submit) a package to the mempool.
AssertLockHeld(pool.cs)