Skip to content

Commit e2714b9

Browse files
committed
dgb: wire get_current_work_template coinbasevalue through #207 SSOT (Stage 4c)
get_current_work_template() now emits the next-block height and its coinbasevalue instead of an empty object. The coinbasevalue is derived through the #207 embedded SSOT (coinbase_value -> resolve_coinbase_value -> subsidy_func) keyed on next_block_height() (#209, == tip.height + 1; == base_height for an empty chain). Embedded path: no external-daemon GBT value is plumbed in yet and mempool-fee aggregation is unwired, so total_fees = 0; a present GBT coinbasevalue stays authoritative and fees add on top of subsidy in later slices without changing this SSOT call. The remaining GBT template fields (previousblockhash, bits, version, curtime, mintime, transactions[]) and the build_connection_coinbase gentx assembly land in following Stage 4c/4d slices. Test: +WorkTemplateEmitsHeightAndCoinbaseValueViaSsot pins height + coinbasevalue to the p2pool-dgb-scrypt oracle subsidy at the phase3 era boundary; existing stub-default assertion relaxed. dgb_work_source_test 14/14.
1 parent bcfd21c commit e2714b9

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/impl/dgb/stratum/work_source.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,26 @@ void DGBWorkSource::update_stratum_worker(const std::string& session_id,
148148

149149
nlohmann::json DGBWorkSource::get_current_work_template() const
150150
{
151-
// Stage 4c: drive dgb::coin::TemplateBuilder over chain_ + mempool_ and
152-
// shape its WorkData into the GBT-style JSON the stratum session expects
153-
// (previousblockhash, bits, version, curtime, mintime, height,
154-
// coinbasevalue, transactions[]). Scrypt nBits, not SHA256d.
155-
return nlohmann::json::object();
151+
// Stage 4c (coinbasevalue wire): the full GBT-shaped template
152+
// (previousblockhash, bits, version, curtime, mintime, transactions[])
153+
// is assembled by the embedded dgb::coin::TemplateBuilder in a following
154+
// slice. What lands here is the consensus-bearing reward field: the
155+
// coinbasevalue for the NEXT block, derived through the #207 SSOT
156+
// (coinbase_value -> resolve_coinbase_value -> subsidy_func) keyed on the
157+
// absolute next-block height from the #209 HeaderChain accessor
158+
// (next_block_height() == tip_height()+1, or base_height for an empty
159+
// chain). Embedded path: no external-daemon GBT value is plumbed in yet
160+
// and mempool-fee aggregation is not wired, so total_fees = 0 here. Both
161+
// compose in later slices WITHOUT changing this SSOT call (a present GBT
162+
// coinbasevalue stays authoritative; fees add on top of subsidy).
163+
const uint32_t next_h = chain_.next_block_height();
164+
const uint64_t coinbasevalue =
165+
coinbase_value(next_h, /*total_fees=*/0, /*gbt_coinbasevalue=*/std::nullopt);
166+
167+
nlohmann::json tmpl = nlohmann::json::object();
168+
tmpl["height"] = next_h;
169+
tmpl["coinbasevalue"] = coinbasevalue;
170+
return tmpl;
156171
}
157172

158173
std::vector<std::string> DGBWorkSource::get_stratum_merkle_branches() const

src/impl/dgb/test/work_source_test.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ TEST(DgbWorkSource, WorkGenStubsReturnSafeDefaults)
135135
// 4a skeleton: every work-generation getter returns its documented
136136
// empty/default form (4c fills them in).
137137
EXPECT_TRUE(ws->get_current_gbt_prevhash().empty());
138+
// get_current_work_template() now emits height + coinbasevalue (Stage 4c
139+
// coinbasevalue wire); its dedicated assertions live in
140+
// WorkTemplateEmitsHeightAndCoinbaseValueViaSsot below.
138141
EXPECT_TRUE(ws->get_current_work_template().is_object());
139-
EXPECT_TRUE(ws->get_current_work_template().empty());
140142
EXPECT_TRUE(ws->get_stratum_merkle_branches().empty());
141143
auto parts = ws->get_coinbase_parts();
142144
EXPECT_TRUE(parts.first.empty());
@@ -174,6 +176,26 @@ TEST(DgbWorkSource, ComputeShareDifficultyReturnsNotYetSentinel)
174176
EXPECT_DOUBLE_EQ(diff, 0.0);
175177
}
176178

179+
// Stage 4c coinbasevalue wire: the work template surfaces the NEXT-block
180+
// height and its coinbasevalue, the latter derived THROUGH the #207 SSOT
181+
// (subsidy_func) keyed on next_block_height() == tip.height + 1 (#209). An
182+
// empty chain makes next_block_height() == base_height, so seeding an oracle
183+
// era boundary pins the value unambiguously to the p2pool-dgb-scrypt subsidy.
184+
TEST(DgbWorkSource, WorkTemplateEmitsHeightAndCoinbaseValueViaSsot)
185+
{
186+
Fixture fx;
187+
fx.chain.set_base_height(400000); // phase3 first block (oracle boundary)
188+
auto ws = fx.make();
189+
auto tmpl = ws->get_current_work_template();
190+
ASSERT_TRUE(tmpl.is_object());
191+
ASSERT_TRUE(tmpl.contains("height"));
192+
ASSERT_TRUE(tmpl.contains("coinbasevalue"));
193+
// next_h = next_block_height() = base_height (empty chain) = 400000.
194+
EXPECT_EQ(tmpl["height"].get<uint32_t>(), 400000u);
195+
// Zero embedded fees, no external GBT -> oracle subsidy at the boundary.
196+
EXPECT_EQ(tmpl["coinbasevalue"].get<uint64_t>(), 2434410000ULL);
197+
}
198+
177199
// ── Embedded coinbasevalue: first production caller of subsidy_func ──────────
178200
// One pin on each side of every DGB reward-era boundary (p2pool-dgb-scrypt
179201
// oracle vectors, test_dgb_subsidy.cpp).

0 commit comments

Comments
 (0)