Skip to content

Commit 15019ef

Browse files
amoylan2colinlyguo
andauthored
feat: add codecv3 for darwin batches (#866)
* feat: add codecv3 for darwin batches * fix lint issue * chore: auto version bump [bot] * update da-codec dependency --------- Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@scroll.io>
1 parent 9aee472 commit 15019ef

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require (
5050
github.com/prometheus/tsdb v0.7.1
5151
github.com/rjeczalik/notify v0.9.1
5252
github.com/rs/cors v1.7.0
53-
github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7
53+
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7
5454
github.com/scroll-tech/zktrie v0.8.4
5555
github.com/shirou/gopsutil v3.21.11+incompatible
5656
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
392392
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
393393
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
394394
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
395-
github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7 h1:CDrPMqifvAVyYqu0x1J5qickVV0b51tApPnOwDYLESI=
396-
github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7/go.mod h1:1wWYii0OPwd5kw+xrz0PFgS420xNadrNF1x/ELJT+TM=
395+
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7 h1:UfiLBLCAMBk9bsTP3fc1fETpNVFSQapQVdLcZveyV0M=
396+
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7/go.mod h1:D6XEESeNVJkQJlv3eK+FyR+ufPkgVQbJzERylQi53Bs=
397397
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
398398
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
399399
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=

params/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 5 // Minor version component of the current release
27-
VersionPatch = 4 // Patch version component of the current release
27+
VersionPatch = 5 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/rollup_sync_service/rollup_sync_service.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/scroll-tech/da-codec/encoding/codecv0"
1313
"github.com/scroll-tech/da-codec/encoding/codecv1"
1414
"github.com/scroll-tech/da-codec/encoding/codecv2"
15+
"github.com/scroll-tech/da-codec/encoding/codecv3"
1516

1617
"github.com/scroll-tech/go-ethereum/accounts/abi"
1718
"github.com/scroll-tech/go-ethereum/common"
@@ -456,10 +457,16 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
456457
return 0, nil, fmt.Errorf("failed to create codecv1 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
457458
}
458459
localBatchHash = daBatch.Hash()
459-
} else { // codecv2: batches after Curie
460+
} else if !chainCfg.IsDarwin(startBlock.Header.Time) { // codecv2: batches after Curie and before Darwin
460461
daBatch, err := codecv2.NewDABatch(batch)
461462
if err != nil {
462-
return 0, nil, fmt.Errorf("failed to create codecv1 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
463+
return 0, nil, fmt.Errorf("failed to create codecv2 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
464+
}
465+
localBatchHash = daBatch.Hash()
466+
} else { // codecv3: batches after Darwin
467+
daBatch, err := codecv3.NewDABatch(batch)
468+
if err != nil {
469+
return 0, nil, fmt.Errorf("failed to create codecv3 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
463470
}
464471
localBatchHash = daBatch.Hash()
465472
}
@@ -555,6 +562,25 @@ func decodeBlockRangesFromEncodedChunks(codecVersion encoding.CodecVersion, chun
555562
StartBlockNumber: daBlocks[0].BlockNumber,
556563
EndBlockNumber: daBlocks[len(daBlocks)-1].BlockNumber,
557564
})
565+
case encoding.CodecV3:
566+
if len(chunk) != 1+numBlocks*60 {
567+
return nil, fmt.Errorf("invalid chunk byte length, expected: %v, got: %v", 1+numBlocks*60, len(chunk))
568+
}
569+
daBlocks := make([]*codecv3.DABlock, numBlocks)
570+
for i := 0; i < numBlocks; i++ {
571+
startIdx := 1 + i*60 // add 1 to skip numBlocks byte
572+
endIdx := startIdx + 60
573+
daBlocks[i] = &codecv3.DABlock{}
574+
if err := daBlocks[i].Decode(chunk[startIdx:endIdx]); err != nil {
575+
return nil, err
576+
}
577+
}
578+
579+
chunkBlockRanges = append(chunkBlockRanges, &rawdb.ChunkBlockRange{
580+
StartBlockNumber: daBlocks[0].BlockNumber,
581+
EndBlockNumber: daBlocks[len(daBlocks)-1].BlockNumber,
582+
})
583+
558584
default:
559585
return nil, fmt.Errorf("unexpected batch version %v", codecVersion)
560586
}

0 commit comments

Comments
 (0)