Page MenuHomePhabricator

Move CheckBlockIndex() from Chainstate to ChainstateManager
ClosedPublic

Authored by PiRK on Wed, Jan 15, 11:00.

Details

Summary

Also rewrite CheckBlockIndex() to perform tests on all chainstates.

This increases sanity-check coverage, as any place in our code where we were
invoke CheckBlockIndex() on a single chainstate will now invoke the sanity
checks on all chainstates.

This change also tightens up the checks on setBlockIndexCandidates and
mapBlocksUnlinked, to more precisely match what we aim for even in the presence
of assumed-valid blocks.

This is a partial backport of core#27746
https://github.com/bitcoin/bitcoin/pull/27746/commits/3556b850221bc0e597d7dd749d4d47ab58dc8083

Depends on D17536

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Wed, Jan 15, 11:00
PiRK planned changes to this revision.Wed, Jan 15, 11:11

needs a rebase

Tail of the build log:

                                  ^
1 error generated.
[443/579] Building CXX object src/test/CMakeFiles/testutil.dir/util/mining.cpp.o
FAILED: src/test/CMakeFiles/testutil.dir/util/mining.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/test/CMakeFiles/testutil.dir/util/mining.cpp.o -MF src/test/CMakeFiles/testutil.dir/util/mining.cpp.o.d -o src/test/CMakeFiles/testutil.dir/util/mining.cpp.o -c /work/src/test/util/mining.cpp
In file included from /work/src/test/util/mining.cpp:12:
In file included from /work/src/./net.h:11:
In file included from /work/src/./avalanche/proofradixtreeadapter.h:8:
In file included from /work/src/./avalanche/proof.h:16:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[444/579] Building CXX object src/test/CMakeFiles/testutil.dir/util/txmempool.cpp.o
FAILED: src/test/CMakeFiles/testutil.dir/util/txmempool.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/test/CMakeFiles/testutil.dir/util/txmempool.cpp.o -MF src/test/CMakeFiles/testutil.dir/util/txmempool.cpp.o.d -o src/test/CMakeFiles/testutil.dir/util/txmempool.cpp.o -c /work/src/test/util/txmempool.cpp
In file included from /work/src/test/util/txmempool.cpp:9:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[445/579] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
FAILED: src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o -MF src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o.d -o src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o -c /work/src/test/util/setup_common.cpp
In file included from /work/src/test/util/setup_common.cpp:23:
In file included from /work/src/./net.h:11:
In file included from /work/src/./avalanche/proofradixtreeadapter.h:8:
In file included from /work/src/./avalanche/proof.h:16:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[446/579] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o
FAILED: src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o -MF src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o.d -o src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o -c /work/src/seeder/bitcoin.cpp
In file included from /work/src/seeder/bitcoin.cpp:11:
In file included from /work/src/./net_processing.h:10:
In file included from /work/src/./net.h:11:
In file included from /work/src/./avalanche/proofradixtreeadapter.h:8:
In file included from /work/src/./avalanche/proof.h:16:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[447/579] Building CXX object src/CMakeFiles/server.dir/wallet/init.cpp.o
FAILED: src/CMakeFiles/server.dir/wallet/init.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/leveldb/helpers/memenv -I/work/src/. -I/work/abc-ci-builds/build-clang/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/wallet/init.cpp.o -MF src/CMakeFiles/server.dir/wallet/init.cpp.o.d -o src/CMakeFiles/server.dir/wallet/init.cpp.o -c /work/src/wallet/init.cpp
In file included from /work/src/wallet/init.cpp:12:
In file included from /work/src/./net.h:11:
In file included from /work/src/./avalanche/proofradixtreeadapter.h:8:
In file included from /work/src/./avalanche/proof.h:16:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[448/579] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/backup.cpp.o
[449/579] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[450/579] Linking CXX static library src/wallet/libwallet.a
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

Tail of the build log:

/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex' [clang-diagnostic-error]
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
2098 warnings and 1 error generated.
Error while processing /work/src/test/util/validation.cpp.
Suppressed 2098 warnings (2098 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
[420/577] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
FAILED: src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o 
/usr/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache --tidy="/usr/bin/clang-tidy-16;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/work/src/test/util/setup_common.cpp -- /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang-tidy/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang-tidy/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o -MF src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o.d -o src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o -c /work/src/test/util/setup_common.cpp
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex' [clang-diagnostic-error]
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
2137 warnings and 1 error generated.
Error while processing /work/src/test/util/setup_common.cpp.
Suppressed 2137 warnings (2137 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
[421/577] Building CXX object src/test/CMakeFiles/testutil.dir/util/wallet.cpp.o
[422/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/sqlite.cpp.o
[423/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/fees.cpp.o
[424/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/transaction.cpp.o
[425/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/signmessage.cpp.o
[426/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/load.cpp.o
[427/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/encrypt.cpp.o
[428/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/salvage.cpp.o
[429/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/util.cpp.o
[430/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/receive.cpp.o
[431/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/dns.cpp.o
[432/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/interfaces.cpp.o
[433/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/spend.cpp.o
[434/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/scriptpubkeyman.cpp.o
[435/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
[436/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletutil.cpp.o
[437/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/db.cpp.o
[438/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/options.cpp.o
[439/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana_interpreter.cpp.o
[440/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana_formatter.cpp.o
[441/577] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[442/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana.cpp.o
[443/577] Linking CXX executable src/iguana/iguana
[444/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[445/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o
FAILED: src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o 
/usr/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache --tidy="/usr/bin/clang-tidy-16;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/work/src/seeder/bitcoin.cpp -- /usr/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_NO_CXX98_FUNCTION_BASE -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I/work/src/. -I/work/abc-ci-builds/build-clang-tidy/src -I/work/src/univalue/include -I/work/abc-ci-builds/build-clang-tidy/src/crypto/.. -I/work/src/secp256k1/include -I/work/src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -std=gnu++17 -MD -MT src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o -MF src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o.d -o src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o -c /work/src/seeder/bitcoin.cpp
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex' [clang-diagnostic-error]
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
2098 warnings and 1 error generated.
Error while processing /work/src/seeder/bitcoin.cpp.
Suppressed 2098 warnings (2098 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
[446/577] Building CXX object src/wallet/CMakeFiles/wallet-tool.dir/wallettool.cpp.o
[447/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/backup.cpp.o
[448/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[449/577] Linking CXX static library src/wallet/libwallet.a
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang-tidy failed with exit code 1
This revision is now accepted and ready to land.Wed, Jan 15, 22:02