@@ -70,16 +70,18 @@ namespace io = boost::asio;
7070static void print_usage ()
7171{
7272 std::cerr <<
73- " Usage: c2pool-btc [--testnet | --testnet4] --bitcoind HOST:PORT\n "
73+ " Usage: c2pool-btc [--testnet | --testnet4 | --regtest ] --bitcoind HOST:PORT\n "
7474 " [--p2pool HOST:PORT]\n "
7575 " \n "
7676 " --testnet BTC testnet3 chain (genesis 000000000933ea01...)\n "
7777 " --testnet4 BTC testnet4 chain (genesis 00000000da84f2ba...)\n "
78+ " --regtest BTC regtest chain (genesis 0f9188f13cb7b2c7...)\n "
7879 " default: mainnet\n "
7980 " --bitcoind H:P bitcoind P2P endpoint host:port\n "
8081 " e.g. 127.0.0.1:8333 (mainnet)\n "
8182 " 127.0.0.1:18333 (testnet3)\n "
8283 " 127.0.0.1:48333 (testnet4)\n "
84+ " 127.0.0.1:18443 (regtest)\n "
8385 " --p2pool H:P BTC p2pool peer (jtoomim/SPB v35 + protocol 3502)\n "
8486 " e.g. p2p-spb.xyz:9333\n "
8587 " --stratum [H:]P stratum TCP listener for miners (B4-stratum)\n "
@@ -101,10 +103,11 @@ static void print_usage()
101103
102104// / BTC wire-protocol magic bytes per network (pchMessageStart).
103105// / Source: ref/bitcoin/src/kernel/chainparams.cpp.
104- static std::vector<std::byte> btc_magic_bytes (bool testnet, bool testnet4)
106+ static std::vector<std::byte> btc_magic_bytes (bool testnet, bool testnet4, bool regtest )
105107{
106108 std::string hex;
107- if (testnet4) hex = " 1c163f28" ; // testnet4 (line 335-338)
109+ if (regtest) hex = " fabfb5da" ; // regtest (CRegTestParams)
110+ else if (testnet4) hex = " 1c163f28" ; // testnet4 (line 335-338)
108111 else if (testnet) hex = " 0b110907" ; // testnet3 (line 235-238)
109112 else hex = " f9beb4d9" ; // mainnet (line 117-120)
110113 return ParseHexBytes (hex);
@@ -116,6 +119,7 @@ int main(int argc, char* argv[])
116119
117120 bool testnet = false ;
118121 bool testnet4 = false ;
122+ bool regtest = false ;
119123 std::string bitcoind_host;
120124 uint16_t bitcoind_port = 0 ;
121125 std::string p2pool_host;
@@ -143,6 +147,10 @@ int main(int argc, char* argv[])
143147 testnet = true ;
144148 testnet4 = true ;
145149 }
150+ else if (arg == " --regtest" )
151+ {
152+ regtest = true ;
153+ }
146154 else if (arg == " --bitcoind" && i + 1 < argc)
147155 {
148156 std::string ep = argv[++i];
@@ -223,14 +231,17 @@ int main(int argc, char* argv[])
223231 std::cerr << " [BTC] warning: --prefix ignored without --network-id\n " ;
224232 btc::PoolConfig::set_network_id (network_id_hex, prefix_hex);
225233
226- auto chain_params = testnet4
227- ? btc::coin::BTCChainParams::testnet4 ()
228- : (testnet ? btc::coin::BTCChainParams::testnet ()
229- : btc::coin::BTCChainParams::mainnet ());
234+ auto chain_params = regtest
235+ ? btc::coin::BTCChainParams::regtest ()
236+ : (testnet4
237+ ? btc::coin::BTCChainParams::testnet4 ()
238+ : (testnet ? btc::coin::BTCChainParams::testnet ()
239+ : btc::coin::BTCChainParams::mainnet ()));
230240
231- const std::string net_subdir = testnet4 ? " bitcoin_testnet4"
241+ const std::string net_subdir = regtest ? " bitcoin_regtest"
242+ : (testnet4 ? " bitcoin_testnet4"
232243 : (testnet ? " bitcoin_testnet"
233- : " bitcoin" );
244+ : " bitcoin" )) ;
234245
235246 const std::filesystem::path net_dir = core::filesystem::config_path () / net_subdir;
236247 std::error_code ec;
@@ -240,7 +251,7 @@ int main(int argc, char* argv[])
240251 const std::string utxo_db_path = (net_dir / " utxo_view_db" ).string ();
241252
242253 LOG_INFO << " [BTC] c2pool-btc starting — net="
243- << (testnet4 ? " testnet4" : (testnet ? " testnet3" : " mainnet" ));
254+ << (regtest ? " regtest " : ( testnet4 ? " testnet4" : (testnet ? " testnet3" : " mainnet" ) ));
244255 LOG_INFO << " [BTC] HeaderChain DB: " << chain_db_path;
245256 LOG_INFO << " [BTC] UTXO DB: " << utxo_db_path;
246257 LOG_INFO << " [BTC] Genesis: " << chain_params.genesis_hash .GetHex ();
@@ -346,9 +357,10 @@ int main(int argc, char* argv[])
346357 btc::Config config (net_subdir);
347358 // Skip Config::init() — it would try to load pool.yaml + coin.yaml
348359 // from disk; for B2-net smoke we set fields directly from chainparams.
349- config.coin ()->m_p2p .prefix = btc_magic_bytes (testnet, testnet4);
360+ config.coin ()->m_p2p .prefix = btc_magic_bytes (testnet, testnet4, regtest );
350361 config.coin ()->m_p2p .address = NetService (bitcoind_host, bitcoind_port);
351- config.coin ()->m_testnet = testnet;
362+ config.coin ()->m_testnet = testnet || regtest;
363+ config.coin ()->m_regtest = regtest;
352364 config.coin ()->m_symbol = " BTC" ;
353365
354366 btc::coin::Node<btc::Config> coin_node (&ioc, &config);
@@ -668,6 +680,14 @@ int main(int argc, char* argv[])
668680 << p2pool_host << " :" << p2pool_port
669681 << " (addrs.json reset to enforce exclusive target)" ;
670682 }
683+ else if (regtest)
684+ {
685+ // Isolated regtest standup: NEVER dial the public mainnet p2pool seeds
686+ // (DEFAULT_BOOTSTRAP_HOSTS). Leaving the addr store empty keeps the
687+ // sharechain solo/local so a won block is never relayed to real peers.
688+ // Supply --p2pool HOST:PORT to dial an explicit isolated tuned-net peer.
689+ LOG_INFO << " [BTC] Sharechain bootstrap: regtest — 0 public seeds (isolated)" ;
690+ }
671691 else
672692 {
673693 // Default seed list (PoolConfig::DEFAULT_BOOTSTRAP_HOSTS, port 9333).
0 commit comments