Skip to content

Commit dca5306

Browse files
author
colinlyguo
committed
changed early break into invariance check
1 parent 20ccb12 commit dca5306

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

rollup/internal/controller/relayer/l2_relayer_sanity.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,17 @@ func (r *Layer2Relayer) getBatchesFromCalldata(info *CalldataInfo) ([]*dbBatchWi
131131
return nil, nil, fmt.Errorf("failed to get L2 blocks for chunk %d: %w", chunk.Index, err)
132132
}
133133
for _, block := range blockWithL1Messages {
134+
bn := block.Header.Number.Uint64()
135+
seenL2 := false
134136
for _, tx := range block.Transactions {
135137
if tx.Type == types.L1MessageTxType {
136-
l1MessagesWithBlockNumbers[block.Header.Number.Uint64()] = append(l1MessagesWithBlockNumbers[block.Header.Number.Uint64()], tx)
138+
if seenL2 {
139+
// Invariant violated: found an L1 after an L2 in the same block.
140+
return nil, nil, fmt.Errorf("L1 message after L2 tx in block %d", bn)
141+
}
142+
l1MessagesWithBlockNumbers[bn] = append(l1MessagesWithBlockNumbers[bn], tx)
137143
} else {
138-
// If it's not an L1 message, we can skip it, which verifies that all L1 messages are put in front of L2 transactions
139-
break
144+
seenL2 = true
140145
}
141146
}
142147
}

0 commit comments

Comments
 (0)