-
Notifications
You must be signed in to change notification settings - Fork 38.7k
refactor: Let CCoinsViewCache::BatchWrite return void #33866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33866. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
big concept ACK, some tests and comments likely still need updating, but can't wait for this to be finally gone, thanks for taking care of it. For the record this is a continuation of #33042:
|
6d18188 to
d1823eb
Compare
|
Updated 6d18188 -> d1823eb (batch_write_void_0 -> batch_write_void_1, compare)
|
src/coins.h
Outdated
| uint256 GetBestBlock() const override; | ||
| void SetBestBlock(const uint256 &hashBlock); | ||
| bool BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) override; | ||
| void BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this change affect the error catchers, e.g.
Line 507 in dfde31f
| * Writes do not need similar protection, as failure to write is handled by the caller. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it does, afaik a write exception through Sync or Flush is just bubbled up and then logged. But I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but aren't read and write symmetric now in that regard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmh, not sure what you are trying to say with that. What is the symmetry there? I think I am missing something, can you try and elaborate a bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment states: "shutdown on LevelDB read errors [...] Writes do not need similar protection".
So now that reads and writes both throw and don't return, do we need to adjust the error catchers - since either reads also don't need protection anymore or writes also do - if I understand the catchers' purpose...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we are changing behaviour here (though I might stand corrected still), so if a change is required to them, the error catchers would have been buggy from the beginning. I have long questioned though to how we catch the db write errors, and if it might lead to an infinite loop in some cases. The exception handling just doesn't seem very robust or thought-through to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the fundamental behavior didn't change, both read and write threw instead of returning. Can we adjust the comments at least to reflect this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also do it in a follow-up, there's enough work in this area...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed in a separate PR: https://github.com/bitcoin/bitcoin/pull/34132/files
Please resolve the comment.
d1823eb to
d35267f
Compare
|
Rebased d1823eb -> d35267f (batch_write_void_1 -> batch_write_void_2, compare)
|
andrewtoth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK d35267f
l0rinc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recreated the change locally and diffed it against the PR: only the mentioned formatting and doc changes differed.
src/coins.h
Outdated
| * to be forgotten. | ||
| * If will_reuse_cache is false, the cache will retain the same memory footprint | ||
| * after flushing and should be destroyed to deallocate. | ||
| * If false is returned, the state of this cache (and its backing view) will be undefined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment should also be updated
| * If false is returned, the state of this cache (and its backing view) will be undefined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be better if we'd mention the exception too, i.e. If an exception occurs the state of this cache (and its backing view) will be undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, I assume it's evident now that it's void - the definition of a side-effectful method
src/coins.cpp
Outdated
| uint256 CCoinsView::GetBestBlock() const { return uint256(); } | ||
| std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); } | ||
| bool CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) { return false; } | ||
| void CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the formatting was already off here. Since I think you need to push again to remove an invalid method doc, could you please reformat the modified lines as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the line break. There is also the longer HaveCoin method below it that also does put everything in one line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not the linebreak:
| void CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) | |
| void CCoinsView::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& hashBlock) |
CCoinsViewCache::BatchWrite always returns true if called from a backed cache, so just return void instead. Also return void from ::Sync and ::Flush. This allows for dropping a FatalError condition and simplifying some dead error handling code a bit. Since we now no longer exercise the "error path" when returning from `CCoinsView::BatchWrite`, make the method clear the cache instead. This should only be exercised by tests and not change production behaviour. This might slightly improve the coins_view fuzz test's ability to generate better coverage. Co-authored-by: l0rinc <[email protected]>
d35267f to
6da6f50
Compare
|
ACK 6da6f50 Thanks for taking care of this! |
|
Updated d35267f -> 6da6f50 (batch_write_void_2 -> batch_write_void_3, compare) |
|
re-ACK 6da6f50 |
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 6da6f50
Good cleanup that removes dead code and simplifies the coins cache API.
|
A few other PRs depend on this, can we get this one merged? rfm? |
|
ACK 6da6f50 |
When `CDBWrapper::Read()` fails deserialization we silently return `false`, which makes decode failures indistinguishable from missing keys. Drop the catch so deserialization errors fail fast. This is in line with other recent changes where we're not trying to recover from database failures - and to make this explicit, see: bitcoin#33866
CCoinsViewCache::BatchWrite always returns true if called from a backed cache, so just return void instead. Also return void from ::Sync and ::Flush.
This allows for dropping a FatalError condition and simplifying some dead error handling code a bit.
Since we now no longer exercise the "error path" when returning from
CCoinsView::BatchWrite, make the method clear the cache instead. This should only be exercised by tests and not change production behaviour. This might slightly improve the coins_view fuzz test's ability to generate better coverage.