explorer icon indicating copy to clipboard operation
explorer copied to clipboard

Orphaned blocks being submitted to the database

Open nibbles83 opened this issue 6 years ago • 7 comments

Hybrid coin PoW & PoS coin I'm seeing spurious blocks being submitted to the database that appear against addresses. These blocks are rejected/orphaned by the network and api/getblock?hash= gives confirmations as "-1" on the network.

The DB keeps these blocks stored and as such reports them against related address's balances. Any idea the best way to fix these issues. Do i just change the way blocks are submitted? maybe wait until a confirmation is received before submitting to the DB?

nibbles83 avatar Aug 02 '18 11:08 nibbles83

Yes, we also get this problem. Orphaned blocks should be removed from database and should not count into the balance of address. Here are some links you can refer to:

  • Address: https://explorer.mediccoin.com/address/MBotyJcXMhMuHwu1Sz3asde6qgiaiJQ4fi
  • Transaction: https://explorer.mediccoin.com/tx/b6926f63c94b25ce4ff6e06ec07971f73e34f7fb3b82c8a967cfaf7661d85923
  • Block: https://explorer.mediccoin.com/block/e115c102439315f2eb54ed24c08952d70d435bf3393566ef84eae22f985cd490
  • Block info via API: https://explorer.mediccoin.com/api/getblock?hash=e115c102439315f2eb54ed24c08952d70d435bf3393566ef84eae22f985cd490

Everybody uses the explorer as their reference for all services from the coin so this brings coin a bad impression due to this issue. I hope this will be fixed soon. Let me know if you need anything else I can help.

Thanks.

Rp70 avatar Aug 28 '18 11:08 Rp70

I've not got a fix for this yet during the normal sync process, I've added a check to the lib/database.js save_tx function to check for block.confirmations > 0, but still seem to get orphans added, for us its due to PoW orphans being added. As a temp fix I've made a hacky script to run as a 10 min cron job. It finds transactions in the last x hours and checks to ensure that the chain reports it as part of a confirmed block, if its reporting orphan it removes it from the DB. Its a bit filthy but does the job for now.

nibbles83 avatar Aug 30 '18 08:08 nibbles83

Thanks for the hacky script. I look forward to see it in action. Thanks for your response.

Rp70 avatar Aug 30 '18 11:08 Rp70

I've not got a fix for this yet during the normal sync process, I've added a check to the lib/database.js save_tx function to check for block.confirmations > 0, but still seem to get orphans added, for us its due to PoW orphans being added. As a temp fix I've made a hacky script to run as a 10 min cron job. It finds transactions in the last x hours and checks to ensure that the chain reports it as part of a confirmed block, if its reporting orphan it removes it from the DB. Its a bit filthy but does the job for now.

What kind of script?

Bob-Thomas avatar Nov 17 '18 16:11 Bob-Thomas

If it helps anyone, I wrote a quick alternative sync:

https://github.com/gabriel-samfira/iquidus-sync/

Which runs in a loop, and treats the case of orphan blocks. When an orphan is detected, the database is rolled back to before the conflicting blocks, and then rolled forward.

Use at your own risk, I recommend you test it on a fresh database. Have only tested it on one PoS coin so far, but BTC should work too. It only implements coinbase and getinfo for total coin supply.

Works for me, at least until this properly gets fixed in the explorer itself.

gabriel-samfira avatar Dec 27 '18 18:12 gabriel-samfira

Here Blackcoin dev. Same thing happens for us. Is this an issue that can be solved?

michelvankessel avatar Apr 19 '20 15:04 michelvankessel

There's a patch here to only save confirmed blocks: https://github.com/TheHolyRogerCoin/RogerXplorer/commit/da16cf6a3f274ef98304f21b7d73296163d9751b

This will be undesirable for some though, as only confirmed transactions will show on the explorer front page.

@uaktags have you had any thoughts on dealing with orphans?

The best method is probably to change the DB so that new blocks are marked "pending", then change the sync process so that it rewinds to re-check them.

TheHolyRoger avatar Jul 16 '20 14:07 TheHolyRoger