Skip to content

Commit ddf789d

Browse files
authored
dgb: inject make_mempool_tx_source into embedded run-loop work source (surface-for-tap, consensus VALUE) (#248)
* dgb: wire embedded mempool tx selection into the work template (fees -> coinbasevalue, transactions[]) EmbeddedCoinNode gains an injected EmbeddedTxSource: the embedded work template's transactions[] and fee total now come from the in-process Mempool instead of being hardcoded empty/0. The fee total folds into coinbasevalue through the #207 resolve_coinbase_value SSOT (subsidy(h) + total_fees); transactions[] passes through build_work_template verbatim. The source defaults empty, so the #237 EmbeddedCoinNode call site stays byte-identical (truthful absence preserved). The heavy tx/UTXO serialization codec (TX_WITH_WITNESS pack + Hash + HexStr) lives out-of-line in embedded_tx_select.cpp (make_mempool_tx_source, compiled into dgb_coin), NOT in embedded_coin_node.hpp -- keeping that header codec-free holds the #143 btclibs SCC trap shut for guard-weight TUs. Per-tx entry shape {data,txid,hash,fee} mirrors btc/coin and the p2pool-dgb-scrypt GBT consumer (fee null when unknown -> base_subsidy fallback; unknown-fee txs excluded to avoid coinbasevalue desync). Tests: dgb_embedded_tx_select_test (3/3) pins the Mempool -> GBT shaping + fee total over a real pool; dgb_embedded_coin_node_test (+2 -> 7/7) pins the fee->coinbasevalue fold (#207) and the empty-source byte-identical invariant. Both registered in ctest + the two build.yml --target allowlists. * dgb: inject make_mempool_tx_source into embedded run-loop work source Wire the #244 EmbeddedTxSource seam into the c2pool-dgb run loop. The EmbeddedCoinNode ctor now receives make_mempool_tx_source(mempool, BLOCK_MAX_WEIGHT): the served work template selects fee-sorted mempool transactions and folds their fees into coinbasevalue via the #207 SSOT, instead of emitting subsidy-only with an empty transactions[]. mempool is hoisted ahead of embedded_coin so the injected source (which captures it by reference) is outlived by the pool; reverse-order destruction tears the source down before the pool. The duplicate lower mempool declaration is removed. Consensus-VALUE: this changes the served template tx-selection path, so it is surface-for-tap, not auto-merge. It is byte-identical to the #237 subsidy-only baseline until the mempool is fed: wire_mempool_ingest (#245) needs an embedded coin-daemon ::dgb::interfaces::Node new_tx relay, and no such node is constructed in the run loop yet (the M3 embedded port; header_chain is likewise still unfed). So the source returns an empty selection today and the broadcast template is unchanged until live tx ingest lands. Build: c2pool-dgb links EXIT=0; --selftest OK. --------- Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
1 parent 5db1801 commit ddf789d

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

src/c2pool/main_dgb.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <impl/dgb/coin/mempool.hpp>
3232
#include <impl/dgb/coin/coin_node.hpp>
3333
#include <impl/dgb/coin/embedded_coin_node.hpp>
34+
#include <impl/dgb/coin/embedded_tx_select.hpp> // make_mempool_tx_source (EmbeddedTxSource)
3435
#include <impl/dgb/coin/won_block_dispatch.hpp>
3536
#include <impl/dgb/coin/node_interface.hpp>
3637
#include <impl/dgb/coin/header_ingest.hpp>
@@ -202,12 +203,31 @@ int run_node(const core::CoinParams& params, bool testnet,
202203
// the same non-owning ref.
203204
c2pool::dgb::HeaderChain header_chain;
204205

206+
// Embedded mempool — the in-process pool the work template selects from.
207+
// Declared HERE (ahead of embedded_coin) because the injected
208+
// EmbeddedTxSource below captures it by reference and MUST be outlived by
209+
// it; reverse-order destruction tears embedded_coin (and its source) down
210+
// before mempool. FEED: wire_mempool_ingest (coin/mempool_ingest.hpp, #245)
211+
// subscribes this pool to an ::dgb::interfaces::Node new_tx relay — but no
212+
// embedded coin-daemon P2P node is constructed in this run-loop yet (the M3
213+
// embedded port; header_chain is likewise still unfed), so nothing calls
214+
// add_tx and the pool stays empty until that node lands. The selection
215+
// below is therefore byte-identical to the subsidy-only #237 baseline today.
216+
dgb::coin::Mempool mempool;
217+
205218
// Embedded in-process work source: assembles GBT-compatible templates
206219
// ENTIRELY from embedded chain state + the coin subsidy schedule (no
207220
// external digibyted). coinbasevalue resolves through the #207 ->
208-
// subsidy_func SSOT; transactions[]/bits are held back truthfully until
209-
// the embedded mempool + next-target source are plumbed.
210-
dgb::coin::EmbeddedCoinNode embedded_coin(header_chain, params.subsidy_func);
221+
// subsidy_func SSOT; bits are held back truthfully until the next-target
222+
// source is plumbed. transactions[] + the fee total come from an injected
223+
// make_mempool_tx_source over the embedded mempool (#244 seam): fee-sorted
224+
// txs up to BLOCK_MAX_WEIGHT with their fees folded into coinbasevalue via
225+
// the #207 SSOT. The source returns an EMPTY selection while the mempool is
226+
// unfed (see above), so the served template stays at the #237 baseline
227+
// until live `tx` ingest lands.
228+
dgb::coin::EmbeddedCoinNode embedded_coin(
229+
header_chain, params.subsidy_func,
230+
dgb::coin::make_mempool_tx_source(mempool, dgb::PoolConfig::BLOCK_MAX_WEIGHT));
211231

212232
// CoinNode seam — embedded-preferred work source (embedded_coin) with the
213233
// external-digibyted submitblock FALLBACK leg of the #82 dual-path
@@ -285,9 +305,9 @@ int run_node(const core::CoinParams& params, bool testnet,
285305
// emitted — the standup proves the StratumServer<->IWorkSource wiring
286306
// end-to-end. Real work-gen / Scrypt share-validation land in 4b/4c.
287307
// This mirrors btc::stratum standing its skeleton wiring up first.
288-
// header_chain is declared above coin_node (it backs the EmbeddedCoinNode
289-
// work source); only the unwired Mempool is declared here.
290-
dgb::coin::Mempool mempool; // unwired (no UTXO/template feed yet)
308+
// header_chain AND mempool are both declared above coin_node now — mempool
309+
// backs the injected EmbeddedCoinNode tx source (declared there so it
310+
// outlives the capturing source).
291311

292312
// ── Embedded coin-daemon ingest surface (Phase B P2P-node standup) ──
293313
//

0 commit comments

Comments
 (0)