Codebase has C++ ODR violations in `net_processing.cpp`
The codebase has ODR (one-definition rule) violations in net_processing.cpp
. The issue is that the mapOrphanTransactions
is not declared exactly the same in denialofservice_tests.cpp
versus internally in net_processing.cpp
.
This is a code smell -- this data structure, and the functions that denialofservice_tests.cpp
imports, should be declared in 1 place -- net_processing.h
.
Note this isn't just some computer science abstract thing -- these ODR violations can lead to subtle bugs in the tests and also strict aliasing violations (and crashes). Note that on Fedora 33 Bitcoin Cash Node v22.1.0 fails to build for x86_64 with a compiler error. On Fedora 32 aarch64 the compiler actually produces invalid ASM (this probably triggers a compiler regression), and the assembler complains. This is a fairly important issue.
I am preparing a fix for this; but this is the issue on GCC 10.2.1 when building the FC-33 .src.rpm
:
../src/test/denialofservice_tests.cpp:55:5: warning: 'mapOrphanTransactions' violates the C++ One Definition Rule [-Wodr]
55 | mapOrphanTransactions GUARDED_BY(g_cs_orphans);
| ^
/usr/include/c++/10/bits/stl_map.h:100:11: note: type name 'std::map<TxId, COrphanTx, std::less<TxId>, std::allocator<std::pair<TxId const, COrphanTx> > >' should match type name 'std::map<uint256, COrphanTx, std::less<uint256>, std::allocator<std::pair<uint256 const, COrphanTx> > >'
100 | class map
| ^
../src/net_processing.cpp:132:27: note: 'mapOrphanTransactions' was previously declared here
132 | std::map<TxId, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
| ^
../src/net_processing.cpp:132:27: note: code may be misoptimized unless '-fno-strict-aliasing' is used
ninja: build stopped: subcommand failed.
error: Bad exit status from /var/tmp/rpm-tmp.bDAzEY (%check)
RPM build errors:
user mockbuild does not exist - using root
group mock does not exist - using root
user mockbuild does not exist - using root
group mock does not exist - using root
user mockbuild does not exist - using root
group mock does not exist - using root
user mockbuild does not exist - using root
group mock does not exist - using root
Bad exit status from /var/tmp/rpm-tmp.bDAzEY (%check)