Select Page

Category:eIquidus Block Explorer
Sub Category:Bug Fix
Date Added:06-Dec-2022
Date Completed:06-May-2023
Completed By:Joe [Team Exor]

When two or more blocks are mined simultaneously, a temporary fork is created where both blocks are momentarily valid. The fork is usually resolved when the next block is found, although the forked chains can span multiple blocks if they continue mining the next block at the exact same time (rare, but possible). When the temporary fork is resolved, all blocks and transactions from the forked chain(s) are marked as invalid/orphaned and the coin balances are updated accordingly. The problem here is that the explorer is not yet equipped to mark the orphaned blocks/transactions as invalid. Therefore, all mined, sent and received coins that originate from orphaned blocks are still attributed to the wallet address balances in the explorer.

To properly handle orphaned blocks, some core changes will need to be made:

  1. A new function will be added to the end of the blockchain sync process (after all new blocks have been synced). This new process will scan the previous blocks in search of forks that have not yet been dealt with. When multiple blocks with the same block height are found, it will remember the forked block height and continue scanning the next blocks until the fork is resolved. Once the orphaned blocks are identified, they will be removed from the transaction database and copied into a new database collection for orphaned transactions only. As each orphaned transaction is moved into the new database, all coins from the affected transactions will be removed from the appropriate wallet addresses. This new functionality will be run every time new blocks are found and become part of the core blockchain sync process. Not only will this process fix newly added orphaned blocks as they happen, but it will also be smart enough to fix orphaned blocks from previously synced blockchains.
  2. Two new values will be added to the stats collection to help keep track of orphaned blocks: orphan_index and orphan_current. orphan_index will remember the last block height that was scanned for orphans. All blocks preceding the orphan_index should already be scanned and dealt with. The orphan_current value will save the most recent orphan block height that has been found but still not dealt with.
  3. A new script will be added that can rescan the transaction database in search of orphaned blocks that have not yet been dealt with and repopulate the internal stats numbers accordingly. If no forks are found, the orphan_current is set to a value of 0 and the orphan_index is set to the same value as stats.last. If one or more forks are found, orphan_current is set to the value of the oldest fork block height and orphan_index is set to the block height immediately before the oldest fork block height (orphan_current - 1).
  4. A new optional page will be added to the explorer for displaying orphaned blocks and/or transactions for informational purposes.