From 07dfea647f3513ae62ce02f7d4a96dd2410e0647 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:02:56 +0100 Subject: [PATCH] (NOBIDS) update cached last block values prior to chain rollbacks --- cmd/eth1indexer/main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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