Skip to content

Commit b56dd9f

Browse files
jonastheisomerfirmakThegaram
authored
refactor(rollup sync service): use CalldataBlobSource to retrieve data from L1 (#1103)
* 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 * Allow using MPT * fix issues after merge * bump version --------- Co-authored-by: Ömer Faruk Irmak <[email protected]> Co-authored-by: Péter Garamvölgyi <[email protected]>
1 parent ea43834 commit b56dd9f

28 files changed

+611
-1353
lines changed

cmd/utils/flags.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1641,15 +1641,15 @@ func setEnableRollupVerify(ctx *cli.Context, cfg *ethconfig.Config) {
16411641
func setDA(ctx *cli.Context, cfg *ethconfig.Config) {
16421642
if ctx.IsSet(DASyncEnabledFlag.Name) {
16431643
cfg.EnableDASyncing = ctx.Bool(DASyncEnabledFlag.Name)
1644-
if ctx.IsSet(DABlobScanAPIEndpointFlag.Name) {
1645-
cfg.DA.BlobScanAPIEndpoint = ctx.String(DABlobScanAPIEndpointFlag.Name)
1646-
}
1647-
if ctx.IsSet(DABlockNativeAPIEndpointFlag.Name) {
1648-
cfg.DA.BlockNativeAPIEndpoint = ctx.String(DABlockNativeAPIEndpointFlag.Name)
1649-
}
1650-
if ctx.IsSet(DABeaconNodeAPIEndpointFlag.Name) {
1651-
cfg.DA.BeaconNodeAPIEndpoint = ctx.String(DABeaconNodeAPIEndpointFlag.Name)
1652-
}
1644+
}
1645+
if ctx.IsSet(DABlobScanAPIEndpointFlag.Name) {
1646+
cfg.DA.BlobScanAPIEndpoint = ctx.String(DABlobScanAPIEndpointFlag.Name)
1647+
}
1648+
if ctx.IsSet(DABlockNativeAPIEndpointFlag.Name) {
1649+
cfg.DA.BlockNativeAPIEndpoint = ctx.String(DABlockNativeAPIEndpointFlag.Name)
1650+
}
1651+
if ctx.IsSet(DABeaconNodeAPIEndpointFlag.Name) {
1652+
cfg.DA.BeaconNodeAPIEndpoint = ctx.String(DABeaconNodeAPIEndpointFlag.Name)
16531653
}
16541654
}
16551655

core/rawdb/accessors_rollup_event.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type ChunkBlockRange struct {
1818

1919
// CommittedBatchMeta holds metadata for committed batches.
2020
type CommittedBatchMeta struct {
21-
Version uint8
21+
Version uint8
22+
// BlobVersionedHashes are the versioned hashes of the blobs in the batch. Currently unused. Left for compatibility.
2223
BlobVersionedHashes []common.Hash
2324
ChunkBlockRanges []*ChunkBlockRange
2425
}

eth/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
245245

246246
if config.EnableRollupVerify {
247247
// initialize and start rollup event sync service
248-
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack)
248+
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack, config.DA)
249249
if err != nil {
250250
return nil, fmt.Errorf("cannot initialize rollup event sync service: %w", err)
251251
}

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 = 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/da_syncer/da/calldata_blob_source.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (ds *CalldataBlobSource) NextData() (Entries, error) {
8181
return da, nil
8282
}
8383

84+
func (ds *CalldataBlobSource) SetL1Height(l1Height uint64) {
85+
ds.l1Height = l1Height
86+
}
87+
8488
func (ds *CalldataBlobSource) L1Height() uint64 {
8589
return ds.l1Height
8690
}
@@ -106,10 +110,22 @@ func (ds *CalldataBlobSource) processRollupEventsToDA(rollupEvents l1.RollupEven
106110
}
107111

108112
case l1.RevertEventType:
109-
entry = NewRevertBatch(rollupEvent.BatchIndex().Uint64())
113+
revertEvent, ok := rollupEvent.(*l1.RevertBatchEvent)
114+
// this should never happen because we just check event type
115+
if !ok {
116+
return nil, fmt.Errorf("unexpected type of rollup event: %T", rollupEvent)
117+
}
118+
119+
entry = NewRevertBatch(revertEvent)
110120

111121
case l1.FinalizeEventType:
112-
entry = NewFinalizeBatch(rollupEvent.BatchIndex().Uint64())
122+
finalizeEvent, ok := rollupEvent.(*l1.FinalizeBatchEvent)
123+
// this should never happen because we just check event type
124+
if !ok {
125+
return nil, fmt.Errorf("unexpected type of rollup event: %T", rollupEvent)
126+
}
127+
128+
entry = NewFinalizeBatch(finalizeEvent)
113129

114130
default:
115131
return nil, fmt.Errorf("unknown rollup event, type: %v", rollupEvent.Type())

rollup/da_syncer/da/commitV0.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

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

9+
"github.com/scroll-tech/go-ethereum/common"
910
"github.com/scroll-tech/go-ethereum/core/rawdb"
1011
"github.com/scroll-tech/go-ethereum/core/types"
1112
"github.com/scroll-tech/go-ethereum/ethdb"
@@ -14,14 +15,14 @@ import (
1415
)
1516

1617
type CommitBatchDAV0 struct {
17-
version uint8
18+
version encoding.CodecVersion
1819
batchIndex uint64
1920
parentTotalL1MessagePopped uint64
2021
skippedL1MessageBitmap []byte
2122
chunks []*encoding.DAChunkRawTx
2223
l1Txs []*types.L1MessageTx
2324

24-
l1BlockNumber uint64
25+
event *l1.CommitBatchEvent
2526
}
2627

2728
func NewCommitBatchDAV0(db ethdb.Database,
@@ -36,16 +37,16 @@ func NewCommitBatchDAV0(db ethdb.Database,
3637
return nil, fmt.Errorf("failed to unpack chunks: %d, err: %w", commitEvent.BatchIndex().Uint64(), err)
3738
}
3839

39-
return NewCommitBatchDAV0WithChunks(db, uint8(codec.Version()), commitEvent.BatchIndex().Uint64(), parentBatchHeader, decodedChunks, skippedL1MessageBitmap, commitEvent.BlockNumber())
40+
return NewCommitBatchDAV0WithChunks(db, codec.Version(), commitEvent.BatchIndex().Uint64(), parentBatchHeader, decodedChunks, skippedL1MessageBitmap, commitEvent)
4041
}
4142

4243
func NewCommitBatchDAV0WithChunks(db ethdb.Database,
43-
version uint8,
44+
version encoding.CodecVersion,
4445
batchIndex uint64,
4546
parentBatchHeader []byte,
4647
decodedChunks []*encoding.DAChunkRawTx,
4748
skippedL1MessageBitmap []byte,
48-
l1BlockNumber uint64,
49+
event *l1.CommitBatchEvent,
4950
) (*CommitBatchDAV0, error) {
5051
parentTotalL1MessagePopped := getBatchTotalL1MessagePopped(parentBatchHeader)
5152
l1Txs, err := getL1Messages(db, parentTotalL1MessagePopped, skippedL1MessageBitmap, getTotalMessagesPoppedFromChunks(decodedChunks))
@@ -60,7 +61,7 @@ func NewCommitBatchDAV0WithChunks(db ethdb.Database,
6061
skippedL1MessageBitmap: skippedL1MessageBitmap,
6162
chunks: decodedChunks,
6263
l1Txs: l1Txs,
63-
l1BlockNumber: l1BlockNumber,
64+
event: event,
6465
}, nil
6566
}
6667

@@ -70,12 +71,28 @@ func NewCommitBatchDAV0Empty() *CommitBatchDAV0 {
7071
}
7172
}
7273

74+
func (c *CommitBatchDAV0) Version() encoding.CodecVersion {
75+
return c.version
76+
}
77+
78+
func (c *CommitBatchDAV0) Chunks() []*encoding.DAChunkRawTx {
79+
return c.chunks
80+
}
81+
82+
func (c *CommitBatchDAV0) BlobVersionedHashes() []common.Hash {
83+
return nil
84+
}
85+
7386
func (c *CommitBatchDAV0) Type() Type {
7487
return CommitBatchV0Type
7588
}
7689

7790
func (c *CommitBatchDAV0) L1BlockNumber() uint64 {
78-
return c.l1BlockNumber
91+
return c.event.BlockNumber()
92+
}
93+
94+
func (c *CommitBatchDAV0) Event() l1.RollupEvent {
95+
return c.event
7996
}
8097

8198
func (c *CommitBatchDAV0) BatchIndex() uint64 {

rollup/da_syncer/da/commitV1.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717

1818
type CommitBatchDAV1 struct {
1919
*CommitBatchDAV0
20+
21+
versionedHashes []common.Hash
2022
}
2123

2224
func NewCommitBatchDAWithBlob(ctx context.Context, db ethdb.Database,
@@ -33,11 +35,17 @@ func NewCommitBatchDAWithBlob(ctx context.Context, db ethdb.Database,
3335
return nil, fmt.Errorf("failed to unpack chunks: %v, err: %w", commitEvent.BatchIndex().Uint64(), err)
3436
}
3537

36-
versionedHash, err := l1Reader.FetchTxBlobHash(commitEvent.TxHash(), commitEvent.BlockHash())
38+
versionedHashes, err := l1Reader.FetchTxBlobHashes(commitEvent.TxHash(), commitEvent.BlockHash())
3739
if err != nil {
3840
return nil, fmt.Errorf("failed to fetch blob hash, err: %w", err)
3941
}
4042

43+
// with CommitBatchDAV1 we expect only one versioned hash as we commit only one blob per batch submission
44+
if len(versionedHashes) != 1 {
45+
return nil, fmt.Errorf("unexpected number of versioned hashes: %d", len(versionedHashes))
46+
}
47+
versionedHash := versionedHashes[0]
48+
4149
header, err := l1Reader.FetchBlockHeaderByNumber(commitEvent.BlockNumber())
4250
if err != nil {
4351
return nil, fmt.Errorf("failed to get header by number, err: %w", err)
@@ -70,14 +78,21 @@ func NewCommitBatchDAWithBlob(ctx context.Context, db ethdb.Database,
7078
return nil, fmt.Errorf("decodedChunks is nil after decoding")
7179
}
7280

73-
v0, err := NewCommitBatchDAV0WithChunks(db, uint8(codec.Version()), commitEvent.BatchIndex().Uint64(), parentBatchHeader, decodedChunks, skippedL1MessageBitmap, commitEvent.BlockNumber())
81+
v0, err := NewCommitBatchDAV0WithChunks(db, codec.Version(), commitEvent.BatchIndex().Uint64(), parentBatchHeader, decodedChunks, skippedL1MessageBitmap, commitEvent)
7482
if err != nil {
7583
return nil, err
7684
}
7785

78-
return &CommitBatchDAV1{v0}, nil
86+
return &CommitBatchDAV1{
87+
CommitBatchDAV0: v0,
88+
versionedHashes: versionedHashes,
89+
}, nil
7990
}
8091

8192
func (c *CommitBatchDAV1) Type() Type {
8293
return CommitBatchWithBlobType
8394
}
95+
96+
func (c *CommitBatchDAV1) BlobVersionedHashes() []common.Hash {
97+
return c.versionedHashes
98+
}

rollup/da_syncer/da/da.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ package da
33
import (
44
"math/big"
55

6+
"github.com/scroll-tech/da-codec/encoding"
7+
8+
"github.com/scroll-tech/go-ethereum/common"
69
"github.com/scroll-tech/go-ethereum/core/types"
10+
"github.com/scroll-tech/go-ethereum/rollup/l1"
711
)
812

913
type Type int
@@ -25,11 +29,15 @@ type Entry interface {
2529
BatchIndex() uint64
2630
L1BlockNumber() uint64
2731
CompareTo(Entry) int
32+
Event() l1.RollupEvent
2833
}
2934

3035
type EntryWithBlocks interface {
3136
Entry
3237
Blocks() []*PartialBlock
38+
Version() encoding.CodecVersion
39+
Chunks() []*encoding.DAChunkRawTx
40+
BlobVersionedHashes() []common.Hash
3341
}
3442

3543
type Entries []Entry

rollup/da_syncer/da/finalize.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package da
22

3-
type FinalizeBatch struct {
4-
batchIndex uint64
3+
import (
4+
"github.com/scroll-tech/go-ethereum/rollup/l1"
5+
)
56

6-
l1BlockNumber uint64
7+
type FinalizeBatch struct {
8+
event *l1.FinalizeBatchEvent
79
}
810

9-
func NewFinalizeBatch(batchIndex uint64) *FinalizeBatch {
11+
func NewFinalizeBatch(event *l1.FinalizeBatchEvent) *FinalizeBatch {
1012
return &FinalizeBatch{
11-
batchIndex: batchIndex,
13+
event: event,
1214
}
1315
}
1416

@@ -17,11 +19,15 @@ func (f *FinalizeBatch) Type() Type {
1719
}
1820

1921
func (f *FinalizeBatch) L1BlockNumber() uint64 {
20-
return f.l1BlockNumber
22+
return f.event.BlockNumber()
2123
}
2224

2325
func (f *FinalizeBatch) BatchIndex() uint64 {
24-
return f.batchIndex
26+
return f.event.BatchIndex().Uint64()
27+
}
28+
29+
func (f *FinalizeBatch) Event() l1.RollupEvent {
30+
return f.event
2531
}
2632

2733
func (f *FinalizeBatch) CompareTo(other Entry) int {

rollup/da_syncer/da/revert.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package da
22

3-
type RevertBatch struct {
4-
batchIndex uint64
3+
import (
4+
"github.com/scroll-tech/go-ethereum/rollup/l1"
5+
)
56

6-
l1BlockNumber uint64
7+
type RevertBatch struct {
8+
event *l1.RevertBatchEvent
79
}
810

9-
func NewRevertBatch(batchIndex uint64) *RevertBatch {
11+
func NewRevertBatch(event *l1.RevertBatchEvent) *RevertBatch {
1012
return &RevertBatch{
11-
batchIndex: batchIndex,
13+
event: event,
1214
}
1315
}
1416

@@ -17,10 +19,14 @@ func (r *RevertBatch) Type() Type {
1719
}
1820

1921
func (r *RevertBatch) L1BlockNumber() uint64 {
20-
return r.l1BlockNumber
22+
return r.event.BlockNumber()
2123
}
2224
func (r *RevertBatch) BatchIndex() uint64 {
23-
return r.batchIndex
25+
return r.event.BatchIndex().Uint64()
26+
}
27+
28+
func (r *RevertBatch) Event() l1.RollupEvent {
29+
return r.event
2430
}
2531

2632
func (r *RevertBatch) CompareTo(other Entry) int {

rollup/l1/abi.go

+20
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ type FinalizeBatchEvent struct {
158158
blockNumber uint64
159159
}
160160

161+
func NewFinalizeBatchEvent(
162+
batchIndex *big.Int,
163+
batchHash common.Hash,
164+
stateRoot common.Hash,
165+
withdrawRoot common.Hash,
166+
txHash common.Hash,
167+
blockHash common.Hash,
168+
blockNumber uint64,
169+
) *FinalizeBatchEvent {
170+
return &FinalizeBatchEvent{
171+
batchIndex: batchIndex,
172+
batchHash: batchHash,
173+
stateRoot: stateRoot,
174+
withdrawRoot: withdrawRoot,
175+
txHash: txHash,
176+
blockHash: blockHash,
177+
blockNumber: blockNumber,
178+
}
179+
}
180+
161181
func (f *FinalizeBatchEvent) TxHash() common.Hash {
162182
return f.txHash
163183
}

rollup/l1/reader.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,23 @@ func (r *Reader) FetchTxData(txHash, blockHash common.Hash) ([]byte, error) {
139139
if err != nil {
140140
return nil, err
141141
}
142+
142143
return tx.Data(), nil
143144
}
144145

145-
// FetchTxBlobHash fetches tx blob hash corresponding to given event log
146-
func (r *Reader) FetchTxBlobHash(txHash, blockHash common.Hash) (common.Hash, error) {
146+
// FetchTxBlobHashes fetches tx blob hash corresponding to given event log
147+
func (r *Reader) FetchTxBlobHashes(txHash, blockHash common.Hash) ([]common.Hash, error) {
147148
tx, err := r.fetchTx(txHash, blockHash)
148149
if err != nil {
149-
return common.Hash{}, err
150+
return nil, fmt.Errorf("failed to fetch tx, tx hash: %v, block hash: %v, err: %w", txHash.Hex(), blockHash.Hex(), err)
150151
}
152+
151153
blobHashes := tx.BlobHashes()
152154
if len(blobHashes) == 0 {
153-
return common.Hash{}, fmt.Errorf("transaction does not contain any blobs, tx hash: %v", txHash.Hex())
155+
return nil, fmt.Errorf("transaction does not contain any blobs, tx hash: %v", txHash.Hex())
154156
}
155-
return blobHashes[0], nil
157+
158+
return blobHashes, nil
156159
}
157160

158161
// FetchRollupEventsInRange retrieves and parses commit/revert/finalize rollup events between block numbers: [from, to].

0 commit comments

Comments
 (0)