1

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?

Gushi
  • 13
  • 4

1 Answers1

0

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.

Sjors Provoost
  • 962
  • 6
  • 16