derohe icon indicating copy to clipboard operation
derohe copied to clipboard

fix: panic: Invalid Major Version in Block

Open 8lecramm opened this issue 1 year ago • 0 comments

Description

In rare cases (e.g. after power outage), the daemon cannot load the chain properly and panics.

...
20/01 22:09:43  INFO    RPC     RPC will listen {"address": "127.0.0.1:10102"}
20/01 22:09:43  INFO    GETWORK GETWORK will listen     {"address": "0.0.0.0:10100"}
panic: Invalid Major Version in Block

goroutine 1 [running]:
github.com/deroproject/derohe/blockchain.(*Blockchain).Load_Block_Timestamp(0x0?, {0xe, 0x73, 0xbc, 0xf, 0xbe, 0xb8, 0xed, 0x1b, 0x2d, ...})
        /home/marcel/go/src/derohe/blockchain/store.go:179 +0x51
github.com/deroproject/derohe/blockchain.Get_Difficulty_At_Tips({0xd317e0, 0xc000256000?}, {0xc0002e4020, 0x1, 0x1?})
        /home/marcel/go/src/derohe/blockchain/difficulty.go:239 +0x4d8
github.com/deroproject/derohe/blockchain.(*Blockchain).Get_Difficulty_At_Tips(0xc000256000, {0xc0002e4020, 0x1, 0x1})
        /home/marcel/go/src/derohe/blockchain/difficulty.go:146 +0x2d1
github.com/deroproject/derohe/blockchain.(*Blockchain).Get_Difficulty(0xc000256000)
        /home/marcel/go/src/derohe/blockchain/blockchain.go:1321 +0x125
github.com/deroproject/derohe/blockchain.(*Blockchain).Get_Network_HashRate(...)
        /home/marcel/go/src/derohe/blockchain/blockchain.go:1325
main.main()
        /home/marcel/go/src/derohe/cmd/derod/main.go:542 +0x1c52

The reason is empty block files. This fix checks the top height for corruption and, in case of an error, rewinds a block.

Type of change

Please select the right one.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update
  • [ ] This will require a HardFork to be enabled

Which part is impacted ?

  • [ ] Wallet
  • [x] Daemon
  • [ ] Miner
  • [ ] Explorer
  • [ ] Simulator
  • [ ] Misc (documentation, comments, text...)

Checklist:

  • [x] I have performed a self-review of my code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] My changes generate no new warnings

License

I'm am contributing & releasing the code under DERO Research License (which can be found here).

8lecramm avatar Jan 20 '24 21:01 8lecramm