@@ -161,18 +161,24 @@ MAIN_FUNCTION
161161 options.fee_check_interval = std::chrono::seconds (args.GetIntArg (" -sv2interval" , 0 ));
162162 }
163163
164- // Connect to existing bitcoin-node process or spawn new one.
164+ // Connect to bitcoin-node via IPC
165+ //
166+ // If the node is not available, keep retrying in a loop every 10 seconds.
165167 std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeBasicInit (" sv2-tp" , argc > 0 ? argv[0 ] : " " )};
166168 assert (mine_init);
167169 std::unique_ptr<interfaces::Init> node_init;
168- try {
169- std::string address{args.GetArg (" -ipcconnect" , " unix" )};
170- node_init = mine_init->ipc ()->connectAddress (address);
171- } catch (const std::exception& exception) {
172- tfm::format (std::cerr, " Error: %s\n " , exception.what ());
173- tfm::format (std::cerr, " Probably bitcoin-node is not running or not listening on a unix socket. Can be started with:\n\n " );
174- tfm::format (std::cerr, " bitcoin-node -chain=%s -ipcbind=unix\n " , args.GetChainTypeString ());
175- return EXIT_FAILURE;
170+ std::string address{args.GetArg (" -ipcconnect" , " unix" )};
171+ while (true ) {
172+ try {
173+ node_init = mine_init->ipc ()->connectAddress (address);
174+ break ; // Success: break out of the loop
175+ } catch (const std::exception& exception) {
176+ LogPrintf (" IPC connection failed: %s\n " , exception.what ());
177+ LogPrintf (" bitcoin-node might not be running or listening on a UNIX socket.\n " );
178+ LogPrintf (" Retrying in 10 seconds...\n " );
179+
180+ std::this_thread::sleep_for (std::chrono::seconds (10 ));
181+ }
176182 }
177183 assert (node_init);
178184 tfm::format (std::cout, " Connected to bitcoin-node\n " );
0 commit comments