Skip to content

Commit

Permalink
Sync halt (#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 authored Aug 23, 2023
1 parent 9d9801f commit 667d846
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
EventID_FinalizerBreakEvenGasPriceBigDifference EventID = "FINALIZER BREAK EVEN GAS PRICE BIG DIFFERENCE"
// EventID_SynchronizerRestart is triggered when the Synchonizer restarts
EventID_SynchronizerRestart EventID = "SYNCHRONIZER RESTART"
// EventID_SynchronizerHalt is triggered when the synchronizer halts
EventID_SynchronizerHalt EventID = "SYNCHRONIZER HALT"
// Source_Node is the source of the event
Source_Node Source = "node"

Expand Down
31 changes: 31 additions & 0 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,10 @@ func (s *ClientSynchronizer) processTrustedBatch(trustedBatch *types.Batch, dbTx
log.Info("Nothing to sync. Node updated. Checking if it is closed")
isBatchClosed := trustedBatch.StateRoot.String() != state.ZeroHash.String()
if isBatchClosed {
//Sanity check
if s.trustedState.lastStateRoot != nil && trustedBatch.StateRoot != *s.trustedState.lastStateRoot {
s.halt(s.ctx, fmt.Errorf("stateRoot calculated (%s) is different from the stateRoot (%s) received during the trustedState synchronization", *s.trustedState.lastStateRoot, trustedBatch.StateRoot))
}
receipt := state.ProcessingReceipt{
BatchNumber: uint64(trustedBatch.Number),
StateRoot: trustedBatch.StateRoot,
Expand Down Expand Up @@ -1381,6 +1385,10 @@ func (s *ClientSynchronizer) processTrustedBatch(trustedBatch *types.Batch, dbTx
log.Debug("TrustedBatch.StateRoot ", trustedBatch.StateRoot)
isBatchClosed := trustedBatch.StateRoot.String() != state.ZeroHash.String()
if isBatchClosed {
//Sanity check
if trustedBatch.StateRoot != processBatchResp.NewStateRoot {
s.halt(s.ctx, fmt.Errorf("stateRoot calculated (%s) is different from the stateRoot (%s) received during the trustedState synchronization", processBatchResp.NewStateRoot, trustedBatch.StateRoot))
}
receipt := state.ProcessingReceipt{
BatchNumber: uint64(trustedBatch.Number),
StateRoot: processBatchResp.NewStateRoot,
Expand Down Expand Up @@ -1631,3 +1639,26 @@ func (s *ClientSynchronizer) checkFlushID(dbTx pgx.Tx) error {
s.previousExecutorFlushID = storedFlushID
return nil
}

// halt halts the Synchronizer
func (s *ClientSynchronizer) halt(ctx context.Context, err error) {
event := &event.Event{
ReceivedAt: time.Now(),
Source: event.Source_Node,
Component: event.Component_Synchronizer,
Level: event.Level_Critical,
EventID: event.EventID_SynchronizerHalt,
Description: fmt.Sprintf("Synchronizer halted due to error: %s", err),
}

eventErr := s.eventLog.LogEvent(ctx, event)
if eventErr != nil {
log.Errorf("error storing Synchronizer halt event: %v", eventErr)
}

for {
log.Errorf("fatal error: %s", err)
log.Error("halting the Synchronizer")
time.Sleep(5 * time.Second) //nolint:gomnd
}
}

0 comments on commit 667d846

Please sign in to comment.