darwinia-network / darwinia-common

Darwinia Runtime Pallet Library and Pangolin/Pangoro Testnet
https://rust-docs.darwinia.network/darwinia-common
GNU General Public License v3.0
30 stars 9 forks source link

DVM mapping sync worker and service should only be enabled in archive mode #716

Closed hackfisher closed 3 years ago

hackfisher commented 3 years ago

There were reports from some crab nodes(pruning mode), found error logs:

Syncing failed with error “Application(UnknownBlock(\“State already discarded for BlockId::Hash(0x34f61bfda344b3fad3c3e38832a91448b3c613b199eb23e5110a635d71c13c65)\“))“, retrying.

And @WoeOm tested that it will be back to normal if the node replace dvm/db with datas from other normal db.

The root cause is that in node pruning mode, the mapping sync worker will not able to sync blocks(might need to read some pruned state data in current rpc implementation).

Fix this by only enabling this worker on archive mode.

https://github.com/darwinia-network/darwinia-common/blob/d8896a3621cd8d6f00fc34238403720b62aad9c1/client/dvm/mapping-sync/src/worker.rs#L121

https://github.com/darwinia-network/darwinia-common/blob/d8896a3621cd8d6f00fc34238403720b62aad9c1/bin/node/cli/src/service.rs#L673

Need companion PR and fix for darwinia repo(Crab)

hackfisher commented 3 years ago

https://crab.subscan.io/block/0x34f61bfda344b3fad3c3e38832a91448b3c613b199eb23e5110a635d71c13c65

0x34f61bfda344b3fad3c3e38832a91448b3c613b199eb23e5110a635d71c13c65 is genesis block.

hackfisher commented 3 years ago

https://crab.subscan.io/block/0x34f61bfda344b3fad3c3e38832a91448b3c613b199eb23e5110a635d71c13c65

0x34f61bfda344b3fad3c3e38832a91448b3c613b199eb23e5110a635d71c13c65 is genesis block.

Actually, syncing headers is OK for pruning nodes as they also store all history headers. The reason why only genesis header has this error, is that it seems genesis header is not in the db, and it uses runtime api to get genesis throw rpc, but before that it need to check whether it have this rpc api in runtime throw query the state at block 0.

Archive mode support the state query at block 0, but no for pruning mode.

Refer

https://github.com/darwinia-network/darwinia-common/blob/d8896a3621cd8d6f00fc34238403720b62aad9c1/client/dvm/mapping-sync/src/lib.rs#L74

boundless-forest commented 3 years ago

Great catch! A related pull request https://github.com/paritytech/frontier/pull/279