@@ -1046,61 +1046,40 @@ static void wait_and_check_bitcoind(struct plugin *p)
1046
1046
{
1047
1047
int in , from , status , ret ;
1048
1048
pid_t child ;
1049
- const char * * cmd = gather_args (bitcoind , "getnetworkinfo" , NULL );
1050
- bool printed = false;
1049
+ const char * * cmd = gather_args (bitcoind , "-rpcwait" , "getnetworkinfo" , NULL );
1051
1050
char * output = NULL ;
1052
1051
1053
- for (;;) {
1054
- tal_free (output );
1052
+ child = pipecmdarr (& in , & from , & from , cast_const2 (char * * , cmd ));
1055
1053
1056
- child = pipecmdarr (& in , & from , & from , cast_const2 (char * * , cmd ));
1057
-
1058
- if (bitcoind -> rpcpass )
1059
- write_all (in , bitcoind -> rpcpass , strlen (bitcoind -> rpcpass ));
1060
-
1061
- close (in );
1054
+ if (bitcoind -> rpcpass )
1055
+ write_all (in , bitcoind -> rpcpass , strlen (bitcoind -> rpcpass ));
1056
+ close (in );
1062
1057
1063
- if (child < 0 ) {
1064
- if (errno == ENOENT )
1065
- bitcoind_failure (p , "bitcoin-cli not found. Is bitcoin-cli "
1066
- "(part of Bitcoin Core) available in your PATH?" );
1067
- plugin_err (p , "%s exec failed: %s" , cmd [0 ], strerror (errno ));
1068
- }
1058
+ if (child < 0 ) {
1059
+ if (errno == ENOENT )
1060
+ bitcoind_failure (p , "bitcoin-cli not found. Is bitcoin-cli "
1061
+ "(part of Bitcoin Core) available in your PATH?" );
1062
+ plugin_err (p , "%s exec failed: %s" , cmd [0 ], strerror (errno ));
1063
+ }
1069
1064
1070
- output = grab_fd (cmd , from );
1071
-
1072
- while ((ret = waitpid (child , & status , 0 )) < 0 && errno == EINTR );
1073
- if (ret != child )
1074
- bitcoind_failure (p , tal_fmt (bitcoind , "Waiting for %s: %s" ,
1075
- cmd [0 ], strerror (errno )));
1076
- if (!WIFEXITED (status ))
1077
- bitcoind_failure (p , tal_fmt (bitcoind , "Death of %s: signal %i" ,
1078
- cmd [0 ], WTERMSIG (status )));
1079
-
1080
- if (WEXITSTATUS (status ) == 0 )
1081
- break ;
1082
-
1083
- /* bitcoin/src/rpc/protocol.h:
1084
- * RPC_IN_WARMUP = -28, //!< Client still warming up
1085
- */
1086
- if (WEXITSTATUS (status ) != 28 ) {
1087
- if (WEXITSTATUS (status ) == 1 )
1088
- bitcoind_failure (p , "Could not connect to bitcoind using"
1089
- " bitcoin-cli. Is bitcoind running?" );
1090
- bitcoind_failure (p , tal_fmt (bitcoind , "%s exited with code %i: %s" ,
1091
- cmd [0 ], WEXITSTATUS (status ), output ));
1092
- }
1065
+ output = grab_fd (cmd , from );
1093
1066
1094
- if (!printed ) {
1095
- plugin_log (p , LOG_UNUSUAL ,
1096
- "Waiting for bitcoind to warm up..." );
1097
- printed = true;
1098
- }
1099
- sleep (1 );
1067
+ while ((ret = waitpid (child , & status , 0 )) < 0 && errno == EINTR );
1068
+ if (ret != child )
1069
+ bitcoind_failure (p , tal_fmt (bitcoind , "Waiting for %s: %s" ,
1070
+ cmd [0 ], strerror (errno )));
1071
+ if (!WIFEXITED (status ))
1072
+ bitcoind_failure (p , tal_fmt (bitcoind , "Death of %s: signal %i" ,
1073
+ cmd [0 ], WTERMSIG (status )));
1074
+
1075
+ if (WEXITSTATUS (status ) != 0 ) {
1076
+ if (WEXITSTATUS (status ) == 1 )
1077
+ bitcoind_failure (p , "Could not connect to bitcoind using bitcoin-cli. Is bitcoind running?" );
1078
+ bitcoind_failure (p , tal_fmt (bitcoind , "%s exited with code %i: %s" ,
1079
+ cmd [0 ], WEXITSTATUS (status ), output ));
1100
1080
}
1101
1081
1102
1082
parse_getnetworkinfo_result (p , output );
1103
-
1104
1083
tal_free (cmd );
1105
1084
}
1106
1085
0 commit comments