diff --git a/event/event.go b/event/event.go index f05e65d634..5f782bde33 100644 --- a/event/event.go +++ b/event/event.go @@ -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" diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 0fd5d98463..610a15cb17 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -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, @@ -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, @@ -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 + } +}