@@ -68,7 +68,7 @@ void print_banner(const char* argv0)
6868 std::cout
6969 << " c2pool-bch " << C2POOL_VERSION << " — Bitcoin Cash (SHA256d, V36)\n\n "
7070 << " Usage: " << argv0 << " [--version] [--help] [--selftest]\n "
71- << " " << argv0 << " --ibd [--testnet] [--near-tip] [--peer HOST:PORT] [--max-seconds N]\n "
71+ << " " << argv0 << " --ibd [--testnet] [--near-tip] [--auto-kick] [-- peer HOST:PORT] [--max-seconds N]\n "
7272 << " " << argv0 << " --leg-c-capture [--rpc-conf PATH]\n "
7373 << " " << argv0 << " --leg-c-capture-p2p [--rpc-conf PATH] [--p2p-port N]\n\n "
7474 << " Status: M5 pool/sharechain + embedded-daemon assembly live.\n "
@@ -123,7 +123,7 @@ int run_selftest()
123123// handshake is up, and logs the evidence tuple every TICK seconds until the
124124// chain catches the peer tip (with no in-flight blocks) or the deadline fires.
125125int run_ibd (const std::string& host, uint16_t port, bool testnet, uint32_t max_seconds,
126- bool near_tip)
126+ bool near_tip, bool auto_kick )
127127{
128128 boost::asio::io_context ctx;
129129
@@ -157,6 +157,16 @@ int run_ibd(const std::string& host, uint16_t port, bool testnet, uint32_t max_s
157157 else
158158 daemon.start_ibd (peer);
159159
160+ // --auto-kick proves the handshake-gated self-start: arm the embedded
161+ // header-sync kick on the P2P node and DO NOT poll ibd_kick_sync(). If the
162+ // synced height advances, the verack handler self-issued the initial
163+ // getheaders on-wire with no external kick (production run() contract).
164+ if (auto_kick) {
165+ daemon.arm_auto_getheaders ();
166+ std::cout << " [ibd] auto-kick armed — header sync self-starts at handshake"
167+ " (no manual getheaders poll)\n " ;
168+ }
169+
160170 const uint32_t init_height = daemon.ibd_synced_height ();
161171 std::cout << " [ibd] read-only sync vs " << host << " :" << port
162172 << (testnet ? " (testnet)" : " (mainnet)" )
@@ -172,10 +182,16 @@ int run_ibd(const std::string& host, uint16_t port, bool testnet, uint32_t max_s
172182 tick.start (TICK , [&]() {
173183 elapsed += TICK ;
174184 if (!kicked && daemon.ibd_handshake_ready ()) {
175- daemon.ibd_kick_sync ();
185+ if (!auto_kick) {
186+ daemon.ibd_kick_sync ();
187+ std::cout << " [ibd] handshake up; getheaders kicked from height "
188+ << daemon.ibd_synced_height () << " \n " ;
189+ } else {
190+ std::cout << " [ibd] handshake up; AUTO getheaders self-started"
191+ " (no manual kick) from height "
192+ << daemon.ibd_synced_height () << " \n " ;
193+ }
176194 kicked = true ;
177- std::cout << " [ibd] handshake up; getheaders kicked from height "
178- << daemon.ibd_synced_height () << " \n " ;
179195 }
180196 const uint32_t h = daemon.ibd_synced_height ();
181197 const uint32_t tip = daemon.ibd_peer_tip ();
@@ -462,6 +478,7 @@ int main(int argc, char** argv)
462478 std::string rpc_conf;
463479 bool testnet = false ;
464480 bool near_tip = false ;
481+ bool auto_kick = false ;
465482 std::string host = " 192.168.86.110" ; // VM300 bchn-bch
466483 uint16_t port = 8333 ;
467484 uint32_t max_seconds = 600 ;
@@ -480,6 +497,7 @@ int main(int argc, char** argv)
480497 if (std::strcmp (argv[i], " --rpc-conf" ) == 0 && i + 1 < argc) rpc_conf = argv[++i];
481498 if (std::strcmp (argv[i], " --testnet" ) == 0 ) { testnet = true ; port = 18333 ; }
482499 if (std::strcmp (argv[i], " --near-tip" ) == 0 ) near_tip = true ;
500+ if (std::strcmp (argv[i], " --auto-kick" ) == 0 ) auto_kick = true ;
483501 if (std::strcmp (argv[i], " --peer" ) == 0 && i + 1 < argc) {
484502 std::string hp = argv[++i];
485503 const auto c = hp.rfind (char (58 )); // ASCII colon
@@ -515,7 +533,7 @@ int main(int argc, char** argv)
515533 }
516534
517535 if (want_ibd)
518- return run_ibd (host, port, testnet, max_seconds, near_tip);
536+ return run_ibd (host, port, testnet, max_seconds, near_tip, auto_kick );
519537
520538 // Default / --selftest: drive the live ABLA budget path, then exit.
521539 return run_selftest ();
0 commit comments