Skip to content

bch(g2): coinbase-author KAT + slice-d pool-serve hot path - #553

Merged
frstrtr merged 5 commits into
masterfrom
bch/g2-work-source
Jul 2, 2026
Merged

bch(g2): coinbase-author KAT + slice-d pool-serve hot path#553
frstrtr merged 5 commits into
masterfrom
bch/g2-work-source

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 26, 2026

Copy link
Copy Markdown
Owner

G2 BCH pool-serve build-out. Merge operator-gated — do NOT auto-merge (consensus-bearing payout values).

Head @1ac084a60 — coinbase-author KAT (this slice)

Pins the v36 coinbase OUTPUT-ASSEMBLY byte-for-byte against the p2pool-merged-v36 oracle.

  • Extracted the assembly (donation forced LAST, >=1-sat marker rule, amount-asc/script-asc sort, dests[-4000:] cap) out of build_connection_coinbase into pure header coinbase_outputs.hpp::assemble_v36_coinbase_outputs() so the KAT exercises the shipping code, not a parallel impl.
  • coinbase_author_kat_test — 3 cases, ground-truth from scripts/gen_g2_oracle.py (verbatim transcription of data.py:920-1085 v36 amounts/dests/payouts):
    1. ordering with a B==C amount tie forcing the script-asc tiebreak; donation marker forced last; <1-sat decrement of the largest (D).
    2. donation forced last even when its amount ties the largest PPLNS payout.
    3. finder-fee removal byte-diff: assembled bytes == oracle v36 gentx AND != the pre-v36 199/200-haircut + subsidy/200 finder-fee control — proves removal, not self-authored.
  • Wired into the pure BCH_ABLA_TESTS CMake list and BOTH build.yml COIN_BCH allowlists (no NOT_BUILT green-by-omission).

Underlying slices (already on branch)

  • @6ed9adbb0 D5: strip v36 finder fee from coinbase author (oracle conform).
  • @fb856b72c D1/D2/D3: coinbase output ordering conform.
  • @5cafef7c8 slice-d: BCHWorkSource mining_submit + coinbase author + share-diff.

Local: KAT 3/3 PASS; work_source.cpp -fsyntax-only RC=0. per-coin isolation: src/impl/bch only; zero p2pool-merged-v36 surface.

@frstrtr
frstrtr force-pushed the bch/g2-work-source branch 3 times, most recently from 55590c0 to eb3a438 Compare July 1, 2026 17:11
frstrtr added 5 commits July 2, 2026 07:45
…ol-merged-v36

The oracle (data.py ~945) fires the subsidy/200 finder fee only in the
not-v36_active branch; the v36 gentx pays no finder fee (pure PPLNS
accounting). The BCH v36 coinbase builder was deducting subsidy/200 from
the donation output and crediting the miner -- a payout-value divergence
from the canonical merged-v36 gentx. Byte-parity is the HARD invariant,
so the sv>=36 path now deducts nothing. Pre-v36 (v35) finder fee remains
in the legacy not-v36 path, untouched. Consensus-bearing (moves payout
values) -- merge stays operator-gated.

BCH-only scope: src/impl/bch/stratum/work_source.cpp. No core, no
bitcoin_family. Syntax-clean. Branch-only on bch/g2-work-source.
…acle

Extract the oracle-conforming coinbase OUTPUT-ASSEMBLY (donation forced last,
>=1-sat marker rule, amount-asc/script-asc sort, dests[-4000:] cap) out of
BCHWorkSource::build_connection_coinbase into the pure header-only
assemble_v36_coinbase_outputs(), so the byte-shape is pinned against the
p2pool-merged-v36 oracle (data.py generate_transaction v36 branch) rather than
asserted against the builder itself.

coinbase_author_kat_test (3 cases, ground-truth from scripts/gen_g2_oracle.py,
a verbatim transcription of the data.py v36 amounts/dests/payouts block):
  1. ordering: amount-asc with a B==C tie exercising the script-asc tiebreak,
     donation marker forced last, <1-sat marker decrement of the largest.
  2. donation forced last even when its amount ties the largest PPLNS payout.
  3. finder-fee removal byte-diff: assembled bytes equal the oracle v36 gentx
     and differ from the pre-v36 199/200-haircut + subsidy/200 finder-fee
     control -- proving the fee was removed, not self-authored.

Wired into the pure BCH_ABLA_TESTS CMake list and BOTH build.yml COIN_BCH
allowlists (no NOT_BUILT green-by-omission). per-coin isolation: src/impl/bch
only; zero p2pool-merged-v36 surface.
Close the M5 served-IWorkSource gap (slice-b criterion 1): standup_pool_run
now constructs bch::stratum::BCHWorkSource off the embedded daemon HeaderChain
+ Mempool and stands up core::StratumServer on the miner-facing bind. A
mainnet-hit (share-author) block routes through the SAME dual-path broadcaster
(embedded P2P primary + BCHN submitblock fallback) as the won-block sink, via
daemon.broadcast_won_block(block_bytes, HexStr(block_bytes)) returning r.any()
-- so the genuine share coinbase is what reaches the network, not a synthetic
solo-cb leg-C block.

stratum_port==0 disables the front-end (daemon-only run-loop preserved). Header
syntax-clean. src/impl/bch only; p2pool-merged-v36 surface NONE (run-loop
bring-up + block dispatch, not share/PPLNS/coinbase bytes). BCH = SHA256d
standalone parent, no-segwit, CashTokens transparent-carry.
First non-harness c2pool-bch entrypoint. --pool stands up the BCH pool
node + embedded coin daemon via bch::standup_pool_run (the prior 0-caller
production standup), binding the dual-path won-block sink and, with
--stratum [HOST:]PORT, the miner-facing BCHWorkSource + StratumServer so a
genuine share-author coinbase is what gets assembled and broadcast.

Config built without a YAML load (matches --ibd harness): P2P magic
(mainnet/testnet/regtest), BCHN peer, and sharechain PREFIX set by hand
from chainparams. External BCHN-RPC fallback retained. --regtest/--anchor
added; banner + arg dispatch wired.

Structural slice (criterion 1): gives standup_pool_run its first caller.
FOUND->ASSEMBLED->ACCEPTED e2e on fresh-genesis regtest is the next
behavioural slice. bch-fenced (src only), p2pool-merged-v36 surface NONE.
--pool --regtest previously collapsed to testnet params (anchor@955700,
P2P->.110) and served unwinnable testnet difficulty, so a single CPU
could never win a block. Thread regtest as a third net distinct from
mainnet/testnet:

- asert.hpp: asert_regtest() + bch_pow_limit_regtest() (fPowNoRetargeting,
  fixed target at powLimit nBits 0x207fffff; ASERT bypassed on regtest)
- header_chain.hpp: BCHChainParams::regtest() (P2P 18444, cold-start tip
  seeded so served nbits == 0x207fffff before first P2P regtest block)
- embedded_daemon.hpp / pool_entrypoint.hpp / main_bch.cpp: is_regtest
  dispatch threaded through the --pool entrypoint

GBT-from-local-regtest-BCHN (regtest_block::build_from_gbt) deferred to a
follow-on sub-slice. Consensus-neutral: regtest-only behavior, no mainnet
path change. Fenced to src/impl/bch/ + main_bch.cpp dispatch.
@frstrtr
frstrtr force-pushed the bch/g2-work-source branch from eb3a438 to a121045 Compare July 2, 2026 07:46
@frstrtr
frstrtr merged commit 47598a0 into master Jul 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant