From 02d0579581e75b6c4f9a0c01464bd253a634da45 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Tue, 1 Sep 2026 14:00:10 -0400 Subject: [PATCH] Confirm equal work forks (prioritized candidate). --- .../database/impl/query/consensus/consensus_work.ipp | 10 ++++------ include/bitcoin/database/query.hpp | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/bitcoin/database/impl/query/consensus/consensus_work.ipp b/include/bitcoin/database/impl/query/consensus/consensus_work.ipp index 09861d2f2..80e2079f0 100644 --- a/include/bitcoin/database/impl/query/consensus/consensus_work.ipp +++ b/include/bitcoin/database/impl/query/consensus/consensus_work.ipp @@ -62,7 +62,7 @@ bool CLASS::get_branch(header_states& branch, TEMPLATE bool CLASS::get_strong_branch(bool& strong, const uint256_t& branch_work, - size_t branch_point) const NOEXCEPT + size_t branch_point, bool tie) const NOEXCEPT { uint256_t work{}; for (auto height = get_top_candidate(); height > branch_point; --height) @@ -71,9 +71,8 @@ bool CLASS::get_strong_branch(bool& strong, const uint256_t& branch_work, if (!get_bits(bits, to_candidate(height))) return false; - // Not strong when candidate_work equals or exceeds branch_work. work += system::chain::header::proof(bits); - if (work >= branch_work) + if (tie ? (work > branch_work) : (work >= branch_work)) { strong = false; return true; @@ -86,7 +85,7 @@ bool CLASS::get_strong_branch(bool& strong, const uint256_t& branch_work, TEMPLATE bool CLASS::get_strong_fork(bool& strong, const uint256_t& fork_work, - size_t fork_point) const NOEXCEPT + size_t fork_point, bool tie) const NOEXCEPT { uint256_t work{}; for (auto height = get_top_confirmed(); height > fork_point; --height) @@ -95,9 +94,8 @@ bool CLASS::get_strong_fork(bool& strong, const uint256_t& fork_work, if (!get_bits(bits, to_confirmed(height))) return false; - // Not strong is confirmed work ever equals or exceeds fork_work. work += system::chain::header::proof(bits); - if (work >= fork_work) + if (tie ? (work > fork_work) : (work >= fork_work)) { strong = false; return true; diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 137b25599..689508e22 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -655,9 +655,9 @@ class query bool get_branch(header_states& branch, const hash_digest& hash) const NOEXCEPT; bool get_work(uint256_t& work, const header_states& states) const NOEXCEPT; bool get_strong_branch(bool& strong, const uint256_t& branch_work, - size_t branch_point) const NOEXCEPT; + size_t branch_point, bool tie=false) const NOEXCEPT; bool get_strong_fork(bool& strong, const uint256_t& fork_work, - size_t fork_point) const NOEXCEPT; + size_t fork_point, bool tie=false) const NOEXCEPT; /// Height indexation. /// -----------------------------------------------------------------------