mempool, refactor: Convert uint256 to Txid
This commit is contained in:
1 parent
aeb0f78330
commit
f6c0d1d231
16 files changed
+65
-69
No files matched your search
@@ -211,7 +211,7 @@ public:
|
|||||||
virtual bool isInMempool(const Txid& txid) = 0;
|
virtual bool isInMempool(const Txid& txid) = 0;
|
||||||
|
|
||||||
//! Check if transaction has descendants in mempool.
|
//! Check if transaction has descendants in mempool.
|
||||||
virtual bool hasDescendantsInMempool(const uint256& txid) = 0;
|
virtual bool hasDescendantsInMempool(const Txid& txid) = 0;
|
||||||
|
|
||||||
//! Transaction is added to memory pool, if the transaction fee is below the
|
//! Transaction is added to memory pool, if the transaction fee is below the
|
||||||
//! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.
|
//! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.
|
||||||
@@ -222,7 +222,7 @@ public:
|
|||||||
std::string& err_string) = 0;
|
std::string& err_string) = 0;
|
||||||
|
|
||||||
//! Calculate mempool ancestor and descendant counts for the given transaction.
|
//! Calculate mempool ancestor and descendant counts for the given transaction.
|
||||||
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
|
virtual void getTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
|
||||||
|
|
||||||
//! For each outpoint, calculate the fee-bumping cost to spend this outpoint at the specified
|
//! For each outpoint, calculate the fee-bumping cost to spend this outpoint at the specified
|
||||||
// feerate, including bumping its ancestors. For example, if the target feerate is 10sat/vbyte
|
// feerate, including bumping its ancestors. For example, if the target feerate is 10sat/vbyte
|
||||||
|
|||||||
@@ -1577,13 +1577,13 @@ void PeerManagerImpl::InitializeNode(const CNode& node, ServiceFlags our_service
|
|||||||
|
|
||||||
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
|
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
|
||||||
{
|
{
|
||||||
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
|
std::set<Txid> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
|
||||||
|
|
||||||
for (const auto& txid : unbroadcast_txids) {
|
for (const auto& txid : unbroadcast_txids) {
|
||||||
CTransactionRef tx = m_mempool.get(txid);
|
CTransactionRef tx = m_mempool.get(txid);
|
||||||
|
|
||||||
if (tx != nullptr) {
|
if (tx != nullptr) {
|
||||||
RelayTransaction(Txid::FromUint256(txid), tx->GetWitnessHash());
|
RelayTransaction(txid, tx->GetWitnessHash());
|
||||||
} else {
|
} else {
|
||||||
m_mempool.RemoveUnbroadcastTx(txid, true);
|
m_mempool.RemoveUnbroadcastTx(txid, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -673,11 +673,11 @@ public:
|
|||||||
LOCK(m_node.mempool->cs);
|
LOCK(m_node.mempool->cs);
|
||||||
return m_node.mempool->exists(txid);
|
return m_node.mempool->exists(txid);
|
||||||
}
|
}
|
||||||
bool hasDescendantsInMempool(const uint256& txid) override
|
bool hasDescendantsInMempool(const Txid& txid) override
|
||||||
{
|
{
|
||||||
if (!m_node.mempool) return false;
|
if (!m_node.mempool) return false;
|
||||||
LOCK(m_node.mempool->cs);
|
LOCK(m_node.mempool->cs);
|
||||||
const auto entry{m_node.mempool->GetEntry(Txid::FromUint256(txid))};
|
const auto entry{m_node.mempool->GetEntry(txid)};
|
||||||
if (entry == nullptr) return false;
|
if (entry == nullptr) return false;
|
||||||
return entry->GetCountWithDescendants() > 1;
|
return entry->GetCountWithDescendants() > 1;
|
||||||
}
|
}
|
||||||
@@ -692,7 +692,7 @@ public:
|
|||||||
// that Chain clients do not need to know about.
|
// that Chain clients do not need to know about.
|
||||||
return TransactionError::OK == err;
|
return TransactionError::OK == err;
|
||||||
}
|
}
|
||||||
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
|
void getTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
|
||||||
{
|
{
|
||||||
ancestors = descendants = 0;
|
ancestors = descendants = 0;
|
||||||
if (!m_node.mempool) return;
|
if (!m_node.mempool) return;
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
|
|||||||
if (active_chainstate.m_chainman.m_interrupt)
|
if (active_chainstate.m_chainman.m_interrupt)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::map<uint256, CAmount> mapDeltas;
|
std::map<Txid, CAmount> mapDeltas;
|
||||||
file >> mapDeltas;
|
file >> mapDeltas;
|
||||||
|
|
||||||
if (opts.apply_fee_delta_priority) {
|
if (opts.apply_fee_delta_priority) {
|
||||||
@@ -131,7 +131,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<uint256> unbroadcast_txids;
|
std::set<Txid> unbroadcast_txids;
|
||||||
file >> unbroadcast_txids;
|
file >> unbroadcast_txids;
|
||||||
if (opts.apply_unbroadcast_set) {
|
if (opts.apply_unbroadcast_set) {
|
||||||
unbroadcast = unbroadcast_txids.size();
|
unbroadcast = unbroadcast_txids.size();
|
||||||
@@ -154,9 +154,9 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
|
|||||||
{
|
{
|
||||||
auto start = SteadyClock::now();
|
auto start = SteadyClock::now();
|
||||||
|
|
||||||
std::map<uint256, CAmount> mapDeltas;
|
std::map<Txid, CAmount> mapDeltas;
|
||||||
std::vector<TxMempoolInfo> vinfo;
|
std::vector<TxMempoolInfo> vinfo;
|
||||||
std::set<uint256> unbroadcast_txids;
|
std::set<Txid> unbroadcast_txids;
|
||||||
|
|
||||||
static Mutex dump_mutex;
|
static Mutex dump_mutex;
|
||||||
LOCK(dump_mutex);
|
LOCK(dump_mutex);
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||||||
return TransactionError::OK;
|
return TransactionError::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, uint256& hashBlock, const BlockManager& blockman)
|
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, uint256& hashBlock, const BlockManager& blockman)
|
||||||
{
|
{
|
||||||
if (mempool && !block_index) {
|
if (mempool && !block_index) {
|
||||||
CTransactionRef ptx = mempool->get(hash);
|
CTransactionRef ptx = mempool->get(hash);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ static const CAmount DEFAULT_MAX_BURN_AMOUNT{0};
|
|||||||
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
|
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
|
||||||
* @returns The tx if found, otherwise nullptr
|
* @returns The tx if found, otherwise nullptr
|
||||||
*/
|
*/
|
||||||
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, uint256& hashBlock, const BlockManager& blockman);
|
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, uint256& hashBlock, const BlockManager& blockman);
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_TRANSACTION_H
|
#endif // BITCOIN_NODE_TRANSACTION_H
|
||||||
+1
-1
@@ -817,7 +817,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
|
|||||||
std::string hashStr;
|
std::string hashStr;
|
||||||
const RESTResponseFormat rf = ParseDataFormat(hashStr, uri_part);
|
const RESTResponseFormat rf = ParseDataFormat(hashStr, uri_part);
|
||||||
|
|
||||||
auto hash{uint256::FromHex(hashStr)};
|
auto hash{Txid::FromHex(hashStr)};
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
|
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
|
|||||||
AddToMempool(pool, entry.FromTx(block.vtx[2]));
|
AddToMempool(pool, entry.FromTx(block.vtx[2]));
|
||||||
BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
|
BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
|
||||||
|
|
||||||
uint256 txhash;
|
Txid txhash;
|
||||||
|
|
||||||
// Test with pre-forwarding tx 1, but not coinbase
|
// Test with pre-forwarding tx 1, but not coinbase
|
||||||
{
|
{
|
||||||
@@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
|
|||||||
AddToMempool(pool, entry.FromTx(block.vtx[1]));
|
AddToMempool(pool, entry.FromTx(block.vtx[1]));
|
||||||
BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
|
BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
|
||||||
|
|
||||||
uint256 txhash;
|
Txid txhash;
|
||||||
|
|
||||||
// Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool
|
// Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
|
|||||||
if (tx_pool.exists(txid)) {
|
if (tx_pool.exists(txid)) {
|
||||||
const auto tx_info{tx_pool.info(txid)};
|
const auto tx_info{tx_pool.info(txid)};
|
||||||
if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
|
if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
|
||||||
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
|
tx_pool.PrioritiseTransaction(txid, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
|
|||||||
txs.back()->GetHash() :
|
txs.back()->GetHash() :
|
||||||
PickValue(fuzzed_data_provider, mempool_outpoints).hash;
|
PickValue(fuzzed_data_provider, mempool_outpoints).hash;
|
||||||
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
||||||
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
|
tx_pool.PrioritiseTransaction(txid, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember all added transactions
|
// Remember all added transactions
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ FUZZ_TARGET(package_rbf, .init = initialize_package_rbf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fuzzed_data_provider.ConsumeBool()) {
|
if (fuzzed_data_provider.ConsumeBool()) {
|
||||||
pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(-100000, 100000));
|
pool.PrioritiseTransaction(mempool_txs.back().GetHash(), fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(-100000, 100000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
|
|||||||
tx->GetHash() :
|
tx->GetHash() :
|
||||||
PickValue(fuzzed_data_provider, outpoints_rbf).hash;
|
PickValue(fuzzed_data_provider, outpoints_rbf).hash;
|
||||||
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
||||||
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
|
tx_pool.PrioritiseTransaction(txid, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember all removed and added transactions
|
// Remember all removed and added transactions
|
||||||
@@ -409,7 +409,7 @@ FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
|
|||||||
mut_tx.GetHash() :
|
mut_tx.GetHash() :
|
||||||
PickValue(fuzzed_data_provider, txids);
|
PickValue(fuzzed_data_provider, txids);
|
||||||
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
|
||||||
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
|
tx_pool.PrioritiseTransaction(txid, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto tx = MakeTransactionRef(mut_tx);
|
const auto tx = MakeTransactionRef(mut_tx);
|
||||||
|
|||||||
@@ -596,7 +596,7 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
|
|||||||
tx.vin[0].scriptSig = CScript() << OP_1;
|
tx.vin[0].scriptSig = CScript() << OP_1;
|
||||||
tx.vout.resize(1);
|
tx.vout.resize(1);
|
||||||
tx.vout[0].nValue = 5000000000LL; // 0 fee
|
tx.vout[0].nValue = 5000000000LL; // 0 fee
|
||||||
uint256 hashFreePrioritisedTx = tx.GetHash();
|
Txid hashFreePrioritisedTx = tx.GetHash();
|
||||||
AddToMempool(tx_mempool, entry.Fee(0).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
AddToMempool(tx_mempool, entry.Fee(0).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
||||||
tx_mempool.PrioritiseTransaction(hashFreePrioritisedTx, 5 * COIN);
|
tx_mempool.PrioritiseTransaction(hashFreePrioritisedTx, 5 * COIN);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||||||
// added to the mempool by their associate fee
|
// added to the mempool by their associate fee
|
||||||
// txHashes[j] is populated with transactions either of
|
// txHashes[j] is populated with transactions either of
|
||||||
// fee = basefee * (j+1)
|
// fee = basefee * (j+1)
|
||||||
std::vector<uint256> txHashes[10];
|
std::vector<Txid> txHashes[10];
|
||||||
|
|
||||||
// Create a transaction template
|
// Create a transaction template
|
||||||
CScript garbage;
|
CScript garbage;
|
||||||
@@ -77,8 +77,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||||||
/*has_no_mempool_parents=*/true)};
|
/*has_no_mempool_parents=*/true)};
|
||||||
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
||||||
}
|
}
|
||||||
uint256 hash = tx.GetHash();
|
txHashes[j].push_back(tx.GetHash());
|
||||||
txHashes[j].push_back(hash);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Create blocks where higher fee txs are included more often
|
//Create blocks where higher fee txs are included more often
|
||||||
@@ -178,8 +177,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||||||
/*has_no_mempool_parents=*/true)};
|
/*has_no_mempool_parents=*/true)};
|
||||||
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
||||||
}
|
}
|
||||||
uint256 hash = tx.GetHash();
|
txHashes[j].push_back(tx.GetHash());
|
||||||
txHashes[j].push_back(hash);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -242,8 +240,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||||||
/*has_no_mempool_parents=*/true)};
|
/*has_no_mempool_parents=*/true)};
|
||||||
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
|
||||||
}
|
}
|
||||||
uint256 hash = tx.GetHash();
|
CTransactionRef ptx = mpool.get(tx.GetHash());
|
||||||
CTransactionRef ptx = mpool.get(hash);
|
|
||||||
if (ptx)
|
if (ptx)
|
||||||
block.push_back(ptx);
|
block.push_back(ptx);
|
||||||
|
|
||||||
|
|||||||
+21
-22
@@ -55,7 +55,7 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
||||||
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
|
const std::set<Txid>& setExclude, std::set<Txid>& descendants_to_remove)
|
||||||
{
|
{
|
||||||
CTxMemPoolEntry::Children stageEntries, descendants;
|
CTxMemPoolEntry::Children stageEntries, descendants;
|
||||||
stageEntries = updateIt->GetMemPoolChildrenConst();
|
stageEntries = updateIt->GetMemPoolChildrenConst();
|
||||||
@@ -105,7 +105,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
|
|||||||
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); });
|
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate)
|
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<Txid>& vHashesToUpdate)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
// For each entry in vHashesToUpdate, store the set of in-mempool, but not
|
// For each entry in vHashesToUpdate, store the set of in-mempool, but not
|
||||||
@@ -115,29 +115,29 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashes
|
|||||||
|
|
||||||
// Use a set for lookups into vHashesToUpdate (these entries are already
|
// Use a set for lookups into vHashesToUpdate (these entries are already
|
||||||
// accounted for in the state of their ancestors)
|
// accounted for in the state of their ancestors)
|
||||||
std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
|
std::set<Txid> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
|
||||||
|
|
||||||
std::set<uint256> descendants_to_remove;
|
std::set<Txid> descendants_to_remove;
|
||||||
|
|
||||||
// Iterate in reverse, so that whenever we are looking at a transaction
|
// Iterate in reverse, so that whenever we are looking at a transaction
|
||||||
// we are sure that all in-mempool descendants have already been processed.
|
// we are sure that all in-mempool descendants have already been processed.
|
||||||
// This maximizes the benefit of the descendant cache and guarantees that
|
// This maximizes the benefit of the descendant cache and guarantees that
|
||||||
// CTxMemPoolEntry::m_children will be updated, an assumption made in
|
// CTxMemPoolEntry::m_children will be updated, an assumption made in
|
||||||
// UpdateForDescendants.
|
// UpdateForDescendants.
|
||||||
for (const uint256& hash : vHashesToUpdate | std::views::reverse) {
|
for (const Txid& hash : vHashesToUpdate | std::views::reverse) {
|
||||||
// calculate children from mapNextTx
|
// calculate children from mapNextTx
|
||||||
txiter it = mapTx.find(hash);
|
txiter it = mapTx.find(hash);
|
||||||
if (it == mapTx.end()) {
|
if (it == mapTx.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto iter = mapNextTx.lower_bound(COutPoint(Txid::FromUint256(hash), 0));
|
auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
|
||||||
// First calculate the children, and update CTxMemPoolEntry::m_children to
|
// First calculate the children, and update CTxMemPoolEntry::m_children to
|
||||||
// include them, and update their CTxMemPoolEntry::m_parents to include this tx.
|
// include them, and update their CTxMemPoolEntry::m_parents to include this tx.
|
||||||
// we cache the in-mempool children to avoid duplicate updates
|
// we cache the in-mempool children to avoid duplicate updates
|
||||||
{
|
{
|
||||||
WITH_FRESH_EPOCH(m_epoch);
|
WITH_FRESH_EPOCH(m_epoch);
|
||||||
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
|
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
|
||||||
const uint256 &childHash = iter->second->GetHash();
|
const Txid &childHash = iter->second->GetHash();
|
||||||
txiter childIter = mapTx.find(childHash);
|
txiter childIter = mapTx.find(childHash);
|
||||||
assert(childIter != mapTx.end());
|
assert(childIter != mapTx.end());
|
||||||
// We can skip updating entries we've encountered before or that
|
// We can skip updating entries we've encountered before or that
|
||||||
@@ -154,7 +154,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashes
|
|||||||
for (const auto& txid : descendants_to_remove) {
|
for (const auto& txid : descendants_to_remove) {
|
||||||
// This txid may have been removed already in a prior call to removeRecursive.
|
// This txid may have been removed already in a prior call to removeRecursive.
|
||||||
// Therefore we ensure it is not yet removed already.
|
// Therefore we ensure it is not yet removed already.
|
||||||
if (const std::optional<txiter> txiter = GetIter(Txid::FromUint256(txid))) {
|
if (const std::optional<txiter> txiter = GetIter(txid)) {
|
||||||
removeRecursive((*txiter)->GetTx(), MemPoolRemovalReason::SIZELIMIT);
|
removeRecursive((*txiter)->GetTx(), MemPoolRemovalReason::SIZELIMIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -780,12 +780,11 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
|
|||||||
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
|
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
|
||||||
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
|
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
|
||||||
}
|
}
|
||||||
for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
|
for (const auto& [_, next_tx] : mapNextTx) {
|
||||||
uint256 hash = it->second->GetHash();
|
auto it = mapTx.find(next_tx->GetHash());
|
||||||
indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
|
const CTransaction& tx = it->GetTx();
|
||||||
const CTransaction& tx = it2->GetTx();
|
assert(it != mapTx.end());
|
||||||
assert(it2 != mapTx.end());
|
assert(&tx == next_tx);
|
||||||
assert(&tx == it->second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(totalTxSize == checkTotal);
|
assert(totalTxSize == checkTotal);
|
||||||
@@ -876,7 +875,7 @@ const CTxMemPoolEntry* CTxMemPool::GetEntry(const Txid& txid) const
|
|||||||
return i == mapTx.end() ? nullptr : &(*i);
|
return i == mapTx.end() ? nullptr : &(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransactionRef CTxMemPool::get(const uint256& hash) const
|
CTransactionRef CTxMemPool::get(const Txid& hash) const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
indexed_transaction_set::const_iterator i = mapTx.find(hash);
|
indexed_transaction_set::const_iterator i = mapTx.find(hash);
|
||||||
@@ -885,7 +884,7 @@ CTransactionRef CTxMemPool::get(const uint256& hash) const
|
|||||||
return i->GetSharedTx();
|
return i->GetSharedTx();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
|
void CTxMemPool::PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
@@ -921,17 +920,17 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const
|
void CTxMemPool::ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
|
std::map<Txid, CAmount>::const_iterator pos = mapDeltas.find(hash);
|
||||||
if (pos == mapDeltas.end())
|
if (pos == mapDeltas.end())
|
||||||
return;
|
return;
|
||||||
const CAmount &delta = pos->second;
|
const CAmount &delta = pos->second;
|
||||||
nFeeDelta += delta;
|
nFeeDelta += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::ClearPrioritisation(const uint256& hash)
|
void CTxMemPool::ClearPrioritisation(const Txid& hash)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
mapDeltas.erase(hash);
|
mapDeltas.erase(hash);
|
||||||
@@ -962,7 +961,7 @@ const CTransaction* CTxMemPool::GetConflictTx(const COutPoint& prevout) const
|
|||||||
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Txid& txid) const
|
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Txid& txid) const
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
auto it = mapTx.find(txid.ToUint256());
|
auto it = mapTx.find(txid);
|
||||||
return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
|
return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1048,7 +1047,7 @@ size_t CTxMemPool::DynamicMemoryUsage() const {
|
|||||||
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(txns_randomized) + cachedInnerUsage;
|
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(txns_randomized) + cachedInnerUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::RemoveUnbroadcastTx(const uint256& txid, const bool unchecked) {
|
void CTxMemPool::RemoveUnbroadcastTx(const Txid& txid, const bool unchecked) {
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
|
||||||
if (m_unbroadcast_txids.erase(txid))
|
if (m_unbroadcast_txids.erase(txid))
|
||||||
@@ -1203,7 +1202,7 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
|
|||||||
return maximum;
|
return maximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* const ancestorsize, CAmount* const ancestorfees) const {
|
void CTxMemPool::GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* const ancestorsize, CAmount* const ancestorfees) const {
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
auto it = mapTx.find(txid);
|
auto it = mapTx.find(txid);
|
||||||
ancestors = descendants = 0;
|
ancestors = descendants = 0;
|
||||||
|
|||||||
+17
-17
@@ -57,7 +57,7 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE
|
|||||||
// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
|
// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
|
||||||
struct mempoolentry_txid
|
struct mempoolentry_txid
|
||||||
{
|
{
|
||||||
typedef uint256 result_type;
|
typedef Txid result_type;
|
||||||
result_type operator() (const CTxMemPoolEntry &entry) const
|
result_type operator() (const CTxMemPoolEntry &entry) const
|
||||||
{
|
{
|
||||||
return entry.GetTx().GetHash();
|
return entry.GetTx().GetHash();
|
||||||
@@ -72,7 +72,7 @@ struct mempoolentry_txid
|
|||||||
// extracts a transaction witness-hash from CTxMemPoolEntry or CTransactionRef
|
// extracts a transaction witness-hash from CTxMemPoolEntry or CTransactionRef
|
||||||
struct mempoolentry_wtxid
|
struct mempoolentry_wtxid
|
||||||
{
|
{
|
||||||
typedef uint256 result_type;
|
typedef Wtxid result_type;
|
||||||
result_type operator() (const CTxMemPoolEntry &entry) const
|
result_type operator() (const CTxMemPoolEntry &entry) const
|
||||||
{
|
{
|
||||||
return entry.GetTx().GetWitnessHash();
|
return entry.GetTx().GetWitnessHash();
|
||||||
@@ -387,7 +387,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Track locally submitted transactions to periodically retry initial broadcast.
|
* Track locally submitted transactions to periodically retry initial broadcast.
|
||||||
*/
|
*/
|
||||||
std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
|
std::set<Txid> m_unbroadcast_txids GUARDED_BY(cs);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -414,7 +414,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
||||||
std::map<uint256, CAmount> mapDeltas GUARDED_BY(cs);
|
std::map<Txid, CAmount> mapDeltas GUARDED_BY(cs);
|
||||||
|
|
||||||
using Options = kernel::MemPoolOptions;
|
using Options = kernel::MemPoolOptions;
|
||||||
|
|
||||||
@@ -459,9 +459,9 @@ public:
|
|||||||
bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/** Affect CreateNewBlock prioritisation of transactions */
|
/** Affect CreateNewBlock prioritisation of transactions */
|
||||||
void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
|
void PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta);
|
||||||
void ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
void ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
struct delta_info {
|
struct delta_info {
|
||||||
/** Whether this transaction is in the mempool. */
|
/** Whether this transaction is in the mempool. */
|
||||||
@@ -471,7 +471,7 @@ public:
|
|||||||
/** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
|
/** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
|
||||||
std::optional<CAmount> modified_fee;
|
std::optional<CAmount> modified_fee;
|
||||||
/** The prioritised transaction's txid. */
|
/** The prioritised transaction's txid. */
|
||||||
const uint256 txid;
|
const Txid txid;
|
||||||
};
|
};
|
||||||
/** Return a vector of all entries in mapDeltas with their corresponding delta_info. */
|
/** Return a vector of all entries in mapDeltas with their corresponding delta_info. */
|
||||||
std::vector<delta_info> GetPrioritisedTransactions() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
std::vector<delta_info> GetPrioritisedTransactions() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
||||||
@@ -506,7 +506,7 @@ public:
|
|||||||
* @param[in] vHashesToUpdate The set of txids from the
|
* @param[in] vHashesToUpdate The set of txids from the
|
||||||
* disconnected block that have been accepted back into the mempool.
|
* disconnected block that have been accepted back into the mempool.
|
||||||
*/
|
*/
|
||||||
void UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
|
void UpdateTransactionsFromBlock(const std::vector<Txid>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to calculate all in-mempool ancestors of entry.
|
* Try to calculate all in-mempool ancestors of entry.
|
||||||
@@ -595,7 +595,7 @@ public:
|
|||||||
* When ancestors is non-zero (ie, the transaction itself is in the mempool),
|
* When ancestors is non-zero (ie, the transaction itself is in the mempool),
|
||||||
* ancestorsize and ancestorfees will also be set to the appropriate values.
|
* ancestorsize and ancestorfees will also be set to the appropriate values.
|
||||||
*/
|
*/
|
||||||
void GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) const;
|
void GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns true if an initial attempt to load the persisted mempool was made, regardless of
|
* @returns true if an initial attempt to load the persisted mempool was made, regardless of
|
||||||
@@ -641,7 +641,7 @@ public:
|
|||||||
|
|
||||||
const CTxMemPoolEntry* GetEntry(const Txid& txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs);
|
const CTxMemPoolEntry* GetEntry(const Txid& txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
CTransactionRef get(const uint256& hash) const;
|
CTransactionRef get(const Txid& hash) const;
|
||||||
|
|
||||||
template <TxidOrWtxid T>
|
template <TxidOrWtxid T>
|
||||||
TxMempoolInfo info(const T& id) const
|
TxMempoolInfo info(const T& id) const
|
||||||
@@ -666,26 +666,26 @@ public:
|
|||||||
size_t DynamicMemoryUsage() const;
|
size_t DynamicMemoryUsage() const;
|
||||||
|
|
||||||
/** Adds a transaction to the unbroadcast set */
|
/** Adds a transaction to the unbroadcast set */
|
||||||
void AddUnbroadcastTx(const uint256& txid)
|
void AddUnbroadcastTx(const Txid& txid)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
// Sanity check the transaction is in the mempool & insert into
|
// Sanity check the transaction is in the mempool & insert into
|
||||||
// unbroadcast set.
|
// unbroadcast set.
|
||||||
if (exists(Txid::FromUint256(txid))) m_unbroadcast_txids.insert(txid);
|
if (exists(txid)) m_unbroadcast_txids.insert(txid);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Removes a transaction from the unbroadcast set */
|
/** Removes a transaction from the unbroadcast set */
|
||||||
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
|
void RemoveUnbroadcastTx(const Txid& txid, const bool unchecked = false);
|
||||||
|
|
||||||
/** Returns transactions in unbroadcast set */
|
/** Returns transactions in unbroadcast set */
|
||||||
std::set<uint256> GetUnbroadcastTxs() const
|
std::set<Txid> GetUnbroadcastTxs() const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
return m_unbroadcast_txids;
|
return m_unbroadcast_txids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether a txid is in the unbroadcast set */
|
/** Returns whether a txid is in the unbroadcast set */
|
||||||
bool IsUnbroadcastTx(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
bool IsUnbroadcastTx(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
return m_unbroadcast_txids.count(txid) != 0;
|
return m_unbroadcast_txids.count(txid) != 0;
|
||||||
@@ -744,7 +744,7 @@ private:
|
|||||||
* removeRecursive them.
|
* removeRecursive them.
|
||||||
*/
|
*/
|
||||||
void UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
void UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
||||||
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
const std::set<Txid>& setExclude, std::set<Txid>& descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
/** Update ancestors of hash to add/remove it as a descendant transaction. */
|
/** Update ancestors of hash to add/remove it as a descendant transaction. */
|
||||||
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
/** Set ancestor state for an entry */
|
/** Set ancestor state for an entry */
|
||||||
|
|||||||
+1
-1
@@ -303,7 +303,7 @@ void Chainstate::MaybeUpdateMempoolForReorg(
|
|||||||
|
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
AssertLockHeld(m_mempool->cs);
|
AssertLockHeld(m_mempool->cs);
|
||||||
std::vector<uint256> vHashUpdate;
|
std::vector<Txid> vHashUpdate;
|
||||||
{
|
{
|
||||||
// disconnectpool is ordered so that the front is the most recently-confirmed
|
// disconnectpool is ordered so that the front is the most recently-confirmed
|
||||||
// transaction (the last tx of the block at the tip) in the disconnected chain.
|
// transaction (the last tx of the block at the tip) in the disconnected chain.
|
||||||
|
|||||||
Reference in new issue
Block a user