feat(bch): wire local-share author path (G2 sharechain accumulation)#642
Merged
Conversation
Add BCH_DEMO_BLOCK_BITS override at the stratum block-found classification site. On a genesis-difficulty isolated net the substrate returns GBT bits 1d00ffff (diff 1), so every pseudoshare trivially clears block and the p2pool sharechain counter cannot increment distinct from block-founds. When set, the env var pins a fixed harder compact-bits block target for the IS-A-BLOCK check only, so the bulk of accepted shares land as shares and the sharechain counter moves off zero while block-founds stay rare. BCH-local (src/impl/bch/stratum only, no shared-core edit); OFF unless the env var is set; never active on normal or mainnet runs. Share acceptance and PPLNS weighting are untouched.
…arechain On an empty sharechain compute_share_target genesis branch returns bits==0, so build_connection_coinbase left share_bits_ at 0. StratumServer then derives pool_difficulty==0, its is_pool_share gate (stratum_server.cpp) never fires, no P2P share is ever created, and share_bits_ can never advance past 0 -> cold-start deadlock. When rh_result.bits==0 and share_bits_ is still unseeded, fall back to rh_result.max_bits (the MAX_TARGET easiest-share floor) so the first real submission clears the gate and bootstraps the chain. Warm path unchanged. BCH-local (src/impl/bch/); no src/core/ change.
Move the env-gated BCH_DEMO_BLOCK_BITS pin off the work_source mining_submit classification site (ineffective: core stratum_server.cpp does its own IS-A-BLOCK check from gbt_block_nbits) onto the mutable build_template result in cached_template(), before it is frozen into the shared cache. All readers -- coinbase, header nBits, and core gbt_block_nbits -- then see one consistent harder block target on the isolated net, so pseudoshares stop trivially clearing block. Verified on regtest: IS-A-BLOCK 100% -> 0% of accepted shares. Isolated-net demo only; OFF unless the env var is set; BCH-local.
…are-create The empty-sharechain cold-start seed for share_bits_ lived in build_connection_coinbase (the share-CREATE path), but that path only runs after core::StratumServer clears its is_pool_share gate, which is derived from pool_difficulty, itself derived from share_bits_. On an empty chain share_bits_==0 => pool_difficulty==0 => the gate never fires => no share is created => share_bits_ never advances: a deadlock the share-create seed cannot break because it sits behind the gate it opens. Relocate a floor-seed into cached_template() on the WORK-GEN path, which runs on every work poll independent of share creation. Seed both atomics to target_to_bits_upper_bound(PoolConfig::max_target()) -- the exact floor compute_share_target emits for max_bits on the genesis branch. Idempotent (fires only while unseeded). Verified on .198 regtest: pool_difficulty 0 -> 1 at cold start, is_pool_share gate now live from first work poll.
Symmetric to BCH_DEMO_BLOCK_BITS. The cold-start share-floor seed hardcoded PoolConfig::max_target() (~diff-1 / 0x1d00ffff), which a CPU grinder cannot clear at a useful rate, so the sharechain STORED counter never advanced independently of block-founds even after the cold-start deadlock fix (f8a1263). BCH_DEMO_SHARE_BITS pins the cold-start share floor to a CPU-clearable compact target on an isolated net so a grinder promotes real STORED shares while BCH_DEMO_BLOCK_BITS keeps block-founds rare -- proving 0->N accumulation without ASIC hashrate. Env-gated, off by default, never active on normal or mainnet runs. BCH-local.
…ares populate the sharechain
BCH ran as a bare stratum proxy: BCHWorkSource accepted miner submissions
that cleared the sharechain target but DROPPED them (accepted (no-tracker),
work_source.cpp) because create_share_fn_ was never wired -- Stored shares
stuck at 0. This wires the sharechain WRITE path (mirrors main_btc.cpp:1118):
- pool_entrypoint.hpp: set_best_share_hash_fn / set_donation_script /
set_create_share_fn. create_share_fn parses the 80B header into a
SmallBlockHeaderType, rebuilds coinbase + merkle branches, and calls
bch::create_local_share under a non-blocking exclusive tracker lock, then
broadcast_share + notify_local_share on success.
- share_tracker.hpp: add(ShareT*) raw-pointer overload (create_local_share
is the first caller; mirrors btc SSOT).
BCH standalone SHA256d parent: merged_addrs={}, segwit_active=false. Verified
on regtest: grinder 8/8 accepted -> create_local_share_v35 added 8 shares ->
ASYNC-THINK chain=8 verified=8 (was 0). ref_hash/pplns are a follow-up slice.
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.
Wires the BCH local-share author path (create_share_fn) in pool_entrypoint.hpp, mirroring main_btc.cpp:1118. Miner-accepted work now flows create_local_share -> tracker.add -> broadcast, so the sharechain accumulates instead of logging accepted (no-tracker).
Fixes G2 Stored=0: prior to this, m_tracker.add only ran on P2P peer-receive (node.cpp:504); there was no local author path, so locally-mined shares never entered the store.
Verified live on regtest .198: grinder 8/8 -> create_share_v35: added share x8, ACCEPTED + ADDED (no more no-tracker), sharechain 0 -> 8, [ASYNC-THINK] chain=8 verified=8.
Residual (tracked separately, non-fatal to local accumulation): verify_share hash mismatch warning on stored share identity (P2P peer-verify path) — merkle/header-field reconstruction divergence between verify_share and create_local_share. Chased on the follow-up ratchet-staging branch.
Scope: src/impl/bch/ only. No cross-coin / bitcoin_family changes. GPG-signed 285EFE76.