Skip to content

Commit 8c82dbf

Browse files
committed
feat(bch): relocate G2 block-target pin to single template source
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.
1 parent d2066f9 commit 8c82dbf

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/impl/bch/stratum/work_source.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ BCHWorkSource::cached_template() const
208208
auto built = bch::coin::TemplateBuilder::build_template(chain_, mempool_, is_testnet_);
209209
if (!built) return nullptr; // chain has no tip yet
210210

211+
// [ISOLATED-NET DEMO / G2] Env-gated block-target pin (single source).
212+
// On a genesis-difficulty isolated net the substrate hands GBT bits =
213+
// powLimit (regtest 0x207fffff), so every pseudoshare trivially clears
214+
// block and the p2pool sharechain counter cannot move distinct from
215+
// block-founds. When BCH_DEMO_BLOCK_BITS is set, pin the template block
216+
// bits to a fixed harder compact target here -- on the mutable build
217+
// result before it is frozen into the shared cache -- so the coinbase,
218+
// the header nBits, and core stratum_server gbt_block_nbits all read one
219+
// consistent value; the bulk of accepted shares then land as STORED
220+
// shares and block-founds stay rare. OFF unless the env var is set;
221+
// never active on normal or mainnet runs. BCH-local (no shared-core edit).
222+
if (const char* e = std::getenv("BCH_DEMO_BLOCK_BITS"); e && *e)
223+
built->m_data["bits"] = std::string(e);
224+
211225
auto sp = std::make_shared<const bch::coin::rpc::WorkData>(std::move(*built));
212226
std::lock_guard<std::mutex> lk(template_mutex_);
213227
template_cache_ = sp;
@@ -557,18 +571,8 @@ nlohmann::json BCHWorkSource::mining_submit(
557571
else share_target.SetCompact(/*diff 1*/ 0x1d00ffff);
558572

559573
uint256 block_target;
560-
{
561-
// [ISOLATED-NET DEMO / G2] Env-gated static block-target pin. When
562-
// BCH_DEMO_BLOCK_BITS is set, classify block-founds against a fixed,
563-
// harder compact-bits target so pseudoshares stop trivially clearing
564-
// block on a genesis-difficulty isolated net (substrate at diff 1 =>
565-
// GBT bits 1d00ffff), letting the p2pool sharechain counter increment
566-
// distinct from block-founds. OFF unless the env var is set -- never
567-
// active on normal or mainnet runs; BCH-local, no shared-core edit.
568-
std::string bt_bits = job->block_nbits.empty() ? job->nbits : job->block_nbits;
569-
if (const char* e = std::getenv("BCH_DEMO_BLOCK_BITS"); e && *e) bt_bits = e;
570-
block_target.SetCompact(parse_be_hex_u32(bt_bits));
571-
}
574+
block_target.SetCompact(parse_be_hex_u32(
575+
job->block_nbits.empty() ? job->nbits : job->block_nbits));
572576

573577
auto pow_hex_short = pow_hash.GetHex().substr(0, 16);
574578

0 commit comments

Comments
 (0)