I use bitcoin core infrequently. I don't want to have it running all the time, but I'm willing to (for now) devote disk space to having it stay current. I'd like to be relatively current whenever I do start it up, without being weeks behind.

What I'd like to do is:

  • Once a week or so, start bitcoin-core up.
  • Have it shut down once it's caught up (I guess defined as "when the latest transaction is less than an hour old).

I know how to handle step one (via cron/launchd/etc). What I don't know how to do is step 2: either having it terminate automatically, or using some kind of CLI-command to check the sync status every so often.

If the answer to this is "put in a feature request to bitcoin core", then I'd be looking for workarounds/alternate methods to use until that worked.

For the record, I'm on OSX, but in theory this question applies to all variants of the client.

Any ideas?

  • Bitcoin-core can never complete synchronising since every 8 - 10 min there's an new block. – Adam Nov 21 '17 at 7:29
  • Asker specified that he considers to be caught up when he's only one hour behind. – Murch Nov 21 '17 at 7:38

You could sleep for e.g. 10 minutes after you started bitcoind, and then do the following:

  1. bitcoin-cli getblockcount, which is the current height of the node
  2. call getpeerinfo, parse the JSON, take the median of startingheight (how far these nodes are)
  3. If difference < 10, stop bitcoind with bitcoin-cli stop and exit
  4. Sleep 1 minute, repeat

Or use something like this to determine if the last known block is less than an hour old.

| improve this answer | |

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