bch(m5): link pool-node TUs into c2pool-bch — stratum serve plumbing#591
Open
frstrtr wants to merge 6 commits into
Open
bch(m5): link pool-node TUs into c2pool-bch — stratum serve plumbing#591frstrtr wants to merge 6 commits into
frstrtr wants to merge 6 commits into
Conversation
…atum serve Stage-a of the G2 pool-serve build-out (g2-pool-serve-gap): c2pool-bch has never served stratum — main_bch.cpp is a harness, the generic pool is LTC-namespace-bound, and standup_pool_run has zero callers. This lands the first concrete piece: a BCH concrete core::stratum::IWorkSource subclass mirroring btc::stratum::BTCWorkSource, forward-declaring bch::coin types so it compiles header-only ahead of the coin-lib wiring. MVP-skeleton (parity with the BTC stage-a posture): method bodies land in follow-on slices b (read-only getters + work assembly off TemplateBuilder), c (share-validation hot path), d (StratumServer wired into standup_pool_run + main_bch --pool serve mode + live .198 bring-up + G2 5-check). BCH divergences captured in-header: no SegWit (non-witness coinbase math), CashTokens transparent-carry, ABLA budget owned by the daemon/TemplateBuilder, BCHN-RPC submitblock fallback ALWAYS retained on the won-block leg. Zero prod surface (not yet wired into node/main/CMake). Syntax-clean vs core/stratum_work_source.hpp under -std=c++20 -I src.
Define src/impl/bch/coin/CMakeLists.txt (mirrors btc_coin: 5 TU rpc/p2p_connection/p2p_node/coin_node/transaction + interface and BCH-specific BCHN headers) and uncomment add_subdirectory(coin) in the bch top CMakeLists so the coin module builds when -DCOIN_BCH=ON. This makes bch::coin::TemplateBuilder (and the rest of the coin lib) a real link target, the prerequisite for slice-c work-assembly off BCHWorkSource. Fenced to src/impl/bch; no bitcoin_family/src/core touch. Verified: cmake -DCOIN_BCH=ON configures; cmake --build --target bch_coin compiles all 5 TUs and archives libbch_coin.a clean (exit 0, no errors).
Implement the read path of bch::stratum::BCHWorkSource: read-only state accessors, per-connection worker registry, and the work-assembly that bridges core::StratumServer to bch::coin::TemplateBuilder::build_template. - cached_template(): single-slot template memo keyed on (work_generation_, tip block_hash). BCH Mempool has no epoch counter, so freshness rides on the tip-move work_generation_ bump plus an explicit bump on mempool roll; the tip-hash key is a belt-and-suspenders rebuild guard. Build runs outside template_mutex_ so a slow build never blocks a cache hit. - get_current_work_template(): returns build_template GBT json, curtime refreshed per-poll. - get_stratum_merkle_branches(): coinbase-left SHA256d siblings over m_hashes (CTOR order from build_template); LE-internal wire hex, no witness commitment. - get_coinbase_parts(), get_current_gbt_prevhash(), get_work_generation(), has_merged_chain()=false (BCH standalone parent), worker bookkeeping, callback setters. Share-WRITE / validation hot path (build_connection_coinbase, mining_submit, compute_share_difficulty) left as safe defaults for slice-d. Build: new bch_stratum static lib (mirrors btc_stratum); add_subdirectory (stratum) under COIN_BCH. Verified on .198: -DCOIN_BCH=ON configures, target bch_stratum compiles work_source.cpp.o + archives libbch_stratum.a, exit 0. Per-coin isolation held (bch tree only). No main/node wiring yet.
…or + share-diff
Implement the three deferred BCHWorkSource hot-path methods, porting the BTC
v35 work source minus the BCH divergences (no SegWit, /c2pool-bch/ tag,
CashTokens transparent-carry, CTOR tx-order owned by TemplateBuilder):
- build_connection_coinbase(): v36 coinbase author — BIP34 height + pool
tag scriptSig, PPLNS payouts (sorted asc amount/script, subsidy/200
finder fee from donation), OP_RETURN ref_hash + 8B nonce slot. NON-witness
throughout; output_count carries no witness-commitment output. Byte-shape
is consensus-bearing (pinned by coinbase-KAT vs p2pool-merged-v36 oracle).
- mining_submit(): reconstruct coinb1||en1||en2||coinb2, SHA256d coinbase
txid, ascend stratum merkle branches, build 80B header, SHA256d classify
vs block/share target. Block-found fires the dual-path broadcaster
(embedded P2P relay + BCHN-RPC submitblock fallback) and screams if a won
block reaches NEITHER sink. Share-target hit dispatches create_share_fn_.
- compute_share_difficulty(): SHA256d header rebuild -> target_to_difficulty
(BCH SHA256d PoW family; no scrypt).
tx_data for full-block assembly built inline (no cross-tree btc memo include —
per-coin isolation). Adds anon-namespace LE byte helpers. Syntax-clean
(-fsyntax-only, -std=c++20). bch tree only; branch-only, merge operator-gated.
Oracle-conforming fix for the G2 coinbase-KAT divergence (data.py generate_transaction, v36_active path): - D1: donation/marker output forced LAST (immediately before OP_RETURN), excluded from the (amount asc, script asc) sort. Prior inline-sorted ordering diverged whenever donation was not the largest payout -> a sharechain fork. - D2: V36 >=1-satoshi consensus marker rule -- when total donation rounds to 0 and subsidy>0, decrement the largest PPLNS payout by 1 sat (deterministic (amount, script) tiebreak) and move it into the donation output. Zero-value donation is no longer dropped by the amount>0 filter. - D3: PPLNS dests capped to the largest 4000 (oracle dests[-4000:]). Single-coin fenced: src/impl/bch/stratum/work_source.cpp only. No core, no bitcoin_family. KAT + finder-fee-vs-oracle confirm follow as next slices; branch-only, merge operator-gated.
Register node.cpp and the BCHWorkSource/protocol dispatch TUs in the c2pool-bch add_executable stanza so NodeImpl:: symbols resolve, closing the --pool/--stratum link gap. Additive single-coin CMake stanza; no shared-base or peer-coin build changes. share_tracker.hpp carries the pool-node share-write integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M5 pool-node link slice — c2pool-bch stratum serve plumbing
Links the BCH pool-node translation units into the
c2pool-bchexecutable sothe pool/stratum serve path builds and resolves. Closes the
--poollink gap(
NodeImpl::symbols were declared but never compiled into the binary).Scope (fence-clean, single-coin)
All changes under
src/impl/bch/*plus one additive stanza insrc/c2pool/CMakeLists.txt(compiles the BCH TUs; no behaviour change for othercoins). No peer coin dirs or shared consensus logic touched.
Slices: BCHWorkSource skeleton (IWorkSource) -> bch_coin library wiring ->
work-assembly off TemplateBuilder -> share-write hot path -> coinbase output
ordering conformed to p2pool-merged-v36 gentx -> link TUs into executable.
Surface-for-tap (NOT auto-merge)
The
conform coinbase output ordering to p2pool-merged-v36 gentxcommit isconsensus-bearing, so this is operator-tap gated per integrator fence ruling.
Not in scope
This is link/serve plumbing only. It does not assert BCH block-production
parity — per-coin block-production (G0-G3) gates on BCH's own migration work
and is tracked separately.
All commits GPG-signed (50AB1379). Rebased clean onto master.