Skip to content

Commit 43f8c5e

Browse files
authored
Merge pull request #646 from frstrtr/dash/643-minproto-ratchet-gate
dash: parameterized min-protocol-version ratchet gate + KAT (#643, option a)
2 parents e7cb777 + e77765f commit 43f8c5e

4 files changed

Lines changed: 131 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
core_test sharechain_test share_test btc_share_test \
103103
test_threading test_weights \
104104
test_header_chain test_mempool test_template_builder \
105-
test_doge_chain test_compact_blocks test_dash_x11_kat test_dash_header_chain test_dash_block_replay test_dash_conformance test_dash_subsidy test_dash_mempool test_dash_simplifiedmns test_dash_quorum test_dash_quorum_root test_dash_mn_state test_dash_embedded_gbt test_dash_smldiff test_dash_p2p_messages test_dash_p2p_connection test_dash_p2p_node test_dash_node_interface test_dash_config test_dash_broadcaster test_dash_broadcaster_full test_dash_share_hash_link test_dash_block_relay test_dash_rpc_request test_dash_rpc_conf test_dash_block_producer test_dash_embedded_relay_e2e test_dash_block_relay_plan test_dash_version_activation_latch test_dash_block_relay_binding test_dash_block_relay_dual_arm test_dash_coinbase_parity test_dash_donation_combined test_dash_g3_assembled test_dash_work_target test_dash_work_job_targets test_dash_stratum_binding test_dash_job_notify_roundtrip test_dash_cb_payee test_dash_stratum_notify_roundtrip test_dash_poolnode_messages test_dash_peer test_dash_share_tracker test_dash_node test_dash_share_messages test_dash_stratum_extranonce_split test_dash_stratum_submit_reassembly test_dash_difficulty_parity test_dash_auto_ratchet \
105+
test_doge_chain test_compact_blocks test_dash_x11_kat test_dash_header_chain test_dash_block_replay test_dash_conformance test_dash_subsidy test_dash_mempool test_dash_simplifiedmns test_dash_quorum test_dash_quorum_root test_dash_mn_state test_dash_embedded_gbt test_dash_smldiff test_dash_p2p_messages test_dash_p2p_connection test_dash_p2p_node test_dash_node_interface test_dash_config test_dash_broadcaster test_dash_broadcaster_full test_dash_share_hash_link test_dash_block_relay test_dash_rpc_request test_dash_rpc_conf test_dash_block_producer test_dash_embedded_relay_e2e test_dash_block_relay_plan test_dash_version_activation_latch test_dash_block_relay_binding test_dash_block_relay_dual_arm test_dash_coinbase_parity test_dash_donation_combined test_dash_g3_assembled test_dash_work_target test_dash_work_job_targets test_dash_stratum_binding test_dash_job_notify_roundtrip test_dash_cb_payee test_dash_stratum_notify_roundtrip test_dash_poolnode_messages test_dash_peer test_dash_share_tracker test_dash_node test_dash_share_messages test_dash_stratum_extranonce_split test_dash_stratum_submit_reassembly test_dash_difficulty_parity test_dash_auto_ratchet test_dash_min_protocol_gate \
106106
test_multiaddress_pplns test_pplns_stress \
107107
test_hash_link test_decay_pplns \
108108
test_pplns_consensus \
@@ -252,7 +252,7 @@ jobs:
252252
test_threading test_weights \
253253
test_header_chain test_mempool test_template_builder \
254254
test_doge_chain test_compact_blocks test_dash_x11_kat \
255-
test_dash_header_chain test_dash_block_replay test_dash_conformance test_dash_subsidy test_dash_mempool test_dash_simplifiedmns test_dash_quorum test_dash_quorum_root test_dash_mn_state test_dash_embedded_gbt test_dash_smldiff test_dash_p2p_messages test_dash_p2p_connection test_dash_p2p_node test_dash_node_interface test_dash_config test_dash_broadcaster test_dash_broadcaster_full test_dash_share_hash_link test_dash_block_relay test_dash_rpc_request test_dash_rpc_conf test_dash_block_producer test_dash_embedded_relay_e2e test_dash_block_relay_plan test_dash_version_activation_latch test_dash_block_relay_binding test_dash_block_relay_dual_arm test_dash_coinbase_parity test_dash_donation_combined test_dash_g3_assembled test_dash_work_target test_dash_work_job_targets test_dash_stratum_binding test_dash_job_notify_roundtrip test_dash_cb_payee test_dash_stratum_notify_roundtrip test_dash_poolnode_messages test_dash_peer test_dash_share_tracker test_dash_node test_dash_share_messages test_dash_stratum_extranonce_split test_dash_stratum_submit_reassembly test_dash_difficulty_parity test_dash_auto_ratchet \
255+
test_dash_header_chain test_dash_block_replay test_dash_conformance test_dash_subsidy test_dash_mempool test_dash_simplifiedmns test_dash_quorum test_dash_quorum_root test_dash_mn_state test_dash_embedded_gbt test_dash_smldiff test_dash_p2p_messages test_dash_p2p_connection test_dash_p2p_node test_dash_node_interface test_dash_config test_dash_broadcaster test_dash_broadcaster_full test_dash_share_hash_link test_dash_block_relay test_dash_rpc_request test_dash_rpc_conf test_dash_block_producer test_dash_embedded_relay_e2e test_dash_block_relay_plan test_dash_version_activation_latch test_dash_block_relay_binding test_dash_block_relay_dual_arm test_dash_coinbase_parity test_dash_donation_combined test_dash_g3_assembled test_dash_work_target test_dash_work_job_targets test_dash_stratum_binding test_dash_job_notify_roundtrip test_dash_cb_payee test_dash_stratum_notify_roundtrip test_dash_poolnode_messages test_dash_peer test_dash_share_tracker test_dash_node test_dash_share_messages test_dash_stratum_extranonce_split test_dash_stratum_submit_reassembly test_dash_difficulty_parity test_dash_auto_ratchet test_dash_min_protocol_gate \
256256
test_hash_link test_decay_pplns \
257257
test_pplns_consensus \
258258
test_v36_script_sorting test_v36_cross_impl_refhash \
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
// DASH sharechain minimum-protocol-version gate (v36 min-proto ratchet, #643).
4+
//
5+
// SCOPE: a parameterized, per-instance policy for the reject-if-proto<floor
6+
// decision at the version handshake. This leaf carries ONLY the policy object
7+
// and its accept/reject predicate; the LIVE call site in NodeImpl::handle_version
8+
// is the reception/handshake slice (B) and is deliberately out of scope here.
9+
//
10+
// RATCHET SEMANTICS (operator #643, integrator-concurred 2026-07-06 option a):
11+
// - The floor defaults to dash::SharechainConfig::MINIMUM_PROTOCOL_VERSION
12+
// (1700), which is the current DASH oracle accept-all floor. At the default
13+
// this gate is a NO-OP: a peer advertising protocol=1700 MUST be accepted.
14+
// - The floor is a per-instance MEMBER, not a baked-in constant, so the actual
15+
// v36 ratchet value is a one-line operator knob set at G2-migration time.
16+
// This leaf commits NO premature v36 constant (DASH share ver 16->36 is
17+
// older-than-v35; the floor is a chosen constant, not an oracle-derived one).
18+
//
19+
// ISOLATION: fenced to src/impl/dash/. Touches NO shared bitcoin_family / core
20+
// version-handshake types (per-coin isolation primitive boundary).
21+
22+
#include <cstdint>
23+
24+
#include "config_pool.hpp"
25+
26+
namespace dash
27+
{
28+
29+
// Per-instance minimum-protocol-version policy. Default-constructed it holds the
30+
// oracle accept-all floor (1700) and accepts every peer at or above it.
31+
struct MinProtocolGate
32+
{
33+
// The rejection floor. A peer is admitted iff peer_protocol >= min_version.
34+
uint32_t min_version = SharechainConfig::MINIMUM_PROTOCOL_VERSION;
35+
36+
MinProtocolGate() = default;
37+
explicit MinProtocolGate(uint32_t floor) : min_version(floor) {}
38+
39+
// reject-if-proto<floor predicate. True => admit the peer.
40+
// At the default floor (1700) this is accept-all for every real DASH peer.
41+
[[nodiscard]] bool accepts(uint32_t peer_protocol) const
42+
{
43+
return peer_protocol >= min_version;
44+
}
45+
46+
// Convenience inverse for handshake sites that branch on rejection.
47+
[[nodiscard]] bool rejects(uint32_t peer_protocol) const
48+
{
49+
return !accepts(peer_protocol);
50+
}
51+
};
52+
53+
} // namespace dash

test/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ if (BUILD_TESTING AND GTest_FOUND)
263263
target_link_libraries(test_dash_conformance PRIVATE c2pool_payout c2pool_hashrate c2pool_merged_mining) # OBJECT-lib SCC direct-naming (#22/#39): core stratum/web_server TUs
264264
gtest_add_tests(test_dash_conformance "" AUTO)
265265

266+
# DASH min-protocol-version ratchet gate KAT (#643, option a): pure, header-only
267+
# policy object; no socket/ltc/pool dependency. Mirrors the test_dash_conformance link set.
268+
add_executable(test_dash_min_protocol_gate test_dash_min_protocol_gate.cpp)
269+
target_link_libraries(test_dash_min_protocol_gate PRIVATE
270+
GTest::gtest_main GTest::gtest
271+
dash_x11 core
272+
nlohmann_json::nlohmann_json
273+
${Boost_LIBRARIES}
274+
)
275+
target_link_libraries(test_dash_min_protocol_gate PRIVATE c2pool_payout c2pool_hashrate c2pool_merged_mining) # OBJECT-lib SCC direct-naming (#22/#39): core stratum/web_server TUs
276+
gtest_add_tests(test_dash_min_protocol_gate "" AUTO)
277+
266278
# DASH S8 pool-node leaf 4 — share_tracker.hpp KAT: DensePPLNSWindow decayed
267279
# weight ring buffer (compute_v36_weights), decay table, donation split,
268280
# window slides. PoW-independent consensus core; socket-free, chain-free.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// KAT for the DASH min-protocol-version ratchet gate (#643, option a).
2+
//
3+
// Pins the two invariants integrator required for the SAFE-ADDITIVE leaf:
4+
// 1. NO-OP AT DEFAULT: a default-constructed gate carries the oracle floor
5+
// (1700) and MUST admit a peer at protocol=1700. Nobody may later read the
6+
// landed leaf as an already-live ratchet.
7+
// 2. PARAMETERIZED, NOT BAKED: the floor is a per-instance member, so raising
8+
// it rejects below-floor peers -- proving the ratchet MECHANISM works while
9+
// the default stays inert.
10+
11+
#include <gtest/gtest.h>
12+
13+
#include "impl/dash/config_pool.hpp"
14+
#include "impl/dash/min_protocol_gate.hpp"
15+
16+
using dash::MinProtocolGate;
17+
using dash::SharechainConfig;
18+
19+
// (1) Default gate == oracle accept-all floor, and it is a genuine no-op there.
20+
TEST(DashMinProtocolGate, DefaultFloorIsOracleAcceptAll)
21+
{
22+
MinProtocolGate gate;
23+
EXPECT_EQ(gate.min_version, SharechainConfig::MINIMUM_PROTOCOL_VERSION);
24+
EXPECT_EQ(gate.min_version, 1700u);
25+
26+
// A peer AT the floor MUST be accepted -- this is the no-op assertion.
27+
EXPECT_TRUE(gate.accepts(1700u));
28+
EXPECT_FALSE(gate.rejects(1700u));
29+
30+
// Real DASH peers advertise >= 1700, so the default admits every one.
31+
EXPECT_TRUE(gate.accepts(1700u));
32+
EXPECT_TRUE(gate.accepts(1800u));
33+
EXPECT_TRUE(gate.accepts(70210u));
34+
}
35+
36+
// (2) Below the default floor is rejected -- boundary is >=, not >.
37+
TEST(DashMinProtocolGate, BelowDefaultFloorRejected)
38+
{
39+
MinProtocolGate gate;
40+
EXPECT_FALSE(gate.accepts(1699u));
41+
EXPECT_TRUE(gate.rejects(1699u));
42+
EXPECT_FALSE(gate.accepts(0u));
43+
// Exact boundary: floor-1 out, floor in.
44+
EXPECT_FALSE(gate.accepts(gate.min_version - 1));
45+
EXPECT_TRUE(gate.accepts(gate.min_version));
46+
}
47+
48+
// (3) The floor is a settable per-instance member -- the ratchet mechanism.
49+
// Raising it to a hypothetical v36 value rejects the old-floor peer, but
50+
// this is a per-instance choice, NOT a committed constant.
51+
TEST(DashMinProtocolGate, RatchetIsParameterizedNotBaked)
52+
{
53+
// Operator knob: raise the floor at G2-migration time.
54+
MinProtocolGate ratcheted(1800u);
55+
EXPECT_EQ(ratcheted.min_version, 1800u);
56+
EXPECT_FALSE(ratcheted.accepts(1700u)); // old-floor peer now rejected
57+
EXPECT_TRUE(ratcheted.accepts(1800u)); // at-new-floor peer admitted
58+
59+
// The default gate is UNAFFECTED -- proving the ratchet is per-instance and
60+
// the leaf commits no premature v36 constant.
61+
MinProtocolGate defaulted;
62+
EXPECT_TRUE(defaulted.accepts(1700u));
63+
EXPECT_EQ(defaulted.min_version, 1700u);
64+
}

0 commit comments

Comments
 (0)