From 842d654838b918c0cc9147b6ff2573a84ffb2dc0 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 16 Jun 2025 16:37:24 +0800 Subject: [PATCH 1/5] feat: support codecv8 --- go.mod | 2 +- go.sum | 4 ++-- params/version.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 1c3397b960a4..2ee69aef4f84 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/prometheus/tsdb v0.7.1 github.com/rjeczalik/notify v0.9.1 github.com/rs/cors v1.7.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250313120912-344f2d5e33e1 + github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd github.com/scroll-tech/zktrie v0.8.4 github.com/shirou/gopsutil v3.21.11+incompatible github.com/sourcegraph/conc v0.3.0 diff --git a/go.sum b/go.sum index a6c9f2ad2aa8..7ddcde8525cf 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scroll-tech/da-codec v0.1.3-0.20250313120912-344f2d5e33e1 h1:Dhd58LE1D+dnoxpgLVeQBMF9uweL/fhQfZHWtWSiOlE= -github.com/scroll-tech/da-codec v0.1.3-0.20250313120912-344f2d5e33e1/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= +github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd h1:VKVDPtKJZIaQNQvhXptVhS7O9GLKl1314egD1fln8SA= +github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd/go.mod h1:T+370kLxwACnmWaq4rgtKGyLCd7QSE6iy0JLfCp1qj4= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= diff --git a/params/version.go b/params/version.go index 01c2565f1582..0a9f4e2b00b5 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 55 // Patch version component of the current release + VersionPatch = 56 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) From 27168a255ec9a42cb502bea795f45af8caba65f8 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Thu, 19 Jun 2025 01:05:41 +0800 Subject: [PATCH 2/5] address comments --- .../rollup_sync_service.go | 12 +- .../rollup_sync_service_test.go | 145 ++++++++++++++++++ 2 files changed, 151 insertions(+), 6 deletions(-) diff --git a/rollup/rollup_sync_service/rollup_sync_service.go b/rollup/rollup_sync_service/rollup_sync_service.go index 8aba65a1d422..d466b675105f 100644 --- a/rollup/rollup_sync_service/rollup_sync_service.go +++ b/rollup/rollup_sync_service/rollup_sync_service.go @@ -464,13 +464,13 @@ func (s *RollupSyncService) getCommittedBatchMeta(commitedBatch da.EntryWithBloc return nil, fmt.Errorf("failed to decode block ranges from chunks, batch index: %v, err: %w", commitedBatch.BatchIndex(), err) } - // With CodecV7 the batch creation changed. We need to compute and store PostL1MessageQueueHash. + // With >= CodecV7 the batch creation changed. We need to compute and store PostL1MessageQueueHash. // PrevL1MessageQueueHash of a batch == PostL1MessageQueueHash of the previous batch. // We need to do this for every committed batch (instead of finalized batch) because the L1MessageQueueHash // is a continuous hash of all L1 messages over all batches. With bundles we only receive the finalize event // for the last batch of the bundle. var lastL1MessageQueueHash common.Hash - if commitedBatch.Version() == encoding.CodecV7 { + if commitedBatch.Version() >= encoding.CodecV7 { parentCommittedBatchMeta, err := rawdb.ReadCommittedBatchMeta(s.db, commitedBatch.BatchIndex()-1) if err != nil { return nil, fmt.Errorf("failed to read parent committed batch meta, batch index: %v, err: %w", commitedBatch.BatchIndex()-1, errors.Join(ErrMissingBatchEvent, err)) @@ -493,11 +493,11 @@ func (s *RollupSyncService) getCommittedBatchMeta(commitedBatch da.EntryWithBloc return nil, fmt.Errorf("failed to get local node info, batch index: %v, err: %w", commitedBatch.BatchIndex(), err) } - // There is no chunks encoded in a batch anymore with CodecV7. + // There is no chunks encoded in a batch anymore with >= CodecV7. // For compatibility reason here we still use a single chunk to store the block ranges of the batch. // We make sure that there is really only one chunk which contains all blocks of the batch. if len(chunks) != 1 { - return nil, fmt.Errorf("invalid argument: chunk count is not 1 for CodecV7, batch index: %v", commitedBatch.BatchIndex()) + return nil, fmt.Errorf("invalid argument: chunk count is not 1 for CodecV%v, batch index: %v", commitedBatch.Version(), commitedBatch.BatchIndex()) } lastL1MessageQueueHash, err = encoding.MessageQueueV2ApplyL1MessagesFromBlocks(prevL1MessageQueueHash, chunks[0].Blocks) @@ -563,11 +563,11 @@ func validateBatch(batchIndex uint64, event *l1.FinalizeBatchEvent, parentFinali Chunks: chunks, } } else { - // With CodecV7 the batch creation changed. There is no chunks encoded in a batch anymore. + // With >= CodecV7 the batch creation changed. There is no chunks encoded in a batch anymore. // For compatibility reason here we still use a single chunk to store the block ranges of the batch. // We make sure that there is really only one chunk which contains all blocks of the batch. if len(chunks) != 1 { - return 0, nil, fmt.Errorf("invalid argument: chunk count is not 1 for CodecV7, batch index: %v", batchIndex) + return 0, nil, fmt.Errorf("invalid argument: chunk count is not 1 for CodecV%v, batch index: %v", committedBatchMeta.Version, batchIndex) } batch = &encoding.Batch{ diff --git a/rollup/rollup_sync_service/rollup_sync_service_test.go b/rollup/rollup_sync_service/rollup_sync_service_test.go index e6f6d7339697..cf8c3d535fca 100644 --- a/rollup/rollup_sync_service/rollup_sync_service_test.go +++ b/rollup/rollup_sync_service/rollup_sync_service_test.go @@ -816,6 +816,151 @@ func TestValidateBatchCodecV7(t *testing.T) { }, finalizedBatchMeta4) } +func TestValidateBatchCodecV8(t *testing.T) { + codecV8 := encoding.NewDACodecV8() + + var finalizedBatchMeta1 *rawdb.FinalizedBatchMeta + var committedBatchMeta1 *rawdb.CommittedBatchMeta + { + block1 := replaceBlockNumber(readBlockFromJSON(t, "./testdata/blockTrace_02.json"), 1) + batch1 := &encoding.Batch{ + Index: 1, + PrevL1MessageQueueHash: common.Hash{}, + PostL1MessageQueueHash: common.Hash{}, + Blocks: []*encoding.Block{block1}, + } + batch1LastBlock := batch1.Blocks[len(batch1.Blocks)-1] + + daBatch1, err := codecV8.NewDABatch(batch1) + require.NoError(t, err) + + event1 := l1.NewFinalizeBatchEvent( + new(big.Int).SetUint64(batch1.Index), + daBatch1.Hash(), + batch1LastBlock.Header.Root, + batch1LastBlock.WithdrawRoot, + common.HexToHash("0x1"), + common.HexToHash("0x1"), + 1, + ) + + committedBatchMeta1 = &rawdb.CommittedBatchMeta{ + Version: uint8(encoding.CodecV8), + PostL1MessageQueueHash: common.Hash{}, + } + + var endBlock1 uint64 + endBlock1, finalizedBatchMeta1, err = validateBatch(event1.BatchIndex().Uint64(), event1, &rawdb.FinalizedBatchMeta{}, &rawdb.CommittedBatchMeta{}, committedBatchMeta1, []*encoding.Chunk{{Blocks: batch1.Blocks}}, nil) + require.NoError(t, err) + require.EqualValues(t, 1, endBlock1) + require.Equal(t, &rawdb.FinalizedBatchMeta{ + BatchHash: daBatch1.Hash(), + TotalL1MessagePopped: 0, + StateRoot: batch1LastBlock.Header.Root, + WithdrawRoot: batch1LastBlock.WithdrawRoot, + }, finalizedBatchMeta1) + } + + // finalize 3 batches with CodecV8 at once + block2 := replaceBlockNumber(readBlockFromJSON(t, "./testdata/blockTrace_03.json"), 2) + batch2 := &encoding.Batch{ + Index: 2, + ParentBatchHash: finalizedBatchMeta1.BatchHash, + PrevL1MessageQueueHash: common.Hash{}, + PostL1MessageQueueHash: common.Hash{}, + Blocks: []*encoding.Block{block2}, + } + batch2LastBlock := batch2.Blocks[len(batch2.Blocks)-1] + + daBatch2, err := codecV8.NewDABatch(batch2) + require.NoError(t, err) + + block3 := replaceBlockNumber(readBlockFromJSON(t, "./testdata/blockTrace_06.json"), 3) + LastL1MessageQueueHashBatch3, err := encoding.MessageQueueV2ApplyL1MessagesFromBlocks(common.Hash{}, []*encoding.Block{block3}) + require.NoError(t, err) + batch3 := &encoding.Batch{ + Index: 3, + ParentBatchHash: daBatch2.Hash(), + PrevL1MessageQueueHash: common.Hash{}, + PostL1MessageQueueHash: LastL1MessageQueueHashBatch3, + Blocks: []*encoding.Block{block3}, + } + batch3LastBlock := batch3.Blocks[len(batch3.Blocks)-1] + + daBatch3, err := codecV8.NewDABatch(batch3) + require.NoError(t, err) + + block4 := replaceBlockNumber(readBlockFromJSON(t, "./testdata/blockTrace_07.json"), 4) + LastL1MessageQueueHashBatch4, err := encoding.MessageQueueV2ApplyL1MessagesFromBlocks(LastL1MessageQueueHashBatch3, []*encoding.Block{block4}) + require.NoError(t, err) + batch4 := &encoding.Batch{ + Index: 4, + ParentBatchHash: daBatch3.Hash(), + PrevL1MessageQueueHash: LastL1MessageQueueHashBatch3, + PostL1MessageQueueHash: LastL1MessageQueueHashBatch4, + Blocks: []*encoding.Block{block4}, + } + batch4LastBlock := batch4.Blocks[len(batch4.Blocks)-1] + + daBatch4, err := codecV8.NewDABatch(batch4) + require.NoError(t, err) + + event2 := l1.NewFinalizeBatchEvent( + new(big.Int).SetUint64(batch4.Index), + daBatch4.Hash(), + batch4LastBlock.Header.Root, + batch4LastBlock.WithdrawRoot, + common.HexToHash("0x1"), + common.HexToHash("0x1"), + 1, + ) + + committedBatchMeta2 := &rawdb.CommittedBatchMeta{ + Version: uint8(encoding.CodecV8), + PostL1MessageQueueHash: common.Hash{}, + } + + committedBatchMeta3 := &rawdb.CommittedBatchMeta{ + Version: uint8(encoding.CodecV8), + PostL1MessageQueueHash: LastL1MessageQueueHashBatch3, + } + + committedBatchMeta4 := &rawdb.CommittedBatchMeta{ + Version: uint8(encoding.CodecV8), + PostL1MessageQueueHash: LastL1MessageQueueHashBatch4, + } + + endBlock2, finalizedBatchMeta2, err := validateBatch(2, event2, finalizedBatchMeta1, committedBatchMeta1, committedBatchMeta2, []*encoding.Chunk{{Blocks: batch2.Blocks}}, nil) + require.NoError(t, err) + require.EqualValues(t, 2, endBlock2) + require.Equal(t, &rawdb.FinalizedBatchMeta{ + BatchHash: daBatch2.Hash(), + TotalL1MessagePopped: 0, + StateRoot: batch2LastBlock.Header.Root, + WithdrawRoot: batch2LastBlock.WithdrawRoot, + }, finalizedBatchMeta2) + + endBlock3, finalizedBatchMeta3, err := validateBatch(3, event2, finalizedBatchMeta2, committedBatchMeta2, committedBatchMeta3, []*encoding.Chunk{{Blocks: batch3.Blocks}}, nil) + require.NoError(t, err) + require.EqualValues(t, 3, endBlock3) + require.Equal(t, &rawdb.FinalizedBatchMeta{ + BatchHash: daBatch3.Hash(), + TotalL1MessagePopped: 1, + StateRoot: batch3LastBlock.Header.Root, + WithdrawRoot: batch3LastBlock.WithdrawRoot, + }, finalizedBatchMeta3) + + endBlock4, finalizedBatchMeta4, err := validateBatch(4, event2, finalizedBatchMeta3, committedBatchMeta3, committedBatchMeta4, []*encoding.Chunk{{Blocks: batch4.Blocks}}, nil) + require.NoError(t, err) + require.EqualValues(t, 4, endBlock4) + require.Equal(t, &rawdb.FinalizedBatchMeta{ + BatchHash: daBatch4.Hash(), + TotalL1MessagePopped: 6, + StateRoot: batch4LastBlock.Header.Root, + WithdrawRoot: batch4LastBlock.WithdrawRoot, + }, finalizedBatchMeta4) +} + func readBlockFromJSON(t *testing.T, filename string) *encoding.Block { data, err := os.ReadFile(filename) assert.NoError(t, err) From 25c7b31c13fc03fc2c8b4549a889481af7c2482c Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 23 Jun 2025 06:15:27 +0800 Subject: [PATCH 3/5] update da-codec commit --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2ee69aef4f84..ce2bd65452fa 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/prometheus/tsdb v0.7.1 github.com/rjeczalik/notify v0.9.1 github.com/rs/cors v1.7.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd + github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9 github.com/scroll-tech/zktrie v0.8.4 github.com/shirou/gopsutil v3.21.11+incompatible github.com/sourcegraph/conc v0.3.0 diff --git a/go.sum b/go.sum index 7ddcde8525cf..ca24a4a02da1 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd h1:VKVDPtKJZIaQNQvhXptVhS7O9GLKl1314egD1fln8SA= -github.com/scroll-tech/da-codec v0.1.3-0.20250616065246-17bf3e4990cd/go.mod h1:T+370kLxwACnmWaq4rgtKGyLCd7QSE6iy0JLfCp1qj4= +github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9 h1:0TsRwqi159i8nMG0O6kgP7q8fF1/eygWTSrT1z5jiO8= +github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9/go.mod h1:T+370kLxwACnmWaq4rgtKGyLCd7QSE6iy0JLfCp1qj4= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= From ba92fff9cab611ba556910f4202a5b9c6c556d17 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Thu, 26 Jun 2025 18:56:22 +0800 Subject: [PATCH 4/5] update da-codec commit --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ce2bd65452fa..9c432ada8f08 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/prometheus/tsdb v0.7.1 github.com/rjeczalik/notify v0.9.1 github.com/rs/cors v1.7.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9 + github.com/scroll-tech/da-codec v0.1.3-0.20250626091118-58b899494da6 github.com/scroll-tech/zktrie v0.8.4 github.com/shirou/gopsutil v3.21.11+incompatible github.com/sourcegraph/conc v0.3.0 diff --git a/go.sum b/go.sum index ca24a4a02da1..1bfb050837ab 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9 h1:0TsRwqi159i8nMG0O6kgP7q8fF1/eygWTSrT1z5jiO8= -github.com/scroll-tech/da-codec v0.1.3-0.20250622220508-c89e7e5e42f9/go.mod h1:T+370kLxwACnmWaq4rgtKGyLCd7QSE6iy0JLfCp1qj4= +github.com/scroll-tech/da-codec v0.1.3-0.20250626091118-58b899494da6 h1:vb2XLvQwCf+F/ifP6P/lfeiQrHY6+Yb/E3R4KHXLqSE= +github.com/scroll-tech/da-codec v0.1.3-0.20250626091118-58b899494da6/go.mod h1:Z6kN5u2khPhiqHyk172kGB7o38bH/nj7Ilrb/46wZGg= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= From ec85eacd3b4ae5dcdb1b439bf4bb20681953e828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Thu, 26 Jun 2025 14:08:33 +0200 Subject: [PATCH 5/5] bump version --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 897b9f4262b0..29165efc44b9 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 61 // Patch version component of the current release + VersionPatch = 62 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )