BlockManager::AddToBlockIndex only replaces best_header when the new header has strictly more chain work. Add a unit test that adds two sibling headers with equal work and checks that best_header keeps pointing to the first one.
Kills the following mutant (https://mutanthub.space/mutants/3806):
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 2ee13aa417..aad52d6d61 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -246,7 +246,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockInde
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
- if (best_header == nullptr || best_header->nChainWork < pindexNew->nChainWork) {
+ if (best_header == nullptr || best_header->nChainWork <= pindexNew->nChainWork) {
best_header = pindexNew;
}