From d87c192e4057cd2cc388cb829c49ccc5776226b5 Mon Sep 17 00:00:00 2001 From: Anatoly Piskunov Date: Wed, 18 Nov 2026 19:18:41 +0100 Subject: [PATCH 1/2] consensus_sim: cover the tie between two siblings at one height Every case in test_certified_sibling_switch.cpp builds at most one rival, so the ranking's tie-break (equal distinct voters, smaller block id) was never executed. That is the shape 18.11.2026 produced at scale: 27 siblings at #86227200 with the votes split 6/... and a quorum of 7, where the question was not 'which block has more votes' but 'who chooses when nobody has more'. The new case builds three siblings at one height (X head, Y and Z sharing its parent), gives Y and Z one vote each - below quorum, so the certified path cannot answer - and asserts that the rule names the SMALLER id, that an independent peer holding the same head and the same votes names the same block, and that both land on it. The losing rival stays in fork_db, so a later vote can still break the tie. Z is produced one slot after Y on purpose: in Y's own slot the block would be byte-identical (same producer, same parent, no transactions) and the tie would silently become a duplicate. --min-cases for the testnet arms 175 -> 176 (the case is inside BUILD_TESTNET). --- .github/workflows/tests.yml | 2 +- tests/consensus_sim/README.md | 2 +- .../test_certified_sibling_switch.cpp | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a358feb4ff..948a070a44 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -256,7 +256,7 @@ jobs: set -euo pipefail cd build/tests/consensus_sim # --min-cases: floor of enabled cases in a testnet build (checked before --filter). - run=(python3 ../../../tests/consensus_sim/run_parallel.py ./consensus_sim_tests -j"$(nproc)" --min-cases 175) + run=(python3 ../../../tests/consensus_sim/run_parallel.py ./consensus_sim_tests -j"$(nproc)" --min-cases 176) if [ "${{ matrix.validators }}" = "2" ]; then "${run[@]}" --filter hf16_boundary_suite,hf16_production_safety_suite,validator_committed_state_suite,canonical_progress_suite,canonical_cache_lifecycle_suite elif [ "${{ matrix.validators }}" = "4" ]; then diff --git a/tests/consensus_sim/README.md b/tests/consensus_sim/README.md index a8dbf48962..9f786af9af 100644 --- a/tests/consensus_sim/README.md +++ b/tests/consensus_sim/README.md @@ -36,7 +36,7 @@ python3 ../../../tests/consensus_sim/run_parallel.py ./consensus_sim_tests --fil ``` The case list is read from two Boost.Test listings that must agree, and CI -passes `--min-cases` (118 for a regular build, 174 with `BUILD_TESTNET=ON`) so +passes `--min-cases` (118 for a regular build, 176 with `BUILD_TESTNET=ON`) so a test file dropped from the build fails the job instead of shrinking it. Raise the floors in `.github/workflows/tests.yml` when you add cases. diff --git a/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp b/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp index 044e8f1082..47d483d6e1 100644 --- a/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp +++ b/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -526,5 +527,84 @@ BOOST_AUTO_TEST_CASE(three_nodes_converge_on_the_same_sibling_without_talking) { BOOST_CHECK(!c.db().canonical_sibling_id().valid()); } +// A TIE between two rivals, which is the one shape the cases above never build (each has exactly one +// candidate). 18.11.2026 produced 27 siblings at one height with the votes split 6/…: the ranking +// then has to choose between blocks that are equal on the only measure it has, and any answer that +// depends on delivery order would put the nodes back where they started. The rule answers with the +// smaller block id; this case pins that, and pins it on two independent peers holding the same head, +// because "each node picks the smaller id" is what makes the answer the same everywhere without talk. +BOOST_AUTO_TEST_CASE(tie_between_two_siblings_resolves_to_the_smaller_id) { + BOOST_REQUIRE_MESSAGE(CHAIN_MAX_VALIDATORS >= 4, + "PREMISE: this build caps the schedule below four identities"); + fixture f(0x71E7u); + + simulated_node c("tie-third-peer", f.gp, f.clk); + replay_to(*f.a, c); + c.db().set_hardfork(CHAIN_HARDFORK_16, true); + + auto [x, y] = f.sibling_pair(); + BOOST_REQUIRE_MESSAGE(c.head_block_id() == x.previous, "PREMISE: the third peer must sit on the shared parent"); + + // Third sibling Z: same height, same parent, produced one slot LATER. In Y's own slot the block + // would be byte-identical to Y (same producer, same parent, no transactions), so the tie this + // case exists to build would silently become a duplicate. + fc::time_point_sec when_z = y.timestamp; + const auto z = produce(c, f.gp, f.keys, when_z); + BOOST_REQUIRE_EQUAL(z.block_num(), x.block_num()); + BOOST_REQUIRE_MESSAGE(z.previous == x.previous, "PREMISE: Z must share the parent of X and Y"); + BOOST_REQUIRE_MESSAGE(z.id() != y.id(), "PREMISE: Z must be a distinct block, not a re-delivery of Y"); + + // Every peer ends on the SAME head X, holding Y and Z as siblings: c takes X first (so it applies) + // and then the other two, which an equal-length head keeps in fork_db. + c.receive_block(x); + BOOST_REQUIRE_MESSAGE(c.head_block_id() == x.id(), "PREMISE: X did not apply on the neutral peer"); + c.receive_block(y); + c.receive_block(z); + BOOST_REQUIRE_MESSAGE(c.db().get_fork_db().fetch_block(y.id()) && c.db().get_fork_db().fetch_block(z.id()), + "PREMISE: both rivals must reach the neutral peer's fork_db"); + f.a->receive_block(z); + BOOST_REQUIRE_MESSAGE(f.a->db().get_fork_db().fetch_block(z.id()), "PREMISE: Z did not reach the producer's fork_db"); + BOOST_REQUIRE_MESSAGE(f.a->head_block_id() == x.id(), "PREMISE: delivering Z moved the head"); + + auto& db_a = f.a->db(); + auto& db_c = c.db(); + const auto quorum = database::block_qc_quorum( + uint32_t(db_a.get_validator_schedule_object().num_scheduled_validators) / CHAIN_BLOCK_VALIDATOR_REPEAT); + BOOST_REQUIRE_MESSAGE(quorum > 1u, "PREMISE: with a quorum of one a single vote certifies, and this is the wrong case"); + + // One vote each, so the rivals tie; head carries none. Both stay below quorum, so the certified + // path cannot be what resolves this. + for (auto* n : {f.a.get(), &c}) { + push_quorum_votes(*n, f.gp, f.keys, y, 1); + push_quorum_votes(*n, f.gp, f.keys, z, 1); + } + BOOST_REQUIRE_MESSAGE(!db_a.get_block_qc(y.block_num()).valid(), "PREMISE: a single vote must not form a QC"); + BOOST_REQUIRE_MESSAGE(f.a->head_block_id() == x.id(), "PREMISE: head must still be the unvoted X"); + + // The tie is real: equal counts, head behind both. Without the id tie-break the answer would be + // whichever block the map happened to reach first. + const block_id_type expected = std::min(y.id(), z.id()); + size_t head_votes = 0, sib_votes = 0; + const auto a_pick = db_a.canonical_sibling_id(&head_votes, &sib_votes); + const auto c_pick = db_c.canonical_sibling_id(); + BOOST_REQUIRE_MESSAGE(a_pick.valid(), "a head with no votes must yield to rivals that have one"); + BOOST_CHECK_EQUAL(head_votes, 0u); + BOOST_CHECK_EQUAL(sib_votes, 1u); + BOOST_CHECK_MESSAGE(*a_pick == expected, "the tie must be broken by the smaller id, not by delivery order"); + BOOST_CHECK_MESSAGE(c_pick.valid() && *c_pick == expected, + "an independent peer holding the same head and votes must name the same block"); + + BOOST_CHECK(db_a.converge_to_canonical_sibling()); + BOOST_CHECK(db_c.converge_to_canonical_sibling()); + BOOST_CHECK_MESSAGE(f.a->head_block_id() == expected, "peer a did not land on the tie-break winner"); + BOOST_CHECK_MESSAGE(c.head_block_id() == expected, "the neutral peer did not land on the tie-break winner"); + BOOST_CHECK_EQUAL(f.a->head_block_num(), x.block_num()); + + // The losing rival is still known and still rankable: the rule moves the head, it does not prune + // the fork, so a later vote that breaks the tie must still be able to act. + BOOST_CHECK(f.a->db().get_fork_db().fetch_block(expected == y.id() ? z.id() : y.id())); + BOOST_CHECK(!db_a.canonical_sibling_id().valid()); +} + BOOST_AUTO_TEST_SUITE_END() #endif From d98e1c2bf0de76a33a2cc587976434acb791c736 Mon Sep 17 00:00:00 2001 From: Anatoly Piskunov Date: Wed, 18 Nov 2026 19:27:56 +0100 Subject: [PATCH 2/2] consensus_sim: give the tie case its own neutral peer The case failed in CI on the 4-validator arm: 'PREMISE: X did not apply on the neutral peer'. The node that produced Z cannot be the neutral peer - its head IS Z the moment it produces, so an equal-length X is stored in fork_db instead of applied. A fourth node, replayed on the shared parent before the split, takes X as its head and holds Y and Z as siblings, which is the state the ranking needs. --- .../test_certified_sibling_switch.cpp | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp b/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp index 47d483d6e1..c72619d108 100644 --- a/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp +++ b/tests/consensus_sim/scenarios/test_certified_sibling_switch.cpp @@ -538,12 +538,17 @@ BOOST_AUTO_TEST_CASE(tie_between_two_siblings_resolves_to_the_smaller_id) { "PREMISE: this build caps the schedule below four identities"); fixture f(0x71E7u); - simulated_node c("tie-third-peer", f.gp, f.clk); + simulated_node c("tie-third-producer", f.gp, f.clk); replay_to(*f.a, c); c.db().set_hardfork(CHAIN_HARDFORK_16, true); + // The neutral peer is a FOURTH node: c cannot serve, its head becomes Z the moment it produces it. + simulated_node d("tie-neutral-peer", f.gp, f.clk); + replay_to(*f.a, d); + d.db().set_hardfork(CHAIN_HARDFORK_16, true); auto [x, y] = f.sibling_pair(); - BOOST_REQUIRE_MESSAGE(c.head_block_id() == x.previous, "PREMISE: the third peer must sit on the shared parent"); + BOOST_REQUIRE_MESSAGE(c.head_block_id() == x.previous, "PREMISE: the third producer must sit on the shared parent"); + BOOST_REQUIRE_MESSAGE(d.head_block_id() == x.previous, "PREMISE: the neutral peer must sit on the shared parent"); // Third sibling Z: same height, same parent, produced one slot LATER. In Y's own slot the block // would be byte-identical to Y (same producer, same parent, no transactions), so the tie this @@ -554,27 +559,28 @@ BOOST_AUTO_TEST_CASE(tie_between_two_siblings_resolves_to_the_smaller_id) { BOOST_REQUIRE_MESSAGE(z.previous == x.previous, "PREMISE: Z must share the parent of X and Y"); BOOST_REQUIRE_MESSAGE(z.id() != y.id(), "PREMISE: Z must be a distinct block, not a re-delivery of Y"); - // Every peer ends on the SAME head X, holding Y and Z as siblings: c takes X first (so it applies) + // Every peer ends on the SAME head X, holding Y and Z as siblings: d takes X first (so it applies) // and then the other two, which an equal-length head keeps in fork_db. - c.receive_block(x); - BOOST_REQUIRE_MESSAGE(c.head_block_id() == x.id(), "PREMISE: X did not apply on the neutral peer"); - c.receive_block(y); - c.receive_block(z); - BOOST_REQUIRE_MESSAGE(c.db().get_fork_db().fetch_block(y.id()) && c.db().get_fork_db().fetch_block(z.id()), + d.receive_block(x); + BOOST_REQUIRE_MESSAGE(d.head_block_id() == x.id(), "PREMISE: X did not apply on the neutral peer"); + d.receive_block(y); + d.receive_block(z); + BOOST_REQUIRE_MESSAGE(d.db().get_fork_db().fetch_block(y.id()) && d.db().get_fork_db().fetch_block(z.id()), "PREMISE: both rivals must reach the neutral peer's fork_db"); f.a->receive_block(z); BOOST_REQUIRE_MESSAGE(f.a->db().get_fork_db().fetch_block(z.id()), "PREMISE: Z did not reach the producer's fork_db"); BOOST_REQUIRE_MESSAGE(f.a->head_block_id() == x.id(), "PREMISE: delivering Z moved the head"); + auto& db_a = f.a->db(); - auto& db_c = c.db(); + auto& db_d = d.db(); const auto quorum = database::block_qc_quorum( uint32_t(db_a.get_validator_schedule_object().num_scheduled_validators) / CHAIN_BLOCK_VALIDATOR_REPEAT); BOOST_REQUIRE_MESSAGE(quorum > 1u, "PREMISE: with a quorum of one a single vote certifies, and this is the wrong case"); // One vote each, so the rivals tie; head carries none. Both stay below quorum, so the certified // path cannot be what resolves this. - for (auto* n : {f.a.get(), &c}) { + for (auto* n : {f.a.get(), &d}) { push_quorum_votes(*n, f.gp, f.keys, y, 1); push_quorum_votes(*n, f.gp, f.keys, z, 1); } @@ -586,18 +592,18 @@ BOOST_AUTO_TEST_CASE(tie_between_two_siblings_resolves_to_the_smaller_id) { const block_id_type expected = std::min(y.id(), z.id()); size_t head_votes = 0, sib_votes = 0; const auto a_pick = db_a.canonical_sibling_id(&head_votes, &sib_votes); - const auto c_pick = db_c.canonical_sibling_id(); + const auto d_pick = db_d.canonical_sibling_id(); BOOST_REQUIRE_MESSAGE(a_pick.valid(), "a head with no votes must yield to rivals that have one"); BOOST_CHECK_EQUAL(head_votes, 0u); BOOST_CHECK_EQUAL(sib_votes, 1u); BOOST_CHECK_MESSAGE(*a_pick == expected, "the tie must be broken by the smaller id, not by delivery order"); - BOOST_CHECK_MESSAGE(c_pick.valid() && *c_pick == expected, + BOOST_CHECK_MESSAGE(d_pick.valid() && *d_pick == expected, "an independent peer holding the same head and votes must name the same block"); BOOST_CHECK(db_a.converge_to_canonical_sibling()); - BOOST_CHECK(db_c.converge_to_canonical_sibling()); + BOOST_CHECK(db_d.converge_to_canonical_sibling()); BOOST_CHECK_MESSAGE(f.a->head_block_id() == expected, "peer a did not land on the tie-break winner"); - BOOST_CHECK_MESSAGE(c.head_block_id() == expected, "the neutral peer did not land on the tie-break winner"); + BOOST_CHECK_MESSAGE(d.head_block_id() == expected, "the neutral peer did not land on the tie-break winner"); BOOST_CHECK_EQUAL(f.a->head_block_num(), x.block_num()); // The losing rival is still known and still rankable: the rule moves the head, it does not prune