harmony-one / harmony

The core protocol of harmony
https://harmony.one
GNU Lesser General Public License v3.0
1.46k stars 286 forks source link

Fix for crosslink snap db. #4675

Closed Frozen closed 2 months ago

Frozen commented 2 months ago

Fix for crosslink snap db.

sophoah commented 2 months ago

Here the reasoning for that PR :

Crosslink before an epoch or blocks that have been pruned using snapDB will set exist to nil in https://github.com/harmony-one/harmony/blob/main/node/node_newblock.go#L243

exist, err := node.Blockchain().ReadCrossLink(pending.ShardID(), pending.BlockNum())

This is what happened last time in mainnet when we tried to add a crosslink for a block/epoch we didn't have. Our solution back then was to remove those pending crosslink because we knew they were already processed.

in theory, crosslink already added on s0 chain are all continuous, so we can create a function that check the lastcrosslink (added on chain) and delete the pending crosslink when the block number in the shard to be processed is older.