2

There are some useful RPC commands that you can use in your bitcoin.conf file to trigger code when blocks have been confirmed, such as the blocknotify command.

Is there are similar command that will execute code when your node is on an old fork, or no longer synced to the tip of the blockchain?

  • I'm not sure I follow the scenario. Your node is never "on an old fork". Either it follows the one competing chaintip that it saw first out of two of equal accumulated difficulty, or it is reorganizing to the best chaintip as soon as it hears about a new block. – Murch Jun 15 at 2:16
  • My question is referring to when a blockchain adds new rules, and your node is no longer reaching consensus. For example, Monero hardforks every 6 months or so, and old nodes will no longer accept blocks because of the new consensus rules. This happens a lot on Bitcoin forked altcoins too, Biblepay is notorious for hardforking every couple of months – Barney Chambers Jun 15 at 2:18
3

There is no way to explicitly know that your node is on a minority-hashrate fork because to do so would mean awareness of all the new rules that makes the majority-hashrate fork valid, and then determining that more proof-of-work is accumulated on that chain. For that to be possible, you must be running an upgraded node already.

There are a few warning signs though: If your node hasn't received a new block in over two hours for example, you might want to manually check it - does it still have a good number of peers? Does log activity look OK?

High-volume Bitcoin merchants and exchanges usually simultaneously run several Bitcoin nodes, even a few different versions (0.19, 0.18, 0.17) and maybe even an alternative implementation (bcoin, btcd). This is how BitMex' https://forkmonitor.info operates.

There is rpc getchaintips: https://chainquery.com/bitcoin-cli/getchaintips

...but this is doing the opposite of what you asked: it will reveal to the user known chain forks (stale blocks, etc) but of course they are all lesser-work than the node's current tip which is always on the most-work valid chain.

| improve this answer | |
  • Thanks for the answer. I guess the best way to check would be to API with a popular explorer, and check your own node's height against it every so often – Barney Chambers Jun 15 at 16:32
  • Yes if you trust that block explorer! – pinhead Jun 15 at 16:46
0

Implementing a rule change that all pre-existing bitcoin nodes will not follow is equivalent to creating a new altcoin network (similar to the creation of BCH, for example).

There is no sensical way for a pre-existing bitcoin node to watch for such changes, and decide that it should follow that new (otherwise invalid) chain instead. A bitcoin node can simply determine which bitcoin chain is valid-- altering the rules is a social phenomenon, not a programmatic one.

| improve this answer | |
  • Maybe for the bitcoin network specifically, but some bitcoin forked coins add changes all the time which invalidate the consensus mechanisms of older versions of the coin (eg biblepay, monero, electroneum) – Barney Chambers Jun 20 at 5:08
  • Yes that is true, and I imagine that such a network would need some sort of rules about watching for upgrades. It creates a lot of centralization of power around protocol devs and processes though. – chytrik Jun 20 at 5:19

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.