Skip to content

Commit 40ebbd6

Browse files
jonastheisomerfirmakThegaram
authored
feat(L1 follower): adjust to recent CodecV7 and contract changes (#1120)
* 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 * port changes from #1073 * chore: auto version bump [bot] * address review comments * add more logs * disable ENRUpdater if DA sync mode is enabled * exit pipeline if context is cancelled * correctly handle override by setting the head of the chain to the parent's height so that created blocks will always become part of canonical chain * fix error with genesis event being nil * chore: auto version bump [bot] * chore: auto version bump [bot] * adjust to renaming in CodecV7 * implement carrying forward of L1 MessageQueue index * fix issue after upgrading from old storage to new format where batchIndex was 0 and all batches would be skipped * add new RevertBatch event * add commitBatches to be able to read calldata of CodecV7/EuclidV2 committed batches * implement finding of L1 message queue height for initial batch in recovery mode * add sanity checks for computed batches from events and batch hashes given via calldata from commit transaction * update ScrollChain ABI * chore: auto version bump [bot] * remove initial batch form DAQueue * go mod tidy * fix underflow bug when l1DeploymentBlock==0 * fix bug with wrong parentBatchHash of first batch of batches submitted in a single tx * update to latest da-codec * address review comments * address review comments * fix bug when l1MessageV2StartIndex==0 serialized to [] (empty slice) which would always be decoded to non-existing instead of 0 * chore: auto version bump [bot] * cache go dependencies in Dockerfile.mockccc * chore: auto version bump [bot] * add INFO log when reverting rollup events in L1 follower mode * change LastProcessedMessageQueueIndex of finalize event to totalL1MessagesPoppedOverall * cleanup * chore: auto version bump [bot] --------- Co-authored-by: Ömer Faruk Irmak <[email protected]> Co-authored-by: Thegaram <[email protected]> Co-authored-by: jonastheis <[email protected]>
1 parent 87e1960 commit 40ebbd6

24 files changed

+754
-229
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
build/_workspace
44
build/_bin
55
tests/testdata
6+
7+
tmp/

Dockerfile.mockccc

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ ARG SCROLL_LIB_PATH=/scroll/lib
77
# Build Geth in a stock Go builder container
88
FROM scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 as builder
99

10-
ADD . /go-ethereum
11-
RUN cd /go-ethereum && env GO111MODULE=on go run build/ci.go install ./cmd/geth
10+
WORKDIR /go-ethereum
11+
COPY go.mod go.sum ./
12+
RUN go mod download -x
13+
14+
ADD . ./
15+
RUN env GO111MODULE=on go run build/ci.go install ./cmd/geth
1216

1317
# Pull Geth into a second stage deploy alpine container
1418
FROM ubuntu:20.04
1519

16-
RUN apt-get -qq update \
17-
&& apt-get -qq install -y --no-install-recommends ca-certificates
20+
#RUN apt-get -qq update \
21+
# && apt-get -qq install -y --no-install-recommends ca-certificates
1822

1923
ENV CGO_LDFLAGS="-ldl"
2024

core/rawdb/accessors_da_syncer.go

+35-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package rawdb
22

33
import (
4+
"bytes"
45
"math/big"
56

67
"github.com/scroll-tech/go-ethereum/ethdb"
78
"github.com/scroll-tech/go-ethereum/log"
9+
"github.com/scroll-tech/go-ethereum/rlp"
810
)
911

10-
// WriteDASyncedL1BlockNumber writes the highest synced L1 block number to the database.
11-
func WriteDASyncedL1BlockNumber(db ethdb.KeyValueWriter, L1BlockNumber uint64) {
12-
value := big.NewInt(0).SetUint64(L1BlockNumber).Bytes()
12+
type DAProcessedBatchMeta struct {
13+
BatchIndex uint64
14+
L1BlockNumber uint64
15+
TotalL1MessagesPopped uint64
16+
}
1317

18+
// WriteDAProcessedBatchMeta writes the batch metadata of the latest processed DA batch.
19+
func WriteDAProcessedBatchMeta(db ethdb.KeyValueWriter, daProcessedBatchMeta *DAProcessedBatchMeta) {
20+
value, err := rlp.EncodeToBytes(daProcessedBatchMeta)
21+
if err != nil {
22+
log.Crit("failed to RLP encode committed batch metadata", "batch index", daProcessedBatchMeta.BatchIndex, "committed batch meta", daProcessedBatchMeta, "err", err)
23+
}
1424
if err := db.Put(daSyncedL1BlockNumberKey, value); err != nil {
15-
log.Crit("Failed to update DA synced L1 block number", "err", err)
25+
log.Crit("Failed to update DAProcessedBatchMeta", "err", err)
1626
}
1727
}
1828

19-
// ReadDASyncedL1BlockNumber retrieves the highest synced L1 block number.
20-
func ReadDASyncedL1BlockNumber(db ethdb.Reader) *uint64 {
29+
// ReadDAProcessedBatchMeta retrieves the batch metadata of the latest processed DA batch.
30+
func ReadDAProcessedBatchMeta(db ethdb.Reader) *DAProcessedBatchMeta {
2131
data, err := db.Get(daSyncedL1BlockNumberKey)
2232
if err != nil && isNotFoundErr(err) {
2333
return nil
@@ -29,11 +39,25 @@ func ReadDASyncedL1BlockNumber(db ethdb.Reader) *uint64 {
2939
return nil
3040
}
3141

32-
number := new(big.Int).SetBytes(data)
33-
if !number.IsUint64() {
34-
log.Crit("Unexpected DA synced L1 block number in database", "number", number)
42+
// Try decoding from the newest format for future proofness, then the older one for old data.
43+
daProcessedBatchMeta := new(DAProcessedBatchMeta)
44+
if err = rlp.Decode(bytes.NewReader(data), daProcessedBatchMeta); err == nil {
45+
return daProcessedBatchMeta
3546
}
3647

37-
value := number.Uint64()
38-
return &value
48+
// Before storing DAProcessedBatchMeta we used to store a single uint64 value for the L1 block number.
49+
l1BlockNumber := new(big.Int).SetBytes(data)
50+
if !l1BlockNumber.IsUint64() {
51+
log.Crit("Unexpected DA synced L1 block number in database", "number", l1BlockNumber)
52+
}
53+
54+
// We can simply set only the L1BlockNumber because carrying forward the totalL1MessagesPopped is not required before EuclidV2 (CodecV7)
55+
// (the parentTotalL1MessagePopped is given via the parentBatchHeader).
56+
// Nodes need to update to the new version to be able to continue syncing after EuclidV2 (CodecV7). Therefore,
57+
// the only nodes that might read a uint64 value are nodes that were running L1 follower before the EuclidV2.
58+
return &DAProcessedBatchMeta{
59+
BatchIndex: 0,
60+
L1BlockNumber: l1BlockNumber.Uint64(),
61+
TotalL1MessagesPopped: 0,
62+
}
3963
}

core/rawdb/accessors_l1_message.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,13 @@ func ReadFirstQueueIndexNotInL2Block(db ethdb.Reader, l2BlockHash common.Hash) *
383383

384384
// WriteL1MessageV2StartIndex writes the start index of L1 messages that are from L1MessageQueueV2.
385385
func WriteL1MessageV2StartIndex(db ethdb.KeyValueWriter, queueIndex uint64) {
386-
value := big.NewInt(0).SetUint64(queueIndex).Bytes()
386+
// Write with binary.BigEndian.PutUint64 to ensure that 0 values are written as 8 bytes.
387+
// big.NewInt(0).SetUint64(l1BlockNumber).Bytes() would write 0 as empty slice which leads to problems when reading
388+
// the value as non-existent and 0 are not distinguishable.
389+
var buf [8]byte
390+
binary.BigEndian.PutUint64(buf[:], queueIndex)
387391

388-
if err := db.Put(l1MessageV2StartIndexKey, value); err != nil {
392+
if err := db.Put(l1MessageV2StartIndexKey, buf[:]); err != nil {
389393
log.Crit("Failed to update L1MessageV2 start index", "err", err)
390394
}
391395
}
@@ -402,13 +406,11 @@ func ReadL1MessageV2StartIndex(db ethdb.Reader) *uint64 {
402406
if len(data) == 0 {
403407
return nil
404408
}
405-
406-
number := new(big.Int).SetBytes(data)
407-
if !number.IsUint64() {
408-
log.Crit("Unexpected number for L1MessageV2 start index", "number", number)
409+
if len(data) != 8 {
410+
return nil
409411
}
412+
res := binary.BigEndian.Uint64(data)
410413

411-
res := number.Uint64()
412414
return &res
413415
}
414416

core/rawdb/accessors_rollup_event.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type CommittedBatchMeta struct {
2525
ChunkBlockRanges []*ChunkBlockRange
2626

2727
// introduced with CodecV7
28-
LastL1MessageQueueHash common.Hash
28+
PostL1MessageQueueHash common.Hash
2929
}
3030

3131
type committedBatchMetaV0 struct {
@@ -170,7 +170,7 @@ func WriteCommittedBatchMeta(db ethdb.KeyValueWriter, batchIndex uint64, committ
170170
committedBatchMetaToStore = &committedBatchMetaV7{
171171
Version: committedBatchMeta.Version,
172172
ChunkBlockRanges: committedBatchMeta.ChunkBlockRanges,
173-
LastL1MessageQueueHash: committedBatchMeta.LastL1MessageQueueHash,
173+
LastL1MessageQueueHash: committedBatchMeta.PostL1MessageQueueHash,
174174
}
175175
}
176176

@@ -202,7 +202,7 @@ func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) (*CommittedBatch
202202
return &CommittedBatchMeta{
203203
Version: cbm7.Version,
204204
ChunkBlockRanges: cbm7.ChunkBlockRanges,
205-
LastL1MessageQueueHash: cbm7.LastL1MessageQueueHash,
205+
PostL1MessageQueueHash: cbm7.LastL1MessageQueueHash,
206206
}, nil
207207
}
208208

@@ -214,7 +214,7 @@ func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) (*CommittedBatch
214214
return &CommittedBatchMeta{
215215
Version: cbm0.Version,
216216
ChunkBlockRanges: cbm0.ChunkBlockRanges,
217-
LastL1MessageQueueHash: common.Hash{},
217+
PostL1MessageQueueHash: common.Hash{},
218218
}, nil
219219
}
220220

core/rawdb/accessors_rollup_event_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ func TestWriteReadDeleteCommittedBatchMeta(t *testing.T) {
182182
meta: &CommittedBatchMeta{
183183
Version: 7,
184184
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}},
185-
LastL1MessageQueueHash: common.Hash{1, 2, 3, 4, 5, 6, 7},
185+
PostL1MessageQueueHash: common.Hash{1, 2, 3, 4, 5, 6, 7},
186186
},
187187
},
188188
{
189189
batchIndex: 255,
190190
meta: &CommittedBatchMeta{
191191
Version: 255,
192192
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 10}, {StartBlockNumber: 11, EndBlockNumber: 20}},
193-
LastL1MessageQueueHash: common.Hash{255},
193+
PostL1MessageQueueHash: common.Hash{255},
194194
},
195195
},
196196
}
@@ -237,7 +237,7 @@ func TestOverwriteCommittedBatchMeta(t *testing.T) {
237237
newMeta := &CommittedBatchMeta{
238238
Version: 255,
239239
ChunkBlockRanges: []*ChunkBlockRange{{StartBlockNumber: 0, EndBlockNumber: 20}, {StartBlockNumber: 21, EndBlockNumber: 30}},
240-
LastL1MessageQueueHash: common.Hash{255},
240+
PostL1MessageQueueHash: common.Hash{255},
241241
}
242242

243243
// write initial meta
@@ -282,5 +282,5 @@ func compareCommittedBatchMeta(a, b *CommittedBatchMeta) bool {
282282
}
283283
}
284284

285-
return a.LastL1MessageQueueHash == b.LastL1MessageQueueHash
285+
return a.PostL1MessageQueueHash == b.PostL1MessageQueueHash
286286
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
github.com/prometheus/tsdb v0.7.1
5252
github.com/rjeczalik/notify v0.9.1
5353
github.com/rs/cors v1.7.0
54-
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995
54+
github.com/scroll-tech/da-codec v0.1.3-0.20250226072559-f8a8d3898f54
5555
github.com/scroll-tech/zktrie v0.8.4
5656
github.com/shirou/gopsutil v3.21.11+incompatible
5757
github.com/sourcegraph/conc v0.3.0

go.sum

+2-2
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.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=
399+
github.com/scroll-tech/da-codec v0.1.3-0.20250226072559-f8a8d3898f54 h1:qVpsVu1J91opTn6HYeuzWcBRVhQmPR8g05i+PlOjlI4=
400+
github.com/scroll-tech/da-codec v0.1.3-0.20250226072559-f8a8d3898f54/go.mod h1:xECEHZLVzbdUn+tNbRJhRIjLGTOTmnFQuTgUTeVLX58=
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

+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 = 8 // Minor version component of the current release
27-
VersionPatch = 17 // Patch version component of the current release
27+
VersionPatch = 18 // 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)