diff --git a/src/coins.cpp b/src/coins.cpp index 5104b558f0d..444516ea3dc 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -18,7 +18,7 @@ std::optional CCoinsView::GetCoin(const COutPoint& outpoint) const { retur std::optional CCoinsView::PeekCoin(const COutPoint& outpoint) const { return GetCoin(outpoint); } uint256 CCoinsView::GetBestBlock() const { return uint256(); } std::vector CCoinsView::GetHeadBlocks() const { return std::vector(); } -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 CCoinsViewBacked::GetCoin(const COutPoint& outpoint) const { return base->GetCoin(outpoint); } std::optional 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 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 CCoinsViewBacked::Cursor() const { return base->Cursor(); } size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); } @@ -49,8 +49,8 @@ std::optional 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) diff --git a/src/coins.h b/src/coins.h index c0bf3c5a174..6cbcb5c9507 100644 --- a/src/coins.h +++ b/src/coins.h @@ -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 Cursor() const; @@ -350,14 +350,14 @@ protected: CCoinsView *base; public: - CCoinsViewBacked(CCoinsView *viewIn); + CCoinsViewBacked(CCoinsView *in_view); std::optional GetCoin(const COutPoint& outpoint) const override; std::optional PeekCoin(const COutPoint& outpoint) const override; bool HaveCoin(const COutPoint &outpoint) const override; uint256 GetBestBlock() const override; std::vector 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 Cursor() const override; size_t EstimateSize() const override; }; @@ -395,7 +395,7 @@ protected: virtual std::optional 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 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 Cursor() const override { throw std::logic_error("CCoinsViewCache cursor iteration not supported."); } diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 8321bf6a18c..f8de7f5d3af 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -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(); diff --git a/src/txdb.cpp b/src/txdb.cpp index 2c39cf2767b..b7f9fdf1bb2 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -97,22 +97,22 @@ std::vector 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 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; diff --git a/src/txdb.h b/src/txdb.h index 248fe43e559..b8c06c2e3e0 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -44,7 +44,7 @@ public: bool HaveCoin(const COutPoint &outpoint) const override; uint256 GetBestBlock() const override; std::vector GetHeadBlocks() const override; - void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) override; + void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override; std::unique_ptr Cursor() const override; //! Whether an unsupported database format is used.