refactor: disallow setting flags in CCoinsCacheEntry constructors

No behavior change because any entries that are added in EmplaceCoinInternalDANGER
have DIRTY assigned to them after, and if they
are not inserted then they will not be
modified as before.
This prepares moving the cache entry
flags field to private access.

Co-Authored-By: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
This commit is contained in:
Andrew Toth 2024-06-28 16:41:01 -04:00
parent 8737c0cefa
commit 4e4fb4cbab
No known key found for this signature in database
GPG Key ID: 60007AFC8938B018
2 changed files with 8 additions and 6 deletions

View File

@ -108,10 +108,13 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
cachedCoinsUsage += coin.DynamicMemoryUsage();
cacheCoins.emplace(
auto [it, inserted] = cacheCoins.emplace(
std::piecewise_construct,
std::forward_as_tuple(std::move(outpoint)),
std::forward_as_tuple(std::move(coin), CCoinsCacheEntry::DIRTY));
std::forward_as_tuple(std::move(coin)));
if (inserted) {
it->second.AddFlags(CCoinsCacheEntry::DIRTY);
}
}
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {

View File

@ -104,7 +104,7 @@ public:
struct CCoinsCacheEntry
{
Coin coin; // The actual cached data.
unsigned char flags;
unsigned char flags{0};
enum Flags {
/**
@ -127,9 +127,8 @@ struct CCoinsCacheEntry
FRESH = (1 << 1),
};
CCoinsCacheEntry() : flags(0) {}
explicit CCoinsCacheEntry(Coin&& coin_) : coin(std::move(coin_)), flags(0) {}
CCoinsCacheEntry(Coin&& coin_, unsigned char flag) : coin(std::move(coin_)), flags(flag) {}
CCoinsCacheEntry() noexcept = default;
explicit CCoinsCacheEntry(Coin&& coin_) noexcept : coin(std::move(coin_)) {}
inline void AddFlags(unsigned char flags) noexcept { this->flags |= flags; }
inline void ClearFlags() noexcept