Skip to content

Commit aa76eb7

Browse files
committed
refactor function comments
1 parent 600ea40 commit aa76eb7

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

rollup/rollup_sync_service/rollup_sync_service.go

+24-5
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,28 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
422422
return nil, fmt.Errorf("unexpected method name: %v", method.Name)
423423
}
424424

425-
// validateBatch verifies the consistency between the L1 contract and L2 node data.
425+
// validateBatch verifies the consistency between L1 contract and L2 node data.
426+
// It performs the following checks:
427+
// 1. Recalculates the batch hash locally
428+
// 2. Compares local state root, withdraw root, and batch hash with L1 data (for the last batch only when "finalize by bundle")
429+
//
426430
// The function will terminate the node and exit if any consistency check fails.
427-
// It returns the number of the end block, a finalized batch meta data, and an error if any.
431+
//
432+
// Parameters:
433+
// - event: L1 finalize batch event data
434+
// - parentBatchMeta: metadata of the parent batch
435+
// - chunks: slice of chunk data for the current batch
436+
// - chainCfg: chain configuration to identify the codec version
437+
// - stack: node stack to terminate the node in case of inconsistency
438+
// - lastBatch: boolean indicating if this is the last batch in a bundle
439+
//
440+
// Returns:
441+
// - uint64: the end block height of the batch
442+
// - *rawdb.FinalizedBatchMeta: finalized batch metadata
443+
// - error: any error encountered during validation
444+
//
445+
// Note: This function is compatible with both "finalize by batch" and "finalize by bundle" methods.
446+
// In "finalize by bundle", only the last batch of each bundle is fully verified.
428447
func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.FinalizedBatchMeta, chunks []*encoding.Chunk, chainCfg *params.ChainConfig, stack *node.Node, lastBatch bool) (uint64, *rawdb.FinalizedBatchMeta, error) {
429448
if len(chunks) == 0 {
430449
return 0, nil, fmt.Errorf("invalid argument: length of chunks is 0, batch index: %v", event.BatchIndex.Uint64())
@@ -499,9 +518,9 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
499518
os.Exit(1)
500519
}
501520

502-
// The rollup verifier recalculates all batch hashes locally.
503-
// Each batch hash depends on the parent hash, so checking the last batch hash of each bundle when "finalize by bundle"
504-
// still ensures all batch hashes are correct.
521+
// Verify batch hash
522+
// This check ensures the correctness of all batch hashes in the bundle
523+
// due to the parent-child relationship between batch hashes
505524
if localBatchHash != event.BatchHash {
506525
log.Error("Batch hash mismatch", "batch index", event.BatchIndex.Uint64(), "start block", startBlock.Header.Number.Uint64(), "end block", endBlock.Header.Number.Uint64(), "parent batch hash", parentBatchMeta.BatchHash.Hex(), "parent TotalL1MessagePopped", parentBatchMeta.TotalL1MessagePopped, "l1 finalized batch hash", event.BatchHash.Hex(), "l2 batch hash", localBatchHash.Hex())
507526
chunksJson, err := json.Marshal(chunks)

0 commit comments

Comments
 (0)