Skip to content

Commit

Permalink
fix: tweak sync logic to account for edgecase
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Dec 7, 2024
1 parent d587745 commit f3b5817
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/sidecar/blockIndexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,26 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error {
return err
}

if latestStateRoot != nil {
s.Logger.Sugar().Infow("Comparing latest block and latest state root",
zap.Int64("latestBlock", latestBlock),
zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber),
)
} else {
if latestStateRoot == nil {
s.Logger.Sugar().Infow("No state roots found, starting from EL genesis")
latestBlock = 0
}
s.Logger.Sugar().Infow("Comparing latest block and latest state root",
zap.Int64("latestBlock", latestBlock),
zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber),
)

if latestBlock == 0 {
s.Logger.Sugar().Infow("No blocks indexed, starting from genesis block", zap.Uint64("genesisBlock", s.Config.GenesisBlockNumber))
latestBlock = int64(s.Config.GenesisBlockNumber)
} else {
if latestStateRoot.EthBlockNumber == uint64(latestBlock) {
s.Logger.Sugar().Infow("Latest block and latest state root are in sync, starting from latest block + 1",
zap.Int64("latestBlock", latestBlock),
zap.Uint64("latestStateRootBlock", latestStateRoot.EthBlockNumber),
)
return nil
}
// if the latest state root is behind the latest block, delete the corrupted state and set the
// latest block to the latest state root + 1
if latestStateRoot != nil && latestStateRoot.EthBlockNumber < uint64(latestBlock) {
Expand Down Expand Up @@ -152,6 +158,11 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error {
s.Logger.Sugar().Fatalw("Failed to get current tip", zap.Error(err))
}

s.Logger.Sugar().Infow("Starting indexing process",
zap.Int64("latestBlock", latestBlock),
zap.Uint64("currentTip", blockNumber),
)

if blockNumber < uint64(latestBlock) {
return errors.New("Current tip is less than latest block. Please make sure your node is synced to tip.")
}
Expand Down

0 comments on commit f3b5817

Please sign in to comment.