Skip to content

Commit ee68f50

Browse files
committed
dash(S8): get_work() consumer capstone -- fuse NodeCoinState::select_work() template source + assemble_work_job_targets()
The embedded get_work chain was fully wired but had NO production consumer: NodeCoinState::select_work() (embedded template when the 4-leg reception wire (#693/#694) has populated the node bundle, else the retained dashd getblocktemplate fallback) and assemble_work_job_targets() (per-miner job-target arithmetic) each existed and were unit-tested, but nothing fused them into a single miner-facing entry. Only the test suites ever called select_work(). Add dash::stratum::get_work() (src/impl/dash/stratum/get_work.hpp): the first non-test caller of the embedded arm. It sources the base block template off the node-held NodeCoinState -- NO direct dashd poll on the hot path when the bundle is populated -- and assembles the job targets over whichever template arm ran. dashd_fallback stays REQUIRED and is invoked ONLY on a set-gap (unpopulated / invalidated bundle): the always-reachable safety + [GBT-XCHECK] cross-check arm, never removed. test_dash_get_work (4/4) pins the fused contract, seeding mirrored exactly from test_dash_node_embedded_wire (no fabricated oracle values): * set-gap routes DashdFallback (invoked once) and still assembles targets; * populated routes Embedded WITHOUT invoking the fallback, byte-equal to a direct build_embedded_workdata() over the node's own held state; * job targets are identical across both template sources; * on_invalidate (reorg) demotes back to the fallback. Registered in both build.yml --target allowlists. STRICTLY single-coin (src/impl/dash/ + test only), SAFE-ADDITIVE.
1 parent ab249df commit ee68f50

4 files changed

Lines changed: 337 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 test_dash_min_protocol_gate test_dash_work_source test_dash_node_coin_state test_dash_coin_state_maintainer test_dash_node_embedded_wire test_dash_node_reception_wire \
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 test_dash_work_source test_dash_node_coin_state test_dash_coin_state_maintainer test_dash_node_embedded_wire test_dash_node_reception_wire test_dash_get_work \
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 test_dash_min_protocol_gate test_dash_work_source test_dash_node_coin_state test_dash_coin_state_maintainer test_dash_node_embedded_wire test_dash_node_reception_wire \
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 test_dash_work_source test_dash_node_coin_state test_dash_coin_state_maintainer test_dash_node_embedded_wire test_dash_node_reception_wire test_dash_get_work \
256256
test_hash_link test_decay_pplns \
257257
test_pplns_consensus \
258258
test_v36_script_sorting test_v36_cross_impl_refhash \

src/impl/dash/stratum/get_work.hpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
#pragma once
3+
4+
/// Phase C-TEMPLATE step 9 (capstone): the fused dash get_work() consumer.
5+
///
6+
/// Every prior slice landed one HALF of get_work in isolation:
7+
/// * select_dash_work() / NodeCoinState::select_work() (work_source.hpp,
8+
/// node_coin_state.hpp, #672/#673) -- the TEMPLATE source: prefer the
9+
/// locally-assembled embedded template (build_embedded_workdata, oracle
10+
/// parity vs frstrtr/p2pool-dash getwork(), older-than-v35) when the
11+
/// node-held coin-state bundle is populated by the 4-leg reception wire
12+
/// (#693/#694), else the RETAINED dashd getblocktemplate fallback;
13+
/// * assemble_work_job_targets() (work_job_targets.hpp) -- the per-miner
14+
/// JOB-TARGET arithmetic (work.py:368-426).
15+
///
16+
/// Nothing fused them: no production (non-test) caller ever ran
17+
/// NodeCoinState::select_work() to source a template AND assembled the miner
18+
/// job over it -- the two halves were exercised only by their own unit KATs.
19+
/// get_work() is that single miner-facing entry point -- the
20+
/// "DASHWorkSource::get_work()" the stratum headers reference as future work.
21+
///
22+
/// CONTRACT (matches the S8 embedded-arm invariants):
23+
/// * the hot path reads the node-held NodeCoinState -- NO direct dashd poll
24+
/// when the bundle is populated (the embedded arm assembles locally);
25+
/// * dashd_fallback is REQUIRED and is invoked ONLY on a set-gap
26+
/// (unpopulated / invalidated bundle) -- the always-reachable safety path
27+
/// and the [GBT-XCHECK] cross-check, NEVER removed;
28+
/// * the job-target assembly is a pure transform of caller inputs and rides
29+
/// on top of EITHER template source unchanged.
30+
///
31+
/// STRICTLY single-coin: src/impl/dash/ only, no bitcoin_family / src/core
32+
/// reach beyond the shared uint256/DashWorkData types the halves already use.
33+
34+
#include <impl/dash/coin/node_coin_state.hpp> // NodeCoinState, WorkSelection, WorkSource
35+
#include <impl/dash/coin/rpc_data.hpp> // DashWorkData
36+
#include <impl/dash/stratum/work_job_targets.hpp> // assemble_work_job_targets, WorkJobTargets, WorkJobTargetInputs
37+
38+
#include <functional>
39+
#include <utility>
40+
41+
namespace dash::stratum {
42+
43+
/// The miner-facing result of get_work(): which arm sourced the template, the
44+
/// selected block template itself, and the assembled stratum job targets.
45+
struct GetWork {
46+
coin::WorkSource source{coin::WorkSource::DashdFallback};
47+
coin::DashWorkData work;
48+
WorkJobTargets targets;
49+
};
50+
51+
/// Fused get_work(): source the base block template off the node-held
52+
/// coin-state (embedded when populated, retained dashd fallback on a set-gap)
53+
/// and assemble the per-miner job targets over it. dashd_fallback is REQUIRED
54+
/// -- it is the always-reachable safety/cross-check arm and is only invoked
55+
/// when the embedded bundle is unavailable.
56+
inline GetWork get_work(
57+
const coin::NodeCoinState& coin_state,
58+
const std::function<coin::DashWorkData()>& dashd_fallback,
59+
const WorkJobTargetInputs& job_in)
60+
{
61+
coin::WorkSelection sel = coin_state.select_work(dashd_fallback);
62+
WorkJobTargets targets = assemble_work_job_targets(job_in);
63+
return GetWork{ sel.source, std::move(sel.work), targets };
64+
}
65+
66+
} // namespace dash::stratum

test/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ if (BUILD_TESTING AND GTest_FOUND)
559559
)
560560
target_link_libraries(test_dash_node_embedded_wire PRIVATE c2pool_payout c2pool_hashrate c2pool_merged_mining c2pool_storage pool) # OBJECT-lib SCC direct-naming (#22/#39)
561561
gtest_add_tests(test_dash_node_embedded_wire "" AUTO)
562+
# get_work() consumer capstone: fuses NodeCoinState::select_work() (embedded
563+
# template source) with assemble_work_job_targets(); same OBJECT-lib SCC.
564+
add_executable(test_dash_get_work test_dash_get_work.cpp)
565+
target_link_libraries(test_dash_get_work PRIVATE
566+
GTest::gtest_main GTest::gtest
567+
dash_x11 core
568+
nlohmann_json::nlohmann_json
569+
${Boost_LIBRARIES}
570+
)
571+
target_link_libraries(test_dash_get_work PRIVATE c2pool_payout c2pool_hashrate c2pool_merged_mining c2pool_storage pool) # OBJECT-lib SCC direct-naming (#22/#39)
572+
gtest_add_tests(test_dash_get_work "" AUTO)
562573

563574
# Reception wire (legs 1-3): interfaces::Node reception Events ->
564575
# CoinStateMaintainer. Proves the wire_*_ingest() subscriptions fold off the

0 commit comments

Comments
 (0)