Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(L1 follower and rollup verifier): support CodecV7 in L1 follower mode and rollup verifier #1105

Merged
merged 48 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ea5a603
port changes from #1013
jonastheis Dec 10, 2024
b30006f
port changes from #1068
jonastheis Dec 10, 2024
de37d47
go.mod tidy
jonastheis Dec 10, 2024
e34fecf
fix compile error
jonastheis Dec 10, 2024
1327771
fix goimports
jonastheis Dec 10, 2024
b05954d
fix log
jonastheis Dec 10, 2024
ce8f785
address review comments
jonastheis Dec 12, 2024
f10c383
upgrade golang.org/x/net to 0.23.0
jonastheis Dec 12, 2024
cb0a90e
Merge branch 'develop' into jt/l1-follower-mode
jonastheis Dec 12, 2024
b918a2b
port changes from #1018
jonastheis Dec 10, 2024
e51182d
fix tests and linter errors
jonastheis Dec 11, 2024
4e6f759
address review comments
jonastheis Dec 12, 2024
fd6bff3
Merge branch 'develop' into jt/l1-follower-mode-l1-reader
jonastheis Dec 26, 2024
ab3e873
refactor rollup sync service / verifier to use CalldataBlobSource to …
jonastheis Dec 26, 2024
4ced6f2
add configuration and initialize blob clients
jonastheis Dec 27, 2024
6aafa74
fix unit tests
jonastheis Dec 27, 2024
da81a2e
remove unused code
jonastheis Dec 27, 2024
8750045
address review comments
jonastheis Jan 2, 2025
2499c69
address more review comments
jonastheis Jan 2, 2025
fb4fe7c
implement first version of new da-codec and to handle multiple batche…
jonastheis Jan 13, 2025
9bf2f25
add CommitBatchDAV7 and handle multiple commit events submitted in a …
jonastheis Jan 22, 2025
d222f58
Merge remote-tracking branch 'origin/develop' into jt/rollup-verifier…
jonastheis Jan 22, 2025
c56be0d
Merge branch 'jt/rollup-verifier-use-code-from-l1-follower' into jt/l…
jonastheis Jan 22, 2025
3950e58
fix bug due to previous batch being empty when processing the first b…
jonastheis Jan 22, 2025
a043d2f
Allow using MPT
omerfirmak Dec 23, 2024
94c0ad5
Merge remote-tracking branch 'origin/omerfirmak/mpt' into jt/rollup-v…
jonastheis Jan 28, 2025
67c1866
Merge branch 'jt/rollup-verifier-use-code-from-l1-follower' into jt/l…
jonastheis Jan 28, 2025
43d54cb
update to latest da-codec
jonastheis Feb 4, 2025
4290d16
add field to CommittedBatchMeta to store LastL1MessageQueueHash for C…
jonastheis Feb 4, 2025
574dd53
adjust rollup verifier to support CodecV7 batches
jonastheis Feb 4, 2025
53b6ebf
address review comments
jonastheis Feb 5, 2025
ab3bedf
Merge remote-tracking branch 'origin/develop' into jt/rollup-verifier…
jonastheis Feb 6, 2025
3335654
fix issues after merge
jonastheis Feb 6, 2025
3e18f7f
Merge remote-tracking branch 'origin/jt/rollup-verifier-use-code-from…
jonastheis Feb 6, 2025
2342335
Merge remote-tracking branch 'origin/develop' into jt/rollup-verifier…
jonastheis Feb 6, 2025
7c14639
Merge remote-tracking branch 'origin/jt/rollup-verifier-use-code-from…
jonastheis Feb 6, 2025
634d1f1
go mod tidy
jonastheis Feb 6, 2025
0fa3743
fix unit tests
jonastheis Feb 7, 2025
e048f53
Merge remote-tracking branch 'origin/develop' into jt/l1-follower-mod…
jonastheis Feb 10, 2025
a2a68e8
update da-codec
jonastheis Feb 10, 2025
ca6649e
add test TestValidateBatchCodecV7
jonastheis Feb 10, 2025
80976ad
go mod tidy
jonastheis Feb 10, 2025
4022989
do not log error on shutdown
jonastheis Feb 11, 2025
d4cc897
add sanity check for version to deserialization of committedBatchMetaV7
jonastheis Feb 12, 2025
6d5af23
chore: auto version bump [bot]
Thegaram Feb 12, 2025
3c21f4e
address review comments
jonastheis Feb 13, 2025
545a026
Merge branch 'develop' into jt/l1-follower-mode-update-da-codec
Thegaram Feb 13, 2025
ca408bc
chore: auto version bump [bot]
Thegaram Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 58 additions & 9 deletions core/rawdb/accessors_rollup_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package rawdb

import (
"bytes"
"fmt"
"math/big"

"github.com/scroll-tech/da-codec/encoding"

"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/log"
Expand All @@ -18,12 +21,26 @@ type ChunkBlockRange struct {

// CommittedBatchMeta holds metadata for committed batches.
type CommittedBatchMeta struct {
Version uint8
ChunkBlockRanges []*ChunkBlockRange

// introduced with CodecV7
LastL1MessageQueueHash common.Hash
}

type committedBatchMetaV0 struct {
Version uint8
// BlobVersionedHashes are the versioned hashes of the blobs in the batch. Currently unused. Left for compatibility.
BlobVersionedHashes []common.Hash
ChunkBlockRanges []*ChunkBlockRange
}

type committedBatchMetaV7 struct {
Version uint8
ChunkBlockRanges []*ChunkBlockRange
LastL1MessageQueueHash common.Hash
}

// FinalizedBatchMeta holds metadata for finalized batches.
type FinalizedBatchMeta struct {
BatchHash common.Hash
Expand Down Expand Up @@ -143,30 +160,62 @@ func ReadLastFinalizedBatchIndex(db ethdb.Reader) *uint64 {

// WriteCommittedBatchMeta stores the CommittedBatchMeta for a specific batch in the database.
func WriteCommittedBatchMeta(db ethdb.KeyValueWriter, batchIndex uint64, committedBatchMeta *CommittedBatchMeta) {
value, err := rlp.EncodeToBytes(committedBatchMeta)
var committedBatchMetaToStore any
if encoding.CodecVersion(committedBatchMeta.Version) < encoding.CodecV7 {
committedBatchMetaToStore = &committedBatchMetaV0{
Version: committedBatchMeta.Version,
ChunkBlockRanges: committedBatchMeta.ChunkBlockRanges,
}
} else {
committedBatchMetaToStore = &committedBatchMetaV7{
Version: committedBatchMeta.Version,
ChunkBlockRanges: committedBatchMeta.ChunkBlockRanges,
LastL1MessageQueueHash: committedBatchMeta.LastL1MessageQueueHash,
}
}

value, err := rlp.EncodeToBytes(committedBatchMetaToStore)
if err != nil {
log.Crit("failed to RLP encode committed batch metadata", "batch index", batchIndex, "committed batch meta", committedBatchMeta, "err", err)
log.Crit("failed to RLP encode committed batch metadata", "batch index", batchIndex, "committed batch meta", committedBatchMetaToStore, "err", err)
}
if err := db.Put(committedBatchMetaKey(batchIndex), value); err != nil {
log.Crit("failed to store committed batch metadata", "batch index", batchIndex, "value", value, "err", err)
}
}

// ReadCommittedBatchMeta fetches the CommittedBatchMeta for a specific batch from the database.
func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) *CommittedBatchMeta {
func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) (*CommittedBatchMeta, error) {
data, err := db.Get(committedBatchMetaKey(batchIndex))
if err != nil && isNotFoundErr(err) {
return nil
return nil, nil
}
if err != nil {
log.Crit("failed to read committed batch metadata from database", "batch index", batchIndex, "err", err)
return nil, fmt.Errorf("failed to read committed batch metadata from database: batch index %d, err: %w", batchIndex, err)
}

cbm := new(CommittedBatchMeta)
if err := rlp.Decode(bytes.NewReader(data), cbm); err != nil {
log.Crit("Invalid CommittedBatchMeta RLP", "batch index", batchIndex, "data", data, "err", err)
// Try decoding from the newest format for future proofness, then the older one for old data.
cbm7 := new(committedBatchMetaV7)
if err = rlp.Decode(bytes.NewReader(data), cbm7); err == nil {
if encoding.CodecVersion(cbm7.Version) < encoding.CodecV7 {
return nil, fmt.Errorf("unexpected committed batch metadata version: batch index %d, version %d", batchIndex, cbm7.Version)
}
return &CommittedBatchMeta{
Version: cbm7.Version,
ChunkBlockRanges: cbm7.ChunkBlockRanges,
LastL1MessageQueueHash: cbm7.LastL1MessageQueueHash,
}, nil
}
return cbm

cbm0 := new(committedBatchMetaV0)
if err = rlp.Decode(bytes.NewReader(data), cbm0); err != nil {
return nil, fmt.Errorf("failed to decode committed batch metadata: batch index %d, err: %w", batchIndex, err)
}

return &CommittedBatchMeta{
Version: cbm0.Version,
ChunkBlockRanges: cbm0.ChunkBlockRanges,
LastL1MessageQueueHash: common.Hash{},
}, nil
}

// DeleteCommittedBatchMeta removes the block ranges of all chunks associated with a specific batch from the database.
Expand Down
84 changes: 47 additions & 37 deletions core/rawdb/accessors_rollup_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package rawdb
import (
"testing"

"github.com/stretchr/testify/require"

"github.com/scroll-tech/go-ethereum/common"
)

Expand Down Expand Up @@ -157,55 +159,67 @@ func TestWriteReadDeleteCommittedBatchMeta(t *testing.T) {
{
batchIndex: 0,
meta: &CommittedBatchMeta{
Version: 0,
BlobVersionedHashes: []common.Hash{},
ChunkBlockRanges: []*ChunkBlockRange{},
Version: 0,
ChunkBlockRanges: []*ChunkBlockRange{},
},
},
{
batchIndex: 1,
meta: &CommittedBatchMeta{
Version: 1,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
},
},
{
batchIndex: 1,
meta: &CommittedBatchMeta{
Version: 2,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
},
},
{
batchIndex: 1,
meta: &CommittedBatchMeta{
Version: 1,
BlobVersionedHashes: []common.Hash{common.HexToHash("0x1234")},
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
Version: 7,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
LastL1MessageQueueHash: common.Hash{1, 2, 3, 4, 5, 6, 7},
},
},
{
batchIndex: 255,
meta: &CommittedBatchMeta{
Version: 255,
BlobVersionedHashes: []common.Hash{common.HexToHash("0xabcd"), common.HexToHash("0xef01")},
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}, {StartBlockNumber: 11, EndBlockNumber: 20}},
Version: 255,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}, {StartBlockNumber: 11, EndBlockNumber: 20}},
LastL1MessageQueueHash: common.Hash{255},
},
},
}

for _, tc := range testCases {
WriteCommittedBatchMeta(db, tc.batchIndex, tc.meta)
got := ReadCommittedBatchMeta(db, tc.batchIndex)

if got == nil {
t.Fatalf("Expected non-nil value for batch index %d", tc.batchIndex)
}
got, err := ReadCommittedBatchMeta(db, tc.batchIndex)
require.NoError(t, err)
require.NotNil(t, got)

if !compareCommittedBatchMeta(tc.meta, got) {
t.Fatalf("CommittedBatchMeta mismatch for batch index %d, expected %+v, got %+v", tc.batchIndex, tc.meta, got)
}
}

// reading a non-existing value
if got := ReadCommittedBatchMeta(db, 256); got != nil {
got, err := ReadCommittedBatchMeta(db, 256)
require.NoError(t, err)
if got != nil {
t.Fatalf("Expected nil for non-existing value, got %+v", got)
}

// delete: revert batch
for _, tc := range testCases {
DeleteCommittedBatchMeta(db, tc.batchIndex)

readChunkRange := ReadCommittedBatchMeta(db, tc.batchIndex)
if readChunkRange != nil {
t.Fatal("Committed batch metadata was not deleted", "batch index", tc.batchIndex)
}
readChunkRange, err := ReadCommittedBatchMeta(db, tc.batchIndex)
require.NoError(t, err)
require.Nil(t, readChunkRange, "Committed batch metadata was not deleted", "batch index", tc.batchIndex)
}

// delete non-existing value: ensure the delete operation handles non-existing values without errors.
Expand All @@ -217,35 +231,37 @@ func TestOverwriteCommittedBatchMeta(t *testing.T) {

batchIndex := uint64(42)
initialMeta := &CommittedBatchMeta{
Version: 1,
BlobVersionedHashes: []common.Hash{common.HexToHash("0x1234")},
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
Version: 1,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
}
newMeta := &CommittedBatchMeta{
Version: 2,
BlobVersionedHashes: []common.Hash{common.HexToHash("0x5678"), common.HexToHash("0x9abc")},
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 20}, {StartBlockNumber: 21, EndBlockNumber: 30}},
Version: 255,
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 20}, {StartBlockNumber: 21, EndBlockNumber: 30}},
LastL1MessageQueueHash: common.Hash{255},
}

// write initial meta
WriteCommittedBatchMeta(db, batchIndex, initialMeta)
got := ReadCommittedBatchMeta(db, batchIndex)
got, err := ReadCommittedBatchMeta(db, batchIndex)
require.NoError(t, err)

if !compareCommittedBatchMeta(initialMeta, got) {
t.Fatalf("Initial write failed, expected %+v, got %+v", initialMeta, got)
}

// overwrite with new meta
WriteCommittedBatchMeta(db, batchIndex, newMeta)
got = ReadCommittedBatchMeta(db, batchIndex)
got, err = ReadCommittedBatchMeta(db, batchIndex)
require.NoError(t, err)

if !compareCommittedBatchMeta(newMeta, got) {
t.Fatalf("Overwrite failed, expected %+v, got %+v", newMeta, got)
}

// read non-existing batch index
nonExistingIndex := uint64(999)
got = ReadCommittedBatchMeta(db, nonExistingIndex)
got, err = ReadCommittedBatchMeta(db, nonExistingIndex)
require.NoError(t, err)

if got != nil {
t.Fatalf("Expected nil for non-existing batch index, got %+v", got)
Expand All @@ -256,14 +272,7 @@ func compareCommittedBatchMeta(a, b *CommittedBatchMeta) bool {
if a.Version != b.Version {
return false
}
if len(a.BlobVersionedHashes) != len(b.BlobVersionedHashes) {
return false
}
for i := range a.BlobVersionedHashes {
if a.BlobVersionedHashes[i] != b.BlobVersionedHashes[i] {
return false
}
}

if len(a.ChunkBlockRanges) != len(b.ChunkBlockRanges) {
return false
}
Expand All @@ -272,5 +281,6 @@ func compareCommittedBatchMeta(a, b *CommittedBatchMeta) bool {
return false
}
}
return true

return a.LastL1MessageQueueHash == b.LastL1MessageQueueHash
}
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.1.3-0.20241218102542-9852fa4e1be5
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995
github.com/scroll-tech/zktrie v0.8.4
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/sourcegraph/conc v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241218102542-9852fa4e1be5 h1:vZ75srkZCStjDWq/kqZGLoucf7Y7qXC13nKjQVZ0zp8=
github.com/scroll-tech/da-codec v0.1.3-0.20241218102542-9852fa4e1be5/go.mod h1:XfQhUl3msmE6dpZEbR/LIwiMxywPQcUQsch9URgXDzs=
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995 h1:Zo1p42CUS9pADSKoDD0ZoDxf4dQ3gttqWZlV+RSeImk=
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
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 = 8 // Minor version component of the current release
VersionPatch = 6 // Patch version component of the current release
VersionPatch = 7 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
Loading