aboutsummaryrefslogtreecommitdiff
path: root/src/coins.cpp
diff options
context:
space:
mode:
authorAlex Morcos <morcos@chaincode.com>2015-11-02 21:27:15 -0500
committerAlex Morcos <morcos@chaincode.com>2015-11-02 21:27:15 -0500
commit14470f9aa6baf02ca7162564f397153a2da0c592 (patch)
tree7fb16312c72044614b80f243347ee1cb1ac0b390 /src/coins.cpp
parent8fe30fb4d130532d4a0e4c9d143f03e1b85a749e (diff)
downloadbitcoin-14470f9aa6baf02ca7162564f397153a2da0c592.tar.xz
ModifyNewCoins saves database lookups
When processing a new transaction, in addition to spending the Coins of its txin's it creates a new Coins for its outputs. The existing ModifyCoins function will first make sure this Coins does not already exist. It can not exist due to BIP 30, but because of that the lookup can't be cached and always has to go to the database. Since we are creating the coins to match the new tx anyway, there is no point in checking if they exist first anyway. However this should not be used for coinbase tx's in order to preserve the historical behavior of overwriting the two existing duplicate tx pairs.
Diffstat (limited to 'src/coins.cpp')
-rw-r--r--src/coins.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/coins.cpp b/src/coins.cpp
index f02949de53..96b336ce77 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -117,6 +117,15 @@ CCoinsModifier CCoinsViewCache::ModifyCoins(const uint256 &txid) {
return CCoinsModifier(*this, ret.first, cachedCoinUsage);
}
+CCoinsModifier CCoinsViewCache::ModifyNewCoins(const uint256 &txid) {
+ assert(!hasModifier);
+ std::pair<CCoinsMap::iterator, bool> ret = cacheCoins.insert(std::make_pair(txid, CCoinsCacheEntry()));
+ ret.first->second.coins.Clear();
+ ret.first->second.flags = CCoinsCacheEntry::FRESH;
+ ret.first->second.flags |= CCoinsCacheEntry::DIRTY;
+ return CCoinsModifier(*this, ret.first, 0);
+}
+
const CCoins* CCoinsViewCache::AccessCoins(const uint256 &txid) const {
CCoinsMap::const_iterator it = FetchCoins(txid);
if (it == cacheCoins.end()) {