Skip to content

Commit

Permalink
Fix: resync
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Feb 3, 2024
1 parent 3d2e1cd commit f8c8101
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/metadata/tzkt/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ func (scanner *Scanner) listen(ctx context.Context) {
case msg := <-scanner.client.Listen():
switch msg.Type {
case events.MessageTypeState:
// on reconnect
if msg.Channel != events.ChannelBlocks {
continue
}

if scanner.level < msg.State {
// if blocks was missed in some reason we should index missed blocks
log.Warn().Uint64("old_state", scanner.level).Uint64("new_level", msg.State).Msg("detect missed blocks. resync...")

if err := scanner.sync(ctx, msg.State); err != nil {
log.Err(err).Msg("resync error")
return
}
}
scanner.level = msg.State

case events.MessageTypeData:
switch msg.Channel {
Expand Down Expand Up @@ -276,6 +291,7 @@ func (scanner *Scanner) handleBlocks(msg events.Message) error {
return errors.Errorf("Empty body: %v", body)
}

scanner.level = body[0].Level
scanner.blocks <- body[0]
return nil
}
Expand Down

0 comments on commit f8c8101

Please sign in to comment.