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