Skip to content

Commit 73de2c1

Browse files
committed
Rename CCoinsCacheEntry::coins to coin
1 parent 119e552 commit 73de2c1

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
@@ -42,19 +42,19 @@ CCoinsMap::iterator CCoinsViewCache::FetchCoins(const COutPoint &outpoint) const
4242
if (!base->GetCoins(outpoint, tmp))
4343
return cacheCoins.end();
4444
CCoinsMap::iterator ret = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
45-
if (ret->second.coins.IsPruned()) {
45+
if (ret->second.coin.IsPruned()) {
4646
// The parent only has an empty entry for this outpoint; we can consider our
4747
// version as fresh.
4848
ret->second.flags = CCoinsCacheEntry::FRESH;
4949
}
50-
cachedCoinsUsage += ret->second.coins.DynamicMemoryUsage();
50+
cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
5151
return ret;
5252
}
5353

5454
bool CCoinsViewCache::GetCoins(const COutPoint &outpoint, Coin &coin) const {
5555
CCoinsMap::const_iterator it = FetchCoins(outpoint);
5656
if (it != cacheCoins.end()) {
57-
coin = it->second.coins;
57+
coin = it->second.coin;
5858
return true;
5959
}
6060
return false;
@@ -68,17 +68,17 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
6868
std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
6969
bool fresh = false;
7070
if (!inserted) {
71-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
71+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
7272
}
7373
if (!possible_overwrite) {
74-
if (!it->second.coins.IsPruned()) {
74+
if (!it->second.coin.IsPruned()) {
7575
throw std::logic_error("Adding new coin that replaces non-pruned entry");
7676
}
7777
fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY);
7878
}
79-
it->second.coins = std::move(coin);
79+
it->second.coin = std::move(coin);
8080
it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0);
81-
cachedCoinsUsage += it->second.coins.DynamicMemoryUsage();
81+
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
8282
}
8383

8484
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight) {
@@ -94,15 +94,15 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight) {
9494
void CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
9595
CCoinsMap::iterator it = FetchCoins(outpoint);
9696
if (it == cacheCoins.end()) return;
97-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
97+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
9898
if (moveout) {
99-
*moveout = std::move(it->second.coins);
99+
*moveout = std::move(it->second.coin);
100100
}
101101
if (it->second.flags & CCoinsCacheEntry::FRESH) {
102102
cacheCoins.erase(it);
103103
} else {
104104
it->second.flags |= CCoinsCacheEntry::DIRTY;
105-
it->second.coins.Clear();
105+
it->second.coin.Clear();
106106
}
107107
}
108108

@@ -113,13 +113,13 @@ const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
113113
if (it == cacheCoins.end()) {
114114
return coinEmpty;
115115
} else {
116-
return it->second.coins;
116+
return it->second.coin;
117117
}
118118
}
119119

120120
bool CCoinsViewCache::HaveCoins(const COutPoint &outpoint) const {
121121
CCoinsMap::const_iterator it = FetchCoins(outpoint);
122-
return (it != cacheCoins.end() && !it->second.coins.IsPruned());
122+
return (it != cacheCoins.end() && !it->second.coin.IsPruned());
123123
}
124124

125125
bool CCoinsViewCache::HaveCoinsInCache(const COutPoint &outpoint) const {
@@ -144,12 +144,12 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn
144144
if (itUs == cacheCoins.end()) {
145145
// The parent cache does not have an entry, while the child does
146146
// We can ignore it if it's both FRESH and pruned in the child
147-
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coins.IsPruned())) {
147+
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coin.IsPruned())) {
148148
// Otherwise we will need to create it in the parent
149149
// and move the data up and mark it as dirty
150150
CCoinsCacheEntry& entry = cacheCoins[it->first];
151-
entry.coins = std::move(it->second.coins);
152-
cachedCoinsUsage += entry.coins.DynamicMemoryUsage();
151+
entry.coin = std::move(it->second.coin);
152+
cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
153153
entry.flags = CCoinsCacheEntry::DIRTY;
154154
// We can mark it FRESH in the parent if it was FRESH in the child
155155
// Otherwise it might have just been flushed from the parent's cache
@@ -162,21 +162,21 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn
162162
// parent cache entry has unspent outputs. If this ever happens,
163163
// it means the FRESH flag was misapplied and there is a logic
164164
// error in the calling code.
165-
if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coins.IsPruned())
165+
if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coin.IsPruned())
166166
throw std::logic_error("FRESH flag misapplied to cache entry for base transaction with spendable outputs");
167167

168168
// Found the entry in the parent cache
169-
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coins.IsPruned()) {
169+
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coin.IsPruned()) {
170170
// The grandparent does not have an entry, and the child is
171171
// modified and being pruned. This means we can just delete
172172
// it from the parent.
173-
cachedCoinsUsage -= itUs->second.coins.DynamicMemoryUsage();
173+
cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
174174
cacheCoins.erase(itUs);
175175
} else {
176176
// A normal modification.
177-
cachedCoinsUsage -= itUs->second.coins.DynamicMemoryUsage();
178-
itUs->second.coins = std::move(it->second.coins);
179-
cachedCoinsUsage += itUs->second.coins.DynamicMemoryUsage();
177+
cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
178+
itUs->second.coin = std::move(it->second.coin);
179+
cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
180180
itUs->second.flags |= CCoinsCacheEntry::DIRTY;
181181
// NOTE: It is possible the child has a FRESH flag here in
182182
// the event the entry we found in the parent is pruned. But
@@ -204,7 +204,7 @@ void CCoinsViewCache::Uncache(const COutPoint& hash)
204204
{
205205
CCoinsMap::iterator it = cacheCoins.find(hash);
206206
if (it != cacheCoins.end() && it->second.flags == 0) {
207-
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
207+
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
208208
cacheCoins.erase(it);
209209
}
210210
}

src/coins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class SaltedOutpointHasher
103103

104104
struct CCoinsCacheEntry
105105
{
106-
Coin coins; // The actual cached data.
106+
Coin coin; // The actual cached data.
107107
unsigned char flags;
108108

109109
enum Flags {
@@ -117,7 +117,7 @@ struct CCoinsCacheEntry
117117
};
118118

119119
CCoinsCacheEntry() : flags(0) {}
120-
explicit CCoinsCacheEntry(Coin&& coin_) : coins(std::move(coin_)), flags(0) {}
120+
explicit CCoinsCacheEntry(Coin&& coin_) : coin(std::move(coin_)), flags(0) {}
121121
};
122122

123123
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() && insecure_rand() % 3 == 0) {
67+
map_[it->first] = it->second.coin;
68+
if (it->second.coin.IsPruned() && insecure_rand() % 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 += it->second.coins.DynamicMemoryUsage();
92+
ret += it->second.coin.DynamicMemoryUsage();
9393
++count;
9494
}
9595
BOOST_CHECK_EQUAL(GetCacheSize(), count);
@@ -554,10 +554,10 @@ size_t InsertCoinsMapEntry(CCoinsMap& map, CAmount value, char flags)
554554
assert(flags != NO_ENTRY);
555555
CCoinsCacheEntry entry;
556556
entry.flags = flags;
557-
SetCoinsValue(value, entry.coins);
557+
SetCoinsValue(value, entry.coin);
558558
auto inserted = map.emplace(OUTPOINT, std::move(entry));
559559
assert(inserted.second);
560-
return inserted.first->second.coins.DynamicMemoryUsage();
560+
return inserted.first->second.coin.DynamicMemoryUsage();
561561
}
562562

563563
void GetCoinsMapEntry(const CCoinsMap& map, CAmount& value, char& flags)
@@ -567,10 +567,10 @@ void GetCoinsMapEntry(const CCoinsMap& map, CAmount& value, char& flags)
567567
value = ABSENT;
568568
flags = NO_ENTRY;
569569
} else {
570-
if (it->second.coins.IsPruned()) {
570+
if (it->second.coin.IsPruned()) {
571571
value = PRUNED;
572572
} else {
573-
value = it->second.coins.out.nValue;
573+
value = it->second.coin.out.nValue;
574574
}
575575
flags = it->second.flags;
576576
assert(flags != NO_ENTRY);

src/txdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
7575
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
7676
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
7777
CoinsEntry entry(&it->first);
78-
if (it->second.coins.IsPruned())
78+
if (it->second.coin.IsPruned())
7979
batch.Erase(entry);
8080
else
81-
batch.Write(entry, it->second.coins);
81+
batch.Write(entry, it->second.coin);
8282
changed++;
8383
}
8484
count++;

0 commit comments

Comments
 (0)