diff --git a/cmd/eth1indexer/main.go b/cmd/eth1indexer/main.go index 1d886b7911..801e50c78b 100644 --- a/cmd/eth1indexer/main.go +++ b/cmd/eth1indexer/main.go @@ -515,6 +515,19 @@ func HandleChainReorgs(bt *db.Bigtable, client *rpc.ErigonClient, depth int) err if !bytes.Equal(nodeBlock.Hash().Bytes(), dbBlock.Hash) { logrus.Warnf("found incosistency at height %v, node block hash: %x, db block hash: %x", i, nodeBlock.Hash().Bytes(), dbBlock.Hash) + // first we set the cached marker of the last block in the blocks/data table to the block prior to the forked one + if i > 0 { + previousBlock := i - 1 + err := bt.SetLastBlockInBlocksTable(int64(previousBlock)) + if err != nil { + return err + } + err = bt.SetLastBlockInDataTable(int64(previousBlock)) + if err != nil { + return err + } + // now we can proceed to delete all blocks including and after the forked block + } // delete all blocks starting from the fork block up to the latest block in the db for j := i; j <= latestNodeBlockNumber; j++ { dbBlock, err := bt.GetBlockFromBlocksTable(j) @@ -525,6 +538,7 @@ func HandleChainReorgs(bt *db.Bigtable, client *rpc.ErigonClient, depth int) err return err } logrus.Infof("deleting block at height %v with hash %x", dbBlock.Number, dbBlock.Hash) + err = bt.DeleteBlock(dbBlock.Number, dbBlock.Hash) if err != nil { return err