Skip to content

Commit 60c73ad

Browse files
siparandom-zebra
authored andcommitted
Rename CCoinsCacheEntry::coins to coin
1 parent 1166f1f commit 60c73ad

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

src/coins.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ CCoinsMap::iterator CCoinsViewCache::FetchCoins(const COutPoint& outpoint) const
4343
if (!base->GetCoins(outpoint, tmp))
4444
return cacheCoins.end();
4545
CCoinsMap::iterator ret = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
46-
if (ret->second.coins.IsPruned()) {
46+
if (ret->second.coin.IsPruned()) {
4747
// The parent only has an empty entry for this outpoint; we can consider our
4848
// version as fresh.
4949
ret->second.flags = CCoinsCacheEntry::FRESH;
5050
}
51-
cachedCoinsUsage += memusage::DynamicUsage(ret->second.coins);
51+
cachedCoinsUsage += memusage::DynamicUsage(ret->second.coin);
5252
return ret;
5353
}
5454

5555
bool CCoinsViewCache::GetCoins(const COutPoint& outpoint, Coin& coin) const
5656
{
5757
CCoinsMap::const_iterator it = FetchCoins(outpoint);
5858
if (it != cacheCoins.end()) {
59-
coin = it->second.coins;
59+
coin = it->second.coin;
6060
return true;
6161
}
6262
return false;
@@ -70,17 +70,17 @@ void CCoinsViewCache::AddCoin(const COutPoint& outpoint, Coin&& coin, bool possi
7070
std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
7171
bool fresh = false;
7272
if (!inserted) {
73-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
73+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
7474
}
7575
if (!possible_overwrite) {
76-
if (!it->second.coins.IsPruned()) {
76+
if (!it->second.coin.IsPruned()) {
7777
throw std::logic_error("Adding new coin that replaces non-pruned entry");
7878
}
7979
fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY);
8080
}
81-
it->second.coins = std::move(coin);
81+
it->second.coin = std::move(coin);
8282
it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0);
83-
cachedCoinsUsage += it->second.coins.DynamicMemoryUsage();
83+
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
8484
}
8585

8686
void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight)
@@ -97,15 +97,15 @@ void CCoinsViewCache::SpendCoin(const COutPoint& outpoint, Coin* moveout)
9797
{
9898
CCoinsMap::iterator it = FetchCoins(outpoint);
9999
if (it == cacheCoins.end()) return;
100-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
100+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
101101
if (moveout) {
102-
*moveout = std::move(it->second.coins);
102+
*moveout = std::move(it->second.coin);
103103
}
104104
if (it->second.flags & CCoinsCacheEntry::FRESH) {
105105
cacheCoins.erase(it);
106106
} else {
107107
it->second.flags |= CCoinsCacheEntry::DIRTY;
108-
it->second.coins.Clear();
108+
it->second.coin.Clear();
109109
}
110110
}
111111

@@ -117,14 +117,14 @@ const Coin& CCoinsViewCache::AccessCoin(const COutPoint& outpoint) const
117117
if (it == cacheCoins.end()) {
118118
return coinEmpty;
119119
} else {
120-
return it->second.coins;
120+
return it->second.coin;
121121
}
122122
}
123123

124124
bool CCoinsViewCache::HaveCoins(const COutPoint& outpoint) const
125125
{
126126
CCoinsMap::const_iterator it = FetchCoins(outpoint);
127-
return (it != cacheCoins.end() && !it->second.coins.IsPruned());
127+
return (it != cacheCoins.end() && !it->second.coin.IsPruned());
128128
}
129129

130130
bool CCoinsViewCache::HaveCoinsInCache(const COutPoint& outpoint) const
@@ -152,12 +152,12 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlockIn
152152
if (itUs == cacheCoins.end()) {
153153
// The parent cache does not have an entry, while the child does
154154
// We can ignore it if it's both FRESH and pruned in the child
155-
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coins.IsPruned())) {
155+
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coin.IsPruned())) {
156156
// Otherwise we will need to create it in the parent
157157
// and move the data up and mark it as dirty
158158
CCoinsCacheEntry& entry = cacheCoins[it->first];
159-
entry.coins = std::move(it->second.coins);
160-
cachedCoinsUsage += memusage::DynamicUsage(entry.coins);
159+
entry.coin = std::move(it->second.coin);
160+
cachedCoinsUsage += memusage::DynamicUsage(entry.coin);
161161
entry.flags = CCoinsCacheEntry::DIRTY;
162162
// We can mark it FRESH in the parent if it was FRESH in the child
163163
// Otherwise it might have just been flushed from the parent's cache
@@ -170,21 +170,21 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlockIn
170170
// parent cache entry has unspent outputs. If this ever happens,
171171
// it means the FRESH flag was misapplied and there is a logic
172172
// error in the calling code.
173-
if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coins.IsPruned())
173+
if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coin.IsPruned())
174174
throw std::logic_error("FRESH flag misapplied to cache entry for base transaction with spendable outputs");
175175

176176
// Found the entry in the parent cache
177-
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coins.IsPruned()) {
177+
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coin.IsPruned()) {
178178
// The grandparent does not have an entry, and the child is
179179
// modified and being pruned. This means we can just delete
180180
// it from the parent.
181-
cachedCoinsUsage -= memusage::DynamicUsage(itUs->second.coins);
181+
cachedCoinsUsage -= memusage::DynamicUsage(itUs->second.coin);
182182
cacheCoins.erase(itUs);
183183
} else {
184184
// A normal modification.
185-
cachedCoinsUsage -= memusage::DynamicUsage(itUs->second.coins);
186-
itUs->second.coins = std::move(it->second.coins);
187-
cachedCoinsUsage += memusage::DynamicUsage(itUs->second.coins);
185+
cachedCoinsUsage -= memusage::DynamicUsage(itUs->second.coin);
186+
itUs->second.coin = std::move(it->second.coin);
187+
cachedCoinsUsage += memusage::DynamicUsage(itUs->second.coin);
188188
itUs->second.flags |= CCoinsCacheEntry::DIRTY;
189189
// NOTE: It is possible the child has a FRESH flag here in
190190
// the event the entry we found in the parent is pruned. But
@@ -213,7 +213,7 @@ void CCoinsViewCache::Uncache(const COutPoint& outpoint)
213213
{
214214
CCoinsMap::iterator it = cacheCoins.find(outpoint);
215215
if (it != cacheCoins.end() && it->second.flags == 0) {
216-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
216+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
217217
cacheCoins.erase(it);
218218
}
219219
}

src/coins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class SaltedOutpointHasher
110110
};
111111

112112
struct CCoinsCacheEntry {
113-
Coin coins; // The actual cached data.
113+
Coin coin; // The actual cached data.
114114
unsigned char flags;
115115

116116
enum Flags {
@@ -119,7 +119,7 @@ struct CCoinsCacheEntry {
119119
};
120120

121121
CCoinsCacheEntry() : flags(0) {}
122-
explicit CCoinsCacheEntry(Coin&& coin_) : coins(std::move(coin_)), flags(0) {}
122+
explicit CCoinsCacheEntry(Coin&& coin_) : coin(std::move(coin_)), flags(0) {}
123123
};
124124

125125
typedef std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher> CCoinsMap;

src/test/coins_tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class CCoinsViewTest : public CCoinsView
6464
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
6565
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
6666
// Same optimization used in CCoinsViewDB is to only write dirty entries.
67-
map_[it->first] = it->second.coins;
68-
if (it->second.coins.IsPruned() && InsecureRandRange(3) == 0) {
67+
map_[it->first] = it->second.coin;
68+
if (it->second.coin.IsPruned() && InsecureRandRange(3) == 0) {
6969
// Randomly delete empty entries on write.
7070
map_.erase(it->first);
7171
}
@@ -89,7 +89,7 @@ class CCoinsViewCacheTest : public CCoinsViewCache
8989
size_t ret = memusage::DynamicUsage(cacheCoins);
9090
size_t count = 0;
9191
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
92-
ret += memusage::DynamicUsage(it->second.coins);
92+
ret += memusage::DynamicUsage(it->second.coin);
9393
++count;
9494
}
9595
BOOST_CHECK_EQUAL(GetCacheSize(), count);
@@ -524,10 +524,10 @@ size_t InsertCoinsMapEntry(CCoinsMap& map, CAmount value, char flags)
524524
assert(flags != NO_ENTRY);
525525
CCoinsCacheEntry entry;
526526
entry.flags = flags;
527-
SetCoinsValue(value, entry.coins);
527+
SetCoinsValue(value, entry.coin);
528528
auto inserted = map.emplace(OUTPOINT, std::move(entry));
529529
assert(inserted.second);
530-
return inserted.first->second.coins.DynamicMemoryUsage();
530+
return inserted.first->second.coin.DynamicMemoryUsage();
531531
}
532532

533533
void GetCoinsMapEntry(const CCoinsMap& map, CAmount& value, char& flags)
@@ -537,10 +537,10 @@ void GetCoinsMapEntry(const CCoinsMap& map, CAmount& value, char& flags)
537537
value = ABSENT;
538538
flags = NO_ENTRY;
539539
} else {
540-
if (it->second.coins.IsPruned()) {
540+
if (it->second.coin.IsPruned()) {
541541
value = PRUNED;
542542
} else {
543-
value = it->second.coins.out.nValue;
543+
value = it->second.coin.out.nValue;
544544
}
545545
flags = it->second.flags;
546546
assert(flags != NO_ENTRY);

src/txdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock)
8282
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
8383
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
8484
CoinEntry entry(&it->first);
85-
if (it->second.coins.IsPruned())
85+
if (it->second.coin.IsPruned())
8686
batch.Erase(entry);
8787
else
88-
batch.Write(entry, it->second.coins);
88+
batch.Write(entry, it->second.coin);
8989
changed++;
9090
}
9191
count++;

0 commit comments

Comments
 (0)