deroproject / derohe

DERO Homomorphic Encryption Blockchain Protocol
Other
209 stars 82 forks source link

fix: panic: Invalid Major Version in Block #154

Open 8lecramm opened 10 months ago

8lecramm commented 10 months ago

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.

Which part is impacted ?

Checklist:

License

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