lightning icon indicating copy to clipboard operation
lightning copied to clipboard

cleanup: Use the `-rpcwait` when waiting for bitcoind to warm up

Open cdecker opened this issue 5 years ago • 3 comments

We currently use a rather lengthy loop to wait for bitcoind to warm up and be ready to serve RPC calls:

https://github.com/ElementsProject/lightning/blob/44d408cc87beb854bdaf60c72108bb4492cfb34b/plugins/bcli.c#L710-L749

This could be simplified if we just call bitcoin-cli with -rpcwait which implements the wait logic internally and allows us to skip checking the returned error (if we get an error it's not the warmup error so we can pass any error up regardless). The downside is that it doesn't allow us to print the warmup ourselves, but we could easily replace that with a single one-shot timer printing the message.

cdecker avatar Feb 11 '20 15:02 cdecker

@cdecker ,Is there some community where I can discuss about the doubts I have on the code of this repository ? I would like to contribute to the lightning network community. I have started reading the book Mastering the lightning network

gerceboss avatar Feb 06 '24 22:02 gerceboss

@gerceboss you can join discord, there is the link on the Readme

vincenzopalazzo avatar Feb 08 '24 09:02 vincenzopalazzo

Open bounty on this: https://community.corelightning.org/c/cln-bounties/3505-cleanup-use-the-rpcwait-when-waiting-for-bitcoind-to-warm-up

BitcoinJiuJitsu avatar Jun 25 '24 01:06 BitcoinJiuJitsu

Hey @cdecker, I was trying to solve the above issue, but I’m stuck at the following point:

we could easily replace that with a single one-shot timer printing the message.

I tried looking at other implementations of timers but couldn’t understand if they could solve the issue. My understanding is that we should only print the message after x seconds if bitcoind hasn’t started serving RPC calls. Could you please point me to some code examples or references for implementing a timer? Thanks!

EDIT: I implemented something similar to the following:

static void log_warm_up(struct plugin *p)
{
    plugin_log(p, LOG_UNUSUAL, "Waiting for bitcoind to warm up...");
}

struct timers *timer = tal(cmd, struct timers);
timers_init(timer, time_mono());
new_reltimer(timer, timer, time_from_sec(30), log_warm_up, p);

From my understanding, the new_reltimer function sets up a timer to execute log_warm_up after 30 seconds.

Will this serve the purpose of a timer to print the warm-up message only if bitcoind doesn't start serving RPC calls within 30 seconds? I looked into some parts of the code and comments, and it seems like this can be used. However, I wanted to confirm if this is the correct approach or if there's a better way to implement it.

NishantBansal2003 avatar Dec 23 '24 12:12 NishantBansal2003

As far as I remember my concern was that unlike our polling, using the rpcwait option does not allow us to enforce a deadline of 60s, i.e., it just waits indefinitely. In LN we need to have access to the Bitcoin backend and the rpcwait option just waiting silently indefinitely is bad. We exit loudly (some refer to it as crash, but we make noise so operators are notified) if we can't talk to the Bitcoin backend. A warning logged and then a call to abort() will do just that 👍

cdecker avatar Jan 03 '25 11:01 cdecker