34 "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n" 35 "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n" 36 "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n" 37 "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n" 38 "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n" 39 "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
43 "Reject transactions whose fee rate is higher than the specified value, expressed in " +
CURRENCY_UNIT +
44 "/kvB.\nSet to 0 to accept any fee rate.\n"},
50 "\nCreate a transaction\n" 51 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
52 "Sign the transaction, and get back the hex\n" 54 "\nSend the transaction (signed hex)\n" 56 "\nAs a JSON-RPC call\n" 67 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
72 const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
77 CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
79 std::string err_string;
87 return tx->GetHash().GetHex();
95 "\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n" 96 "\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" 97 "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n" 99 "\nThis checks if transactions violate the consensus or policy rules.\n" 100 "\nSee sendrawtransaction call.\n",
108 "Reject transactions whose fee rate is higher than the specified value, expressed in " +
CURRENCY_UNIT +
"/kvB\n"},
111 RPCResult::Type::ARR,
"",
"The result of the mempool acceptance test for each raw transaction in the input array.\n" 112 "Returns results for each transaction in the same order they were passed in.\n" 113 "Transactions that cannot be fully validated due to failures in other transactions will not contain an 'allowed' result.\n",
119 {
RPCResult::Type::STR,
"package-error",
true,
"Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
120 {
RPCResult::Type::BOOL,
"allowed",
true,
"Whether this tx would be accepted to the mempool and pass client-specified maxfeerate. " 121 "If not present, the tx was not fully validated due to a failure in another tx in the list."},
122 {
RPCResult::Type::NUM,
"vsize",
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)"},
127 {
RPCResult::Type::STR,
"reject-reason",
true,
"Rejection string (only present when 'allowed' is false)"},
132 "\nCreate a transaction\n" 133 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
134 "Sign the transaction, and get back the hex\n" 136 "\nTest acceptance of the transaction (signed hex)\n" 138 "\nAs a JSON-RPC call\n" 153 const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
157 std::vector<CTransactionRef> txns;
158 txns.reserve(raw_transactions.
size());
159 for (
const auto& rawtx : raw_transactions.
getValues()) {
163 "TX decode failed: " + rawtx.get_str() +
" Make sure the tx has at least one input.");
184 bool exit_early{
false};
185 for (
const auto& tx : txns) {
187 result_inner.
pushKV(
"txid", tx->GetHash().GetHex());
188 result_inner.
pushKV(
"wtxid", tx->GetWitnessHash().GetHex());
192 auto it = package_result.
m_tx_results.find(tx->GetWitnessHash());
193 if (exit_early || it == package_result.
m_tx_results.end()) {
198 const auto& tx_result = it->second;
202 const CAmount fee = tx_result.m_base_fees.value();
204 const int64_t virtual_size = tx_result.m_vsize.value();
205 const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
206 if (max_raw_tx_fee && fee > max_raw_tx_fee) {
207 result_inner.
pushKV(
"allowed",
false);
208 result_inner.
pushKV(
"reject-reason",
"max-fee-exceeded");
213 result_inner.
pushKV(
"allowed",
true);
214 result_inner.
pushKV(
"vsize", virtual_size);
217 result_inner.
pushKV(
"fees", fees);
220 result_inner.
pushKV(
"allowed",
false);
223 result_inner.
pushKV(
"reject-reason",
"missing-inputs");
238 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."},
258 RPCResult{
RPCResult::Type::BOOL,
"bip125-replaceable",
"Whether this transaction signals BIP125 replaceability or has an unconfirmed ancestor signaling BIP125 replaceability.\n"},
259 RPCResult{
RPCResult::Type::BOOL,
"unbroadcast",
"Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)"},
267 info.pushKV(
"vsize", (
int)e.GetTxSize());
268 info.pushKV(
"weight", (
int)e.GetTxWeight());
270 info.pushKV(
"height", (
int)e.GetHeight());
271 info.pushKV(
"descendantcount", e.GetCountWithDescendants());
272 info.pushKV(
"descendantsize", e.GetSizeWithDescendants());
273 info.pushKV(
"ancestorcount", e.GetCountWithAncestors());
274 info.pushKV(
"ancestorsize", e.GetSizeWithAncestors());
275 info.pushKV(
"wtxid", pool.vTxHashes[e.vTxHashesIdx].first.ToString());
282 info.pushKV(
"fees", fees);
285 std::set<std::string> setDepends;
293 for (
const std::string& dep : setDepends)
298 info.pushKV(
"depends", depends);
304 spent.
push_back(child.GetTx().GetHash().ToString());
307 info.pushKV(
"spentby", spent);
310 bool rbfStatus =
false;
318 info.pushKV(
"bip125-replaceable", rbfStatus);
319 info.pushKV(
"unbroadcast", pool.IsUnbroadcastTx(tx.
GetHash()));
325 if (include_mempool_sequence) {
341 uint64_t mempool_sequence;
342 std::vector<uint256> vtxid;
349 for (
const uint256& hash : vtxid)
352 if (!include_mempool_sequence) {
357 o.
pushKV(
"mempool_sequence", mempool_sequence);
366 "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n" 367 "\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
370 {
"mempool_sequence",
RPCArg::Type::BOOL,
RPCArg::Default{
false},
"If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
383 RPCResult{
"for verbose = false and mempool_sequence = true",
399 bool fVerbose =
false;
400 if (!request.params[0].isNull())
401 fVerbose = request.params[0].
get_bool();
403 bool include_mempool_sequence =
false;
404 if (!request.params[1].isNull()) {
405 include_mempool_sequence = request.params[1].get_bool();
416 "\nIf txid is in the mempool, returns all in-mempool ancestors.\n",
437 bool fVerbose =
false;
438 if (!request.params[1].isNull())
439 fVerbose = request.params[1].
get_bool();
447 if (it == mempool.mapTx.end()) {
452 uint64_t noLimit = std::numeric_limits<uint64_t>::max();
459 o.
push_back(ancestorIt->GetTx().GetHash().ToString());
480 "\nIf txid is in the mempool, returns all in-mempool descendants.\n",
501 bool fVerbose =
false;
502 if (!request.params[1].isNull())
503 fVerbose = request.params[1].
get_bool();
511 if (it == mempool.mapTx.end()) {
518 setDescendants.erase(it);
523 o.
push_back(descendantIt->GetTx().GetHash().ToString());
545 "\nReturns mempool data for given transaction\n",
563 if (it == mempool.mapTx.end()) {
578 "Scans the mempool to find transactions spending any of the given outputs",
598 {
RPCResult::Type::STR_HEX,
"spendingtxid",
true,
"the transaction id of the mempool transaction spending this output (omitted if unspent)"},
603 HelpExampleCli(
"gettxspendingprevout",
"\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
604 +
HelpExampleRpc(
"gettxspendingprevout",
"\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
609 const UniValue& output_params = request.params[0];
610 if (output_params.
empty()) {
614 std::vector<COutPoint> prevouts;
615 prevouts.reserve(output_params.
size());
617 for (
unsigned int idx = 0; idx < output_params.
size(); idx++) {
632 prevouts.emplace_back(txid, nOutput);
640 for (
const COutPoint& prevout : prevouts) {
642 o.
pushKV(
"txid", prevout.hash.ToString());
643 o.
pushKV(
"vout", (uint64_t)prevout.n);
646 if (spendingTx !=
nullptr) {
664 ret.pushKV(
"size", (int64_t)pool.
size());
680 "Returns details on the active state of the TX memory pool.",
687 {
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"},
694 {
RPCResult::Type::NUM,
"unbroadcastcount",
"Current number of transactions that haven't passed initial broadcast yet"},
695 {
RPCResult::Type::BOOL,
"fullrbf",
"True if the mempool accepts RBF without replaceability signaling inspection"},
711 "\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
748 "Submit a package of raw transactions (serialized, hex-encoded) to local node (-regtest only).\n" 749 "The package will be validated according to consensus and mempool policy rules. If all transactions pass, they will be accepted to mempool.\n" 750 "This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n" 751 "Warning: until package relay is in use, successful submission does not mean the transaction will propagate to other nodes on the network.\n" 752 "Currently, each transaction is broadcasted individually after submission, which means they must meet other nodes' feerate requirements alone.\n" 768 {
RPCResult::Type::STR_HEX,
"other-wtxid",
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."},
775 {
RPCResult::Type::STR_AMOUNT,
"package-feerate",
true,
"package feerate used for feerate checks in " +
CURRENCY_UNIT +
" per KvB. Excludes transactions which were deduplicated or accepted individually."},
789 throw std::runtime_error(
"submitpackage is for regression testing (-regtest mode) only");
800 std::vector<CTransactionRef> txns;
801 txns.reserve(raw_transactions.
size());
802 for (
const auto& rawtx : raw_transactions.
getValues()) {
806 "TX decode failed: " + rawtx.get_str() +
" Make sure the tx has at least one input.");
817 switch(package_result.m_state.GetResult()) {
822 package_result.m_state.GetRejectReason());
827 package_result.m_state.GetRejectReason());
831 for (
const auto& tx : txns) {
832 auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
833 if (it != package_result.m_tx_results.end() && it->second.m_state.IsInvalid()) {
835 strprintf(
"%s failed: %s", tx->GetHash().ToString(), it->second.m_state.GetRejectReason()));
842 for (
const auto& tx : txns) {
843 size_t num_submitted{0};
844 std::string err_string;
848 strprintf(
"transaction broadcast failed: %s (all transactions were submitted, %d transactions were broadcast successfully)",
849 err_string, num_submitted));
854 std::set<uint256> replaced_txids;
855 for (
const auto& tx : txns) {
856 auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
859 result_inner.pushKV(
"txid", tx->GetHash().GetHex());
861 result_inner.pushKV(
"other-wtxid", it->second.m_other_wtxid.value().GetHex());
865 result_inner.pushKV(
"vsize", int64_t{it->second.m_vsize.value()});
868 result_inner.pushKV(
"fees", fees);
869 if (it->second.m_replaced_transactions.has_value()) {
870 for (
const auto& ptx : it->second.m_replaced_transactions.value()) {
871 replaced_txids.insert(ptx->GetHash());
875 tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), result_inner);
877 rpc_result.pushKV(
"tx-results", tx_result_map);
878 if (package_result.m_package_feerate.has_value()) {
879 rpc_result.pushKV(
"package-feerate",
ValueFromAmount(package_result.m_package_feerate.value().GetFeePerK()));
882 for (
const uint256& hash : replaced_txids) replaced_list.
push_back(hash.ToString());
883 rpc_result.pushKV(
"replaced-transactions", replaced_list);
903 for (
const auto& c : commands) {
904 t.appendCommand(c.name, &c);
std::shared_ptr< const CTransaction > CTransactionRef
void queryHashes(std::vector< uint256 > &vtxid) const
void push_back(UniValue val)
const std::vector< UniValue > & getValues() const
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
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...
static RPCHelpMan getmempoolinfo()
The package itself is invalid (e.g. too many transactions).
Valid, transaction was already in the mempool.
Either this tx or a mempool ancestor signals rbf.
CTxMemPool & EnsureMemPool(const NodeContext &node)
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Unconfirmed tx that does not signal rbf and is not in the mempool.
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
const int64_t m_max_size_bytes
size_t DynamicMemoryUsage() const
transaction was missing some of its inputs
#define CHECK_NONFATAL(condition)
Identity function.
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
unsigned long size() const
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::set< txiter, CompareIteratorByHash > setEntries
const UniValue & get_array() const
static RPCHelpMan savemempool()
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
const std::vector< CTxIn > vin
Invalid, missing or duplicate parameter.
const UniValue & find_value(const UniValue &obj, const std::string &name)
RBFTransactionState
The rbf state of unconfirmed transactions.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
int64_t CAmount
Amount in satoshis (Can be negative)
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Special type that is a STR with only hex chars.
NodeContext struct containing references to chain state and connection state.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
uint256 ParseHashO(const UniValue &o, std::string strKey)
UniValue JSONRPCError(int code, const std::string &message)
Special string with only hex chars.
static CAmount AmountFromValue(const UniValue &value)
Chainstate stores and provides an API to update our local knowledge of the current best chain...
Validation result for package mempool acceptance.
An input of a transaction.
const uint256 & GetHash() const
static RPCHelpMan getrawmempool()
const PackageValidationState m_state
static RPCHelpMan testmempoolaccept()
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Validate (and maybe submit) a package to the mempool.
const CFeeRate m_min_relay_feerate
const std::string CURRENCY_UNIT
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.
void RegisterMempoolRPCCommands(CRPCTable &t)
General application defined errors.
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::string ToString() const
CTxMemPool & EnsureAnyMemPool(const std::any &context)
At least one tx is invalid.
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
CFeeRate GetMinFee(size_t sizelimit) const
Special numeric to denote unix epoch time.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
const CFeeRate m_incremental_relay_feerate
constexpr int64_t count_seconds(std::chrono::seconds t)
bool GetLoadTried() const
static CTransactionRef MakeTransactionRef(Tx &&txIn)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Optional argument with default value omitted because they are implicitly clear.
static RPCHelpMan gettxspendingprevout()
#define EXCLUSIVE_LOCKS_REQUIRED(...)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Special string to represent a floating point amount.
std::set< uint256 > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
const CChainParams & Params()
Return the currently selected parameters.
void pushKV(std::string key, UniValue val)
const CTransaction & GetTx() const
fs::path MempoolPath(const ArgsManager &argsman)
ChainstateManager & EnsureChainman(const NodeContext &node)
CAmount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
const UniValue & get_obj() const
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Special type representing a floating point amount (can be either NUM or STR)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
static RPCHelpMan sendrawtransaction()
std::string u8string() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
UniValue ValueFromAmount(const CAmount amount)
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
ArgsManager & EnsureAnyArgsman(const std::any &context)
#define AssertLockNotHeld(cs)
static RPCHelpMan submitpackage()
static void entryToJSON(const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
A mutable version of CTransaction.
static RPCHelpMan getmempoolentry()
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
The basic transaction that is broadcasted on the network and contained in blocks. ...
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Chainstate & ActiveChainstate() const
The most-work chain.
Special dictionary with keys that are not literals.
std::string GetRejectReason() const
static std::vector< RPCResult > MempoolEntryDescription()
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
static RPCHelpMan getmempooldescendants()
Initial value. The package has not yet been rejected.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool IsMockableChain() const
If this chain allows time to be mocked.
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
void __pushKV(std::string key, UniValue val)
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
static GenTxid Txid(const uint256 &hash)
NodeContext & EnsureAnyNodeContext(const std::any &context)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Error parsing or validating structure in raw format.
static RPCHelpMan getmempoolancestors()
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.