Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Mar 14, 2015

This adds a -checkblockindex (defaulting to true for regtest), which occasionally does a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive, and mapBlocksUnlinked.

@sipa sipa force-pushed the checkblockindex branch from 3a72aec to 1190449 Compare March 14, 2015 17:57
@sipa sipa force-pushed the checkblockindex branch 4 times, most recently from 070b25f to 2a8bb41 Compare March 26, 2015 00:06
This adds a -checkblockindex (defaulting to true for regtest), which occasionally
does a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive, and
mapBlocksUnlinked.
@sipa sipa force-pushed the checkblockindex branch from 2a8bb41 to 3fcfbc8 Compare March 27, 2015 20:39
@sipa
Copy link
Member Author

sipa commented Mar 27, 2015

Ready for review.

Ping @morcos.

@laanwj
Copy link
Member

laanwj commented Mar 30, 2015

I wanted to do a full sync with this enabled, but the extra checking is slow, even at the lower blocks it takes about a second per block (executing the test twice, sometimes it happens more often);

2015-03-30 10:51:32 Checked block index in 645ms
2015-03-30 10:51:32 Checked block index in 565ms
2015-03-30 10:51:32 UpdateTip: new best=00000000bc55e94d87fc6f2565abb2b781cf0b588b2c65f5fcb91e38a69ec93e  height=8189  log2_work=44.99967  tx=8273  date=2009-03-21 01:25:02 progress=0.000058  cache=23
2015-03-30 10:51:33 Checked block index in 647ms
2015-03-30 10:51:34 Checked block index in 565ms
2015-03-30 10:51:34 UpdateTip: new best=000000002136a553f9bf7ba9979781548453aaf836e275febf273cc1c67dd3fe  height=8190  log2_work=44.999846  tx=8274  date=2009-03-21 01:27:49 progress=0.000058  cache=24
2015-03-30 10:51:34 Checked block index in 665ms
2015-03-30 10:51:35 Checked block index in 576ms
2015-03-30 10:51:35 UpdateTip: new best=000000007b8668d5592a7121834c43237d7cfd28104f6276eebedab94901ff66  height=8191  log2_work=45.000022  tx=8275  date=2009-03-21 01:43:09 progress=0.000058  cache=25
2015-03-30 10:51:36 Checked block index in 653ms

Not a huge issue for a hidden troubleshooting option, though enabling this by default on regtest could slow down the RPC tests.

@sdaftuar
Copy link
Member

I've been looking at this in the context of #5863 and so far this code has found one bug we introduced there, in LoadBlockIndexDB (we have an incorrect test for adding things to mapBlocksUnlinked). Still working my way through to determine if this catches any other bugs.

I've also started to identify the tests/assumptions introduced in this code which would need to change to support autoprune, would it be helpful to discuss those here?

@sipa
Copy link
Member Author

sipa commented Apr 1, 2015

@laanwj A full sync is probably not very interesting, as it's mostly a single linear synchronization run.

We could perhaps have -checkblockindex=[float] to only run the test with the specified frequency, or have it only check blocks with height above a certain number or not in the main chain.

@laanwj
Copy link
Member

laanwj commented Apr 1, 2015

@sipa OK, I don't think that needs to be changed, likely this is based on a misunderstanding. I was assuming it was just another level of checking that can be enabled relatively innocuously during normal use, but it has too much impact for that.

Could use a little bit of documentation (maybe in -help-debug?) about when and how to use this mode.

CBlockIndex* pindexFirstNotTreeValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_TREE (regardless of being valid or not).
CBlockIndex* pindexFirstNotChainValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_CHAIN (regardless of being valid or not).
CBlockIndex* pindexFirstNotScriptsValid = NULL; // Oldest ancestor of pindex which does not have BLOCK_VALID_SCRIPTS (regardless of being valid or not).
while (pindex != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like there aren't any explicit consistency checks for BLOCK_VALID_TRANSACTIONS. As I understand it there are two properties:

  • BLOCK_VALID_TRANSACTIONS implies all parents are at least TREE. We get this test implicitly since we already check that for everything TREE or greater, all its parents are at least TREE, so I don't think an additional test is needed for this condition.
  • If pindex and all parents are at least BLOCK_VALID_TRANSACTIONS then nChainTx is set. I don't believe this consistency check is performed anywhere -- seems like this is worth adding? I think right now the only check on nChainTx is based on whether pindexFirstMissing is set (a few lines down).

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds correct to me. Feel free to PR an extra check for this?

Copy link
Member

Choose a reason for hiding this comment

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

Yep -- please see #5959

@laanwj laanwj merged commit 3fcfbc8 into bitcoin:master Apr 1, 2015
laanwj added a commit that referenced this pull request Apr 1, 2015
3fcfbc8 Add a consistency check for the block chain data structures (Pieter Wuille)
laanwj added a commit that referenced this pull request Apr 1, 2015
a1f425b Add a consistency check for the block chain data structures (Pieter Wuille)

This is a port of #5900 to 0.10.

Github-Pull: #5900
laanwj added a commit that referenced this pull request Apr 1, 2015
@morcos
Copy link
Contributor

morcos commented Apr 2, 2015

Belated ACK

dexX7 added a commit to dexX7/bitcoin that referenced this pull request Apr 27, 2015
d8ac901 doc: improve credits in release notes (Gregory Maxwell)
bf8ad0d update release notes for 0.10.1rc3 (Wladimir J. van der Laan)
139cd81 Cap nAttempts penalty at 8 and switch to pow instead of a division loop. (Gregory Maxwell)
bac6fca Set nSequenceId when a block is fully linked (Suhas Daftuar)
323de27 Initialization: setup environment before starting QT tests (dexX7)
7494e09 Initialization: setup environment before starting tests (dexX7)
df45564 Initialization: set fallback locale as environment variable (dexX7)
57d1f46 Fix CheckBlockIndex for reindex. (mrbandrews)
eae305f Fix missing lock in submitblock (Matt Corallo)
34127c7 doc: update release notes pre rc2 (Wladimir J. van der Laan)
1c62e84 Keep mempool consistent during block-reorgs (Gavin Andresen)
149c1d8 doc: Credit Jonas Nick in release notes (Wladimir J. van der Laan)
bf1cc80 Docs: Use new Bitcoin.org download URLs (David A. Harding)
9e1cc16 doc: add historical release notes for 0.10.0 (Wladimir J. van der Laan)
fe31225 update release notes for bitcoin#5953/bitcoin#5900 (Wladimir J. van der Laan)
a1f425b Add a consistency check for the block chain data structures (Pieter Wuille)
ae1479a update release notes after bitcoin#5941 (Wladimir J. van der Laan)
aa587d4 Scale up addrman (Pieter Wuille)
0c6f334 Always use a 50% chance to choose between tried and new entries (Pieter Wuille)
214154e Do not bias outgoing connections towards fresh addresses (Pieter Wuille)
2218d4b Simplify hashing code (Pieter Wuille)
cf0218f Make addrman's bucket placement deterministic. (Pieter Wuille)
b788994 Switch addrman key from vector to uint256 (Pieter Wuille)
90bef66 No notable changes for minor release (Wladimir J. van der Laan)
4635a4c Translations update from transifex (Wladimir J. van der Laan)
0eccf0a Add commits (up to now) to release notes (Wladimir J. van der Laan)
78f64ef don't trickle for whitelisted nodes (Ruben de Vries)
a316622 Clean out release notes for 0.10.1 (Wladimir J. van der Laan)
dexX7 added a commit to OmniLayer/omnicore that referenced this pull request May 16, 2015
16f4560 doc: small amandment to release notes (Wladimir J. van der Laan)
ff32503 Release notes 0.10.2 (Wladimir J. van der Laan)
da65606 Avoid crash on start in TestBlockValidity with gen=1. (Gregory Maxwell)
49e4d14 Translations update (Wladimir J. van der Laan)
d7e7727 Preparations for 0.10.2 release (Wladimir J. van der Laan)
424ae66 don't imbue boost::filesystem::path with locale "C" on windows (Jonas Schnelli)
824c011 wallet: fix boost::get usage with boost 1.58 (Cory Fields)
ebc0e41 qt: translation update for next 0.10 point release (Wladimir J. van der Laan)
d8ac901 doc: improve credits in release notes (Gregory Maxwell)
bf8ad0d update release notes for 0.10.1rc3 (Wladimir J. van der Laan)
139cd81 Cap nAttempts penalty at 8 and switch to pow instead of a division loop. (Gregory Maxwell)
bac6fca Set nSequenceId when a block is fully linked (Suhas Daftuar)
323de27 Initialization: setup environment before starting QT tests (dexX7)
7494e09 Initialization: setup environment before starting tests (dexX7)
df45564 Initialization: set fallback locale as environment variable (dexX7)
57d1f46 Fix CheckBlockIndex for reindex. (mrbandrews)
eae305f Fix missing lock in submitblock (Matt Corallo)
34127c7 doc: update release notes pre rc2 (Wladimir J. van der Laan)
1c62e84 Keep mempool consistent during block-reorgs (Gavin Andresen)
149c1d8 doc: Credit Jonas Nick in release notes (Wladimir J. van der Laan)
bf1cc80 Docs: Use new Bitcoin.org download URLs (David A. Harding)
9e1cc16 doc: add historical release notes for 0.10.0 (Wladimir J. van der Laan)
fe31225 update release notes for bitcoin#5953/bitcoin#5900 (Wladimir J. van der Laan)
a1f425b Add a consistency check for the block chain data structures (Pieter Wuille)
ae1479a update release notes after bitcoin#5941 (Wladimir J. van der Laan)
aa587d4 Scale up addrman (Pieter Wuille)
0c6f334 Always use a 50% chance to choose between tried and new entries (Pieter Wuille)
214154e Do not bias outgoing connections towards fresh addresses (Pieter Wuille)
2218d4b Simplify hashing code (Pieter Wuille)
cf0218f Make addrman's bucket placement deterministic. (Pieter Wuille)
b788994 Switch addrman key from vector to uint256 (Pieter Wuille)
90bef66 No notable changes for minor release (Wladimir J. van der Laan)
4635a4c Translations update from transifex (Wladimir J. van der Laan)
0eccf0a Add commits (up to now) to release notes (Wladimir J. van der Laan)
78f64ef don't trickle for whitelisted nodes (Ruben de Vries)
a316622 Clean out release notes for 0.10.1 (Wladimir J. van der Laan)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants