Skip to content

fix(bch): store coinbase input scriptSig in share m_coinbase (verified=0 root)#645

Open
frstrtr wants to merge 5 commits into
masterfrom
bch/g2-local-share-author
Open

fix(bch): store coinbase input scriptSig in share m_coinbase (verified=0 root)#645
frstrtr wants to merge 5 commits into
masterfrom
bch/g2-local-share-author

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Residual on top of merged #642. Closes the verified=0 root: create_share_fn was feeding the entire serialized coinbase tx into the share m_coinbase field, but share_init_verify enforces the consensus 2..100 byte bound on the coinbase input scriptSig — so every locally-authored G2 share threw "bad coinbase size" and stayed unverified. Fix parses the coinbase tx and stores only the input scriptSig; the full tx still rides via actual_coinbase_bytes for gentx byte-parity.

Scope: single-coin, src/impl/bch only. No shared-base / src/core / other-coin changes.

Evidence:

  • Build GREEN.
  • Regtest grind: 13 accepted, 0 rejected.
  • Pool-side bad-coinbase throws: zero (was every share).
  • verified count moved 0 -> 1 (shares verify for the first time).

SHA 477c695, GPG-signed. Not self-merged — awaiting integrator/operator merge-tap after full CI rollup is green.

Known follow-on (separate, not in this PR): chain holds at height 2; stratum job not refreshing to the new verified tip per share. Tracked next inside src/impl/bch.

frstrtr added 5 commits July 5, 2026 21:09
…or (G2 peer-verify)

The local-share author path emitted a bare coinbase (no p2pool OP_RETURN
ref_hash) and ran create_local_share with has_frozen=false, so every share
it produced was non-peer-verifiable: recomputed ref_hash != stored, 100% of
the time (verify_share mismatch). Root cause was a missing set_ref_hash_fn
call in the pool entrypoint -- the work-source scaffolding already gated the
OP_RETURN emit and the frozen snapshot on ref_hash_fn being set.

Wire set_ref_hash_fn to a lambda that walks the share tracker for the
share target (compute_share_target), absheight, abswork and far_share_hash
with a clipped timestamp, mirroring create_local_share_v35s chain-position
math, and computes the ref_hash via compute_ref_hash_for_work. Thread the
resulting frozen snapshot (job.frozen_ref) back into create_local_share with
has_frozen=true so the create-side reconstruction is byte-exact by
construction (frozen round-trip) and the frozen values are chain-correct.

BCH is standalone SHA256d: no segwit, no merged dimension. Diff fenced to
the BCH tree (pool entrypoint only).
…ref_hash/frozen/gate read one share target (G2 verify_share conform)

Isolated-net demo knob (env-gated OFF on normal/mainnet). On a CPU-grind
regtest the ref_hash previously read compute_share_target ~diff-1 floor
while the core pool_difficulty gate read the BCH_DEMO_SHARE_BITS floor --
two share targets, so verify_share recompute could not match the stored
share. Reading ONE target here eliminates the verify_share hash mismatch.
BCH-local; fenced to src/impl/bch/.
…freshes with new tip as prev_share (G2 chain-link)

Every authored share landed height=1 prev=0000 as an orphan sibling
because the miner kept grinding the job frozen at pool start (prev=
genesis): notify_local_share updated the internal best/think() but never
rang the stratum work-refresh. Core StratumServer::notify_all() already
re-polls best_share_hash_fn and pushes a clean mining.notify with the new
sharechain tip; this wires the local-share author path to it (BCH-side
only, core unchanged). Restores chain growth past height 1.
…chain-grow)

The prev-link fix lets the sharechain grow past height 1, but two 99-deep
get_nth_parent_key(prev,99) far_share walks -- the ref_hash_fn lambda in
pool_entrypoint and the create_local_share author in share_check -- threw
get_nth_parent_key: chain too short once the chain outgrew genesis yet was
still shorter than the 99 lookback, aborting every share past height 2. The
_v35 author already degrades to far=None via try/catch on this exact case;
mirror that guard into both sites so far_share collapses to None on a short
chain (matches p2pool get_nth_parent_hash(prev,99) semantics). Regtest grind
now grows chain 1->12 with zero create-share throws.
create_share_fn fed the entire serialized coinbase transaction into the
share m_coinbase field; share_init_verify enforces the consensus 2..100
byte bound on the coinbase input scriptSig and threw "bad coinbase size",
leaving every locally-authored G2 share unverified (verified=0). Parse the
coinbase tx and extract only the input scriptSig; the full tx still rides
via actual_coinbase_bytes for gentx byte-parity.
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