Error Observed: Bad block/Invalid Merkle

Created by Daniel Anthony, Modified on Thu, 11 Jan 2024 at 08:29 PM by Daniel Anthony

Description: A bad block or invalid Merkle root error occurs when the Heimdall and Bor layers are not in sync. Heimdall, as the consensus layer for Polygon POS chain, directs Bor to create blocks accordingly. A bad block error occurs when the Bor moves ahead to create a block which has not been directed by Heimdall. This causes an invalid hash being created, and hence results in an invalid Merkle root.

Solution 1: Restart the Bor service by using the following command

    sudo service bor restart

Typically a restart of the Bor service should resolve the problem, and that’s because restarting causes Bor to reconnect with Heimdall, start syncing, and create blocks correctly.

If restarting the Bor service does not fix the problem, then try the next option.

Solution 2: Make the following checks

  • Check if your Heimdall and REST servers are running.

    The Heimdall service might have stopped, and thus causing the bad block issue on Bor.

  • Check the logs for your Heimdall first,

        journalctl -u heimdalld -f
  • Check if everything is working correctly.

  • Additionally, check your REST server logs,

        journalctl -u heimdalld-rest-server -f
  • Restart the services not running.

       This should cause Bor to automatically resolve the problem

If restarting both the Bor and Heimdall services doesn’t solve the problem, it could be that Bor is stuck on some block.

Solution 3: Check the bad block in logs for Bor

  • Check Bor logs with this command
           journalctl -u bor -f

The bad block is typically displayed in the logs as shown in the below figure:

  • Note the bad block number.
  • Convert the block number to a hexadecimal number.

Use this tool to convert the block number to a hexadecimal number.

  • Roll back the Blockchain by a few hundred blocks. That is, set Bor at the right block height, with the debug.setHead() function. Use the following command
    bor attach ./.bor/data/bor.ipc
    > debug.setHead("0xE92570")

The debug.setHead() function allows Bor to set the tip at a particular block height, resyncing from a previous block.

A successful output of the above command is a null. Once this is achieved, monitoring of the Bor can resume and see if the blochain goes passed the previously bad block number.

If none of these solutions works for you, please contact the Polygon Support team immediately.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article