[coins/mempool] extend CCoinsViewMemPool to track temporary coins
This commit is contained in:
1 parent
42cf8b25df
commit
897e348f59
2 files changed
+23
-1
No files matched your search
@@ -922,6 +922,13 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
|
|||||||
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
|
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
|
||||||
|
|
||||||
bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const {
|
bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const {
|
||||||
|
// Check to see if the inputs are made available by another tx in the package.
|
||||||
|
// These Coins would not be available in the underlying CoinsView.
|
||||||
|
if (auto it = m_temp_added.find(outpoint); it != m_temp_added.end()) {
|
||||||
|
coin = it->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// If an entry in the mempool exists, always return that one, as it's guaranteed to never
|
// If an entry in the mempool exists, always return that one, as it's guaranteed to never
|
||||||
// conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
|
// conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
|
||||||
// transactions. First checking the underlying cache risks returning a pruned entry instead.
|
// transactions. First checking the underlying cache risks returning a pruned entry instead.
|
||||||
@@ -937,6 +944,13 @@ bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const {
|
|||||||
return base->GetCoin(outpoint, coin);
|
return base->GetCoin(outpoint, coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCoinsViewMemPool::PackageAddTransaction(const CTransactionRef& tx)
|
||||||
|
{
|
||||||
|
for (unsigned int n = 0; n < tx->vout.size(); ++n) {
|
||||||
|
m_temp_added.emplace(COutPoint(tx->GetHash(), n), Coin(tx->vout[n], MEMPOOL_HEIGHT, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t CTxMemPool::DynamicMemoryUsage() const {
|
size_t CTxMemPool::DynamicMemoryUsage() const {
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
// Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
|
// Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
|
||||||
|
|||||||
+9
-1
@@ -852,7 +852,8 @@ public:
|
|||||||
* CCoinsView that brings transactions from a mempool into view.
|
* CCoinsView that brings transactions from a mempool into view.
|
||||||
* It does not check for spendings by memory pool transactions.
|
* It does not check for spendings by memory pool transactions.
|
||||||
* Instead, it provides access to all Coins which are either unspent in the
|
* Instead, it provides access to all Coins which are either unspent in the
|
||||||
* base CCoinsView, or are outputs from any mempool transaction!
|
* base CCoinsView, are outputs from any mempool transaction, or are
|
||||||
|
* tracked temporarily to allow transaction dependencies in package validation.
|
||||||
* This allows transaction replacement to work as expected, as you want to
|
* This allows transaction replacement to work as expected, as you want to
|
||||||
* have all inputs "available" to check signatures, and any cycles in the
|
* have all inputs "available" to check signatures, and any cycles in the
|
||||||
* dependency graph are checked directly in AcceptToMemoryPool.
|
* dependency graph are checked directly in AcceptToMemoryPool.
|
||||||
@@ -862,12 +863,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
class CCoinsViewMemPool : public CCoinsViewBacked
|
class CCoinsViewMemPool : public CCoinsViewBacked
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Coins made available by transactions being validated. Tracking these allows for package
|
||||||
|
* validation, since we can access transaction outputs without submitting them to mempool.
|
||||||
|
*/
|
||||||
|
std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
|
||||||
protected:
|
protected:
|
||||||
const CTxMemPool& mempool;
|
const CTxMemPool& mempool;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
|
CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
|
||||||
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
|
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
|
||||||
|
/** Add the coins created by this transaction. */
|
||||||
|
void PackageAddTransaction(const CTransactionRef& tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user