What changed, and why it matters
This commit is a routine code cleanup. It removes an unused cursor-iteration method from the base coin-view interface and its empty/forwarding/throwing implementations, keeping the method only on the concrete database class that actually supports iteration. It also removes a fuzz test that only checked the now-deleted unsupported-throw path. There is no security-relevant change.
No security action required. Review as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the CCoinsView class hierarchy: CCoinsView::Cursor() pure virtual is removed, CCoinsViewBacked/CoinsViewCacheCursor empty/forwarding overrides are removed, and CCoinsViewCache’s throwing Cursor() override is removed. CCoinsViewDB::Cursor() remains as a non-virtual method. The coins_view fuzz target loses its assert for the CCoinsViewCache::Cursor() std::logic_error path. This is an API simplification with no functional or security behavior change.
Changed components
src/coins.hsrc/txdb.hsrc/test/fuzz/coins_view.cppInspect captured patch +2 / −16
diff --git a/src/coins.h b/src/coins.h
index ae7f34f4..df29c00b 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -335,9 +335,6 @@ public:
//! The passed cursor is used to iterate through the coins.
virtual void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) = 0;
- //! Get a cursor to iterate over the whole state. Implementations may return nullptr.
- virtual std::unique_ptr<CCoinsViewCursor> Cursor() const = 0;
-
//! Estimate database size
virtual size_t EstimateSize() const = 0;
};
@@ -363,7 +360,6 @@ public:
{
for (auto it{cursor.Begin()}; it != cursor.End(); it = cursor.NextAndMaybeErase(*it)) { }
}
- std::unique_ptr<CCoinsViewCursor> Cursor() const override { return {}; }
size_t EstimateSize() const override { return 0; }
};
@@ -384,7 +380,6 @@ public:
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(); }
};
@@ -435,9 +430,6 @@ public:
uint256 GetBestBlock() const 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.");
- }
/**
* Check if we have the given utxo already loaded in this cache.
diff --git a/src/test/fuzz/coins_view.cpp b/src/test/fuzz/coins_view.cpp
index 6116150e..bee42024 100644
--- a/src/test/fuzz/coins_view.cpp
+++ b/src/test/fuzz/coins_view.cpp
@@ -227,13 +227,6 @@ void TestCoinsView(FuzzedDataProvider& fuzzed_data_provider, CCoinsViewCache& co
}
{
- bool expected_code_path = false;
- try {
- (void)coins_view_cache.Cursor();
- } catch (const std::logic_error&) {
- expected_code_path = true;
- }
- assert(expected_code_path);
(void)coins_view_cache.DynamicMemoryUsage();
(void)coins_view_cache.EstimateSize();
(void)coins_view_cache.GetBestBlock();
diff --git a/src/txdb.h b/src/txdb.h
index 8d4e2cc8..87239566 100644
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -52,7 +52,8 @@ public:
uint256 GetBestBlock() const override;
std::vector<uint256> GetHeadBlocks() const override;
void BatchWrite(CoinsViewCacheCursor& cursor, const uint256& block_hash) override;
- std::unique_ptr<CCoinsViewCursor> Cursor() const override;
+ //! Get a cursor to iterate over the whole state.
+ std::unique_ptr<CCoinsViewCursor> Cursor() const;
//! Whether an unsupported database format is used.
bool NeedsUpgrade();
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.