Page MenuHomePhabricator

Tighten requirements for adding elements to setBlockIndexCandidates
ClosedPublic

Authored by PiRK on Wed, Jan 15, 10:53.

Details

Summary

When using assumeutxo, we only need the background chainstate to consider
blocks that are on the chain leading to the snapshotted block.

Note that this introduces the new invariant that we can only have an assumeutxo
snapshot where the snapshotted blockhash is in our block index. Unknown block
hashes that are somehow passed in will cause assertion failures when processing
new blocks.

Includes test fixes and improvements by Andrew Chow and Fabian Jahr.

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

We also need a change from https://github.com/bitcoin/bitcoin/pull/27596/commits/49ef778158c43859946a592e11ec34fe1b93a5b6 in validation_chainstatemanager_tests to make the c2.ActivateBestChain call succesfully pass the CheckBlockIndex tests (which are more aggressive in our codebase as of D4717). Specifically, we need to have the chain tip be in c2.setBlockIndexCandidates, or else we will trigger an assertion in validation.cpp:6049 ( setBlockIndexCandidates.count(pindex) !=0)

Depends on D17533

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, 10:53
src/test/validation_chainstatemanager_tests.cpp
90–97 ↗(On Diff #52205)

Tail of the build log:

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/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.
[447/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.
[448/579] Building CXX object src/test/CMakeFiles/testutil.dir/util/validation.cpp.o
FAILED: src/test/CMakeFiles/testutil.dir/util/validation.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/validation.cpp.o -MF src/test/CMakeFiles/testutil.dir/util/validation.cpp.o.d -o src/test/CMakeFiles/testutil.dir/util/validation.cpp.o -c /work/src/test/util/validation.cpp
In file included from /work/src/test/util/validation.cpp:5:
In file included from /work/src/./test/util/validation.h:8:
/work/src/./validation.h:1449:35: error: use of undeclared identifier 'cs_avalancheFinalizedBlockIndex'
        EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
                                  ^
1 error generated.
[449/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.
[450/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.
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

Tail of the build log:

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).
[415/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/db.cpp.o
[416/577] Building CXX object src/test/CMakeFiles/testutil.dir/util/transaction_utils.cpp.o
[417/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/crypter.cpp.o
[418/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).
[419/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/coinselection.cpp.o
[420/577] Building CXX object src/CMakeFiles/server.dir/txmempool.cpp.o
[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/receive.cpp.o
[426/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/signmessage.cpp.o
[427/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/interfaces.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/scriptpubkeyman.cpp.o
[430/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/util.cpp.o
[431/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/backup.cpp.o
[432/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/dns.cpp.o
[433/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
[434/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana_formatter.cpp.o
[435/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/db.cpp.o
[436/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana_interpreter.cpp.o
[437/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/spend.cpp.o
[438/577] Building CXX object src/iguana/CMakeFiles/iguana.dir/iguana.cpp.o
[439/577] Linking CXX executable src/iguana/iguana
[440/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/load.cpp.o
[441/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).
[442/577] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/options.cpp.o
[443/577] Building CXX object src/wallet/CMakeFiles/wallet-tool.dir/wallettool.cpp.o
[444/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletutil.cpp.o
[445/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[446/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[447/577] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/encrypt.cpp.o
[448/577] Linking CXX static library src/wallet/libwallet.a
[449/577] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang-tidy failed with exit code 1
PiRK planned changes to this revision.Wed, Jan 15, 11:10

needs a rebase

This revision is now accepted and ready to land.Wed, Jan 15, 21:49