Skip to content

Commit 7de11ed

Browse files
jonastheisomerfirmakThegaram
authored
feat(L1 follower and rollup verifier): support CodecV7 in L1 follower mode and rollup verifier (#1105)
* port changes from #1013 * port changes from #1068 * go.mod tidy * fix compile error * fix goimports * fix log * address review comments * upgrade golang.org/x/net to 0.23.0 * port changes from #1018 * fix tests and linter errors * address review comments * refactor rollup sync service / verifier to use CalldataBlobSource to retrieve data from L1 * add configuration and initialize blob clients * fix unit tests * remove unused code * address review comments * address more review comments * implement first version of new da-codec and to handle multiple batches submitted in one transaction * add CommitBatchDAV7 and handle multiple commit events submitted in a single transactions * fix bug due to previous batch being empty when processing the first batch within a set of batches * Allow using MPT * update to latest da-codec * add field to CommittedBatchMeta to store LastL1MessageQueueHash for CodecV7 batches * adjust rollup verifier to support CodecV7 batches * address review comments * fix issues after merge * go mod tidy * fix unit tests * update da-codec * add test TestValidateBatchCodecV7 * go mod tidy * do not log error on shutdown * add sanity check for version to deserialization of committedBatchMetaV7 * chore: auto version bump [bot] * address review comments * chore: auto version bump [bot] --------- Co-authored-by: Ömer Faruk Irmak <[email protected]> Co-authored-by: Thegaram <[email protected]> Co-authored-by: Péter Garamvölgyi <[email protected]>
1 parent 127845d commit 7de11ed

File tree

14 files changed

+5287
-144
lines changed

14 files changed

+5287
-144
lines changed

core/rawdb/accessors_rollup_event.go

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package rawdb
22

33
import (
44
"bytes"
5+
"fmt"
56
"math/big"
67

8+
"github.com/scroll-tech/da-codec/encoding"
9+
710
"github.com/scroll-tech/go-ethereum/common"
811
"github.com/scroll-tech/go-ethereum/ethdb"
912
"github.com/scroll-tech/go-ethereum/log"
@@ -18,12 +21,26 @@ type ChunkBlockRange struct {
1821

1922
// CommittedBatchMeta holds metadata for committed batches.
2023
type CommittedBatchMeta struct {
24+
Version uint8
25+
ChunkBlockRanges []*ChunkBlockRange
26+
27+
// introduced with CodecV7
28+
LastL1MessageQueueHash common.Hash
29+
}
30+
31+
type committedBatchMetaV0 struct {
2132
Version uint8
2233
// BlobVersionedHashes are the versioned hashes of the blobs in the batch. Currently unused. Left for compatibility.
2334
BlobVersionedHashes []common.Hash
2435
ChunkBlockRanges []*ChunkBlockRange
2536
}
2637

38+
type committedBatchMetaV7 struct {
39+
Version uint8
40+
ChunkBlockRanges []*ChunkBlockRange
41+
LastL1MessageQueueHash common.Hash
42+
}
43+
2744
// FinalizedBatchMeta holds metadata for finalized batches.
2845
type FinalizedBatchMeta struct {
2946
BatchHash common.Hash
@@ -143,30 +160,62 @@ func ReadLastFinalizedBatchIndex(db ethdb.Reader) *uint64 {
143160

144161
// WriteCommittedBatchMeta stores the CommittedBatchMeta for a specific batch in the database.
145162
func WriteCommittedBatchMeta(db ethdb.KeyValueWriter, batchIndex uint64, committedBatchMeta *CommittedBatchMeta) {
146-
value, err := rlp.EncodeToBytes(committedBatchMeta)
163+
var committedBatchMetaToStore any
164+
if encoding.CodecVersion(committedBatchMeta.Version) < encoding.CodecV7 {
165+
committedBatchMetaToStore = &committedBatchMetaV0{
166+
Version: committedBatchMeta.Version,
167+
ChunkBlockRanges: committedBatchMeta.ChunkBlockRanges,
168+
}
169+
} else {
170+
committedBatchMetaToStore = &committedBatchMetaV7{
171+
Version: committedBatchMeta.Version,
172+
ChunkBlockRanges: committedBatchMeta.ChunkBlockRanges,
173+
LastL1MessageQueueHash: committedBatchMeta.LastL1MessageQueueHash,
174+
}
175+
}
176+
177+
value, err := rlp.EncodeToBytes(committedBatchMetaToStore)
147178
if err != nil {
148-
log.Crit("failed to RLP encode committed batch metadata", "batch index", batchIndex, "committed batch meta", committedBatchMeta, "err", err)
179+
log.Crit("failed to RLP encode committed batch metadata", "batch index", batchIndex, "committed batch meta", committedBatchMetaToStore, "err", err)
149180
}
150181
if err := db.Put(committedBatchMetaKey(batchIndex), value); err != nil {
151182
log.Crit("failed to store committed batch metadata", "batch index", batchIndex, "value", value, "err", err)
152183
}
153184
}
154185

155186
// ReadCommittedBatchMeta fetches the CommittedBatchMeta for a specific batch from the database.
156-
func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) *CommittedBatchMeta {
187+
func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) (*CommittedBatchMeta, error) {
157188
data, err := db.Get(committedBatchMetaKey(batchIndex))
158189
if err != nil && isNotFoundErr(err) {
159-
return nil
190+
return nil, nil
160191
}
161192
if err != nil {
162-
log.Crit("failed to read committed batch metadata from database", "batch index", batchIndex, "err", err)
193+
return nil, fmt.Errorf("failed to read committed batch metadata from database: batch index %d, err: %w", batchIndex, err)
163194
}
164195

165-
cbm := new(CommittedBatchMeta)
166-
if err := rlp.Decode(bytes.NewReader(data), cbm); err != nil {
167-
log.Crit("Invalid CommittedBatchMeta RLP", "batch index", batchIndex, "data", data, "err", err)
196+
// Try decoding from the newest format for future proofness, then the older one for old data.
197+
cbm7 := new(committedBatchMetaV7)
198+
if err = rlp.Decode(bytes.NewReader(data), cbm7); err == nil {
199+
if encoding.CodecVersion(cbm7.Version) < encoding.CodecV7 {
200+
return nil, fmt.Errorf("unexpected committed batch metadata version: batch index %d, version %d", batchIndex, cbm7.Version)
201+
}
202+
return &CommittedBatchMeta{
203+
Version: cbm7.Version,
204+
ChunkBlockRanges: cbm7.ChunkBlockRanges,
205+
LastL1MessageQueueHash: cbm7.LastL1MessageQueueHash,
206+
}, nil
168207
}
169-
return cbm
208+
209+
cbm0 := new(committedBatchMetaV0)
210+
if err = rlp.Decode(bytes.NewReader(data), cbm0); err != nil {
211+
return nil, fmt.Errorf("failed to decode committed batch metadata: batch index %d, err: %w", batchIndex, err)
212+
}
213+
214+
return &CommittedBatchMeta{
215+
Version: cbm0.Version,
216+
ChunkBlockRanges: cbm0.ChunkBlockRanges,
217+
LastL1MessageQueueHash: common.Hash{},
218+
}, nil
170219
}
171220

172221
// DeleteCommittedBatchMeta removes the block ranges of all chunks associated with a specific batch from the database.

core/rawdb/accessors_rollup_event_test.go

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package rawdb
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/scroll-tech/go-ethereum/common"
79
)
810

@@ -157,55 +159,67 @@ func TestWriteReadDeleteCommittedBatchMeta(t *testing.T) {
157159
{
158160
batchIndex: 0,
159161
meta: &CommittedBatchMeta{
160-
Version: 0,
161-
BlobVersionedHashes: []common.Hash{},
162-
ChunkBlockRanges: []*ChunkBlockRange{},
162+
Version: 0,
163+
ChunkBlockRanges: []*ChunkBlockRange{},
164+
},
165+
},
166+
{
167+
batchIndex: 1,
168+
meta: &CommittedBatchMeta{
169+
Version: 1,
170+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
171+
},
172+
},
173+
{
174+
batchIndex: 1,
175+
meta: &CommittedBatchMeta{
176+
Version: 2,
177+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
163178
},
164179
},
165180
{
166181
batchIndex: 1,
167182
meta: &CommittedBatchMeta{
168-
Version: 1,
169-
BlobVersionedHashes: []common.Hash{common.HexToHash("0x1234")},
170-
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
183+
Version: 7,
184+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
185+
LastL1MessageQueueHash: common.Hash{1, 2, 3, 4, 5, 6, 7},
171186
},
172187
},
173188
{
174189
batchIndex: 255,
175190
meta: &CommittedBatchMeta{
176-
Version: 255,
177-
BlobVersionedHashes: []common.Hash{common.HexToHash("0xabcd"), common.HexToHash("0xef01")},
178-
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}, {StartBlockNumber: 11, EndBlockNumber: 20}},
191+
Version: 255,
192+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}, {StartBlockNumber: 11, EndBlockNumber: 20}},
193+
LastL1MessageQueueHash: common.Hash{255},
179194
},
180195
},
181196
}
182197

183198
for _, tc := range testCases {
184199
WriteCommittedBatchMeta(db, tc.batchIndex, tc.meta)
185-
got := ReadCommittedBatchMeta(db, tc.batchIndex)
186-
187-
if got == nil {
188-
t.Fatalf("Expected non-nil value for batch index %d", tc.batchIndex)
189-
}
200+
got, err := ReadCommittedBatchMeta(db, tc.batchIndex)
201+
require.NoError(t, err)
202+
require.NotNil(t, got)
190203

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

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

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

205-
readChunkRange := ReadCommittedBatchMeta(db, tc.batchIndex)
206-
if readChunkRange != nil {
207-
t.Fatal("Committed batch metadata was not deleted", "batch index", tc.batchIndex)
208-
}
220+
readChunkRange, err := ReadCommittedBatchMeta(db, tc.batchIndex)
221+
require.NoError(t, err)
222+
require.Nil(t, readChunkRange, "Committed batch metadata was not deleted", "batch index", tc.batchIndex)
209223
}
210224

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

218232
batchIndex := uint64(42)
219233
initialMeta := &CommittedBatchMeta{
220-
Version: 1,
221-
BlobVersionedHashes: []common.Hash{common.HexToHash("0x1234")},
222-
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
234+
Version: 1,
235+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
223236
}
224237
newMeta := &CommittedBatchMeta{
225-
Version: 2,
226-
BlobVersionedHashes: []common.Hash{common.HexToHash("0x5678"), common.HexToHash("0x9abc")},
227-
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 20}, {StartBlockNumber: 21, EndBlockNumber: 30}},
238+
Version: 255,
239+
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 20}, {StartBlockNumber: 21, EndBlockNumber: 30}},
240+
LastL1MessageQueueHash: common.Hash{255},
228241
}
229242

230243
// write initial meta
231244
WriteCommittedBatchMeta(db, batchIndex, initialMeta)
232-
got := ReadCommittedBatchMeta(db, batchIndex)
245+
got, err := ReadCommittedBatchMeta(db, batchIndex)
246+
require.NoError(t, err)
233247

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

238252
// overwrite with new meta
239253
WriteCommittedBatchMeta(db, batchIndex, newMeta)
240-
got = ReadCommittedBatchMeta(db, batchIndex)
254+
got, err = ReadCommittedBatchMeta(db, batchIndex)
255+
require.NoError(t, err)
241256

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

246261
// read non-existing batch index
247262
nonExistingIndex := uint64(999)
248-
got = ReadCommittedBatchMeta(db, nonExistingIndex)
263+
got, err = ReadCommittedBatchMeta(db, nonExistingIndex)
264+
require.NoError(t, err)
249265

250266
if got != nil {
251267
t.Fatalf("Expected nil for non-existing batch index, got %+v", got)
@@ -256,14 +272,7 @@ func compareCommittedBatchMeta(a, b *CommittedBatchMeta) bool {
256272
if a.Version != b.Version {
257273
return false
258274
}
259-
if len(a.BlobVersionedHashes) != len(b.BlobVersionedHashes) {
260-
return false
261-
}
262-
for i := range a.BlobVersionedHashes {
263-
if a.BlobVersionedHashes[i] != b.BlobVersionedHashes[i] {
264-
return false
265-
}
266-
}
275+
267276
if len(a.ChunkBlockRanges) != len(b.ChunkBlockRanges) {
268277
return false
269278
}
@@ -272,5 +281,6 @@ func compareCommittedBatchMeta(a, b *CommittedBatchMeta) bool {
272281
return false
273282
}
274283
}
275-
return true
284+
285+
return a.LastL1MessageQueueHash == b.LastL1MessageQueueHash
276286
}

go.mod

Lines changed: 1 addition & 1 deletion
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.1.3-0.20241218102542-9852fa4e1be5
53+
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995
5454
github.com/scroll-tech/zktrie v0.8.4
5555
github.com/shirou/gopsutil v3.21.11+incompatible
5656
github.com/sourcegraph/conc v0.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
396396
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
397397
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
398398
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
399-
github.com/scroll-tech/da-codec v0.1.3-0.20241218102542-9852fa4e1be5 h1:vZ75srkZCStjDWq/kqZGLoucf7Y7qXC13nKjQVZ0zp8=
400-
github.com/scroll-tech/da-codec v0.1.3-0.20241218102542-9852fa4e1be5/go.mod h1:XfQhUl3msmE6dpZEbR/LIwiMxywPQcUQsch9URgXDzs=
399+
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995 h1:Zo1p42CUS9pADSKoDD0ZoDxf4dQ3gttqWZlV+RSeImk=
400+
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
401401
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
402402
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
403403
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=

params/version.go

Lines changed: 1 addition & 1 deletion
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 = 8 // Minor version component of the current release
27-
VersionPatch = 6 // Patch version component of the current release
27+
VersionPatch = 7 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)