unfork.sh

A tool for checking if you’re forked and optionally unforking you

walkjivefly
Crown Platform
4 min readMay 29, 2019

--

In a recent article we described how to check if your masternode/systemnode or wallet is on a forked blockchain. The article also described a method for getting back on the correct chain without having to resync the entire chain. It was prompted by a recent period of instability caused by syncing difficulties with v0.13.2. The difficulties were resolved with the release of v0.13.4. There have been other forkfests in the past, and it’s in the nature of blockchains that there could be more in the future.

In another recent article we promised a useful tool building on the API functionality of the newly released Crown PoS Explorer.

Well here it is, unfork.sh!

It’s a bash shell script, designed to be used on your VPS or with a linux wallet. It does two things:

  • Checks whether your node/wallet is on the same chain as the explorer.
  • Optionally executes the appropriate commands to get you back on the same chain as the explorer.

The script assumes that the explorer is on the correct chain. If you suspect you are forked, and the script says you are, then you should check if the explorer is believed to be on the correct chain before letting it (attempt to) fix the problem. Ask in Discord or Telegram. If the consensus is that the explorer is on the correct chain then you can re-run the script with the fix option and let it work its magic.

Download and install

Sign on to your VPS with the userid you use to run your masternode or systemnode.

Enter

If you login as root you don’t need to use the sudo prefix.

You can also use the script on your linux wallet machine. If you normally run the QT wallet you’ll need to shut it down and run the daemon wallet instead.

Customise

If you installed your node using the crown_server_install.sh script then it is likely you don’t need to do anything here. However, if your datadir is not called .crown and located in the logged in user’s home directory then you need to customise the script.

Use vi or nano or your favourite editor to customise the values for CONFIG and DATADIR.

Additionally, if you choose not to install the script in /usr/local/bin, customise the PREFIX variable with the appropriate value.

Run manually

At any time simply enter:

to get a current sit rep.

Unforked example

Forked example

Here, the script has detected the node is behind the explorer and not on the same chain. It used a binary chop method to identify the fork point and then reported the situation to the user.

Forked example with fix option

If you’re running the script on your wallet machine rather than a node VPS, it is good practice to make a backup of your wallet.dat before proceeding further.

Then re-run the script with the fix option for it to attempt to resolve the problem without having to resync from scratch.

You can see the first attempt after restarting at a getblockcount failed with an error message because the daemon was busy reloading the block index. A few seconds later the retried command worked and the daemon had caught up with the explorer.

Automated execution

You could create a crontab entry to run the script automatically but doing so isn’t really recommended. The reason it’s not recommended is that the explorer is not an Oracle; it’s just as likely to be on a forked chain as anyone else.

Comments or questions?

Leave your feedback in the #general channel in Discord. In particular, if you’re a Windows user and care to rewrite it as a batch file, or try running it in win-bash or the Windows Subsystem for Linux, we’d be interested to know how you get on.

--

--