From b650ff67994d573a3ba54e79555a6117f929aa14 Mon Sep 17 00:00:00 2001 From: Kamen Stoykov <24619432+kstoykov@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:54:41 +0300 Subject: [PATCH] feat(sequencer): add safety checks (#1243) --- zk/stages/stage_sequence_execute_state.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/zk/stages/stage_sequence_execute_state.go b/zk/stages/stage_sequence_execute_state.go index 7e8af94a78c..d756bf4c99f 100644 --- a/zk/stages/stage_sequence_execute_state.go +++ b/zk/stages/stage_sequence_execute_state.go @@ -84,8 +84,8 @@ func newBatchState(forkId, batchNumber, blockNumber uint64, hasExecutorForThisBa batchState.limboRecoveryData = newLimboRecoveryData(limboBlock.BlockTimestamp, limboTxHash) } - if batchState.isL1Recovery() && batchState.isLimboRecovery() { - panic("Both recoveries cannot be active simultaneously") + if batchState.isMoreThanSingleRecovery() { + panic(fmt.Errorf("only single recovery could be active at a time, L1Recovery: %t, limboRecovery: %t, ResequenceRecovery: %t", batchState.isL1Recovery(), batchState.isLimboRecovery(), batchState.isResequence())) } } @@ -108,6 +108,24 @@ func (bs *BatchState) isAnyRecovery() bool { return bs.isL1Recovery() || bs.isLimboRecovery() || bs.isResequence() } +func (bs *BatchState) isMoreThanSingleRecovery() bool { + recoveryCounter := 0 + + if bs.isL1Recovery() { + recoveryCounter++ + } + + if bs.isLimboRecovery() { + recoveryCounter++ + } + + if bs.isResequence() { + recoveryCounter++ + } + + return recoveryCounter > 1 +} + func (bs *BatchState) isThereAnyTransactionsToRecover() bool { if !bs.isL1Recovery() { return false