mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
node: Use mempool from node context instead of global
This commit is contained in:
parent
facbaf092f
commit
fa660d65d7
8 changed files with 16 additions and 14 deletions
|
@ -263,7 +263,7 @@ public:
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(coins); }
|
||||
void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(m_node, coins); }
|
||||
double guessVerificationProgress(const uint256& block_hash) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
|
|
@ -167,8 +167,8 @@ public:
|
|||
}
|
||||
int64_t getTotalBytesRecv() override { return m_context.connman ? m_context.connman->GetTotalBytesRecv() : 0; }
|
||||
int64_t getTotalBytesSent() override { return m_context.connman ? m_context.connman->GetTotalBytesSent() : 0; }
|
||||
size_t getMempoolSize() override { return ::mempool.size(); }
|
||||
size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); }
|
||||
size_t getMempoolSize() override { return m_context.mempool ? m_context.mempool->size() : 0; }
|
||||
size_t getMempoolDynamicUsage() override { return m_context.mempool ? m_context.mempool->DynamicMemoryUsage() : 0; }
|
||||
bool getHeaderTip(int& height, int64_t& block_time) override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
|
||||
#include <node/coin.h>
|
||||
|
||||
#include <node/context.h>
|
||||
#include <txmempool.h>
|
||||
#include <validation.h>
|
||||
|
||||
void FindCoins(std::map<COutPoint, Coin>& coins)
|
||||
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
|
||||
{
|
||||
LOCK2(cs_main, ::mempool.cs);
|
||||
assert(node.mempool);
|
||||
LOCK2(cs_main, node.mempool->cs);
|
||||
CCoinsViewCache& chain_view = ::ChainstateActive().CoinsTip();
|
||||
CCoinsViewMemPool mempool_view(&chain_view, ::mempool);
|
||||
CCoinsViewMemPool mempool_view(&chain_view, *node.mempool);
|
||||
for (auto& coin : coins) {
|
||||
if (!mempool_view.GetCoin(coin.first, coin.second)) {
|
||||
// Either the coin is not in the CCoinsViewCache or is spent. Clear it.
|
||||
|
|
|
@ -9,14 +9,16 @@
|
|||
|
||||
class COutPoint;
|
||||
class Coin;
|
||||
struct NodeContext;
|
||||
|
||||
/**
|
||||
* Look up unspent output information. Returns coins in the mempool and in the
|
||||
* current chain UTXO set. Iterates through all the keys in the map and
|
||||
* populates the values.
|
||||
*
|
||||
* @param[in] node The node context to use for lookup
|
||||
* @param[in,out] coins map to fill
|
||||
*/
|
||||
void FindCoins(std::map<COutPoint, Coin>& coins);
|
||||
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins);
|
||||
|
||||
#endif // BITCOIN_NODE_COIN_H
|
||||
|
|
|
@ -20,6 +20,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||
// node.connman is assigned both before chain clients and before RPC server is accepting calls,
|
||||
// and reset after chain clients and RPC sever are stopped. node.connman should never be null here.
|
||||
assert(node.connman);
|
||||
assert(node.mempool);
|
||||
std::promise<void> promise;
|
||||
uint256 hashTx = tx->GetHash();
|
||||
bool callback_set = false;
|
||||
|
@ -35,10 +36,10 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||
// So if the output does exist, then this transaction exists in the chain.
|
||||
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
|
||||
}
|
||||
if (!mempool.exists(hashTx)) {
|
||||
if (!node.mempool->exists(hashTx)) {
|
||||
// Transaction is not already in the mempool. Submit it.
|
||||
TxValidationState state;
|
||||
if (!AcceptToMemoryPool(mempool, state, std::move(tx),
|
||||
if (!AcceptToMemoryPool(*node.mempool, state, std::move(tx),
|
||||
nullptr /* plTxnReplaced */, false /* bypass_limits */, max_tx_fee)) {
|
||||
err_string = FormatStateMessage(state);
|
||||
if (state.IsInvalid()) {
|
||||
|
|
|
@ -134,6 +134,7 @@ void TestGUI(interfaces::Node& node)
|
|||
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
||||
}
|
||||
node.context()->connman = std::move(test.m_node.connman);
|
||||
node.context()->mempool = std::move(test.m_node.mempool);
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
|
|
|
@ -759,7 +759,7 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
|
|||
for (const CTxIn& txin : mtx.vin) {
|
||||
coins[txin.prevout]; // Create empty map entry keyed by prevout.
|
||||
}
|
||||
FindCoins(coins);
|
||||
FindCoins(*g_rpc_node, coins);
|
||||
|
||||
// Parse the prevtxs array
|
||||
ParsePrevouts(request.params[2], &keystore, coins);
|
||||
|
|
|
@ -112,14 +112,10 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
|
|||
std::string notsigned = r.get_str();
|
||||
std::string privkey1 = "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\"";
|
||||
std::string privkey2 = "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\"";
|
||||
NodeContext node;
|
||||
node.chain = interfaces::MakeChain(node);
|
||||
g_rpc_node = &node;
|
||||
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout);
|
||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false);
|
||||
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout);
|
||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true);
|
||||
g_rpc_node = nullptr;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rpc_createraw_op_return)
|
||||
|
|
Loading…
Add table
Reference in a new issue