Skip to content

Commit 69a80d4

Browse files
committed
add testCommitBatchAndFinalizeBundleCodecV7 for relayer
1 parent 8db5339 commit 69a80d4

File tree

4 files changed

+218
-13
lines changed

4 files changed

+218
-13
lines changed

rollup/go.sum

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,9 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
249249
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
250250
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
251251
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
252-
github.com/scroll-tech/da-codec v0.1.3-0.20250205043214-894a93bb6b53 h1:07eHUuUhQ2rOP6ij5+KV1MgQurkwyweomkxp5nAG6o8=
253-
github.com/scroll-tech/da-codec v0.1.3-0.20250205043214-894a93bb6b53/go.mod h1:irqXJdRI5fsGkilJCpNTnJb8oV8KR51j68QXIWoth6U=
254-
github.com/scroll-tech/da-codec v0.1.3-0.20250207090156-f4b274c7bc1f h1:v63UX3vFLBA2KDLh26y0FEK2RQFOhq2z7+Dc7UUPN5c=
255-
github.com/scroll-tech/da-codec v0.1.3-0.20250207090156-f4b274c7bc1f/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
256-
github.com/scroll-tech/da-codec v0.1.3-0.20250209233450-14d07e75cf31 h1:PTTelRlF/X6dprfKgrjd5kbiI82a4VtyMDFeQ1lqxHY=
257-
github.com/scroll-tech/da-codec v0.1.3-0.20250209233450-14d07e75cf31/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
258-
github.com/scroll-tech/da-codec v0.1.3-0.20250209234523-cfb316bd5d65 h1:5OLPpOmvg0N6UignItMVeMSibXlGoVAdzprmxgmnMRM=
259-
github.com/scroll-tech/da-codec v0.1.3-0.20250209234523-cfb316bd5d65/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
260-
github.com/scroll-tech/da-codec v0.1.3-0.20250210001855-2171a439ff1a h1:rz66/mKGbFdDdJNovhVu8sd8E8DTpNdWmCsPmIwf7CE=
261-
github.com/scroll-tech/da-codec v0.1.3-0.20250210001855-2171a439ff1a/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
262252
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995 h1:Zo1p42CUS9pADSKoDD0ZoDxf4dQ3gttqWZlV+RSeImk=
263253
github.com/scroll-tech/da-codec v0.1.3-0.20250210041951-d028c537b995/go.mod h1:UZhhjzqYsyEhcvY0Y+SP+oMdeOUqFn/UXpbAYuPGzg0=
264-
github.com/scroll-tech/go-ethereum v1.10.14-0.20250129031936-44c72cd3fa47 h1:JbYYsGZMU1yAYsF/Ds6STMlItYy0SXj86nqdXC7nHyk=
265-
github.com/scroll-tech/go-ethereum v1.10.14-0.20250129031936-44c72cd3fa47/go.mod h1:8WbNuuUjie/LTdFXGGT7Z711MRW8Vv2zWLrcibg7hDc=
254+
github.com/scroll-tech/go-ethereum v1.10.14-0.20250206083728-ea43834c198f h1:WgIRuMWa7Q/xD1LHPEbQ9PpltasNiYR04qFzatiP/R0=
266255
github.com/scroll-tech/go-ethereum v1.10.14-0.20250206083728-ea43834c198f/go.mod h1:Ik3OBLl7cJxPC+CFyCBYNXBPek4wpdzkWehn/y5qLM8=
267256
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
268257
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*db
11521152
// TODO: this needs to be updated once the contract interface is finalized
11531153
calldata, err := r.l1RollupABI.Pack("commitBatches", version, firstParentBatch.BatchHeader)
11541154
if err != nil {
1155-
return nil, nil, 0, 0, fmt.Errorf("failed to pack commitBatchWithBlobProof: %w", err)
1155+
return nil, nil, 0, 0, fmt.Errorf("failed to pack commitBatches: %w", err)
11561156
}
11571157
return calldata, blobs, maxBlockHeight, totalGasUsed, nil
11581158
}

rollup/tests/bridge_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func TestFunction(t *testing.T) {
209209
// l1 rollup and watch rollup events
210210
t.Run("TestCommitAndFinalizeGenesisBatch", testCommitAndFinalizeGenesisBatch)
211211
t.Run("TestCommitBatchAndFinalizeBundleCodecV4", testCommitBatchAndFinalizeBundleCodecV4)
212+
t.Run("TestCommitBatchAndFinalizeBundleCodecV7", testCommitBatchAndFinalizeBundleCodecV7)
212213

213214
// l1/l2 gas oracle
214215
t.Run("TestImportL1GasPrice", testImportL1GasPrice)

rollup/tests/rollup_test.go

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"context"
5+
"fmt"
56
"math"
67
"math/big"
78
"testing"
@@ -12,6 +13,7 @@ import (
1213
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
1314
"github.com/scroll-tech/go-ethereum/params"
1415
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1517

1618
"scroll-tech/common/database"
1719
"scroll-tech/common/types"
@@ -216,3 +218,216 @@ func testCommitBatchAndFinalizeBundleCodecV4(t *testing.T) {
216218
database.CloseDB(db)
217219
}
218220
}
221+
222+
func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) {
223+
db := setupDB(t)
224+
225+
prepareContracts(t)
226+
227+
chainConfig := &params.ChainConfig{
228+
LondonBlock: big.NewInt(0),
229+
BernoulliBlock: big.NewInt(0),
230+
CurieBlock: big.NewInt(0),
231+
DarwinTime: new(uint64),
232+
DarwinV2Time: new(uint64),
233+
EuclidTime: new(uint64),
234+
EuclidV2Time: new(uint64),
235+
}
236+
237+
// Create L2Relayer
238+
l2Cfg := rollupApp.Config.L2Config
239+
l2Relayer, err := relayer.NewLayer2Relayer(context.Background(), l2Client, db, l2Cfg.RelayerConfig, chainConfig, true, relayer.ServiceTypeL2RollupRelayer, nil)
240+
require.NoError(t, err)
241+
242+
defer l2Relayer.StopSenders()
243+
defer database.CloseDB(db)
244+
245+
// add some blocks to db
246+
var blocks []*encoding.Block
247+
genesis, err := l2Client.HeaderByNumber(context.Background(), big.NewInt(0))
248+
require.NoError(t, err)
249+
250+
var l1MessageIndex uint64 = 0
251+
parentHash := genesis.Hash()
252+
for i := int64(0); i < 10; i++ {
253+
header := gethTypes.Header{
254+
Number: big.NewInt(i + 1),
255+
ParentHash: parentHash,
256+
Difficulty: big.NewInt(i + 1),
257+
BaseFee: big.NewInt(i + 1),
258+
Root: common.HexToHash("0x1"),
259+
}
260+
fmt.Println("block number: ", i+1, header.Hash(), parentHash)
261+
var transactions []*gethTypes.TransactionData
262+
if i%2 == 0 {
263+
txs := []*gethTypes.Transaction{
264+
gethTypes.NewTx(&gethTypes.L1MessageTx{
265+
QueueIndex: l1MessageIndex,
266+
Gas: 0,
267+
To: &common.Address{1, 2, 3},
268+
Value: big.NewInt(10),
269+
Data: nil,
270+
Sender: common.Address{1, 2, 3},
271+
}),
272+
}
273+
transactions = append(transactions, encoding.TxsToTxsData(txs)...)
274+
l1MessageIndex++
275+
}
276+
277+
blocks = append(blocks, &encoding.Block{
278+
Header: &header,
279+
Transactions: transactions,
280+
WithdrawRoot: common.HexToHash("0x2"),
281+
RowConsumption: &gethTypes.RowConsumption{},
282+
})
283+
parentHash = header.Hash()
284+
}
285+
286+
cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
287+
MaxBlockNumPerChunk: 100,
288+
MaxTxNumPerChunk: 10000,
289+
MaxL1CommitGasPerChunk: 50000000000,
290+
MaxL1CommitCalldataSizePerChunk: 1000000,
291+
MaxRowConsumptionPerChunk: 1048319,
292+
ChunkTimeoutSec: 300,
293+
MaxUncompressedBatchBytesSize: math.MaxUint64,
294+
}, encoding.CodecV7, chainConfig, db, nil)
295+
296+
bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{
297+
MaxL1CommitGasPerBatch: 50000000000,
298+
MaxL1CommitCalldataSizePerBatch: 1000000,
299+
BatchTimeoutSec: 300,
300+
MaxUncompressedBatchBytesSize: math.MaxUint64,
301+
}, encoding.CodecV7, chainConfig, db, nil)
302+
303+
bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{
304+
MaxBatchNumPerBundle: 1000000,
305+
BundleTimeoutSec: 300,
306+
}, encoding.CodecV7, chainConfig, db, nil)
307+
308+
l2BlockOrm := orm.NewL2Block(db)
309+
batchOrm := orm.NewBatch(db)
310+
bundleOrm := orm.NewBundle(db)
311+
312+
fmt.Println("insert first 5 blocks ------------------------")
313+
err = l2BlockOrm.InsertL2Blocks(context.Background(), blocks[:5])
314+
require.NoError(t, err)
315+
batch1ExpectedLastL1MessageQueueHash, err := encoding.MessageQueueV2ApplyL1MessagesFromBlocks(common.Hash{}, blocks[:5])
316+
require.NoError(t, err)
317+
318+
cp.TryProposeChunk()
319+
bap.TryProposeBatch()
320+
321+
fmt.Println("insert last 5 blocks ------------------------")
322+
err = l2BlockOrm.InsertL2Blocks(context.Background(), blocks[5:])
323+
require.NoError(t, err)
324+
batch2ExpectedLastL1MessageQueueHash, err := encoding.MessageQueueV2ApplyL1MessagesFromBlocks(batch1ExpectedLastL1MessageQueueHash, blocks[5:])
325+
require.NoError(t, err)
326+
327+
cp.TryProposeChunk()
328+
bap.TryProposeBatch()
329+
330+
bup.TryProposeBundle() // The proposed bundle contains two batches when codec version is codecv3.
331+
332+
// make sure that batches are created as expected
333+
require.Eventually(t, func() bool {
334+
batches, getErr := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0)
335+
if getErr != nil {
336+
return false
337+
}
338+
if len(batches) != 3 {
339+
return false
340+
}
341+
342+
// batches[0] is the genesis batch, no need to check
343+
344+
// assert correctness of L1 message queue hashes
345+
require.Equal(t, common.Hash{}, common.HexToHash(batches[1].InitialL1MessageQueueHash))
346+
require.Equal(t, batch1ExpectedLastL1MessageQueueHash, common.HexToHash(batches[1].LastL1MessageQueueHash))
347+
require.Equal(t, batch1ExpectedLastL1MessageQueueHash, common.HexToHash(batches[2].InitialL1MessageQueueHash))
348+
require.Equal(t, batch2ExpectedLastL1MessageQueueHash, common.HexToHash(batches[2].LastL1MessageQueueHash))
349+
350+
return true
351+
}, 30*time.Second, time.Second)
352+
353+
// simulate proof generation -> all batches and bundle are verified
354+
{
355+
batchProof := &message.BatchProof{
356+
Proof: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
357+
Instances: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
358+
Vk: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
359+
}
360+
batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0)
361+
require.NoError(t, err)
362+
batches = batches[1:]
363+
for _, batch := range batches {
364+
err = batchOrm.UpdateProofByHash(context.Background(), batch.Hash, batchProof, 100)
365+
require.NoError(t, err)
366+
err = batchOrm.UpdateProvingStatus(context.Background(), batch.Hash, types.ProvingTaskVerified)
367+
require.NoError(t, err)
368+
}
369+
370+
bundleProof := &message.BundleProof{
371+
Proof: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
372+
Instances: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
373+
Vk: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
374+
}
375+
bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{}, nil, 0)
376+
require.NoError(t, err)
377+
for _, bundle := range bundles {
378+
err = bundleOrm.UpdateProofAndProvingStatusByHash(context.Background(), bundle.Hash, bundleProof, types.ProvingTaskVerified, 100)
379+
require.NoError(t, err)
380+
}
381+
}
382+
383+
//return
384+
// TODO: assert that batches have been submitted together in a single transaction after contract ABI is updated
385+
//for _, batch := range batches {
386+
// fmt.Println("batch hash: ", batch.Hash, batch.Index, batch.RollupStatus)
387+
// //if types.RollupCommitted != types.RollupStatus(batch.RollupStatus) {
388+
// // return false
389+
// //}
390+
//}
391+
//l2Relayer.ProcessPendingBatches()
392+
//
393+
//assert.Eventually(t, func() bool {
394+
// l2Relayer.ProcessPendingBundles()
395+
//
396+
// batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0)
397+
// assert.NoError(t, err)
398+
// assert.Len(t, batches, 3)
399+
// batches = batches[1:]
400+
// for _, batch := range batches {
401+
// if types.RollupStatus(batch.RollupStatus) != types.RollupFinalized {
402+
// return false
403+
// }
404+
//
405+
// assert.NotEmpty(t, batch.FinalizeTxHash)
406+
// receipt, getErr := l1Client.TransactionReceipt(context.Background(), common.HexToHash(batch.FinalizeTxHash))
407+
// assert.NoError(t, getErr)
408+
// assert.Equal(t, gethTypes.ReceiptStatusSuccessful, receipt.Status)
409+
// }
410+
//
411+
// bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{}, nil, 0)
412+
// assert.NoError(t, err)
413+
// assert.Len(t, bundles, 1)
414+
//
415+
// bundle := bundles[0]
416+
// if types.RollupStatus(bundle.RollupStatus) != types.RollupFinalized {
417+
// return false
418+
// }
419+
// assert.NotEmpty(t, bundle.FinalizeTxHash)
420+
// receipt, err := l1Client.TransactionReceipt(context.Background(), common.HexToHash(bundle.FinalizeTxHash))
421+
// assert.NoError(t, err)
422+
// assert.Equal(t, gethTypes.ReceiptStatusSuccessful, receipt.Status)
423+
// batches, err = batchOrm.GetBatches(context.Background(), map[string]interface{}{"bundle_hash": bundle.Hash}, nil, 0)
424+
// assert.NoError(t, err)
425+
// assert.Len(t, batches, 2)
426+
// for _, batch := range batches {
427+
// assert.Equal(t, batch.RollupStatus, bundle.RollupStatus)
428+
// assert.Equal(t, bundle.FinalizeTxHash, batch.FinalizeTxHash)
429+
// }
430+
//
431+
// return true
432+
//}, 30*time.Second, time.Second)
433+
}

0 commit comments

Comments
 (0)