Skip to content

Conversation

jamesob
Copy link
Contributor

@jamesob jamesob commented Mar 24, 2021

This is part of the assumeutxo project (parent PR: #15606)


Pretty cut and dry; parameterizes CVerifyDB methods so that we can run the verify procedure on multiple chainstates.

Two minor tweaks to ensure that VerifyDB can be run on multiple chainstates and a corresponding rename.

@jamesob jamesob force-pushed the 2021-03-au-verifydb branch from d758ad1 to cd93f82 Compare March 24, 2021 16:33
@jamesob
Copy link
Contributor Author

jamesob commented Mar 24, 2021

I guess after rebasing on top of 2bdf37f, most of this is just a name change. But there are still a few changes of substance and the rename is probably worth doing.

@jamesob jamesob changed the title validation: parameterize VerifyDB by chainstate validation: run VerifyDB on all chainstates Mar 24, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 24, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK cd93f82. This seems safe and straightforward. I think it would be good to put the renames in a separate commit from the two more substantive changes, but it's not very important.

re: #21523 (comment)

Two minor tweaks to ensure that VerifyDB can be run on multiple chainstates and a corresponding rename.

IIUC the two tweaks are:

  • Updating AppInitMain to call VerifyDB on all chainstates, not just the active one
  • Tweaking VerifyDB to treat a snapshot chainstate like a pruned chainstate and not fail trying to read missing blocks

And everything else is cleanups and renames

break;
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
if ((fPruneMode || g_chainman.IsSnapshotActive()) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "validation: parameterize VerifyDB by chainstate" (cd93f82)

Could comment below be updated to explain the g_chainman check?

Also could logprint below be updated to not mention pruning if block isn't pruned?

Also it would seem more direct and less likely to hide errors to check here if chainstate specifically is an unvalidated snapshot, instead of checking if there is just any snapshot. This would avoid hiding legitimate errors if the background chainstate is missing blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would avoid hiding legitimate errors if the background chainstate is missing blocks.

Good catch! Fixed.

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK cd93f82

But I agree with @ryanofsky that the comment and log message look like they should be updated as mentioned in #21523 (comment).

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK cd93f82

I agree with other reviewers, would be better to split in its own commit renaming.

@jamesob jamesob force-pushed the 2021-03-au-verifydb branch 3 times, most recently from 54584a6 to c47a00d Compare April 13, 2021 14:50
@jamesob
Copy link
Contributor Author

jamesob commented Apr 13, 2021

Thanks for the reviews so far @ryanofsky @fjahr @ariard. I've incorporated your feedback and split out the rename commit.

@ariard
Copy link

ariard commented Apr 13, 2021

Code Review ACK c47a00d

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK c47a00d with caveat that first commit currently doesn't compile, but problems are fixed after. Changes since last review: splitting commits, making the BLOCK_HAVE_DATA check a little broader so it doesn't expect blocks from the non-snapshot chainstate, dropping type cast, adding IsSnapshotActive comment

if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage() + active_chainstate.CoinsTip().DynamicMemoryUsage()) <= active_chainstate.m_coinstip_cache_size_bytes) {
int64_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage();

if (nCheckLevel >= 3 && static_cast<unsigned long>(curr_coins_usage) <= chainstate.m_coinstip_cache_size_bytes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "refactor: rename active_chainstate in VerifyDB" (de83651)

It doesn't really matter and this is fixed in the next commit, but there are three different types here: int64_t for curr_coins_usage, unsigned long for the cast, and size_t for m_coinstip_cache_size_bytes, and it would be nice to use size_t for all three from the start.

@fjahr
Copy link
Contributor

fjahr commented Apr 14, 2021

Code Review ACK c47a00d

jamesob added 3 commits April 23, 2021 15:02
To prepare VerifyDB semantics for multiple
chainstate use.
Removes assumptions of use only on the active chainstate.
@jamesob jamesob force-pushed the 2021-03-au-verifydb branch from c47a00d to 844ad0e Compare April 23, 2021 19:13
@jamesob
Copy link
Contributor Author

jamesob commented Apr 23, 2021

Rebased and fixed compilation for the first commit. Thanks for the looks all.

@fjahr
Copy link
Contributor

fjahr commented Apr 23, 2021

Code review re-ACK 844ad0e

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review ACK 844ad0e 🐥

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 844ad0eccaa1dbfefc30d19804d95d67c3d5f06d 🐥
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUicJAv9ExcrfQAEyZXbnZ9PJ6yiL++S/RdO9zGQpraFXR3geg2Jzez5Lmnj+KYr
+xHKFZVGVFTL1CdmHFivTAe8HRLMoyaGmzQDfwJl8WBm96EKVWg+Gk9gtvWp+6Pl
Qv9M2uyKuKbSCAS/dKBhPzcsK6o41Ji2zrqmc9VhaS3uWA16VxNeaRAAmf0cBymL
pOBb/EbsmgpuxeyefrTgR+bvT/jQ4t15r9TC3QBVVKH6X/bNfB0Tzb1vKv34DmX0
rtGprvutdAgmHwxnsFhyeRT9ZIrasO2/0bMWEuaH/xqbjcDLa98bf7RV/0acPvsp
HQR/iC0xXoGWa4Zj4ydrbGr18HrG9PYc6sAqxG5LQ/KIFgyUco/0PDEDpO35wYEr
3Cv7scuEEoeVBH1tzjss8dp7sCRArnSISzQMm45X9ZqjmsBjjvUtPGzkHgRh8xz/
mgfhIg/V1MNOdCRXxCLnQ8gsw98LiwTMvLXPGSbB66qUACqvBaqCS9bWpdcQByd2
AIGXoVA5
=gUOg
-----END PGP SIGNATURE-----

Timestamp of file with hash 9b4c4c61593ad7aa160c2fb769c97159e09b00e6c5ba6cc0c987f607bb34c988 -


if (nCheckLevel >= 3 && static_cast<unsigned long>(curr_coins_usage) <= chainstate.m_coinstip_cache_size_bytes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9b604c0: Maybe move this hunk to the previous commit?

@@ -4135,8 +4138,9 @@ bool CVerifyDB::VerifyDB(
uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false);
if (pindex->nHeight <= chainstate.m_chain.Height()-nCheckDepth)
break;
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
// If pruning, only go back as far as we have data.
if ((fPruneMode || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9b604c0: Wouldn't it be easier to remove the prune and snapshot condition and simply check HAVE_DATA? Performance shouldn't decrease and it would be less code, which is nice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess your goal is to treat it as error when block data is missing, but pruning is off an no snapshot is loaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - I think we want to fail here if we're lacking block data when not pruning or operating from snapshot.

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 13, 2022
Summary:
> refactor: rename active_chainstate in VerifyDB
>
> To prepare VerifyDB semantics for multiple chainstate use.

> validation: prepare VerifyDB for assumeutxo
>
> Removes assumptions of use only on the active chainstate.

> doc: IsSnapshotActive

This is a backport of [[bitcoin/bitcoin#21523 | core#21523]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11334
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants