Skip to content

Commit

Permalink
feat: add codecv3 for darwin batches (#866)
Browse files Browse the repository at this point in the history
* feat: add codecv3 for darwin batches

* fix lint issue

* chore: auto version bump [bot]

* update da-codec dependency

---------

Co-authored-by: colin <[email protected]>
Co-authored-by: colinlyguo <[email protected]>
Co-authored-by: colinlyguo <[email protected]>
  • Loading branch information
4 people authored Jul 9, 2024
1 parent 9aee472 commit 15019ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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.0.0-20240605080813-32bfc9fccde7
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7
github.com/scroll-tech/zktrie v0.8.4
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,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.0.0-20240605080813-32bfc9fccde7 h1:CDrPMqifvAVyYqu0x1J5qickVV0b51tApPnOwDYLESI=
github.com/scroll-tech/da-codec v0.0.0-20240605080813-32bfc9fccde7/go.mod h1:1wWYii0OPwd5kw+xrz0PFgS420xNadrNF1x/ELJT+TM=
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7 h1:UfiLBLCAMBk9bsTP3fc1fETpNVFSQapQVdLcZveyV0M=
github.com/scroll-tech/da-codec v0.1.1-0.20240703091800-5b6cded48ab7/go.mod h1:D6XEESeNVJkQJlv3eK+FyR+ufPkgVQbJzERylQi53Bs=
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=
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 5 // Minor version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
30 changes: 28 additions & 2 deletions rollup/rollup_sync_service/rollup_sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/scroll-tech/da-codec/encoding/codecv0"
"github.com/scroll-tech/da-codec/encoding/codecv1"
"github.com/scroll-tech/da-codec/encoding/codecv2"
"github.com/scroll-tech/da-codec/encoding/codecv3"

"github.com/scroll-tech/go-ethereum/accounts/abi"
"github.com/scroll-tech/go-ethereum/common"
Expand Down Expand Up @@ -456,10 +457,16 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
return 0, nil, fmt.Errorf("failed to create codecv1 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
}
localBatchHash = daBatch.Hash()
} else { // codecv2: batches after Curie
} else if !chainCfg.IsDarwin(startBlock.Header.Time) { // codecv2: batches after Curie and before Darwin
daBatch, err := codecv2.NewDABatch(batch)
if err != nil {
return 0, nil, fmt.Errorf("failed to create codecv1 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
return 0, nil, fmt.Errorf("failed to create codecv2 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
}
localBatchHash = daBatch.Hash()
} else { // codecv3: batches after Darwin
daBatch, err := codecv3.NewDABatch(batch)
if err != nil {
return 0, nil, fmt.Errorf("failed to create codecv3 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
}
localBatchHash = daBatch.Hash()
}
Expand Down Expand Up @@ -555,6 +562,25 @@ func decodeBlockRangesFromEncodedChunks(codecVersion encoding.CodecVersion, chun
StartBlockNumber: daBlocks[0].BlockNumber,
EndBlockNumber: daBlocks[len(daBlocks)-1].BlockNumber,
})
case encoding.CodecV3:
if len(chunk) != 1+numBlocks*60 {
return nil, fmt.Errorf("invalid chunk byte length, expected: %v, got: %v", 1+numBlocks*60, len(chunk))
}
daBlocks := make([]*codecv3.DABlock, numBlocks)
for i := 0; i < numBlocks; i++ {
startIdx := 1 + i*60 // add 1 to skip numBlocks byte
endIdx := startIdx + 60
daBlocks[i] = &codecv3.DABlock{}
if err := daBlocks[i].Decode(chunk[startIdx:endIdx]); err != nil {
return nil, err
}
}

chunkBlockRanges = append(chunkBlockRanges, &rawdb.ChunkBlockRange{
StartBlockNumber: daBlocks[0].BlockNumber,
EndBlockNumber: daBlocks[len(daBlocks)-1].BlockNumber,
})

default:
return nil, fmt.Errorf("unexpected batch version %v", codecVersion)
}
Expand Down

0 comments on commit 15019ef

Please sign in to comment.