Skip to content

Commit 39fb299

Browse files
author
colinlyguo
committed
refactor
1 parent 925ef74 commit 39fb299

File tree

2 files changed

+285
-284
lines changed

2 files changed

+285
-284
lines changed

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,6 @@ func (r *Layer2Relayer) initializeGenesis() error {
278278
}
279279

280280
func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte, stateRoot common.Hash) error {
281-
// Basic sanity checks
282-
if batchHash == "" {
283-
return fmt.Errorf("batch hash is empty")
284-
}
285-
286-
if len(batchHeader) == 0 {
287-
return fmt.Errorf("batch header is empty")
288-
}
289-
290-
if stateRoot == (common.Hash{}) {
291-
return fmt.Errorf("state root is zero")
292-
}
293-
294281
var calldata []byte
295282
var packErr error
296283

@@ -310,7 +297,11 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
310297
log.Info("Rollup importGenesis", "calldata", common.Bytes2Hex(calldata), "stateRoot", stateRoot)
311298
}
312299

313-
// Check generated calldata is not empty
300+
// Sanity checks before sending the transaction
301+
if stateRoot == (common.Hash{}) {
302+
return fmt.Errorf("state root is zero")
303+
}
304+
314305
if len(calldata) == 0 {
315306
return fmt.Errorf("generated calldata is empty")
316307
}
@@ -492,12 +483,6 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
492483
log.Info("Forcing submission of batches due to timeout", "batch index", batchesToSubmit[0].Batch.Index, "first block created at", oldestBlockTimestamp)
493484
}
494485

495-
// Sanity checks before constructing the transaction
496-
if err := r.sanityChecksBeforeConstructingTransaction(batchesToSubmit); err != nil {
497-
log.Error("Sanity checks failed before constructing transaction", "batches count", len(batchesToSubmit), "first batch index", batchesToSubmit[0].Batch.Index, "last batch index", batchesToSubmit[len(batchesToSubmit)-1].Batch.Index, "err", err)
498-
return
499-
}
500-
501486
// We have at least 1 batch to commit
502487
firstBatch := batchesToSubmit[0].Batch
503488
lastBatch := batchesToSubmit[len(batchesToSubmit)-1].Batch
@@ -527,9 +512,9 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
527512
return
528513
}
529514

530-
err = r.sanityChecksCommitBatchCodecV7CalldataAndBlobs(calldata, blobs, batchesToSubmit, firstBatch, lastBatch)
515+
err = r.sanityChecksCommitBatchCodecV7CalldataAndBlobs(calldata, blobs)
531516
if err != nil {
532-
log.Error("Sanity check failed for calldata and blobs", "err", err)
517+
log.Error("Sanity check failed for calldata and blobs", "codecVersion", codecVersion, "start index", firstBatch.Index, "end index", lastBatch.Index, "err", err)
533518
return
534519
}
535520
}
@@ -972,25 +957,6 @@ func (r *Layer2Relayer) handleL2RollupRelayerConfirmLoop(ctx context.Context) {
972957
}
973958

974959
func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*dbBatchWithChunks, firstBatch, lastBatch *orm.Batch) ([]byte, []*kzg4844.Blob, uint64, uint64, error) {
975-
// Basic sanity checks
976-
if len(batchesToSubmit) == 0 {
977-
return nil, nil, 0, 0, fmt.Errorf("no batches to submit")
978-
}
979-
if firstBatch == nil {
980-
return nil, nil, 0, 0, fmt.Errorf("first batch is nil")
981-
}
982-
if lastBatch == nil {
983-
return nil, nil, 0, 0, fmt.Errorf("last batch is nil")
984-
}
985-
986-
// Check firstBatch and lastBatch match batchesToSubmit
987-
if firstBatch.Index != batchesToSubmit[0].Batch.Index {
988-
return nil, nil, 0, 0, fmt.Errorf("first batch index mismatch: expected %d, got %d", batchesToSubmit[0].Batch.Index, firstBatch.Index)
989-
}
990-
if lastBatch.Index != batchesToSubmit[len(batchesToSubmit)-1].Batch.Index {
991-
return nil, nil, 0, 0, fmt.Errorf("last batch index mismatch: expected %d, got %d", batchesToSubmit[len(batchesToSubmit)-1].Batch.Index, lastBatch.Index)
992-
}
993-
994960
var maxBlockHeight uint64
995961
var totalGasUsed uint64
996962
blobs := make([]*kzg4844.Blob, 0, len(batchesToSubmit))
@@ -1070,23 +1036,10 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*db
10701036
return nil, nil, 0, 0, fmt.Errorf("failed to pack commitBatches: %w", err)
10711037
}
10721038

1073-
if len(calldata) == 0 {
1074-
return nil, nil, 0, 0, fmt.Errorf("generated calldata is empty")
1075-
}
1076-
10771039
return calldata, blobs, maxBlockHeight, totalGasUsed, nil
10781040
}
10791041

10801042
func (r *Layer2Relayer) constructCommitBatchPayloadValidium(batch *dbBatchWithChunks) ([]byte, uint64, uint64, error) {
1081-
// Basic sanity checks
1082-
if batch == nil || batch.Batch == nil {
1083-
return nil, 0, 0, fmt.Errorf("batch is nil")
1084-
}
1085-
1086-
if len(batch.Chunks) == 0 {
1087-
return nil, 0, 0, fmt.Errorf("batch %d has no chunks", batch.Batch.Index)
1088-
}
1089-
10901043
// Check state root is not zero
10911044
stateRoot := common.HexToHash(batch.Batch.StateRoot)
10921045
if stateRoot == (common.Hash{}) {
@@ -1137,25 +1090,6 @@ func (r *Layer2Relayer) constructCommitBatchPayloadValidium(batch *dbBatchWithCh
11371090
}
11381091

11391092
func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV7(dbBatch *orm.Batch, endChunk *orm.Chunk, aggProof *message.OpenVMBundleProof) ([]byte, error) {
1140-
// Basic sanity checks
1141-
if dbBatch == nil {
1142-
return nil, fmt.Errorf("batch is nil")
1143-
}
1144-
if endChunk == nil {
1145-
return nil, fmt.Errorf("end chunk is nil")
1146-
}
1147-
1148-
// Check batch header
1149-
if len(dbBatch.BatchHeader) == 0 {
1150-
return nil, fmt.Errorf("batch %d header is empty", dbBatch.Index)
1151-
}
1152-
1153-
// Check state root is not zero
1154-
stateRoot := common.HexToHash(dbBatch.StateRoot)
1155-
if stateRoot == (common.Hash{}) {
1156-
return nil, fmt.Errorf("batch %d state root is zero", dbBatch.Index)
1157-
}
1158-
11591093
// Check proof if present
11601094
if aggProof != nil && len(aggProof.Proof()) == 0 {
11611095
return nil, fmt.Errorf("aggregate proof is empty")
@@ -1174,10 +1108,6 @@ func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV7(dbBatch *orm.Batch
11741108
return nil, fmt.Errorf("failed to pack finalizeBundlePostEuclidV2 with proof: %w", packErr)
11751109
}
11761110

1177-
if len(calldata) == 0 {
1178-
return nil, fmt.Errorf("generated calldata with proof is empty")
1179-
}
1180-
11811111
return calldata, nil
11821112
}
11831113

@@ -1195,27 +1125,10 @@ func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV7(dbBatch *orm.Batch
11951125
return nil, fmt.Errorf("failed to pack finalizeBundlePostEuclidV2NoProof: %w", packErr)
11961126
}
11971127

1198-
if len(calldata) == 0 {
1199-
return nil, fmt.Errorf("generated calldata without proof is empty")
1200-
}
1201-
12021128
return calldata, nil
12031129
}
12041130

12051131
func (r *Layer2Relayer) constructFinalizeBundlePayloadValidium(dbBatch *orm.Batch, endChunk *orm.Chunk, aggProof *message.OpenVMBundleProof) ([]byte, error) {
1206-
// Basic sanity checks
1207-
if dbBatch == nil {
1208-
return nil, fmt.Errorf("batch is nil")
1209-
}
1210-
if endChunk == nil {
1211-
return nil, fmt.Errorf("end chunk is nil")
1212-
}
1213-
1214-
// Check batch header is not empty
1215-
if len(dbBatch.BatchHeader) == 0 {
1216-
return nil, fmt.Errorf("batch %d header is empty", dbBatch.Index)
1217-
}
1218-
12191132
// Check proof if present
12201133
if aggProof != nil && len(aggProof.Proof()) == 0 {
12211134
return nil, fmt.Errorf("aggregate proof is empty")
@@ -1238,10 +1151,6 @@ func (r *Layer2Relayer) constructFinalizeBundlePayloadValidium(dbBatch *orm.Batc
12381151
return nil, fmt.Errorf("failed to pack validium finalizeBundle: %w", packErr)
12391152
}
12401153

1241-
if len(calldata) == 0 {
1242-
return nil, fmt.Errorf("generated calldata is empty for batch %d", dbBatch.Index)
1243-
}
1244-
12451154
return calldata, nil
12461155
}
12471156

0 commit comments

Comments
 (0)