Skip to content

test: add test for coins database read error handling#93

Draft
l0rinc wants to merge 1 commit intomasterfrom
detached476
Draft

test: add test for coins database read error handling#93
l0rinc wants to merge 1 commit intomasterfrom
detached476

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented Jan 13, 2026

WIP

The error was also reworded to avoid the leading repetition (see expected stderr).

### Reproducers
The test failure can be triggered manually by:
```patch
std::optional<Coin> CCoinsViewErrorCatcher::GetCoin(const COutPoint& outpoint) const
{
-    return ExecuteBackedWrapper<std::optional<Coin>>([&]() { return CCoinsViewBacked::GetCoin(outpoint); }, m_err_callbacks);
+    return CCoinsViewBacked::GetCoin(outpoint);
}
```

### Notes
Note that CCoinsViewErrorCatcher::HaveCoin failure isn't tested since it doesn't seem to be used in production code, all tests pass with:
```patch
bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint& outpoint) const
{
-    return ExecuteBackedWrapper<bool>([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
+    throw "CCoinsViewBacked::HaveCoin";
}
```

### Context:

On 64-bit systems, LevelDB uses mmap which reflects file changes immediately.
On 32-bit systems (i686, armhf), mmap is disabled (kDefaultMmapLimit=0 in leveldb/util/env_posix.cc), so LevelDB uses block cache which serves stale data.
The node must be restarted after corruption to clear the cache.

Corruption is placed at the middle to avoid LevelDB's paranoid_checks verification during database open, and -checkblocks=0 -checklevel=0 skips Bitcoin's block verification.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant