scripted-diff: normalize CCoinsView naming

Standardize coins view naming with a mechanical rename pass.
This keeps subsequent commits focused on the interface and behavioral changes.

Co-authored-by: Andrew Toth <andrewstoth@gmail.com>

-BEGIN VERIFY SCRIPT-
git grep -qE '\bin_base\b|\bin_view\b|\bin_block_hash\b|\bblock_hash\b' -- src/coins.cpp src/coins.h src/txdb.cpp src/txdb.h src/test/coins_tests.cpp && { echo "Error: target names already exist in scoped files"; exit 1; }

perl -pi -e '
  s/\bbaseIn\b/in_base/g;
  s/\bhashBlockIn\b/in_block_hash/g;
  s/\bhashBlock\b/block_hash/g;
  s/\bviewIn\b/in_view/g;
  ' src/coins.cpp src/coins.h src/txdb.cpp src/txdb.h src/test/coins_tests.cpp
-END VERIFY SCRIPT-
This commit is contained in:
Lőrinc
2026-02-15 15:24:53 +01:00
parent 06172ef0d5
commit 38a99f3344
5 changed files with 35 additions and 35 deletions

View File

@@ -18,7 +18,7 @@ std::optional<Coin> CCoinsView::GetCoin(const COutPoint& outpoint) const { retur
std::optional<Coin> CCoinsView::PeekCoin(const COutPoint& outpoint) const { return GetCoin(outpoint); }
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
void CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock)
void CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash)
{
for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) { }
}
@@ -30,14 +30,14 @@ bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
return GetCoin(outpoint).has_value();
}
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *in_view) : base(in_view) { }
std::optional<Coin> CCoinsViewBacked::GetCoin(const COutPoint& outpoint) const { return base->GetCoin(outpoint); }
std::optional<Coin> CCoinsViewBacked::PeekCoin(const COutPoint& outpoint) const { return base->PeekCoin(outpoint); }
bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
void CCoinsViewBacked::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) { base->BatchWrite(cursor, hashBlock); }
void CCoinsViewBacked::SetBackend(CCoinsView &in_view) { base = &in_view; }
void CCoinsViewBacked::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) { base->BatchWrite(cursor, block_hash); }
std::unique_ptr<CCoinsViewCursor> CCoinsViewBacked::Cursor() const { return base->Cursor(); }
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
@@ -49,8 +49,8 @@ std::optional<Coin> CCoinsViewCache::PeekCoin(const COutPoint& outpoint) const
return base->PeekCoin(outpoint);
}
CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn, bool deterministic) :
CCoinsViewBacked(baseIn), m_deterministic(deterministic),
CCoinsViewCache::CCoinsViewCache(CCoinsView* in_base, bool deterministic) :
CCoinsViewBacked(in_base), m_deterministic(deterministic),
cacheCoins(0, SaltedOutpointHasher(/*deterministic=*/deterministic), CCoinsMap::key_equal{}, &m_cache_coins_memory_resource)
{
m_sentinel.second.SelfRef(m_sentinel);
@@ -201,11 +201,11 @@ uint256 CCoinsViewCache::GetBestBlock() const {
return m_block_hash;
}
void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
m_block_hash = hashBlockIn;
void CCoinsViewCache::SetBestBlock(const uint256 &in_block_hash) {
m_block_hash = in_block_hash;
}
void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlockIn)
void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& in_block_hash)
{
for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) {
if (!it->second.IsDirty()) { // TODO a cursor can only contain dirty entries
@@ -273,7 +273,7 @@ void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& ha
}
}
}
SetBestBlock(hashBlockIn);
SetBestBlock(in_block_hash);
}
void CCoinsViewCache::Flush(bool reallocate_cache)

View File

@@ -229,7 +229,7 @@ using CCoinsMapMemoryResource = CCoinsMap::allocator_type::ResourceType;
class CCoinsViewCursor
{
public:
CCoinsViewCursor(const uint256 &hashBlockIn): hashBlock(hashBlockIn) {}
CCoinsViewCursor(const uint256 &in_block_hash): block_hash(in_block_hash) {}
virtual ~CCoinsViewCursor() = default;
virtual bool GetKey(COutPoint &key) const = 0;
@@ -239,9 +239,9 @@ public:
virtual void Next() = 0;
//! Get best block at the time this cursor was created
const uint256 &GetBestBlock() const { return hashBlock; }
const uint256 &GetBestBlock() const { return block_hash; }
private:
uint256 hashBlock;
uint256 block_hash;
};
/**
@@ -330,7 +330,7 @@ public:
//! Do a bulk modification (multiple Coin changes + BestBlock change).
//! The passed cursor is used to iterate through the coins.
virtual void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock);
virtual void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash);
//! Get a cursor to iterate over the whole state
virtual std::unique_ptr<CCoinsViewCursor> Cursor() const;
@@ -350,14 +350,14 @@ protected:
CCoinsView *base;
public:
CCoinsViewBacked(CCoinsView *viewIn);
CCoinsViewBacked(CCoinsView *in_view);
std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;
bool HaveCoin(const COutPoint &outpoint) const override;
uint256 GetBestBlock() const override;
std::vector<uint256> GetHeadBlocks() const override;
void SetBackend(CCoinsView &viewIn);
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
void SetBackend(CCoinsView &in_view);
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override;
std::unique_ptr<CCoinsViewCursor> Cursor() const override;
size_t EstimateSize() const override;
};
@@ -395,7 +395,7 @@ protected:
virtual std::optional<Coin> FetchCoinFromBase(const COutPoint& outpoint) const;
public:
CCoinsViewCache(CCoinsView *baseIn, bool deterministic = false);
CCoinsViewCache(CCoinsView *in_base, bool deterministic = false);
/**
* By deleting the copy constructor, we prevent accidentally using it when one intends to create a cache on top of a base cache.
@@ -407,8 +407,8 @@ public:
std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;
bool HaveCoin(const COutPoint &outpoint) const override;
uint256 GetBestBlock() const override;
void SetBestBlock(const uint256 &hashBlock);
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
void SetBestBlock(const uint256 &block_hash);
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override;
std::unique_ptr<CCoinsViewCursor> Cursor() const override {
throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
}

View File

@@ -55,7 +55,7 @@ public:
uint256 GetBestBlock() const override { return hashBestBlock_; }
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override
{
for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)){
if (it->second.IsDirty()) {
@@ -67,8 +67,8 @@ public:
}
}
}
if (!hashBlock.IsNull())
hashBestBlock_ = hashBlock;
if (!block_hash.IsNull())
hashBestBlock_ = block_hash;
}
};
@@ -910,7 +910,7 @@ void TestFlushBehavior(
for (auto i = all_caches.rbegin(); i != all_caches.rend(); ++i) {
auto& cache = *i;
cache->SanityCheck();
// hashBlock must be filled before flushing to disk; value is
// block_hash must be filled before flushing to disk; value is
// unimportant here. This is normally done during connect/disconnect block.
cache->SetBestBlock(m_rng.rand256());
erase ? cache->Flush() : cache->Sync();

View File

@@ -97,22 +97,22 @@ std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const {
return vhashHeadBlocks;
}
void CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock)
void CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash)
{
CDBBatch batch(*m_db);
size_t count = 0;
const size_t dirty_count{cursor.GetDirtyCount()};
assert(!hashBlock.IsNull());
assert(!block_hash.IsNull());
uint256 old_tip = GetBestBlock();
if (old_tip.IsNull()) {
// We may be in the middle of replaying.
std::vector<uint256> old_heads = GetHeadBlocks();
if (old_heads.size() == 2) {
if (old_heads[0] != hashBlock) {
if (old_heads[0] != block_hash) {
LogError("The coins database detected an inconsistent state, likely due to a previous crash or shutdown. You will need to restart bitcoind with the -reindex-chainstate or -reindex configuration option.\n");
}
assert(old_heads[0] == hashBlock);
assert(old_heads[0] == block_hash);
old_tip = old_heads[1];
}
}
@@ -122,11 +122,11 @@ void CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashB
dirty_count, cursor.GetTotalCount()), BCLog::BENCH);
// In the first batch, mark the database as being in the middle of a
// transition from old_tip to hashBlock.
// transition from old_tip to block_hash.
// A vector is used for future extensibility, as we may want to support
// interrupting after partial writes from multiple independent reorgs.
batch.Erase(DB_BEST_BLOCK);
batch.Write(DB_HEAD_BLOCKS, Vector(hashBlock, old_tip));
batch.Write(DB_HEAD_BLOCKS, Vector(block_hash, old_tip));
for (auto it{cursor.Begin()}; it != cursor.End();) {
if (it->second.IsDirty()) {
@@ -154,9 +154,9 @@ void CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashB
}
}
// In the last batch, mark the database as consistent with hashBlock again.
// In the last batch, mark the database as consistent with block_hash again.
batch.Erase(DB_HEAD_BLOCKS);
batch.Write(DB_BEST_BLOCK, hashBlock);
batch.Write(DB_BEST_BLOCK, block_hash);
LogDebug(BCLog::COINDB, "Writing final batch of %.2f MiB\n", batch.ApproximateSize() * (1.0 / 1048576.0));
m_db->WriteBatch(batch);
@@ -174,8 +174,8 @@ class CCoinsViewDBCursor: public CCoinsViewCursor
public:
// Prefer using CCoinsViewDB::Cursor() since we want to perform some
// cache warmup on instantiation.
CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&hashBlockIn):
CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {}
CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&in_block_hash):
CCoinsViewCursor(in_block_hash), pcursor(pcursorIn) {}
~CCoinsViewDBCursor() = default;
bool GetKey(COutPoint &key) const override;

View File

@@ -44,7 +44,7 @@ public:
bool HaveCoin(const COutPoint &outpoint) const override;
uint256 GetBestBlock() const override;
std::vector<uint256> GetHeadBlocks() const override;
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override;
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override;
std::unique_ptr<CCoinsViewCursor> Cursor() const override;
//! Whether an unsupported database format is used.