Skip to content

Commit bf372f4

Browse files
committed
bch(g3): --testnet4 net-params path -- magic e2b7daaf + own-genesis selector
Wire BCH testnet4 into the c2pool-bch --pool entrypoint so the embedded daemon selects testnet4 consensus params instead of falling back to testnet3. Prior: run_pool had no testnet4 branch, so it emitted testnet3 magic f4e5f3f4 + testnet3 genesis; BCHN EOF-dropped the peer right after connect and HeaderChain stuck at h0. - config_coin.hpp: m_testnet4 flag (testnet-class for ABLA/ASERT). - embedded_daemon.hpp: select BCHChainParams::testnet4() (own genesis 000000001dd4.., ASERT anchor 16844) when m_testnet4. - main_bch.cpp: --testnet4 arg (port 28333); bch_magic_bytes() emits e2b7daaf (CTestNet4Params, verified vs bchn29 rodata); run_pool threads testnet4 through magic / params / banner label. testnet4() + asert_testnet4() consensus constants already in master; this is CLI + selector wiring only. Behavioural proof: --pool --testnet4 vs a testnet4 BCHN substrate handshakes off h0 (start_height=312925, BCHN 29.0.0), EOF-drop gone, HeaderChain advances past h0. No p2pool-merged-v36 surface change (subsidy / payout / version-gate untouched) -> surface-for-tap. Per-coin isolation intact: only src/impl/bch/ plus the c2pool-bch-exclusive main_bch.cpp entrypoint; no src/core / bitcoin_family / peer-coin hunks. Cosmetic follow-up (tracked, non-consensus): leveldb path + BCHWorkSource still label bitcoincash_testnet for testnet4; magic/genesis/P2P path proven correct by sync off the real testnet4 chain.
1 parent f092355 commit bf372f4

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

src/c2pool/main_bch.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void print_banner(const char* argv0)
7474
<< " " << argv0 << " --with-peer-verify [--testnet] [--peer HOST:PORT] [--max-seconds N]\n"
7575
<< " " << argv0 << " --leg-c-capture [--rpc-conf PATH]\n"
7676
<< " " << argv0 << " --leg-c-capture-p2p [--rpc-conf PATH] [--p2p-port N]\n"
77-
<< " " << argv0 << " --pool [--testnet|--regtest] [--stratum [HOST:]PORT] [--peer HOST:PORT] [--anchor N] [--rpc-conf PATH]\n\n"
77+
<< " " << argv0 << " --pool [--testnet|--testnet4|--regtest] [--stratum [HOST:]PORT] [--peer HOST:PORT] [--anchor N] [--rpc-conf PATH]\n\n"
7878
<< "Status: M5 pool/sharechain + embedded-daemon assembly live.\n"
7979
<< " The embedded daemon (coin/embedded_daemon.hpp) is the primary\n"
8080
<< " work source; external BCHN-RPC stays as the fallback.\n"
@@ -603,8 +603,21 @@ int run_leg_c_capture_p2p(const std::string& conf_path, uint16_t p2p_port)
603603
//
604604
// p2pool-merged-v36 surface: NONE -- run-loop bring-up + block dispatch, not
605605
// share/PPLNS/coinbase/PoW bytes. PER-COIN ISOLATION: src/impl/bch only.
606+
// BCH wire-protocol magic bytes per network (pchMessageStart).
607+
// Source: BCHN chainparams.cpp, verified vs staged bchn29 bitcoind rodata:
608+
// mainnet e3e1f3e8, testnet3 f4e5f3f4, testnet4 e2b7daaf, regtest dab5bffa.
609+
static std::vector<std::byte> bch_magic_bytes(bool testnet, bool testnet4, bool regtest)
610+
{
611+
std::string hex;
612+
if (regtest) hex = "dab5bffa"; // CRegTestParams
613+
else if (testnet4) hex = "e2b7daaf"; // CTestNet4Params
614+
else if (testnet) hex = "f4e5f3f4"; // CTestNetParams (testnet3)
615+
else hex = "e3e1f3e8"; // CMainParams
616+
return ParseHexBytes(hex);
617+
}
618+
606619
int run_pool(const std::string& peer_host, uint16_t peer_port, bool testnet,
607-
bool regtest, uint32_t anchor_height,
620+
bool testnet4, bool regtest, uint32_t anchor_height,
608621
const std::string& stratum_addr, uint16_t stratum_port,
609622
const std::string& rpc_conf)
610623
{
@@ -615,17 +628,14 @@ int run_pool(const std::string& peer_host, uint16_t peer_port, bool testnet,
615628
bch::Config config("bch");
616629
// Skip Config::init() (no on-disk pool.yaml/coin.yaml); set only the fields
617630
// the run-loop touches, from BCH chainparams.
618-
config.coin()->m_testnet = testnet || regtest;
631+
config.coin()->m_testnet = testnet || testnet4 || regtest;
632+
config.coin()->m_testnet4 = testnet4; // -> BCHChainParams::testnet4() (own genesis 000000001dd4.., magic e2b7daaf)
619633
config.coin()->m_symbol = "BCH";
620634
config.coin()->m_p2p.address = NetService(peer_host, peer_port);
621635
// BCH P2P network magic (pchMessageStart, BCHN chainparams.cpp): mainnet
622636
// e3e1f3e8, testnet3 f4e5f3f4, regtest dab5bffa. Wrong magic == BCHN drops
623637
// the peer with EOF right after connect.
624-
config.coin()->m_p2p.prefix = regtest
625-
? std::vector<std::byte>{ std::byte{0xda}, std::byte{0xb5}, std::byte{0xbf}, std::byte{0xfa} }
626-
: (testnet
627-
? std::vector<std::byte>{ std::byte{0xf4}, std::byte{0xe5}, std::byte{0xf3}, std::byte{0xf4} }
628-
: std::vector<std::byte>{ std::byte{0xe3}, std::byte{0xe1}, std::byte{0xf3}, std::byte{0xe8} });
638+
config.coin()->m_p2p.prefix = bch_magic_bytes(testnet, testnet4, regtest);
629639
// Sharechain identity: BCH p2pool PREFIX namespaces the sharechain P2P
630640
// framing. standup_pool_run's Node reads pool()->m_prefix.
631641
config.pool()->m_prefix = ParseHexBytes(bch::PoolConfig::prefix_hex());
@@ -651,7 +661,7 @@ int run_pool(const std::string& peer_host, uint16_t peer_port, bool testnet,
651661

652662
std::cout
653663
<< "[pool] c2pool-bch pool run-loop"
654-
<< (regtest ? " (regtest)" : (testnet ? " (testnet)" : " (mainnet)"))
664+
<< (regtest ? " (regtest)" : (testnet4 ? " (testnet4)" : (testnet ? " (testnet)" : " (mainnet)")))
655665
<< " -- BCHN peer " << peer_host << ":" << peer_port
656666
<< ", cold-start anchor=" << anchor_height;
657667
if (stratum_port)
@@ -662,7 +672,7 @@ int run_pool(const std::string& peer_host, uint16_t peer_port, bool testnet,
662672

663673
try {
664674
bch::standup_pool_run(ioc, config, anchor_height,
665-
stratum_addr, stratum_port, testnet || regtest, regtest);
675+
stratum_addr, stratum_port, testnet || testnet4 || regtest, regtest);
666676
} catch (const std::exception& e) {
667677
std::cout << "[pool] FATAL: " << e.what() << "\n";
668678
return 1;
@@ -687,6 +697,7 @@ int main(int argc, char** argv)
687697
uint16_t leg_c_p2p_port = 18444; // BCHN regtest P2P default
688698
std::string rpc_conf;
689699
bool testnet = false;
700+
bool testnet4 = false;
690701
bool near_tip = false;
691702
bool auto_kick = false;
692703
std::string host = "192.168.86.110"; // VM300 bchn-bch
@@ -721,6 +732,7 @@ int main(int argc, char** argv)
721732
leg_c_p2p_port = static_cast<uint16_t>(std::stoul(argv[++i]));
722733
if (std::strcmp(argv[i], "--rpc-conf") == 0 && i + 1 < argc) rpc_conf = argv[++i];
723734
if (std::strcmp(argv[i], "--testnet") == 0) { testnet = true; port = 18333; }
735+
if (std::strcmp(argv[i], "--testnet4") == 0) { testnet4 = true; port = 28333; }
724736
if (std::strcmp(argv[i], "--near-tip") == 0) near_tip = true;
725737
if (std::strcmp(argv[i], "--auto-kick") == 0) auto_kick = true;
726738
if (std::strcmp(argv[i], "--peer") == 0 && i + 1 < argc) {
@@ -758,7 +770,7 @@ int main(int argc, char** argv)
758770
}
759771

760772
if (want_pool)
761-
return run_pool(host, port, testnet, regtest, anchor_height, stratum_addr, stratum_port, rpc_conf);
773+
return run_pool(host, port, testnet, testnet4, regtest, anchor_height, stratum_addr, stratum_port, rpc_conf);
762774

763775
if (want_with_peer_verify)
764776
return run_with_peer_verify(host, port, testnet, max_seconds);

src/impl/bch/coin/embedded_daemon.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ class EmbeddedDaemon {
8585
bool is_regtest = false)
8686
: m_config(config),
8787
m_chain(is_regtest ? BCHChainParams::regtest()
88-
: (config->m_testnet ? BCHChainParams::testnet()
89-
: BCHChainParams::mainnet())),
88+
: (config->m_testnet4 ? BCHChainParams::testnet4()
89+
: (config->m_testnet ? BCHChainParams::testnet()
90+
: BCHChainParams::mainnet()))),
9091
m_pool(),
9192
m_embedded(m_chain, m_pool, config->m_testnet),
9293
m_node(context, config),

src/impl/bch/config_coin.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CoinConfig : protected core::Fileconfig
106106
std::string m_symbol;
107107
int m_share_period{};
108108
bool m_testnet {false};
109+
bool m_testnet4 {false}; // BCH testnet4: OWN genesis (000000001dd4..) + magic e2b7daaf; testnet-class for ABLA/ASERT
109110
};
110111

111112
} // namespace bch

0 commit comments

Comments
 (0)