Skip to content

Commit 4abbd51

Browse files
committed
dgb(#82): wire captured-template txs into won-block reconstruct
Replace the interim coinbase-only template_other_txs_fn stub in the #82 forced-won live seam with the production capture->bridge path: - declare a run-loop-scoped dgb::coin::TemplateCapture (#300/#271) that outlives every tracker callback the provider() is installed into - feed it through make_template_other_txs_fn (#299) as the reconstruct closure template_other_txs_fn, so a won block replays the EXACT non-coinbase set the share committed to (merkle-consistent) instead of reconstructing coinbase-only - seed_forced_from_gbt captures the node-B GBT transactions[] keyed by the forced share hash; coinbasevalue already includes those fees so the regenerated gentx subsidy stays balanced A capture MISS still decodes to an empty set -> a valid coinbase-only block (never fail-closed). Per-coin: src/impl/dgb + main_dgb only.
1 parent c37ec37 commit 4abbd51

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

src/c2pool/main_dgb.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <impl/dgb/coin/embedded_tx_select.hpp> // make_mempool_tx_source (EmbeddedTxSource)
3535
#include <impl/dgb/coin/won_block_dispatch.hpp>
3636
#include <impl/dgb/coin/reconstruct_closure.hpp> // make_reconstruct_closure_from_template (#280)
37+
#include <impl/dgb/coin/template_capture.hpp> // TemplateCapture per-job retain (#300/#271)
38+
#include <impl/dgb/coin/template_other_txs.hpp> // make_template_other_txs_fn bridge (#299)
3739
#include <impl/dgb/coin/won_block_finalize.hpp> // finalize_won_block_pow -- forced-won PoW grind JOINT (#82 gate)
3840
#include <impl/dgb/coin/header_sample_build.hpp> // c2pool::dgb::compact_to_target (nBits -> u256)
3941
#include <impl/dgb/coin/won_share_inputs.hpp> // won_share_inputs (#279)
@@ -356,6 +358,14 @@ int run_node(const core::CoinParams& params, bool testnet,
356358
// self-deadlock — the corrected consume-seam audit). Fail-closed end to
357359
// end: any error in a builder fn throws, is caught inside the closure ->
358360
// std::nullopt (announce + audit; the RPC submitblock fallback still fires).
361+
// #82 tx-bearing won block: retain each handed-out template's
362+
// transactions[] keyed by the resulting share_hash so the reconstructor
363+
// replays the EXACT non-coinbase set the share committed to (merkle-
364+
// consistent), replacing the interim coinbase-only stub. Plain local:
365+
// outlives every tracker callback the provider() is installed into
366+
// (all bound within this main scope, before ioc.run()).
367+
dgb::coin::TemplateCapture template_capture;
368+
359369
auto& reconstruct_tracker = p2p_node.tracker();
360370
auto faithful_reconstruct = dgb::coin::make_reconstruct_closure_from_template(
361371
/*won_share_fields_fn=*/
@@ -386,9 +396,10 @@ int run_node(const core::CoinParams& params, bool testnet,
386396
return gc.bytes;
387397
},
388398
/*template_other_txs_fn=*/
389-
[](const uint256&) -> std::vector<dgb::coin::MutableTransaction> {
390-
return {}; // coinbase-only today (see note above)
391-
});
399+
// #300/#299: replay the captured per-job template transactions[]
400+
// keyed by share_hash (TemplateCapture above feeds it at seed time);
401+
// a capture MISS decodes to an empty set -> valid coinbase-only block.
402+
dgb::coin::make_template_other_txs_fn(template_capture.provider()));
392403

393404
// -- #82 forced-won PoW finalize -------------------------------------
394405
// A forced-won share (the regtest --regtest-force-won-share live seam)
@@ -714,7 +725,7 @@ int run_node(const core::CoinParams& params, bool testnet,
714725
// reconstruct closure frames it; --soak-regrind then grinds the
715726
// nonce to satisfy THIS bits. Regtest-only; coinbase-only =>
716727
// merkle root == gentx txid by construction (no bad-txnmrklroot).
717-
auto seed_forced_from_gbt = [forced, &rpc, &header_chain]() {
728+
auto seed_forced_from_gbt = [forced, forced_hash, &rpc, &template_capture, &header_chain]() {
718729
if (!rpc) {
719730
// Unreachable on the gated path (--regtest-force-won-share
720731
// requires --coin-daemon, which arms rpc); without the GBT
@@ -727,6 +738,13 @@ int run_node(const core::CoinParams& params, bool testnet,
727738
}
728739
try {
729740
auto gbt = rpc->getblocktemplate({"segwit"});
741+
// #82 tx-bearing: retain this template transactions[]
742+
// under the forced share hash so the won-block
743+
// reconstructor replays them (coinbasevalue already
744+
// includes their fees -> subsidy/merkle consistent).
745+
template_capture.capture(
746+
forced_hash,
747+
gbt.value("transactions", nlohmann::json::array()));
730748
auto& mh = forced->m_min_header;
731749
mh.m_version = gbt.at("version").get<uint64_t>();
732750
mh.m_previous_block.SetHex(

0 commit comments

Comments
 (0)