refactor: inline `CCoinsViewBacked` implementation
What changed, and why it matters
This commit is a straightforward code cleanup: it moves the implementation of a simple wrapper class (CCoinsViewBacked) from a .cpp file into the header file as inline functions. There is no change to what the code does, only where the code is written. It does not fix or introduce any security issue.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch inlines CCoinsViewBacked’s constructor and delegating overrides in src/coins.h and removes their out-of-line definitions from src/coins.cpp. The constructor now uses explicit and Assert(in_view), but the effective behavior is unchanged: previously base was initialized from in_view unconditionally, and now it is initialized after asserting in_view is non-null. All methods remain pure delegates to base. This is a refactor with no functional or security change.
Changed components
src/coins.hsrc/coins.cppInspect captured patch +12 / −21
diff --git a/src/coins.cpp b/src/coins.cpp
index 2eadfde9..c403e006 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -14,17 +14,6 @@ TRACEPOINT_SEMAPHORE(utxocache, add);
TRACEPOINT_SEMAPHORE(utxocache, spent);
TRACEPOINT_SEMAPHORE(utxocache, uncache);
-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& 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(); }
-
CoinsViewEmpty& CoinsViewEmpty::Get()
{
static CoinsViewEmpty instance;
diff --git a/src/coins.h b/src/coins.h
index c18f7e10..e1f1bee7 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -374,16 +374,18 @@ protected:
CCoinsView* base;
public:
- 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& in_view);
- void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override;
- std::unique_ptr<CCoinsViewCursor> Cursor() const override;
- size_t EstimateSize() const override;
+ explicit CCoinsViewBacked(CCoinsView* in_view) : base{Assert(in_view)} {}
+
+ void SetBackend(CCoinsView& in_view) { base = &in_view; }
+
+ std::optional<Coin> GetCoin(const COutPoint& outpoint) const override { return base->GetCoin(outpoint); }
+ std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override { return base->PeekCoin(outpoint); }
+ bool HaveCoin(const COutPoint& outpoint) const override { return base->HaveCoin(outpoint); }
+ uint256 GetBestBlock() const override { return base->GetBestBlock(); }
+ std::vector<uint256> GetHeadBlocks() const override { return base->GetHeadBlocks(); }
+ void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override { base->BatchWrite(cursor, block_hash); }
+ std::unique_ptr<CCoinsViewCursor> Cursor() const override { return base->Cursor(); }
+ size_t EstimateSize() const override { return base->EstimateSize(); }
};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.