diff options
Diffstat (limited to 'src/rpc/mempool.cpp')
-rw-r--r-- | src/rpc/mempool.cpp | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index e6fe3c7ebd..4a0e96fd75 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -82,7 +82,7 @@ static RPCHelpMan sendrawtransaction() CTransactionRef tx(MakeTransactionRef(std::move(mtx))); - const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))}; + const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))}; int64_t virtual_size = GetVirtualTransactionSize(*tx); CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); @@ -162,7 +162,7 @@ static RPCHelpMan testmempoolaccept() "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions."); } - const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))}; + const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))}; std::vector<CTransactionRef> txns; txns.reserve(raw_transactions.size()); @@ -202,7 +202,7 @@ static RPCHelpMan testmempoolaccept() auto it = package_result.m_tx_results.find(tx->GetWitnessHash()); if (exit_early || it == package_result.m_tx_results.end()) { // Validation unfinished. Just return the txid and wtxid. - rpc_result.push_back(result_inner); + rpc_result.push_back(std::move(result_inner)); continue; } const auto& tx_result = it->second; @@ -229,8 +229,8 @@ static RPCHelpMan testmempoolaccept() for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) { effective_includes_res.push_back(wtxid.ToString()); } - fees.pushKV("effective-includes", effective_includes_res); - result_inner.pushKV("fees", fees); + fees.pushKV("effective-includes", std::move(effective_includes_res)); + result_inner.pushKV("fees", std::move(fees)); } } else { result_inner.pushKV("allowed", false); @@ -241,7 +241,7 @@ static RPCHelpMan testmempoolaccept() result_inner.pushKV("reject-reason", state.GetRejectReason()); } } - rpc_result.push_back(result_inner); + rpc_result.push_back(std::move(result_inner)); } return rpc_result; }, @@ -295,7 +295,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants())); - info.pushKV("fees", fees); + info.pushKV("fees", std::move(fees)); const CTransaction& tx = e.GetTx(); std::set<std::string> setDepends; @@ -311,14 +311,14 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool depends.push_back(dep); } - info.pushKV("depends", depends); + info.pushKV("depends", std::move(depends)); UniValue spent(UniValue::VARR); for (const CTxMemPoolEntry& child : e.GetMemPoolChildrenConst()) { spent.push_back(child.GetTx().GetHash().ToString()); } - info.pushKV("spentby", spent); + info.pushKV("spentby", std::move(spent)); // Add opt-in RBF status bool rbfStatus = false; @@ -347,7 +347,7 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo // Mempool has unique entries so there is no advantage in using // UniValue::pushKV, which checks if the key already exists in O(N). // UniValue::pushKVEnd is used instead which currently is O(1). - o.pushKVEnd(e.GetTx().GetHash().ToString(), info); + o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info)); } return o; } else { @@ -364,7 +364,7 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo return a; } else { UniValue o(UniValue::VOBJ); - o.pushKV("txids", a); + o.pushKV("txids", std::move(a)); o.pushKV("mempool_sequence", mempool_sequence); return o; } @@ -474,7 +474,7 @@ static RPCHelpMan getmempoolancestors() const uint256& _hash = e.GetTx().GetHash(); UniValue info(UniValue::VOBJ); entryToJSON(mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_hash.ToString(), std::move(info)); } return o; } @@ -539,7 +539,7 @@ static RPCHelpMan getmempooldescendants() const uint256& _hash = e.GetTx().GetHash(); UniValue info(UniValue::VOBJ); entryToJSON(mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_hash.ToString(), std::move(info)); } return o; } @@ -653,7 +653,7 @@ static RPCHelpMan gettxspendingprevout() o.pushKV("spendingtxid", spendingTx->GetHash().ToString()); } - result.push_back(o); + result.push_back(std::move(o)); } return result; @@ -671,12 +671,12 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool) ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize()); ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage()); ret.pushKV("total_fee", ValueFromAmount(pool.GetTotalFee())); - ret.pushKV("maxmempool", pool.m_max_size_bytes); - ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(), pool.m_min_relay_feerate).GetFeePerK())); - ret.pushKV("minrelaytxfee", ValueFromAmount(pool.m_min_relay_feerate.GetFeePerK())); - ret.pushKV("incrementalrelayfee", ValueFromAmount(pool.m_incremental_relay_feerate.GetFeePerK())); + ret.pushKV("maxmempool", pool.m_opts.max_size_bytes); + ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(), pool.m_opts.min_relay_feerate).GetFeePerK())); + ret.pushKV("minrelaytxfee", ValueFromAmount(pool.m_opts.min_relay_feerate.GetFeePerK())); + ret.pushKV("incrementalrelayfee", ValueFromAmount(pool.m_opts.incremental_relay_feerate.GetFeePerK())); ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()}); - ret.pushKV("fullrbf", pool.m_full_rbf); + ret.pushKV("fullrbf", pool.m_opts.full_rbf); return ret; } @@ -813,13 +813,14 @@ static RPCHelpMan submitpackage() { return RPCHelpMan{"submitpackage", "Submit a package of raw transactions (serialized, hex-encoded) to local node.\n" - "The package must consist of a child with its parents, and none of the parents may depend on one another.\n" "The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.\n" "This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n" "Warning: successful submission does not mean the transactions will propagate throughout the network.\n" , { - {"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.", + {"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.\n" + "The package must solely consist of a child and its parents. None of the parents may depend on each other.\n" + "The package must be topologically sorted, with the child being the last element in the array.", { {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""}, }, @@ -860,19 +861,19 @@ static RPCHelpMan submitpackage() }, }, RPCExamples{ - HelpExampleCli("testmempoolaccept", "[rawtx1, rawtx2]") + - HelpExampleCli("submitpackage", "[rawtx1, rawtx2]") + HelpExampleRpc("submitpackage", R"(["rawtx1", "rawtx2"])") + + HelpExampleCli("submitpackage", R"('["rawtx1", "rawtx2"]')") }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const UniValue raw_transactions = request.params[0].get_array(); - if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) { + if (raw_transactions.size() < 2 || raw_transactions.size() > MAX_PACKAGE_COUNT) { throw JSONRPCError(RPC_INVALID_PARAMETER, - "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions."); + "Array must contain between 2 and " + ToString(MAX_PACKAGE_COUNT) + " transactions."); } // Fee check needs to be run with chainstate and package context - const CFeeRate max_raw_tx_fee_rate = ParseFeeRate(self.Arg<UniValue>(1)); + const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))}; std::optional<CFeeRate> client_maxfeerate{max_raw_tx_fee_rate}; // 0-value is special; it's mapped to no sanity check if (max_raw_tx_fee_rate == CFeeRate(0)) { @@ -991,20 +992,20 @@ static RPCHelpMan submitpackage() for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) { effective_includes_res.push_back(wtxid.ToString()); } - fees.pushKV("effective-includes", effective_includes_res); + fees.pushKV("effective-includes", std::move(effective_includes_res)); } - result_inner.pushKV("fees", fees); + result_inner.pushKV("fees", std::move(fees)); for (const auto& ptx : it->second.m_replaced_transactions) { replaced_txids.insert(ptx->GetHash()); } break; } - tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), result_inner); + tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), std::move(result_inner)); } - rpc_result.pushKV("tx-results", tx_result_map); + rpc_result.pushKV("tx-results", std::move(tx_result_map)); UniValue replaced_list(UniValue::VARR); for (const uint256& hash : replaced_txids) replaced_list.push_back(hash.ToString()); - rpc_result.pushKV("replaced-transactions", replaced_list); + rpc_result.pushKV("replaced-transactions", std::move(replaced_list)); return rpc_result; }, }; |