2

I keep getting the wrong numbers returned daily in the beginning of the day because Bitcoin Core has not yet synced the blockchain from the computer being powered off during the night. So I need a way to determine if it's been synced fully or not, so that I can avoid using the numbers until it has synced fully.

I've looked through https://bitcoincore.org/en/doc/0.21.0/ but can't find anything such as "getsyncamount" or "isfullysynced".

How is it done?

2

Use getblockchaininfo and check the value of the initialblockdownload field. If it is true, BItcoin Core is still syncing. If it is false, it is done syncing (or very very close to done).

3
  • Thank you. Seems to work. But I do wonder why they call it "initial" block download, as if it's just referring to the very first time you sync the blockchain on the computer (as opposed to catching up after just being offline for a few hours). I also wonder why you say "or very very close to done"? – Donyai Mar 7 at 21:55
  • It's called "initial" because that's the first thing it does to make sure the blockchain is up to date. I say "very very close to done" because IBD uses heuristics to determine whether it is synced. It is actually impossible for a node to know whether it is fully synced because the blockchain is decentralized. It can only check for some heuristics that indicate it is most likely fully synced. In some cases, it may think IBD is complete but it might actually be a couple of blocks off. In those cases though, catching up those few blocks is very quick anyways so it doesn't really matter. – Andrew Chow Mar 7 at 22:02
  • Ah. Makes sense. (I'd upvote if the site let me.) – Donyai Mar 7 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.