Skip to content

Commit

Permalink
Fix: node stucking rule
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Apr 29, 2022
1 parent 9940d70 commit 49a1567
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/indexer/indexer/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,8 @@ func (bi *BoostIndexer) indexBlock(ctx context.Context, wg *sync.WaitGroup) {
case <-ticker.C:
if block, ok := bi.blocks[bi.state.Level+1]; ok {
if bi.state.Level > 0 && block.Header.Predecessor != bi.state.Hash {
if !time.Now().Add(time.Duration(-5) * time.Minute).After(block.Header.Timestamp) { // Check that node is out of sync
if err := bi.Rollback(ctx); err != nil {
logger.Error().Err(err).Msg("Rollback")
}
if err := bi.Rollback(ctx); err != nil {
logger.Error().Err(err).Msg("Rollback")
}
} else {
if err := bi.handleBlock(ctx, block); err != nil {
Expand Down Expand Up @@ -333,6 +331,10 @@ func (bi *BoostIndexer) process(ctx context.Context) error {
logger.Info().Str("network", bi.Network.String()).Msgf("Current node state: %7d", head.Level)
logger.Info().Str("network", bi.Network.String()).Msgf("Current indexer state: %7d", bi.state.Level)

if !time.Now().Add(time.Duration(-5) * time.Minute).After(head.Timestamp) {
return errors.Errorf("node is stucking...")
}

if head.Level > bi.state.Level {
if err := bi.Index(ctx, head); err != nil {
if errors.Is(err, errBcdQuit) {
Expand Down

0 comments on commit 49a1567

Please sign in to comment.