Skip to content

Commit e8586ea

Browse files
plugin-bcli: changed configs
Changelog-None Signed-off-by: Nishant Bansal <[email protected]>
1 parent 673ae85 commit e8586ea

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

cln-rpc/src/codec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Decoder for JsonCodec {
105105
/// A codec that reads fully formed [crate::messages::JsonRpc]
106106
/// messages. Internally it uses the [JsonCodec] which itself is built
107107
/// on the [MultiLineCodec].
108+
#[allow(dead_code)]
108109
#[derive(Default)]
109110
pub(crate) struct JsonRpcCodec {
110111
inner: JsonCodec,

plugins/bcli.c

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static const char **gather_argsv(const tal_t *ctx, const char *cmd, va_list ap)
101101
const char *arg;
102102

103103
args[0] = bitcoind->cli ? bitcoind->cli : chainparams->cli;
104-
add_arg(&args, "-rpcwait");
104+
105105
if (chainparams->cli_args)
106106
add_arg(&args, chainparams->cli_args);
107107
if (bitcoind->datadir)
@@ -1038,53 +1038,50 @@ static void wait_and_check_bitcoind(struct plugin *p)
10381038
{
10391039
int in, from, status, ret;
10401040
pid_t child;
1041-
const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
1041+
const char **cmd =
1042+
gather_args(bitcoind, "-rpcwait", "getnetworkinfo", NULL);
10421043
char *output = NULL;
10431044

1044-
for (;;) {
1045-
tal_free(output);
1045+
// plugin_log(p, LOG_UNUSUAL, "Waiting for bitcoind to warm up...");
10461046

1047-
child = pipecmdarr(&in, &from, &from, cast_const2(char **, cmd));
1047+
child = pipecmdarr(&in, &from, &from, cast_const2(char **, cmd));
10481048

1049-
if (bitcoind->rpcpass)
1050-
write_all(in, bitcoind->rpcpass, strlen(bitcoind->rpcpass));
1049+
if (bitcoind->rpcpass)
1050+
write_all(in, bitcoind->rpcpass, strlen(bitcoind->rpcpass));
10511051

1052-
close(in);
1052+
close(in);
10531053

1054-
if (child < 0) {
1055-
if (errno == ENOENT)
1056-
bitcoind_failure(p, "bitcoin-cli not found. Is bitcoin-cli "
1057-
"(part of Bitcoin Core) available in your PATH?");
1058-
plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
1059-
}
1054+
if (child < 0) {
1055+
if (errno == ENOENT)
1056+
bitcoind_failure(
1057+
p,
1058+
"bitcoin-cli not found. Is bitcoin-cli "
1059+
"(part of Bitcoin Core) available in your PATH?");
1060+
plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
1061+
}
10601062

1061-
output = grab_fd(cmd, from);
1062-
1063-
while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR);
1064-
if (ret != child)
1065-
bitcoind_failure(p, tal_fmt(bitcoind, "Waiting for %s: %s",
1066-
cmd[0], strerror(errno)));
1067-
if (!WIFEXITED(status))
1068-
bitcoind_failure(p, tal_fmt(bitcoind, "Death of %s: signal %i",
1069-
cmd[0], WTERMSIG(status)));
1070-
1071-
if (WEXITSTATUS(status) == 0)
1072-
break;
1073-
1074-
/* bitcoin/src/rpc/protocol.h:
1075-
* RPC_IN_WARMUP = -28, //!< Client still warming up
1076-
*/
1077-
if (WEXITSTATUS(status) != 28) {
1078-
if (WEXITSTATUS(status) == 1)
1079-
bitcoind_failure(p, "Could not connect to bitcoind using"
1080-
" bitcoin-cli. Is bitcoind running?");
1081-
bitcoind_failure(p, tal_fmt(bitcoind, "%s exited with code %i: %s",
1082-
cmd[0], WEXITSTATUS(status), output));
1083-
}
1063+
output = grab_fd(cmd, from);
10841064

1085-
plugin_log(p, LOG_UNUSUAL,
1086-
"Waiting for bitcoind to warm up...");
1087-
sleep(1);
1065+
while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR)
1066+
;
1067+
if (ret != child)
1068+
bitcoind_failure(p, tal_fmt(bitcoind, "Waiting for %s: %s",
1069+
cmd[0], strerror(errno)));
1070+
if (!WIFEXITED(status))
1071+
bitcoind_failure(p, tal_fmt(bitcoind, "Death of %s: signal %i",
1072+
cmd[0], WTERMSIG(status)));
1073+
1074+
/* bitcoin/src/rpc/protocol.h:
1075+
* RPC_IN_WARMUP = -28, //!< Client still warming up
1076+
*/
1077+
if (WEXITSTATUS(status) != 0 && WEXITSTATUS(status) != 28) {
1078+
if (WEXITSTATUS(status) == 1)
1079+
bitcoind_failure(p,
1080+
"Could not connect to bitcoind using"
1081+
" bitcoin-cli. Is bitcoind running?");
1082+
bitcoind_failure(p,
1083+
tal_fmt(bitcoind, "%s exited with code %i: %s",
1084+
cmd[0], WEXITSTATUS(status), output));
10881085
}
10891086

10901087
parse_getnetworkinfo_result(p, output);

0 commit comments

Comments
 (0)