From f6f91e71da9f4773795848aebebb3f9d2988db46 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Sat, 10 May 2025 17:22:06 +0800 Subject: [PATCH 01/13] simplify rollup-relayer --- common/version/version.go | 2 +- rollup/abi/bridge_abi_test.go | 79 ---- rollup/cmd/proposer_tool/app/app.go | 3 + rollup/cmd/rollup_relayer/app/app.go | 4 + rollup/conf/config.json | 10 +- rollup/docker-compose-proposer-tool.yml | 2 +- rollup/go.mod | 2 +- rollup/go.sum | 4 +- rollup/internal/config/l2.go | 25 +- rollup/internal/config/relayer.go | 2 - rollup/internal/controller/relayer/common.go | 9 - .../internal/controller/relayer/l2_relayer.go | 229 +---------- .../controller/relayer/l2_relayer_test.go | 307 +++++++------- .../controller/watcher/batch_proposer.go | 90 +---- .../controller/watcher/batch_proposer_test.go | 374 +++++------------- .../controller/watcher/bundle_proposer.go | 5 - .../watcher/bundle_proposer_test.go | 31 +- .../controller/watcher/chunk_proposer.go | 239 ++--------- .../controller/watcher/chunk_proposer_test.go | 242 ++++-------- .../internal/controller/watcher/l2_watcher.go | 16 +- .../controller/watcher/l2_watcher_metrics.go | 16 +- .../controller/watcher/watcher_test.go | 13 +- rollup/internal/orm/batch.go | 46 ++- rollup/internal/orm/chunk.go | 9 +- rollup/internal/orm/l2_block.go | 17 - rollup/internal/orm/orm_test.go | 2 + rollup/internal/utils/utils.go | 62 +-- rollup/proposer-tool-config.json | 9 +- rollup/tests/bridge_test.go | 1 - rollup/tests/gas_oracle_test.go | 10 +- rollup/tests/process_start_test.go | 4 +- rollup/tests/rollup_test.go | 189 +-------- 32 files changed, 466 insertions(+), 1587 deletions(-) diff --git a/common/version/version.go b/common/version/version.go index 794e3c5978..1a52f93d65 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.9" +var tag = "v4.5.10" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/rollup/abi/bridge_abi_test.go b/rollup/abi/bridge_abi_test.go index 5bed6ebb96..572da6c223 100644 --- a/rollup/abi/bridge_abi_test.go +++ b/rollup/abi/bridge_abi_test.go @@ -10,33 +10,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPackCommitBatch(t *testing.T) { - scrollChainABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - version := uint8(1) - var parentBatchHeader []byte - var chunks [][]byte - var skippedL1MessageBitmap []byte - - _, err = scrollChainABI.Pack("commitBatch", version, parentBatchHeader, chunks, skippedL1MessageBitmap) - assert.NoError(t, err) -} - -func TestPackCommitBatchWithBlobProof(t *testing.T) { - scrollChainABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - version := uint8(1) - var parentBatchHeader []byte - var chunks [][]byte - var skippedL1MessageBitmap []byte - var blobDataProof []byte - - _, err = scrollChainABI.Pack("commitBatchWithBlobProof", version, parentBatchHeader, chunks, skippedL1MessageBitmap, blobDataProof) - assert.NoError(t, err) -} - func TestPackCommitBatches(t *testing.T) { scrollChainABI, err := ScrollChainMetaData.GetAbi() assert.NoError(t, err) @@ -49,58 +22,6 @@ func TestPackCommitBatches(t *testing.T) { assert.NoError(t, err) } -func TestPackFinalizeBatchWithProof(t *testing.T) { - l1RollupABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - var batchHeader []byte - var prevStateRoot common.Hash - var postStateRoot common.Hash - var withdrawRoot common.Hash - var aggrProof []byte - - _, err = l1RollupABI.Pack("finalizeBatchWithProof", batchHeader, prevStateRoot, postStateRoot, withdrawRoot, aggrProof) - assert.NoError(t, err) -} - -func TestPackFinalizeBatchWithProof4844(t *testing.T) { - l1RollupABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - var batchHeader []byte - var prevStateRoot common.Hash - var postStateRoot common.Hash - var withdrawRoot common.Hash - var blobDataProof []byte - var aggrProof []byte - - _, err = l1RollupABI.Pack("finalizeBatchWithProof4844", batchHeader, prevStateRoot, postStateRoot, withdrawRoot, blobDataProof, aggrProof) - assert.NoError(t, err) -} - -func TestPackFinalizeBundleWithProof(t *testing.T) { - l1RollupABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - var batchHeader []byte - var postStateRoot common.Hash - var withdrawRoot common.Hash - var aggrProof []byte - - _, err = l1RollupABI.Pack("finalizeBundleWithProof", batchHeader, postStateRoot, withdrawRoot, aggrProof) - assert.NoError(t, err) -} - -func TestPackFinalizeEuclidInitialBatch(t *testing.T) { - l1RollupABI, err := ScrollChainMetaData.GetAbi() - assert.NoError(t, err) - - var postStateRoot common.Hash - - _, err = l1RollupABI.Pack("finalizeEuclidInitialBatch", postStateRoot) - assert.NoError(t, err) -} - func TestPackFinalizeBundlePostEuclidV2(t *testing.T) { l1RollupABI, err := ScrollChainMetaData.GetAbi() assert.NoError(t, err) diff --git a/rollup/cmd/proposer_tool/app/app.go b/rollup/cmd/proposer_tool/app/app.go index 1ade4c678e..e2429d3dc4 100644 --- a/rollup/cmd/proposer_tool/app/app.go +++ b/rollup/cmd/proposer_tool/app/app.go @@ -54,6 +54,9 @@ func action(ctx *cli.Context) error { } minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name)) + if minCodecVersion < encoding.CodecV7 { + log.Crit("min codec version must be greater than or equal to CodecV7", "minCodecVersion", minCodecVersion) + } // sanity check config if cfg.L2Config.BatchProposerConfig.MaxChunksPerBatch <= 0 { diff --git a/rollup/cmd/rollup_relayer/app/app.go b/rollup/cmd/rollup_relayer/app/app.go index d6d1e8a763..168b58aeed 100644 --- a/rollup/cmd/rollup_relayer/app/app.go +++ b/rollup/cmd/rollup_relayer/app/app.go @@ -102,6 +102,10 @@ func action(ctx *cli.Context) error { } minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name)) + if minCodecVersion < encoding.CodecV7 { + log.Crit("min codec version must be greater than or equal to CodecV7", "minCodecVersion", minCodecVersion) + } + chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, registry) batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, registry) bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry) diff --git a/rollup/conf/config.json b/rollup/conf/config.json index 941be1b006..e280f8018d 100644 --- a/rollup/conf/config.json +++ b/rollup/conf/config.json @@ -95,21 +95,15 @@ "max_block_num_per_chunk": 100, "max_tx_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, - "max_l1_commit_gas_per_chunk": 11234567, - "max_l1_commit_calldata_size_per_chunk": 112345, "chunk_timeout_sec": 300, - "max_row_consumption_per_chunk": 1048319, - "gas_cost_increase_multiplier": 1.2, - "max_uncompressed_batch_bytes_size": 634880 + "gas_cost_increase_multiplier": 1.2 }, "batch_proposer_config": { "propose_interval_milliseconds": 1000, "max_l1_commit_gas_per_batch": 11234567, - "max_l1_commit_calldata_size_per_batch": 112345, "batch_timeout_sec": 300, "gas_cost_increase_multiplier": 1.2, - "max_uncompressed_batch_bytes_size": 634880, - "max_chunks_per_batch": 12 + "max_chunks_per_batch": 45 }, "bundle_proposer_config": { "max_batch_num_per_bundle": 20, diff --git a/rollup/docker-compose-proposer-tool.yml b/rollup/docker-compose-proposer-tool.yml index 3d4d4a723c..f54974b591 100644 --- a/rollup/docker-compose-proposer-tool.yml +++ b/rollup/docker-compose-proposer-tool.yml @@ -27,7 +27,7 @@ services: command: [ "--config", "/app/conf/proposer-tool-config.json", "--genesis", "/app/conf/proposer-tool-genesis.json", - "--min-codec-version", "4", + "--min-codec-version", "7", "--start-l2-block", "10000", "--log.debug", "--verbosity", "3" ] diff --git a/rollup/go.mod b/rollup/go.mod index d06be48597..cb945ff486 100644 --- a/rollup/go.mod +++ b/rollup/go.mod @@ -11,7 +11,7 @@ require ( github.com/holiman/uint256 v1.3.2 github.com/mitchellh/mapstructure v1.5.0 github.com/prometheus/client_golang v1.16.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493 + github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82 github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 github.com/smartystreets/goconvey v1.8.0 github.com/spf13/viper v1.19.0 diff --git a/rollup/go.sum b/rollup/go.sum index e87d0e6980..273d589508 100644 --- a/rollup/go.sum +++ b/rollup/go.sum @@ -249,8 +249,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493 h1:Ioc01J0WEMxuwFvEPGJeBKXdf2KY4Yc3XbFky/IxLlI= -github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= +github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82 h1:8mqkSusH9qz7Hzz7MtQ9uMXX0ej2c1NyeG14W1LTCQk= +github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= diff --git a/rollup/internal/config/l2.go b/rollup/internal/config/l2.go index cb07e162b1..582e96d571 100644 --- a/rollup/internal/config/l2.go +++ b/rollup/internal/config/l2.go @@ -28,27 +28,18 @@ type L2Config struct { // ChunkProposerConfig loads chunk_proposer configuration items. type ChunkProposerConfig struct { - ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"` - MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"` - MaxTxNumPerChunk uint64 `json:"max_tx_num_per_chunk"` - MaxL2GasPerChunk uint64 `json:"max_l2_gas_per_chunk"` - MaxL1CommitGasPerChunk uint64 `json:"max_l1_commit_gas_per_chunk"` - MaxL1CommitCalldataSizePerChunk uint64 `json:"max_l1_commit_calldata_size_per_chunk"` - ChunkTimeoutSec uint64 `json:"chunk_timeout_sec"` - MaxRowConsumptionPerChunk uint64 `json:"max_row_consumption_per_chunk"` - GasCostIncreaseMultiplier float64 `json:"gas_cost_increase_multiplier"` - MaxUncompressedBatchBytesSize uint64 `json:"max_uncompressed_batch_bytes_size"` + ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"` + MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"` + MaxTxNumPerChunk uint64 `json:"max_tx_num_per_chunk"` + MaxL2GasPerChunk uint64 `json:"max_l2_gas_per_chunk"` + ChunkTimeoutSec uint64 `json:"chunk_timeout_sec"` } // BatchProposerConfig loads batch_proposer configuration items. type BatchProposerConfig struct { - ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"` - MaxL1CommitGasPerBatch uint64 `json:"max_l1_commit_gas_per_batch"` - MaxL1CommitCalldataSizePerBatch uint64 `json:"max_l1_commit_calldata_size_per_batch"` - BatchTimeoutSec uint64 `json:"batch_timeout_sec"` - GasCostIncreaseMultiplier float64 `json:"gas_cost_increase_multiplier"` - MaxUncompressedBatchBytesSize uint64 `json:"max_uncompressed_batch_bytes_size"` - MaxChunksPerBatch int `json:"max_chunks_per_batch"` + ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"` + BatchTimeoutSec uint64 `json:"batch_timeout_sec"` + MaxChunksPerBatch int `json:"max_chunks_per_batch"` } // BundleProposerConfig loads bundle_proposer configuration items. diff --git a/rollup/internal/config/relayer.go b/rollup/internal/config/relayer.go index a691076961..10444d2a73 100644 --- a/rollup/internal/config/relayer.go +++ b/rollup/internal/config/relayer.go @@ -73,8 +73,6 @@ type RelayerConfig struct { // Indicates if bypass features specific to testing environments are enabled. EnableTestEnvBypassFeatures bool `json:"enable_test_env_bypass_features"` - // Sets rollup-relayer to stop fake finalizing at the fork boundary - TestEnvBypassOnlyUntilForkBoundary bool `json:"test_env_bypass_only_until_fork_boundary"` // The timeout in seconds for finalizing a batch without proof, only used when EnableTestEnvBypassFeatures is true. FinalizeBatchWithoutProofTimeoutSec uint64 `json:"finalize_batch_without_proof_timeout_sec"` // The timeout in seconds for finalizing a bundle without proof, only used when EnableTestEnvBypassFeatures is true. diff --git a/rollup/internal/controller/relayer/common.go b/rollup/internal/controller/relayer/common.go index f36a49d1a3..fe7add2c3d 100644 --- a/rollup/internal/controller/relayer/common.go +++ b/rollup/internal/controller/relayer/common.go @@ -1,20 +1,11 @@ package relayer -import "errors" - const ( gasPriceDiffPrecision = 1000000 defaultGasPriceDiff = 50000 // 5% ) -var ( - // ErrExecutionRevertedMessageExpired error of Message expired - ErrExecutionRevertedMessageExpired = errors.New("execution reverted: Message expired") - // ErrExecutionRevertedAlreadySuccessExecuted error of Message was already successfully executed - ErrExecutionRevertedAlreadySuccessExecuted = errors.New("execution reverted: Message was already successfully executed") -) - // ServiceType defines the various types of services within the relayer. type ServiceType int diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 15ac84445e..8fcb084b1f 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -14,7 +14,6 @@ import ( "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/accounts/abi" "github.com/scroll-tech/go-ethereum/common" - gethTypes "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/crypto" "github.com/scroll-tech/go-ethereum/crypto/kzg4844" "github.com/scroll-tech/go-ethereum/ethclient" @@ -159,14 +158,7 @@ func (r *Layer2Relayer) initializeGenesis() error { log.Info("retrieved L2 genesis header", "hash", genesis.Hash().String()) - chunk := &encoding.Chunk{ - Blocks: []*encoding.Block{{ - Header: genesis, - Transactions: nil, - WithdrawRoot: common.Hash{}, - RowConsumption: &gethTypes.RowConsumption{}, - }}, - } + chunk := &encoding.Chunk{Blocks: []*encoding.Block{{Header: genesis}}} err = r.db.Transaction(func(dbTX *gorm.DB) error { if err = r.l2BlockOrm.InsertL2Blocks(r.ctx, chunk.Blocks); err != nil { @@ -277,12 +269,6 @@ func (r *Layer2Relayer) ProcessPendingBatches() { var batchesToSubmit []*dbBatchWithChunksAndParent var forceSubmit bool for i, dbBatch := range dbBatches { - if i == 0 && encoding.CodecVersion(dbBatch.CodecVersion) < encoding.CodecV7 { - // if the first batch is not >= V7 then we need to submit batches one by one - r.processPendingBatchesV4(dbBatches) - return - } - var dbChunks []*orm.Chunk var dbParentBatch *orm.Batch @@ -454,117 +440,6 @@ type dbBatchWithChunksAndParent struct { ParentBatch *orm.Batch } -func (r *Layer2Relayer) processPendingBatchesV4(dbBatches []*orm.Batch) { - for _, dbBatch := range dbBatches { - r.metrics.rollupL2RelayerProcessPendingBatchTotal.Inc() - - dbChunks, err := r.chunkOrm.GetChunksInRange(r.ctx, dbBatch.StartChunkIndex, dbBatch.EndChunkIndex) - if err != nil { - log.Error("failed to get chunks in range", "err", err) - return - } - - // check codec version - for _, dbChunk := range dbChunks { - if dbBatch.CodecVersion != dbChunk.CodecVersion { - log.Error("batch codec version is different from chunk codec version", "batch index", dbBatch.Index, "chunk index", dbChunk.Index, "batch codec version", dbBatch.CodecVersion, "chunk codec version", dbChunk.CodecVersion) - return - } - } - - chunks := make([]*encoding.Chunk, len(dbChunks)) - for i, c := range dbChunks { - blocks, getErr := r.l2BlockOrm.GetL2BlocksInRange(r.ctx, c.StartBlockNumber, c.EndBlockNumber) - if getErr != nil { - log.Error("failed to get blocks in range", "err", getErr) - return - } - chunks[i] = &encoding.Chunk{Blocks: blocks} - } - - if dbBatch.Index == 0 { - log.Error("invalid args: batch index is 0, should only happen in committing genesis batch") - return - } - - dbParentBatch, getErr := r.batchOrm.GetBatchByIndex(r.ctx, dbBatch.Index-1) - if getErr != nil { - log.Error("failed to get parent batch header", "err", getErr) - return - } - - if dbParentBatch.CodecVersion > dbBatch.CodecVersion { - log.Error("parent batch codec version is greater than current batch codec version", "index", dbBatch.Index, "hash", dbBatch.Hash, "parent codec version", dbParentBatch.CodecVersion, "current codec version", dbBatch.CodecVersion) - return - } - - var calldata []byte - var blob *kzg4844.Blob - codecVersion := encoding.CodecVersion(dbBatch.CodecVersion) - switch codecVersion { - case encoding.CodecV4, encoding.CodecV5, encoding.CodecV6: - calldata, blob, err = r.constructCommitBatchPayloadCodecV4(dbBatch, dbParentBatch, dbChunks, chunks) - if err != nil { - log.Error("failed to construct commitBatchWithBlobProof payload for V4", "codecVersion", codecVersion, "index", dbBatch.Index, "err", err) - return - } - default: - log.Error("unsupported codec version in processPendingBatchesV4", "codecVersion", codecVersion) - return - } - - // fallbackGasLimit is non-zero only in sending non-blob transactions. - fallbackGasLimit := uint64(float64(dbBatch.TotalL1CommitGas) * r.cfg.L1CommitGasLimitMultiplier) - if types.RollupStatus(dbBatch.RollupStatus) == types.RollupCommitFailed { - // use eth_estimateGas if this batch has been committed and failed at least once. - fallbackGasLimit = 0 - log.Warn("Batch commit previously failed, using eth_estimateGas for the re-submission", "hash", dbBatch.Hash) - } - - txHash, err := r.commitSender.SendTransaction(dbBatch.Hash, &r.cfg.RollupContractAddress, calldata, []*kzg4844.Blob{blob}, fallbackGasLimit) - if err != nil { - if errors.Is(err, sender.ErrTooManyPendingBlobTxs) { - r.metrics.rollupL2RelayerProcessPendingBatchErrTooManyPendingBlobTxsTotal.Inc() - log.Debug( - "Skipped sending commitBatch tx to L1: too many pending blob txs", - "maxPending", r.cfg.SenderConfig.MaxPendingBlobTxs, - "err", err, - ) - return - } - log.Error( - "Failed to send commitBatch tx to layer1", - "index", dbBatch.Index, - "hash", dbBatch.Hash, - "RollupContractAddress", r.cfg.RollupContractAddress, - "err", err, - "calldata", common.Bytes2Hex(calldata), - ) - return - } - - err = r.batchOrm.UpdateCommitTxHashAndRollupStatus(r.ctx, dbBatch.Hash, txHash.String(), types.RollupCommitting) - if err != nil { - log.Error("UpdateCommitTxHashAndRollupStatus failed", "hash", dbBatch.Hash, "index", dbBatch.Index, "err", err) - return - } - - var maxBlockHeight uint64 - var totalGasUsed uint64 - for _, dbChunk := range dbChunks { - if dbChunk.EndBlockNumber > maxBlockHeight { - maxBlockHeight = dbChunk.EndBlockNumber - } - totalGasUsed += dbChunk.TotalL2TxGas - } - r.metrics.rollupL2RelayerCommitBlockHeight.Set(float64(maxBlockHeight)) - r.metrics.rollupL2RelayerCommitThroughput.Add(float64(totalGasUsed)) - - r.metrics.rollupL2RelayerProcessPendingBatchSuccessTotal.Inc() - log.Info("Sent the commitBatch tx to layer1", "batch index", dbBatch.Index, "batch hash", dbBatch.Hash, "tx hash", txHash.String()) - } -} - // ProcessPendingBundles submits proof to layer 1 rollup contract func (r *Layer2Relayer) ProcessPendingBundles() { r.metrics.rollupL2RelayerProcessPendingBundlesTotal.Inc() @@ -599,33 +474,6 @@ func (r *Layer2Relayer) ProcessPendingBundles() { return } - lastFinalizedChunk, err := r.chunkOrm.GetChunkByIndex(r.ctx, lastBatch.EndChunkIndex) - if err != nil { - log.Error("failed to get last finalized chunk", "chunk index", lastBatch.EndChunkIndex) - return - } - - firstUnfinalizedBatch, err := r.batchOrm.GetBatchByIndex(r.ctx, bundle.StartBatchIndex) - if err != nil { - log.Error("failed to get first unfinalized batch", "batch index", bundle.StartBatchIndex) - return - } - - firstUnfinalizedChunk, err := r.chunkOrm.GetChunkByIndex(r.ctx, firstUnfinalizedBatch.StartChunkIndex) - if err != nil { - log.Error("failed to get firsr unfinalized chunk", "chunk index", firstUnfinalizedBatch.StartChunkIndex) - return - } - - if r.cfg.TestEnvBypassOnlyUntilForkBoundary { - lastFork := encoding.GetHardforkName(r.chainCfg, lastFinalizedChunk.StartBlockNumber, lastFinalizedChunk.StartBlockTime) - nextFork := encoding.GetHardforkName(r.chainCfg, firstUnfinalizedChunk.StartBlockNumber, firstUnfinalizedChunk.StartBlockTime) - if lastFork != nextFork { - log.Info("not fake finalizing past the fork boundary", "last fork", lastFork, "next fork", nextFork) - return - } - } - if err := r.finalizeBundle(bundle, false); err != nil { log.Error("failed to finalize timeout bundle without proof", "bundle index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err) return @@ -740,11 +588,6 @@ func (r *Layer2Relayer) finalizeBundle(bundle *orm.Bundle, withProof bool) error var calldata []byte switch encoding.CodecVersion(bundle.CodecVersion) { - case encoding.CodecV4, encoding.CodecV5, encoding.CodecV6: - calldata, err = r.constructFinalizeBundlePayloadCodecV4(dbBatch, aggProof) - if err != nil { - return fmt.Errorf("failed to construct finalizeBundle payload codecv4, bundle index: %v, last batch index: %v, err: %w", bundle.Index, dbBatch.Index, err) - } case encoding.CodecV7: calldata, err = r.constructFinalizeBundlePayloadCodecV7(dbBatch, endChunk, aggProof) if err != nil { @@ -950,48 +793,6 @@ func (r *Layer2Relayer) handleL2RollupRelayerConfirmLoop(ctx context.Context) { } } -func (r *Layer2Relayer) constructCommitBatchPayloadCodecV4(dbBatch *orm.Batch, dbParentBatch *orm.Batch, dbChunks []*orm.Chunk, chunks []*encoding.Chunk) ([]byte, *kzg4844.Blob, error) { - batch := &encoding.Batch{ - Index: dbBatch.Index, - TotalL1MessagePoppedBefore: dbChunks[0].TotalL1MessagesPoppedBefore, - ParentBatchHash: common.HexToHash(dbParentBatch.Hash), - Chunks: chunks, - } - - codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion)) - if err != nil { - return nil, nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err) - } - - daBatch, createErr := codec.NewDABatch(batch) - if createErr != nil { - return nil, nil, fmt.Errorf("failed to create DA batch: %w", createErr) - } - - encodedChunks := make([][]byte, len(dbChunks)) - for i, c := range dbChunks { - daChunk, createErr := codec.NewDAChunk(chunks[i], c.TotalL1MessagesPoppedBefore) - if createErr != nil { - return nil, nil, fmt.Errorf("failed to create DA chunk: %w", createErr) - } - encodedChunks[i], err = daChunk.Encode() - if err != nil { - return nil, nil, fmt.Errorf("failed to encode DA chunk: %w", err) - } - } - - blobDataProof, err := daBatch.BlobDataProofForPointEvaluation() - if err != nil { - return nil, nil, fmt.Errorf("failed to get blob data proof for point evaluation: %w", err) - } - - calldata, packErr := r.l1RollupABI.Pack("commitBatchWithBlobProof", daBatch.Version(), dbParentBatch.BatchHeader, encodedChunks, daBatch.SkippedL1MessageBitmap(), blobDataProof) - if packErr != nil { - return nil, nil, fmt.Errorf("failed to pack commitBatchWithBlobProof: %w", packErr) - } - return calldata, daBatch.Blob(), nil -} - func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*dbBatchWithChunksAndParent, firstBatch, lastBatch *orm.Batch) ([]byte, []*kzg4844.Blob, uint64, uint64, error) { var maxBlockHeight uint64 var totalGasUsed uint64 @@ -1049,34 +850,6 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*db return calldata, blobs, maxBlockHeight, totalGasUsed, nil } -func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV4(dbBatch *orm.Batch, aggProof message.BundleProof) ([]byte, error) { - if aggProof != nil { // finalizeBundle with proof. - calldata, packErr := r.l1RollupABI.Pack( - "finalizeBundleWithProof", - dbBatch.BatchHeader, - common.HexToHash(dbBatch.StateRoot), - common.HexToHash(dbBatch.WithdrawRoot), - aggProof.Proof(), - ) - if packErr != nil { - return nil, fmt.Errorf("failed to pack finalizeBundleWithProof: %w", packErr) - } - return calldata, nil - } - - // finalizeBundle without proof. - calldata, packErr := r.l1RollupABI.Pack( - "finalizeBundle", - dbBatch.BatchHeader, - common.HexToHash(dbBatch.StateRoot), - common.HexToHash(dbBatch.WithdrawRoot), - ) - if packErr != nil { - return nil, fmt.Errorf("failed to pack finalizeBundle: %w", packErr) - } - return calldata, nil -} - func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV7(dbBatch *orm.Batch, endChunk *orm.Chunk, aggProof message.BundleProof) ([]byte, error) { if aggProof != nil { // finalizeBundle with proof. calldata, packErr := r.l1RollupABI.Pack( diff --git a/rollup/internal/controller/relayer/l2_relayer_test.go b/rollup/internal/controller/relayer/l2_relayer_test.go index 3126cc6313..216507d506 100644 --- a/rollup/internal/controller/relayer/l2_relayer_test.go +++ b/rollup/internal/controller/relayer/l2_relayer_test.go @@ -48,202 +48,186 @@ func testCreateNewRelayer(t *testing.T) { } func testL2RelayerProcessPendingBatches(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupL2RelayerDB(t) - defer database.CloseDB(db) - - l2Cfg := cfg.L2Config - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } + db := setupL2RelayerDB(t) + defer database.CloseDB(db) - relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) - assert.NoError(t, err) + l2Cfg := cfg.L2Config + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} - patchGuard := gomonkey.ApplyMethodFunc(l2Cli, "SendTransaction", func(_ context.Context, _ *gethTypes.Transaction) error { - return nil - }) + relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) + assert.NoError(t, err) - l2BlockOrm := orm.NewL2Block(db) - err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) - assert.NoError(t, err) - chunkOrm := orm.NewChunk(db) - _, err = chunkOrm.InsertChunk(context.Background(), chunk1, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) - _, err = chunkOrm.InsertChunk(context.Background(), chunk2, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) + patchGuard := gomonkey.ApplyMethodFunc(l2Cli, "SendTransaction", func(_ context.Context, _ *gethTypes.Transaction) error { + return nil + }) - batch := &encoding.Batch{ - Index: 1, - TotalL1MessagePoppedBefore: 0, - ParentBatchHash: common.Hash{}, - Chunks: []*encoding.Chunk{chunk1, chunk2}, - } + l2BlockOrm := orm.NewL2Block(db) + err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) + assert.NoError(t, err) + chunkOrm := orm.NewChunk(db) + _, err = chunkOrm.InsertChunk(context.Background(), chunk1, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) + _, err = chunkOrm.InsertChunk(context.Background(), chunk2, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) - batchOrm := orm.NewBatch(db) - dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, codecVersion, rutils.BatchMetrics{}) - assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 1, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, + } - relayer.ProcessPendingBatches() + batchOrm := orm.NewBatch(db) + dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV7, rutils.BatchMetrics{}) + assert.NoError(t, err) - statuses, err := batchOrm.GetRollupStatusByHashList(context.Background(), []string{dbBatch.Hash}) - assert.NoError(t, err) - assert.Equal(t, 1, len(statuses)) - assert.Equal(t, types.RollupCommitting, statuses[0]) - relayer.StopSenders() - patchGuard.Reset() - } + relayer.ProcessPendingBatches() + + statuses, err := batchOrm.GetRollupStatusByHashList(context.Background(), []string{dbBatch.Hash}) + assert.NoError(t, err) + assert.Equal(t, 1, len(statuses)) + assert.Equal(t, types.RollupCommitting, statuses[0]) + relayer.StopSenders() + patchGuard.Reset() } func testL2RelayerProcessPendingBundles(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupL2RelayerDB(t) - defer database.CloseDB(db) - - l2Cfg := cfg.L2Config - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - } - relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) - assert.NoError(t, err) + db := setupL2RelayerDB(t) + defer database.CloseDB(db) - batch := &encoding.Batch{ - Index: 1, - TotalL1MessagePoppedBefore: 0, - ParentBatchHash: common.Hash{}, - Chunks: []*encoding.Chunk{chunk1, chunk2}, - } + l2Cfg := cfg.L2Config + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} + relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) + assert.NoError(t, err) - chunkOrm := orm.NewChunk(db) - _, err = chunkOrm.InsertChunk(context.Background(), chunk1, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) - _, err = chunkOrm.InsertChunk(context.Background(), chunk2, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 1, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, + } - batchOrm := orm.NewBatch(db) - dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, codecVersion, rutils.BatchMetrics{}) - assert.NoError(t, err) + chunkOrm := orm.NewChunk(db) + _, err = chunkOrm.InsertChunk(context.Background(), chunk1, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) + _, err = chunkOrm.InsertChunk(context.Background(), chunk2, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) - bundleOrm := orm.NewBundle(db) - bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, codecVersion) - assert.NoError(t, err) + batchOrm := orm.NewBatch(db) + dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV7, rutils.BatchMetrics{}) + assert.NoError(t, err) - err = bundleOrm.UpdateRollupStatus(context.Background(), bundle.Hash, types.RollupPending) - assert.NoError(t, err) + bundleOrm := orm.NewBundle(db) + bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, encoding.CodecV7) + assert.NoError(t, err) - err = bundleOrm.UpdateProvingStatus(context.Background(), dbBatch.Hash, types.ProvingTaskVerified) - assert.NoError(t, err) + err = bundleOrm.UpdateRollupStatus(context.Background(), bundle.Hash, types.RollupPending) + assert.NoError(t, err) - relayer.ProcessPendingBundles() + err = bundleOrm.UpdateProvingStatus(context.Background(), bundle.Hash, types.ProvingTaskVerified) + assert.NoError(t, err) - bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) - assert.NoError(t, err) - assert.Equal(t, 1, len(bundles)) - // no valid proof, rollup status remains the same - assert.Equal(t, types.RollupPending, types.RollupStatus(bundles[0].RollupStatus)) - - proof := &message.Halo2BundleProof{ - RawProof: []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}, - 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}, - 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}, - } - err = bundleOrm.UpdateProofAndProvingStatusByHash(context.Background(), bundle.Hash, proof, types.ProvingTaskVerified, 600) - assert.NoError(t, err) + relayer.ProcessPendingBundles() - relayer.ProcessPendingBundles() - bundles, err = bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) - assert.NoError(t, err) - assert.Equal(t, 1, len(bundles)) - assert.Equal(t, types.RollupFinalizing, types.RollupStatus(bundles[0].RollupStatus)) - relayer.StopSenders() - } + bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) + assert.NoError(t, err) + assert.Equal(t, 1, len(bundles)) + // no valid proof, rollup status remains the same + assert.Equal(t, types.RollupPending, types.RollupStatus(bundles[0].RollupStatus)) + + patchGuard := gomonkey.ApplyMethodFunc((*message.OpenVMBundleProof)(nil), "SanityCheck", func() error { + return nil + }) + defer patchGuard.Reset() + + proof := &message.OpenVMBundleProof{EvmProof: &message.OpenVMEvmProof{Instances: make([]byte, 384)}} + err = bundleOrm.UpdateProofAndProvingStatusByHash(context.Background(), bundle.Hash, proof, types.ProvingTaskVerified, 600) + assert.NoError(t, err) + + relayer.ProcessPendingBundles() + bundles, err = bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) + assert.NoError(t, err) + assert.Equal(t, 1, len(bundles)) + assert.Equal(t, types.RollupFinalizing, types.RollupStatus(bundles[0].RollupStatus)) + relayer.StopSenders() } func testL2RelayerFinalizeTimeoutBundles(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupL2RelayerDB(t) - defer database.CloseDB(db) - - l2Cfg := cfg.L2Config - l2Cfg.RelayerConfig.EnableTestEnvBypassFeatures = true - l2Cfg.RelayerConfig.FinalizeBundleWithoutProofTimeoutSec = 0 - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - } - relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) - assert.NoError(t, err) + db := setupL2RelayerDB(t) + defer database.CloseDB(db) - l2BlockOrm := orm.NewL2Block(db) - err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) - assert.NoError(t, err) - chunkOrm := orm.NewChunk(db) - chunkDB1, err := chunkOrm.InsertChunk(context.Background(), chunk1, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) - chunkDB2, err := chunkOrm.InsertChunk(context.Background(), chunk2, codecVersion, rutils.ChunkMetrics{}) - assert.NoError(t, err) + l2Cfg := cfg.L2Config + l2Cfg.RelayerConfig.EnableTestEnvBypassFeatures = true + l2Cfg.RelayerConfig.FinalizeBundleWithoutProofTimeoutSec = 0 + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} + relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, l2Cfg.RelayerConfig, chainConfig, ServiceTypeL2RollupRelayer, nil) + assert.NoError(t, err) - batch := &encoding.Batch{ - Index: 1, - TotalL1MessagePoppedBefore: 0, - ParentBatchHash: common.Hash{}, - Chunks: []*encoding.Chunk{chunk1, chunk2}, - } + l2BlockOrm := orm.NewL2Block(db) + err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) + assert.NoError(t, err) + chunkOrm := orm.NewChunk(db) + chunkDB1, err := chunkOrm.InsertChunk(context.Background(), chunk1, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) + chunkDB2, err := chunkOrm.InsertChunk(context.Background(), chunk2, encoding.CodecV7, rutils.ChunkMetrics{}) + assert.NoError(t, err) - batchOrm := orm.NewBatch(db) - dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, codecVersion, rutils.BatchMetrics{}) - assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 1, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, + } - err = batchOrm.UpdateRollupStatus(context.Background(), dbBatch.Hash, types.RollupCommitted) - assert.NoError(t, err) + batchOrm := orm.NewBatch(db) + dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV7, rutils.BatchMetrics{}) + assert.NoError(t, err) - err = chunkOrm.UpdateBatchHashInRange(context.Background(), chunkDB1.Index, chunkDB2.Index, dbBatch.Hash, nil) - assert.NoError(t, err) + err = batchOrm.UpdateRollupStatus(context.Background(), dbBatch.Hash, types.RollupCommitted) + assert.NoError(t, err) - bundleOrm := orm.NewBundle(db) - bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, codecVersion) - assert.NoError(t, err) + err = chunkOrm.UpdateBatchHashInRange(context.Background(), chunkDB1.Index, chunkDB2.Index, dbBatch.Hash, nil) + assert.NoError(t, err) - err = batchOrm.UpdateBundleHashInRange(context.Background(), dbBatch.Index, dbBatch.Index, bundle.Hash, nil) - assert.NoError(t, err) + bundleOrm := orm.NewBundle(db) + bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, encoding.CodecV7) + assert.NoError(t, err) - assert.Eventually(t, func() bool { - relayer.ProcessPendingBundles() + err = batchOrm.UpdateBundleHashInRange(context.Background(), dbBatch.Index, dbBatch.Index, bundle.Hash, nil) + assert.NoError(t, err) - bundleInDB, bundleErr := bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) - if bundleErr != nil { - return false - } + assert.Eventually(t, func() bool { + relayer.ProcessPendingBundles() + + bundleInDB, bundleErr := bundleOrm.GetBundles(context.Background(), map[string]interface{}{"hash": bundle.Hash}, nil, 0) + if bundleErr != nil { + return false + } - bundleStatus := len(bundleInDB) == 1 && types.RollupStatus(bundleInDB[0].RollupStatus) == types.RollupFinalizing && - types.ProvingStatus(bundleInDB[0].ProvingStatus) == types.ProvingTaskVerified + bundleStatus := len(bundleInDB) == 1 && types.RollupStatus(bundleInDB[0].RollupStatus) == types.RollupFinalizing && + types.ProvingStatus(bundleInDB[0].ProvingStatus) == types.ProvingTaskVerified - batchInDB, batchErr := batchOrm.GetBatches(context.Background(), map[string]interface{}{"hash": dbBatch.Hash}, nil, 0) - if batchErr != nil { - return false - } + batchInDB, batchErr := batchOrm.GetBatches(context.Background(), map[string]interface{}{"hash": dbBatch.Hash}, nil, 0) + if batchErr != nil { + return false + } - batchStatus := len(batchInDB) == 1 && types.ProvingStatus(batchInDB[0].ProvingStatus) == types.ProvingTaskVerified + batchStatus := len(batchInDB) == 1 && types.ProvingStatus(batchInDB[0].ProvingStatus) == types.ProvingTaskVerified - chunks, chunkErr := chunkOrm.GetChunksByBatchHash(context.Background(), dbBatch.Hash) - if chunkErr != nil { - return false - } + chunks, chunkErr := chunkOrm.GetChunksByBatchHash(context.Background(), dbBatch.Hash) + if chunkErr != nil { + return false + } - chunkStatus := len(chunks) == 2 && types.ProvingStatus(chunks[0].ProvingStatus) == types.ProvingTaskVerified && - types.ProvingStatus(chunks[1].ProvingStatus) == types.ProvingTaskVerified + chunkStatus := len(chunks) == 2 && types.ProvingStatus(chunks[0].ProvingStatus) == types.ProvingTaskVerified && + types.ProvingStatus(chunks[1].ProvingStatus) == types.ProvingTaskVerified - return bundleStatus && batchStatus && chunkStatus - }, 5*time.Second, 100*time.Millisecond, "Bundle or Batch or Chunk status did not update as expected") - relayer.StopSenders() - } + return bundleStatus && batchStatus && chunkStatus + }, 5*time.Second, 100*time.Millisecond, "Bundle or Batch or Chunk status did not update as expected") + relayer.StopSenders() } func testL2RelayerCommitConfirm(t *testing.T) { @@ -268,6 +252,7 @@ func testL2RelayerCommitConfirm(t *testing.T) { TotalL1MessagePoppedBefore: 0, ParentBatchHash: common.Hash{}, Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, } dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, rutils.BatchMetrics{}) @@ -326,13 +311,14 @@ func testL2RelayerFinalizeBundleConfirm(t *testing.T) { TotalL1MessagePoppedBefore: 0, ParentBatchHash: common.Hash{}, Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, } dbBatch, err := batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, rutils.BatchMetrics{}) assert.NoError(t, err) batchHashes[i] = dbBatch.Hash - bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, encoding.CodecV4) + bundle, err := bundleOrm.InsertBundle(context.Background(), []*orm.Batch{dbBatch}, encoding.CodecV7) assert.NoError(t, err) bundleHashes[i] = bundle.Hash @@ -412,6 +398,7 @@ func testGetBatchStatusByIndex(t *testing.T) { TotalL1MessagePoppedBefore: 0, ParentBatchHash: common.Hash{}, Chunks: []*encoding.Chunk{chunk1, chunk2}, + Blocks: []*encoding.Block{block1, block2}, } batchOrm := orm.NewBatch(db) diff --git a/rollup/internal/controller/watcher/batch_proposer.go b/rollup/internal/controller/watcher/batch_proposer.go index bb08e885c8..b34248d3ec 100644 --- a/rollup/internal/controller/watcher/batch_proposer.go +++ b/rollup/internal/controller/watcher/batch_proposer.go @@ -29,12 +29,8 @@ type BatchProposer struct { chunkOrm *orm.Chunk l2BlockOrm *orm.L2Block - maxL1CommitGasPerBatch uint64 - maxL1CommitCalldataSizePerBatch uint64 - batchTimeoutSec uint64 - gasCostIncreaseMultiplier float64 - maxUncompressedBatchBytesSize uint64 - maxChunksPerBatch int + batchTimeoutSec uint64 + maxChunksPerBatch int replayMode bool minCodecVersion encoding.CodecVersion @@ -44,14 +40,10 @@ type BatchProposer struct { proposeBatchFailureTotal prometheus.Counter proposeBatchUpdateInfoTotal prometheus.Counter proposeBatchUpdateInfoFailureTotal prometheus.Counter - totalL1CommitGas prometheus.Gauge - totalL1CommitCalldataSize prometheus.Gauge totalL1CommitBlobSize prometheus.Gauge batchChunksNum prometheus.Gauge batchFirstBlockTimeoutReached prometheus.Counter batchChunksProposeNotEnoughTotal prometheus.Counter - batchEstimateGasTime prometheus.Gauge - batchEstimateCalldataSizeTime prometheus.Gauge batchEstimateBlobSizeTime prometheus.Gauge // total number of times that batch proposer stops early due to compressed data compatibility breach @@ -64,28 +56,20 @@ type BatchProposer struct { // NewBatchProposer creates a new BatchProposer instance. func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer { log.Info("new batch proposer", - "maxL1CommitGasPerBatch", cfg.MaxL1CommitGasPerBatch, - "maxL1CommitCalldataSizePerBatch", cfg.MaxL1CommitCalldataSizePerBatch, "batchTimeoutSec", cfg.BatchTimeoutSec, - "gasCostIncreaseMultiplier", cfg.GasCostIncreaseMultiplier, - "maxBlobSize", maxBlobSize, - "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize) + "maxBlobSize", maxBlobSize) p := &BatchProposer{ - ctx: ctx, - db: db, - batchOrm: orm.NewBatch(db), - chunkOrm: orm.NewChunk(db), - l2BlockOrm: orm.NewL2Block(db), - maxL1CommitGasPerBatch: cfg.MaxL1CommitGasPerBatch, - maxL1CommitCalldataSizePerBatch: cfg.MaxL1CommitCalldataSizePerBatch, - batchTimeoutSec: cfg.BatchTimeoutSec, - gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier, - maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize, - maxChunksPerBatch: cfg.MaxChunksPerBatch, - replayMode: false, - minCodecVersion: minCodecVersion, - chainCfg: chainCfg, + ctx: ctx, + db: db, + batchOrm: orm.NewBatch(db), + chunkOrm: orm.NewChunk(db), + l2BlockOrm: orm.NewL2Block(db), + batchTimeoutSec: cfg.BatchTimeoutSec, + maxChunksPerBatch: cfg.MaxChunksPerBatch, + replayMode: false, + minCodecVersion: minCodecVersion, + chainCfg: chainCfg, batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_propose_batch_circle_total", @@ -107,14 +91,6 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minC Name: "rollup_propose_batch_due_to_compressed_data_compatibility_breach_total", Help: "Total number of propose batch due to compressed data compatibility breach.", }), - totalL1CommitGas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_batch_total_l1_commit_gas", - Help: "The total l1 commit gas", - }), - totalL1CommitCalldataSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_batch_total_l1_call_data_size", - Help: "The total l1 call data size", - }), totalL1CommitBlobSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_batch_total_l1_commit_blob_size", Help: "The total l1 commit blob size", @@ -131,14 +107,6 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minC Name: "rollup_propose_batch_chunks_propose_not_enough_total", Help: "Total number of batch chunk propose not enough", }), - batchEstimateGasTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_batch_estimate_gas_time", - Help: "Time taken to estimate gas for the chunk.", - }), - batchEstimateCalldataSizeTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_batch_estimate_calldata_size_time", - Help: "Time taken to estimate calldata size for the chunk.", - }), batchEstimateBlobSizeTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_batch_estimate_blob_size_time", Help: "Time taken to estimate blob size for the chunk.", @@ -319,9 +287,7 @@ func (p *BatchProposer) proposeBatch() error { for i, chunk := range daChunks { batch.Chunks = append(batch.Chunks, chunk) - if codec.Version() >= encoding.CodecV7 { - batch.Blocks = append(batch.Blocks, chunk.Blocks...) - } + batch.Blocks = append(batch.Blocks, chunk.Blocks...) batch.PostL1MessageQueueHash = common.HexToHash(dbChunks[i].PostL1MessageQueueHash) metrics, calcErr := utils.CalculateBatchMetrics(&batch, codec.Version()) @@ -331,33 +297,21 @@ func (p *BatchProposer) proposeBatch() error { p.recordTimerBatchMetrics(metrics) - totalOverEstimateL1CommitGas := uint64(p.gasCostIncreaseMultiplier * float64(metrics.L1CommitGas)) - if metrics.L1CommitCalldataSize > p.maxL1CommitCalldataSizePerBatch || totalOverEstimateL1CommitGas > p.maxL1CommitGasPerBatch || - metrics.L1CommitBlobSize > maxBlobSize || metrics.L1CommitUncompressedBatchBytesSize > p.maxUncompressedBatchBytesSize { + if metrics.L1CommitBlobSize > maxBlobSize { if i == 0 { // The first chunk exceeds hard limits, which indicates a bug in the chunk-proposer, manual fix is needed. - return fmt.Errorf("the first chunk exceeds limits; start block number: %v, end block number: %v, limits: %+v, maxChunkNum: %v, maxL1CommitCalldataSize: %v, maxL1CommitGas: %v, maxBlobSize: %v, maxUncompressedBatchBytesSize: %v", - dbChunks[0].StartBlockNumber, dbChunks[0].EndBlockNumber, metrics, maxChunksThisBatch, p.maxL1CommitCalldataSizePerBatch, p.maxL1CommitGasPerBatch, maxBlobSize, p.maxUncompressedBatchBytesSize) + return fmt.Errorf("the first chunk exceeds limits; start block number: %v, end block number: %v, limits: %+v, maxChunkNum: %v, maxBlobSize: %v", + dbChunks[0].StartBlockNumber, dbChunks[0].EndBlockNumber, metrics, maxChunksThisBatch, maxBlobSize) } log.Debug("breaking limit condition in batching", - "l1CommitCalldataSize", metrics.L1CommitCalldataSize, - "maxL1CommitCalldataSize", p.maxL1CommitCalldataSizePerBatch, - "l1CommitGas", metrics.L1CommitGas, - "overEstimateL1CommitGas", totalOverEstimateL1CommitGas, - "maxL1CommitGas", p.maxL1CommitGasPerBatch, "l1CommitBlobSize", metrics.L1CommitBlobSize, - "maxBlobSize", maxBlobSize, - "L1CommitUncompressedBatchBytesSize", metrics.L1CommitUncompressedBatchBytesSize, - "maxUncompressedBatchBytesSize", p.maxUncompressedBatchBytesSize) + "maxBlobSize", maxBlobSize) lastChunk := batch.Chunks[len(batch.Chunks)-1] batch.Chunks = batch.Chunks[:len(batch.Chunks)-1] batch.PostL1MessageQueueHash = common.HexToHash(dbChunks[i-1].PostL1MessageQueueHash) - - if codec.Version() >= encoding.CodecV7 { - batch.Blocks = batch.Blocks[:len(batch.Blocks)-len(lastChunk.Blocks)] - } + batch.Blocks = batch.Blocks[:len(batch.Blocks)-len(lastChunk.Blocks)] metrics, err = utils.CalculateBatchMetrics(&batch, codec.Version()) if err != nil { @@ -410,17 +364,11 @@ func (p *BatchProposer) getDAChunks(dbChunks []*orm.Chunk) ([]*encoding.Chunk, e } func (p *BatchProposer) recordAllBatchMetrics(metrics *utils.BatchMetrics) { - p.totalL1CommitGas.Set(float64(metrics.L1CommitGas)) - p.totalL1CommitCalldataSize.Set(float64(metrics.L1CommitCalldataSize)) p.batchChunksNum.Set(float64(metrics.NumChunks)) p.totalL1CommitBlobSize.Set(float64(metrics.L1CommitBlobSize)) - p.batchEstimateGasTime.Set(float64(metrics.EstimateGasTime)) - p.batchEstimateCalldataSizeTime.Set(float64(metrics.EstimateCalldataSizeTime)) p.batchEstimateBlobSizeTime.Set(float64(metrics.EstimateBlobSizeTime)) } func (p *BatchProposer) recordTimerBatchMetrics(metrics *utils.BatchMetrics) { - p.batchEstimateGasTime.Set(float64(metrics.EstimateGasTime)) - p.batchEstimateCalldataSizeTime.Set(float64(metrics.EstimateCalldataSizeTime)) p.batchEstimateBlobSizeTime.Set(float64(metrics.EstimateBlobSizeTime)) } diff --git a/rollup/internal/controller/watcher/batch_proposer_test.go b/rollup/internal/controller/watcher/batch_proposer_test.go index 9bd03fde4a..718581e81c 100644 --- a/rollup/internal/controller/watcher/batch_proposer_test.go +++ b/rollup/internal/controller/watcher/batch_proposer_test.go @@ -20,60 +20,24 @@ import ( "scroll-tech/rollup/internal/utils" ) -func testBatchProposerLimitsCodecV4(t *testing.T) { +func testBatchProposerLimitsCodecV7(t *testing.T) { tests := []struct { name string - maxL1CommitGas uint64 - maxL1CommitCalldataSize uint64 batchTimeoutSec uint64 expectedBatchesLen int expectedChunksInFirstBatch uint64 // only be checked when expectedBatchesLen > 0 }{ { - name: "NoLimitReached", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 0, + name: "NoLimitReached", + batchTimeoutSec: 1000000000000, + expectedBatchesLen: 0, }, { name: "Timeout", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, batchTimeoutSec: 0, expectedBatchesLen: 1, expectedChunksInFirstBatch: 2, }, - { - name: "MaxL1CommitGasPerBatchIs0", - maxL1CommitGas: 0, - maxL1CommitCalldataSize: 1000000, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 0, - }, - { - name: "MaxL1CommitCalldataSizePerBatchIs0", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 0, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 0, - }, - { - name: "MaxL1CommitGasPerBatchIsFirstChunk", - maxL1CommitGas: 249179, - maxL1CommitCalldataSize: 1000000, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 1, - expectedChunksInFirstBatch: 1, - }, - { - name: "MaxL1CommitCalldataSizePerBatchIsFirstChunk", - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 60, - batchTimeoutSec: 1000000000000, - expectedBatchesLen: 1, - expectedChunksInFirstBatch: 1, - }, } for _, tt := range tests { @@ -86,7 +50,6 @@ func testBatchProposerLimitsCodecV4(t *testing.T) { Header: &gethTypes.Header{ Number: big.NewInt(0), }, - RowConsumption: &gethTypes.RowConsumption{}, } chunk := &encoding.Chunk{ Blocks: []*encoding.Block{block}, @@ -109,45 +72,33 @@ func testBatchProposerLimitsCodecV4(t *testing.T) { assert.NoError(t, err) cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 1, - MaxTxNumPerChunk: 10000, - MaxL2GasPerChunk: 20000000, - MaxL1CommitGasPerChunk: 50000000000, - MaxL1CommitCalldataSizePerChunk: 1000000, - MaxRowConsumptionPerChunk: 1000000, - ChunkTimeoutSec: 300, - GasCostIncreaseMultiplier: 1.2, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, ¶ms.ChainConfig{ + MaxBlockNumPerChunk: 1, + MaxTxNumPerChunk: 10000, + MaxL2GasPerChunk: 20000000, + ChunkTimeoutSec: 300, + }, encoding.CodecV7, ¶ms.ChainConfig{ LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), + EuclidTime: new(uint64), + EuclidV2Time: new(uint64), }, db, nil) cp.TryProposeChunk() // chunk1 contains block1 cp.TryProposeChunk() // chunk2 contains block2 - chunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) - assert.NoError(t, err) - assert.Equal(t, uint64(51124), chunks[0].TotalL1CommitGas) - assert.Equal(t, uint64(60), chunks[0].TotalL1CommitCalldataSize) - assert.Equal(t, uint64(51124), chunks[1].TotalL1CommitGas) - assert.Equal(t, uint64(60), chunks[1].TotalL1CommitCalldataSize) - bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: tt.maxL1CommitGas, - MaxL1CommitCalldataSizePerBatch: tt.maxL1CommitCalldataSize, - BatchTimeoutSec: tt.batchTimeoutSec, - GasCostIncreaseMultiplier: 1.2, - MaxUncompressedBatchBytesSize: math.MaxUint64, - MaxChunksPerBatch: math.MaxInt32, - }, encoding.CodecV4, ¶ms.ChainConfig{ + MaxChunksPerBatch: math.MaxInt32, + BatchTimeoutSec: tt.batchTimeoutSec, + }, encoding.CodecV7, ¶ms.ChainConfig{ LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), + EuclidTime: new(uint64), + EuclidV2Time: new(uint64), }, db, nil) bp.TryProposeBatch() @@ -173,7 +124,7 @@ func testBatchProposerLimitsCodecV4(t *testing.T) { } } -func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) { +func testBatchProposerBlobSizeLimitCodecV7(t *testing.T) { db := setupDB(t) defer database.CloseDB(db) @@ -182,7 +133,6 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) { Header: &gethTypes.Header{ Number: big.NewInt(0), }, - RowConsumption: &gethTypes.RowConsumption{}, } chunk := &encoding.Chunk{ Blocks: []*encoding.Block{block}, @@ -200,230 +150,106 @@ func testBatchCommitGasAndCalldataSizeEstimationCodecV4(t *testing.T) { _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) assert.NoError(t, err) - l2BlockOrm := orm.NewL2Block(db) - err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) - assert.NoError(t, err) + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 1, - MaxTxNumPerChunk: 10000, - MaxL2GasPerChunk: 20_000_000, - MaxL1CommitGasPerChunk: 50000000000, - MaxL1CommitCalldataSizePerChunk: 1000000, - MaxRowConsumptionPerChunk: 1000000, - ChunkTimeoutSec: 300, - GasCostIncreaseMultiplier: 1.2, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil) - cp.TryProposeChunk() // chunk1 contains block1 - cp.TryProposeChunk() // chunk2 contains block2 - - chunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) - assert.NoError(t, err) - assert.Equal(t, uint64(51124), chunks[0].TotalL1CommitGas) - assert.Equal(t, uint64(60), chunks[0].TotalL1CommitCalldataSize) - assert.Equal(t, uint64(51124), chunks[1].TotalL1CommitGas) - assert.Equal(t, uint64(60), chunks[1].TotalL1CommitCalldataSize) + MaxBlockNumPerChunk: math.MaxUint64, + MaxTxNumPerChunk: math.MaxUint64, + MaxL2GasPerChunk: math.MaxUint64, + ChunkTimeoutSec: 0, + }, encoding.CodecV7, chainConfig, db, nil) + + blockHeight := uint64(0) + block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") + for total := int64(0); total < 90; total++ { + for i := int64(0); i < 30; i++ { + blockHeight++ + l2BlockOrm := orm.NewL2Block(db) + block.Header.Number = new(big.Int).SetUint64(blockHeight) + block.Header.Time = blockHeight + err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) + assert.NoError(t, err) + } + cp.TryProposeChunk() + } bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: 50000000000, - MaxL1CommitCalldataSizePerBatch: 1000000, - BatchTimeoutSec: 0, - GasCostIncreaseMultiplier: 1.2, - MaxUncompressedBatchBytesSize: math.MaxUint64, - MaxChunksPerBatch: math.MaxInt32, - }, encoding.CodecV4, ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil) - bp.TryProposeBatch() + MaxChunksPerBatch: math.MaxInt32, + BatchTimeoutSec: math.MaxUint32, + }, encoding.CodecV7, chainConfig, db, nil) + + for i := 0; i < 2; i++ { + bp.TryProposeBatch() + } batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) - assert.NoError(t, err) - assert.Len(t, batches, 2) batches = batches[1:] - assert.Equal(t, uint64(1), batches[0].StartChunkIndex) - assert.Equal(t, uint64(2), batches[0].EndChunkIndex) - assert.Equal(t, types.RollupPending, types.RollupStatus(batches[0].RollupStatus)) - assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(batches[0].ProvingStatus)) - - dbChunks, err := chunkOrm.GetChunksInRange(context.Background(), 1, 2) assert.NoError(t, err) - assert.Len(t, dbChunks, 2) - for _, chunk := range dbChunks { - assert.Equal(t, batches[0].Hash, chunk.BatchHash) - assert.Equal(t, types.ProvingTaskUnassigned, types.ProvingStatus(chunk.ProvingStatus)) - } - - assert.Equal(t, uint64(209350), batches[0].TotalL1CommitGas) - assert.Equal(t, uint64(120), batches[0].TotalL1CommitCalldataSize) -} - -func testBatchProposerBlobSizeLimitCodecV4(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupDB(t) - - // Add genesis batch. - block := &encoding.Block{ - Header: &gethTypes.Header{ - Number: big.NewInt(0), - }, - RowConsumption: &gethTypes.RowConsumption{}, - } - chunk := &encoding.Chunk{ - Blocks: []*encoding.Block{block}, - } - chunkOrm := orm.NewChunk(db) - _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) - assert.NoError(t, err) - batch := &encoding.Batch{ - Index: 0, - TotalL1MessagePoppedBefore: 0, - ParentBatchHash: common.Hash{}, - Chunks: []*encoding.Chunk{chunk}, - } - batchOrm := orm.NewBatch(db) - _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) - assert.NoError(t, err) - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } - - cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: math.MaxUint64, - MaxTxNumPerChunk: math.MaxUint64, - MaxL2GasPerChunk: math.MaxUint64, - MaxL1CommitGasPerChunk: math.MaxUint64, - MaxL1CommitCalldataSizePerChunk: math.MaxUint64, - MaxRowConsumptionPerChunk: math.MaxUint64, - ChunkTimeoutSec: 0, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) - - blockHeight := int64(0) - block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") - for total := int64(0); total < 90; total++ { - for i := int64(0); i < 30; i++ { - blockHeight++ - l2BlockOrm := orm.NewL2Block(db) - block.Header.Number = big.NewInt(blockHeight) - err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) - assert.NoError(t, err) - } - cp.TryProposeChunk() - } - - bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: math.MaxUint64, - MaxL1CommitCalldataSizePerBatch: math.MaxUint64, - BatchTimeoutSec: math.MaxUint32, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - MaxChunksPerBatch: math.MaxInt32, - }, encoding.CodecV4, chainConfig, db, nil) - - for i := 0; i < 2; i++ { - bp.TryProposeBatch() - } - - batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) - batches = batches[1:] - assert.NoError(t, err) + var expectedNumBatches int = 1 + var numChunksMultiplier uint64 = 64 + assert.Len(t, batches, expectedNumBatches) - var expectedNumBatches int - var numChunksMultiplier uint64 - if codecVersion == encoding.CodecV4 { - expectedNumBatches = 2 - numChunksMultiplier = 45 - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } - assert.Len(t, batches, expectedNumBatches) - - for i, batch := range batches { - assert.Equal(t, numChunksMultiplier*(uint64(i)+1), batch.EndChunkIndex) - } - database.CloseDB(db) + for i, batch := range batches { + assert.Equal(t, numChunksMultiplier*(uint64(i)+1), batch.EndChunkIndex) } } -func testBatchProposerMaxChunkNumPerBatchLimitCodecV4(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupDB(t) - - // Add genesis batch. - block := &encoding.Block{ - Header: &gethTypes.Header{ - Number: big.NewInt(0), - }, - RowConsumption: &gethTypes.RowConsumption{}, - } - chunk := &encoding.Chunk{ - Blocks: []*encoding.Block{block}, - } - chunkOrm := orm.NewChunk(db) - _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) - assert.NoError(t, err) - batch := &encoding.Batch{ - Index: 0, - TotalL1MessagePoppedBefore: 0, - ParentBatchHash: common.Hash{}, - Chunks: []*encoding.Chunk{chunk}, - } - batchOrm := orm.NewBatch(db) - _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) - assert.NoError(t, err) - - var expectedChunkNum uint64 - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - expectedChunkNum = 45 - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } - - cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: math.MaxUint64, - MaxTxNumPerChunk: math.MaxUint64, - MaxL2GasPerChunk: math.MaxUint64, - MaxL1CommitGasPerChunk: math.MaxUint64, - MaxL1CommitCalldataSizePerChunk: math.MaxUint64, - MaxRowConsumptionPerChunk: math.MaxUint64, - ChunkTimeoutSec: 0, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) +func testBatchProposerMaxChunkNumPerBatchLimitCodecV7(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) - block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") - for blockHeight := int64(1); blockHeight <= 60; blockHeight++ { - block.Header.Number = big.NewInt(blockHeight) - err = orm.NewL2Block(db).InsertL2Blocks(context.Background(), []*encoding.Block{block}) - assert.NoError(t, err) - cp.TryProposeChunk() - } + // Add genesis batch. + block := &encoding.Block{ + Header: &gethTypes.Header{ + Number: big.NewInt(0), + }, + } + chunk := &encoding.Chunk{ + Blocks: []*encoding.Block{block}, + } + chunkOrm := orm.NewChunk(db) + _, err := chunkOrm.InsertChunk(context.Background(), chunk, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) + batch := &encoding.Batch{ + Index: 0, + TotalL1MessagePoppedBefore: 0, + ParentBatchHash: common.Hash{}, + Chunks: []*encoding.Chunk{chunk}, + } + batchOrm := orm.NewBatch(db) + _, err = batchOrm.InsertBatch(context.Background(), batch, encoding.CodecV0, utils.BatchMetrics{}) + assert.NoError(t, err) - bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: math.MaxUint64, - MaxL1CommitCalldataSizePerBatch: math.MaxUint64, - BatchTimeoutSec: math.MaxUint32, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - MaxChunksPerBatch: math.MaxInt32, - }, encoding.CodecV4, chainConfig, db, nil) - bp.TryProposeBatch() + var expectedChunkNum uint64 = 45 + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} - batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: math.MaxUint64, + MaxTxNumPerChunk: math.MaxUint64, + MaxL2GasPerChunk: math.MaxUint64, + ChunkTimeoutSec: 0, + }, encoding.CodecV7, chainConfig, db, nil) + + block = readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") + for blockHeight := uint64(1); blockHeight <= 60; blockHeight++ { + block.Header.Number = new(big.Int).SetUint64(blockHeight) + block.Header.Time = blockHeight + err = orm.NewL2Block(db).InsertL2Blocks(context.Background(), []*encoding.Block{block}) assert.NoError(t, err) - assert.Len(t, batches, 2) - dbBatch := batches[1] + cp.TryProposeChunk() + } - assert.Equal(t, expectedChunkNum, dbBatch.EndChunkIndex) + bp := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ + MaxChunksPerBatch: 45, + BatchTimeoutSec: math.MaxUint32, + }, encoding.CodecV7, chainConfig, db, nil) + bp.TryProposeBatch() - database.CloseDB(db) - } + batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) + assert.NoError(t, err) + assert.Len(t, batches, 2) + dbBatch := batches[1] + + assert.Equal(t, expectedChunkNum, dbBatch.EndChunkIndex) } diff --git a/rollup/internal/controller/watcher/bundle_proposer.go b/rollup/internal/controller/watcher/bundle_proposer.go index bb180cd61e..3633750101 100644 --- a/rollup/internal/controller/watcher/bundle_proposer.go +++ b/rollup/internal/controller/watcher/bundle_proposer.go @@ -161,11 +161,6 @@ func (p *BundleProposer) proposeBundle() error { return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, p.minCodecVersion) } - if codecVersion == encoding.CodecV5 { - maxBatchesThisBundle = 1 - batches = batches[:maxBatchesThisBundle] - } - for i := 1; i < len(batches); i++ { // Make sure that all batches have been committed. if len(batches[i].CommitTxHash) == 0 { diff --git a/rollup/internal/controller/watcher/bundle_proposer_test.go b/rollup/internal/controller/watcher/bundle_proposer_test.go index 50f39fdb38..be5edc73a5 100644 --- a/rollup/internal/controller/watcher/bundle_proposer_test.go +++ b/rollup/internal/controller/watcher/bundle_proposer_test.go @@ -23,7 +23,7 @@ import ( "scroll-tech/rollup/internal/utils" ) -func testBundleProposerLimitsCodecV4(t *testing.T) { +func testBundleProposerLimitsCodecV7(t *testing.T) { tests := []struct { name string maxBatchNumPerBundle uint64 @@ -69,7 +69,6 @@ func testBundleProposerLimitsCodecV4(t *testing.T) { Header: &gethTypes.Header{ Number: big.NewInt(0), }, - RowConsumption: &gethTypes.RowConsumption{}, } chunk := &encoding.Chunk{ Blocks: []*encoding.Block{block}, @@ -91,27 +90,19 @@ func testBundleProposerLimitsCodecV4(t *testing.T) { err = l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) assert.NoError(t, err) - chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 1, - MaxTxNumPerChunk: math.MaxUint64, - MaxL2GasPerChunk: math.MaxUint64, - MaxL1CommitGasPerChunk: math.MaxUint64, - MaxL1CommitCalldataSizePerChunk: math.MaxUint64, - MaxRowConsumptionPerChunk: math.MaxUint64, - ChunkTimeoutSec: math.MaxUint32, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) + MaxBlockNumPerChunk: 1, + MaxTxNumPerChunk: math.MaxUint64, + MaxL2GasPerChunk: math.MaxUint64, + ChunkTimeoutSec: math.MaxUint32, + }, encoding.CodecV7, chainConfig, db, nil) bap := NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: math.MaxUint64, - MaxL1CommitCalldataSizePerBatch: math.MaxUint64, - BatchTimeoutSec: 0, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) + MaxChunksPerBatch: math.MaxInt32, + BatchTimeoutSec: 0, + }, encoding.CodecV7, chainConfig, db, nil) cp.TryProposeChunk() // chunk1 contains block1 bap.TryProposeBatch() // batch1 contains chunk1 @@ -121,7 +112,7 @@ func testBundleProposerLimitsCodecV4(t *testing.T) { bup := NewBundleProposer(context.Background(), &config.BundleProposerConfig{ MaxBatchNumPerBundle: tt.maxBatchNumPerBundle, BundleTimeoutSec: tt.bundleTimeoutSec, - }, encoding.CodecV4, chainConfig, db, nil) + }, encoding.CodecV7, chainConfig, db, nil) batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, []string{}, 0) require.NoError(t, err) diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index 03db91e43d..f79e5187c9 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -26,15 +26,10 @@ type ChunkProposer struct { chunkOrm *orm.Chunk l2BlockOrm *orm.L2Block - maxBlockNumPerChunk uint64 - maxTxNumPerChunk uint64 - maxL2GasPerChunk uint64 - maxL1CommitGasPerChunk uint64 - maxL1CommitCalldataSizePerChunk uint64 - maxRowConsumptionPerChunk uint64 - chunkTimeoutSec uint64 - gasCostIncreaseMultiplier float64 - maxUncompressedBatchBytesSize uint64 + maxBlockNumPerChunk uint64 + maxTxNumPerChunk uint64 + maxL2GasPerChunk uint64 + chunkTimeoutSec uint64 replayMode bool minCodecVersion encoding.CodecVersion @@ -46,20 +41,12 @@ type ChunkProposer struct { proposeChunkUpdateInfoFailureTotal prometheus.Counter chunkTxNum prometheus.Gauge chunkL2Gas prometheus.Gauge - chunkEstimateL1CommitGas prometheus.Gauge - totalL1CommitCalldataSize prometheus.Gauge totalL1CommitBlobSize prometheus.Gauge - maxTxConsumption prometheus.Gauge chunkBlocksNum prometheus.Gauge chunkFirstBlockTimeoutReached prometheus.Counter chunkBlocksProposeNotEnoughTotal prometheus.Counter - chunkEstimateGasTime prometheus.Gauge - chunkEstimateCalldataSizeTime prometheus.Gauge chunkEstimateBlobSizeTime prometheus.Gauge - // total number of times that chunk proposer stops early due to compressed data compatibility breach - compressedDataCompatibilityBreachTotal prometheus.Counter - chunkProposeBlockHeight prometheus.Gauge chunkProposeThroughput prometheus.Counter } @@ -70,31 +57,21 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC "maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk, "maxTxNumPerChunk", cfg.MaxTxNumPerChunk, "maxL2GasPerChunk", cfg.MaxL2GasPerChunk, - "maxL1CommitGasPerChunk", cfg.MaxL1CommitGasPerChunk, - "maxL1CommitCalldataSizePerChunk", cfg.MaxL1CommitCalldataSizePerChunk, - "maxRowConsumptionPerChunk", cfg.MaxRowConsumptionPerChunk, "chunkTimeoutSec", cfg.ChunkTimeoutSec, - "gasCostIncreaseMultiplier", cfg.GasCostIncreaseMultiplier, - "maxBlobSize", maxBlobSize, - "maxUncompressedBatchBytesSize", cfg.MaxUncompressedBatchBytesSize) + "maxBlobSize", maxBlobSize) p := &ChunkProposer{ - ctx: ctx, - db: db, - chunkOrm: orm.NewChunk(db), - l2BlockOrm: orm.NewL2Block(db), - maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk, - maxTxNumPerChunk: cfg.MaxTxNumPerChunk, - maxL2GasPerChunk: cfg.MaxL2GasPerChunk, - maxL1CommitGasPerChunk: cfg.MaxL1CommitGasPerChunk, - maxL1CommitCalldataSizePerChunk: cfg.MaxL1CommitCalldataSizePerChunk, - maxRowConsumptionPerChunk: cfg.MaxRowConsumptionPerChunk, - chunkTimeoutSec: cfg.ChunkTimeoutSec, - gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier, - maxUncompressedBatchBytesSize: cfg.MaxUncompressedBatchBytesSize, - replayMode: false, - minCodecVersion: minCodecVersion, - chainCfg: chainCfg, + ctx: ctx, + db: db, + chunkOrm: orm.NewChunk(db), + l2BlockOrm: orm.NewL2Block(db), + maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk, + maxTxNumPerChunk: cfg.MaxTxNumPerChunk, + maxL2GasPerChunk: cfg.MaxL2GasPerChunk, + chunkTimeoutSec: cfg.ChunkTimeoutSec, + replayMode: false, + minCodecVersion: minCodecVersion, + chainCfg: chainCfg, chunkProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_propose_chunk_circle_total", @@ -112,10 +89,6 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_update_info_failure_total", Help: "Total number of propose chunk update info failure total.", }), - compressedDataCompatibilityBreachTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ - Name: "rollup_propose_chunk_due_to_compressed_data_compatibility_breach_total", - Help: "Total number of propose chunk due to compressed data compatibility breach.", - }), chunkTxNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_tx_num", Help: "The chunk tx num", @@ -124,22 +97,10 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_l2_gas", Help: "The chunk l2 gas", }), - chunkEstimateL1CommitGas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_estimate_l1_commit_gas", - Help: "The chunk estimate l1 commit gas", - }), - totalL1CommitCalldataSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_total_l1_commit_call_data_size", - Help: "The total l1 commit call data size", - }), totalL1CommitBlobSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_total_l1_commit_blob_size", Help: "The total l1 commit blob size", }), - maxTxConsumption: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_max_tx_consumption", - Help: "The max tx consumption", - }), chunkBlocksNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_chunk_block_number", Help: "The number of blocks in the chunk", @@ -152,14 +113,6 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_blocks_propose_not_enough_total", Help: "Total number of chunk block propose not enough", }), - chunkEstimateGasTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_estimate_gas_time", - Help: "Time taken to estimate gas for the chunk.", - }), - chunkEstimateCalldataSizeTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_estimate_calldata_size_time", - Help: "Time taken to estimate calldata size for the chunk.", - }), chunkEstimateBlobSizeTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_estimate_blob_size_time", Help: "Time taken to estimate blob size for the chunk.", @@ -196,52 +149,11 @@ func (p *ChunkProposer) TryProposeChunk() { } func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion encoding.CodecVersion, metrics *utils.ChunkMetrics) error { - if chunk == nil { + if chunk == nil || len(chunk.Blocks) == 0 { return nil } - compatibilityBreachOccurred := false - - for { - compatible, err := encoding.CheckChunkCompressedDataCompatibility(chunk, codecVersion) - if err != nil { - log.Error("Failed to check chunk compressed data compatibility", "start block number", chunk.Blocks[0].Header.Number, "codecVersion", codecVersion, "err", err) - return err - } - - if compatible { - break - } - - compatibilityBreachOccurred = true - - if len(chunk.Blocks) == 1 { - log.Warn("Disable compression: cannot truncate chunk with only 1 block for compatibility", "block number", chunk.Blocks[0].Header.Number) - break - } - - chunk.Blocks = chunk.Blocks[:len(chunk.Blocks)-1] - - log.Info("Chunk not compatible with compressed data, removing last block", "start block number", chunk.Blocks[0].Header.Number, "truncated block length", len(chunk.Blocks)) - } - - if compatibilityBreachOccurred { - p.compressedDataCompatibilityBreachTotal.Inc() - - // recalculate chunk metrics after truncation - var calcErr error - metrics, calcErr = utils.CalculateChunkMetrics(chunk, codecVersion) - if calcErr != nil { - return fmt.Errorf("failed to calculate chunk metrics, start block number: %v, error: %w", chunk.Blocks[0].Header.Number, calcErr) - } - - p.recordTimerChunkMetrics(metrics) - p.recordAllChunkMetrics(metrics) - } - - if len(chunk.Blocks) > 0 { - p.chunkProposeBlockHeight.Set(float64(chunk.Blocks[len(chunk.Blocks)-1].Header.Number.Uint64())) - } + p.chunkProposeBlockHeight.Set(float64(chunk.Blocks[len(chunk.Blocks)-1].Header.Number.Uint64())) p.chunkProposeThroughput.Add(float64(chunk.TotalGasUsed())) p.proposeChunkUpdateInfoTotal.Inc() @@ -305,53 +217,30 @@ func (p *ChunkProposer) proposeChunk() error { return fmt.Errorf("unsupported codec version: %v, expected at least %v", codecVersion, p.minCodecVersion) } - // Including Curie block in a sole chunk. - if p.chainCfg.CurieBlock != nil && blocks[0].Header.Number.Cmp(p.chainCfg.CurieBlock) == 0 { - chunk := encoding.Chunk{Blocks: blocks[:1]} - metrics, calcErr := utils.CalculateChunkMetrics(&chunk, codecVersion) - if calcErr != nil { - return fmt.Errorf("failed to calculate chunk metrics: %w", calcErr) - } - p.recordTimerChunkMetrics(metrics) - return p.updateDBChunkInfo(&chunk, codecVersion, metrics) - } - - if proposed, err := p.tryProposeEuclidTransitionChunk(blocks); proposed || err != nil { - return err - } - var chunk encoding.Chunk - // From CodecV7 / EuclidV2 onwards we need to provide the PrevL1MessageQueueHash and PostL1MessageQueueHash. - // PrevL1MessageQueueHash of the first chunk in the fork needs to be the empty hash. - if codecVersion >= encoding.CodecV7 { - parentChunk, err := p.chunkOrm.GetLatestChunk(p.ctx) - if err != nil || parentChunk == nil { - return fmt.Errorf("failed to get parent chunk: %w", err) - } - - chunk.PrevL1MessageQueueHash = common.HexToHash(parentChunk.PostL1MessageQueueHash) + parentChunk, err := p.chunkOrm.GetLatestChunk(p.ctx) + if err != nil || parentChunk == nil { + return fmt.Errorf("failed to get parent chunk: %w", err) + } - // previous chunk is not CodecV7, this means this is the first chunk of the fork. - if encoding.CodecVersion(parentChunk.CodecVersion) < codecVersion { - chunk.PrevL1MessageQueueHash = common.Hash{} - } + chunk.PrevL1MessageQueueHash = common.HexToHash(parentChunk.PostL1MessageQueueHash) - chunk.PostL1MessageQueueHash = chunk.PrevL1MessageQueueHash + // previous chunk is not CodecV7, this means this is the first chunk of the fork. + if encoding.CodecVersion(parentChunk.CodecVersion) < codecVersion { + chunk.PrevL1MessageQueueHash = common.Hash{} } + chunk.PostL1MessageQueueHash = chunk.PrevL1MessageQueueHash + var previousPostL1MessageQueueHash common.Hash chunk.Blocks = make([]*encoding.Block, 0, len(blocks)) for i, block := range blocks { chunk.Blocks = append(chunk.Blocks, block) - // Compute rolling PostL1MessageQueueHash for the chunk. Each block's L1 messages are applied to the previous - // hash starting from the PrevL1MessageQueueHash for the chunk. - if codecVersion >= encoding.CodecV7 { - previousPostL1MessageQueueHash = chunk.PostL1MessageQueueHash - chunk.PostL1MessageQueueHash, err = encoding.MessageQueueV2ApplyL1MessagesFromBlocks(previousPostL1MessageQueueHash, []*encoding.Block{block}) - if err != nil { - return fmt.Errorf("failed to calculate last L1 message queue hash for block %d: %w", block.Header.Number.Uint64(), err) - } + previousPostL1MessageQueueHash = chunk.PostL1MessageQueueHash + chunk.PostL1MessageQueueHash, err = encoding.MessageQueueV2ApplyL1MessagesFromBlocks(previousPostL1MessageQueueHash, []*encoding.Block{block}) + if err != nil { + return fmt.Errorf("failed to calculate last L1 message queue hash for block %d: %w", block.Header.Number.Uint64(), err) } metrics, calcErr := utils.CalculateChunkMetrics(&chunk, codecVersion) @@ -361,18 +250,13 @@ func (p *ChunkProposer) proposeChunk() error { p.recordTimerChunkMetrics(metrics) - overEstimatedL1CommitGas := uint64(p.gasCostIncreaseMultiplier * float64(metrics.L1CommitGas)) if metrics.TxNum > p.maxTxNumPerChunk || metrics.L2Gas > p.maxL2GasPerChunk || - metrics.L1CommitCalldataSize > p.maxL1CommitCalldataSizePerChunk || - overEstimatedL1CommitGas > p.maxL1CommitGasPerChunk || - metrics.CrcMax > p.maxRowConsumptionPerChunk || - metrics.L1CommitBlobSize > maxBlobSize || - metrics.L1CommitUncompressedBatchBytesSize > p.maxUncompressedBatchBytesSize { + metrics.L1CommitBlobSize > maxBlobSize { if i == 0 { // The first block exceeds hard limits, which indicates a bug in the sequencer, manual fix is needed. - return fmt.Errorf("the first block exceeds limits; block number: %v, limits: %+v, maxTxNum: %v, maxL1CommitCalldataSize: %v, maxL1CommitGas: %v, maxRowConsumption: %v, maxBlobSize: %v, maxUncompressedBatchBytesSize: %v", - block.Header.Number, metrics, p.maxTxNumPerChunk, p.maxL1CommitCalldataSizePerChunk, p.maxL1CommitGasPerChunk, p.maxRowConsumptionPerChunk, maxBlobSize, p.maxUncompressedBatchBytesSize) + return fmt.Errorf("the first block exceeds limits; block number: %v, limits: %+v, maxTxNum: %v, maxBlobSize: %v", + block.Header.Number, metrics, p.maxTxNumPerChunk, maxBlobSize) } log.Debug("breaking limit condition in chunking", @@ -380,17 +264,8 @@ func (p *ChunkProposer) proposeChunk() error { "maxTxNum", p.maxTxNumPerChunk, "l2Gas", metrics.L2Gas, "maxL2Gas", p.maxL2GasPerChunk, - "l1CommitCalldataSize", metrics.L1CommitCalldataSize, - "maxL1CommitCalldataSize", p.maxL1CommitCalldataSizePerChunk, - "l1CommitGas", metrics.L1CommitGas, - "overEstimatedL1CommitGas", overEstimatedL1CommitGas, - "maxL1CommitGas", p.maxL1CommitGasPerChunk, - "rowConsumption", metrics.CrcMax, - "maxRowConsumption", p.maxRowConsumptionPerChunk, "l1CommitBlobSize", metrics.L1CommitBlobSize, - "maxBlobSize", maxBlobSize, - "L1CommitUncompressedBatchBytesSize", metrics.L1CommitUncompressedBatchBytesSize, - "maxUncompressedBatchBytesSize", p.maxUncompressedBatchBytesSize) + "maxBlobSize", maxBlobSize) chunk.Blocks = chunk.Blocks[:len(chunk.Blocks)-1] chunk.PostL1MessageQueueHash = previousPostL1MessageQueueHash @@ -431,54 +306,12 @@ func (p *ChunkProposer) proposeChunk() error { func (p *ChunkProposer) recordAllChunkMetrics(metrics *utils.ChunkMetrics) { p.chunkTxNum.Set(float64(metrics.TxNum)) - p.maxTxConsumption.Set(float64(metrics.CrcMax)) p.chunkBlocksNum.Set(float64(metrics.NumBlocks)) p.chunkL2Gas.Set(float64(metrics.L2Gas)) - p.totalL1CommitCalldataSize.Set(float64(metrics.L1CommitCalldataSize)) - p.chunkEstimateL1CommitGas.Set(float64(metrics.L1CommitGas)) p.totalL1CommitBlobSize.Set(float64(metrics.L1CommitBlobSize)) - p.chunkEstimateGasTime.Set(float64(metrics.EstimateGasTime)) - p.chunkEstimateCalldataSizeTime.Set(float64(metrics.EstimateCalldataSizeTime)) p.chunkEstimateBlobSizeTime.Set(float64(metrics.EstimateBlobSizeTime)) } func (p *ChunkProposer) recordTimerChunkMetrics(metrics *utils.ChunkMetrics) { - p.chunkEstimateGasTime.Set(float64(metrics.EstimateGasTime)) - p.chunkEstimateCalldataSizeTime.Set(float64(metrics.EstimateCalldataSizeTime)) p.chunkEstimateBlobSizeTime.Set(float64(metrics.EstimateBlobSizeTime)) } - -func (p *ChunkProposer) tryProposeEuclidTransitionChunk(blocks []*encoding.Block) (bool, error) { - // If we are in replay mode, there is a corner case when StartL2Block is set as 0 in this check, - // it needs to get genesis block, but in mainnet db there is no genesis block, so we need to bypass this check. - if p.replayMode { - return false, nil - } - - if !p.chainCfg.IsEuclid(blocks[0].Header.Time) { - return false, nil - } - - prevBlocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, blocks[0].Header.Number.Uint64()-1, 1) - if err != nil || len(prevBlocks) == 0 || prevBlocks[0].Header.Hash() != blocks[0].Header.ParentHash { - return false, fmt.Errorf("failed to get parent block: %w", err) - } - - if p.chainCfg.IsEuclid(prevBlocks[0].Header.Time) { - // Parent is still Euclid, transition happened already - return false, nil - } - - // blocks[0] is Euclid, but parent is not, propose a chunk with only blocks[0] - chunk := encoding.Chunk{Blocks: blocks[:1]} - codecVersion := encoding.CodecV5 - metrics, calcErr := utils.CalculateChunkMetrics(&chunk, codecVersion) - if calcErr != nil { - return false, fmt.Errorf("failed to calculate chunk metrics: %w", calcErr) - } - p.recordTimerChunkMetrics(metrics) - if err := p.updateDBChunkInfo(&chunk, codecVersion, metrics); err != nil { - return false, err - } - return true, nil -} diff --git a/rollup/internal/controller/watcher/chunk_proposer_test.go b/rollup/internal/controller/watcher/chunk_proposer_test.go index 974db79b06..8c125818e1 100644 --- a/rollup/internal/controller/watcher/chunk_proposer_test.go +++ b/rollup/internal/controller/watcher/chunk_proposer_test.go @@ -7,6 +7,7 @@ import ( "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/common/math" + gethTypes "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/params" "github.com/stretchr/testify/assert" @@ -14,107 +15,57 @@ import ( "scroll-tech/rollup/internal/config" "scroll-tech/rollup/internal/orm" + "scroll-tech/rollup/internal/utils" ) -func testChunkProposerLimitsCodecV4(t *testing.T) { +func testChunkProposerLimitsCodecV7(t *testing.T) { tests := []struct { name string maxBlockNum uint64 maxTxNum uint64 maxL2Gas uint64 - maxL1CommitGas uint64 - maxL1CommitCalldataSize uint64 - maxRowConsumption uint64 chunkTimeoutSec uint64 expectedChunksLen int expectedBlocksInFirstChunk int // only be checked when expectedChunksLen > 0 }{ { - name: "NoLimitReached", - maxBlockNum: 100, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, + name: "NoLimitReached", + maxBlockNum: 100, + maxTxNum: 10000, + maxL2Gas: 20_000_000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, }, { name: "Timeout", maxBlockNum: 100, maxTxNum: 10000, maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, chunkTimeoutSec: 0, expectedChunksLen: 1, expectedBlocksInFirstChunk: 2, }, { - name: "MaxTxNumPerChunkIs0", - maxBlockNum: 10, - maxTxNum: 0, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, + name: "MaxTxNumPerChunkIs0", + maxBlockNum: 10, + maxTxNum: 0, + maxL2Gas: 20_000_000, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, }, { - name: "MaxL2GasPerChunkIs0", - maxBlockNum: 10, - maxTxNum: 10, - maxL2Gas: 0, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, - }, - { - name: "MaxL1CommitGasPerChunkIs0", - maxBlockNum: 10, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 0, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, - }, - { - name: "MaxL1CommitCalldataSizePerChunkIs0", - maxBlockNum: 10, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 0, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, - }, - { - name: "MaxRowConsumptionPerChunkIs0", - maxBlockNum: 100, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 0, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, + name: "MaxL2GasPerChunkIs0", + maxBlockNum: 10, + maxTxNum: 10, + maxL2Gas: 0, + chunkTimeoutSec: 1000000000000, + expectedChunksLen: 0, }, { name: "MaxBlockNumPerChunkIs1", maxBlockNum: 1, maxTxNum: 10000, maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, @@ -124,9 +75,6 @@ func testChunkProposerLimitsCodecV4(t *testing.T) { maxBlockNum: 10, maxTxNum: 2, maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, @@ -138,45 +86,6 @@ func testChunkProposerLimitsCodecV4(t *testing.T) { maxBlockNum: 10, maxTxNum: 10000, maxL2Gas: 1_153_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - }, - { - name: "MaxL1CommitGasPerChunkIsFirstBlock", - maxBlockNum: 10, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 62500, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - }, - { - name: "MaxL1CommitCalldataSizePerChunkIsFirstBlock", - maxBlockNum: 10, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 60, - maxRowConsumption: 1000000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - }, - { - name: "MaxRowConsumptionPerChunkIs1", - maxBlockNum: 10, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - maxL1CommitGas: 50000000000, - maxL1CommitCalldataSize: 1000000, - maxRowConsumption: 1, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, expectedBlocksInFirstChunk: 1, @@ -192,21 +101,20 @@ func testChunkProposerLimitsCodecV4(t *testing.T) { err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block1, block2}) assert.NoError(t, err) + // Add genesis chunk. + chunkOrm := orm.NewChunk(db) + _, err = chunkOrm.InsertChunk(context.Background(), &encoding.Chunk{Blocks: []*encoding.Block{{Header: &gethTypes.Header{Number: big.NewInt(0)}}}}, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: tt.maxBlockNum, - MaxTxNumPerChunk: tt.maxTxNum, - MaxL2GasPerChunk: tt.maxL2Gas, - MaxL1CommitGasPerChunk: tt.maxL1CommitGas, - MaxL1CommitCalldataSizePerChunk: tt.maxL1CommitCalldataSize, - MaxRowConsumptionPerChunk: tt.maxRowConsumption, - ChunkTimeoutSec: tt.chunkTimeoutSec, - GasCostIncreaseMultiplier: 1.2, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)}, db, nil) + MaxBlockNumPerChunk: tt.maxBlockNum, + MaxTxNumPerChunk: tt.maxTxNum, + MaxL2GasPerChunk: tt.maxL2Gas, + ChunkTimeoutSec: tt.chunkTimeoutSec, + }, encoding.CodecV7, ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}, db, nil) cp.TryProposeChunk() - chunkOrm := orm.NewChunk(db) - chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 0, 0) + chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 1, 0) assert.NoError(t, err) assert.Len(t, chunks, tt.expectedChunksLen) @@ -224,61 +132,49 @@ func testChunkProposerLimitsCodecV4(t *testing.T) { } } -func testChunkProposerBlobSizeLimitCodecV4(t *testing.T) { - codecVersions := []encoding.CodecVersion{encoding.CodecV4} - for _, codecVersion := range codecVersions { - db := setupDB(t) - block := readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") - for i := int64(0); i < 510; i++ { - l2BlockOrm := orm.NewL2Block(db) - block.Header.Number = big.NewInt(i + 1) - err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) - assert.NoError(t, err) - } +func testChunkProposerBlobSizeLimitCodecV7(t *testing.T) { + db := setupDB(t) + defer database.CloseDB(db) + block := readBlockFromJSON(t, "../../../testdata/blockTrace_03.json") + for i := uint64(0); i < 510; i++ { + l2BlockOrm := orm.NewL2Block(db) + block.Header.Number = new(big.Int).SetUint64(i + 1) + block.Header.Time = i + 1 + err := l2BlockOrm.InsertL2Blocks(context.Background(), []*encoding.Block{block}) + assert.NoError(t, err) + } - var chainConfig *params.ChainConfig - if codecVersion == encoding.CodecV4 { - chainConfig = ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64)} - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } + // Add genesis chunk. + chunkOrm := orm.NewChunk(db) + _, err := chunkOrm.InsertChunk(context.Background(), &encoding.Chunk{Blocks: []*encoding.Block{{Header: &gethTypes.Header{Number: big.NewInt(0)}}}}, encoding.CodecV0, utils.ChunkMetrics{}) + assert.NoError(t, err) - cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 255, - MaxTxNumPerChunk: math.MaxUint64, - MaxL2GasPerChunk: math.MaxUint64, - MaxL1CommitGasPerChunk: math.MaxUint64, - MaxL1CommitCalldataSizePerChunk: math.MaxUint64, - MaxRowConsumptionPerChunk: math.MaxUint64, - ChunkTimeoutSec: math.MaxUint32, - GasCostIncreaseMultiplier: 1, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) + chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)} - for i := 0; i < 2; i++ { - cp.TryProposeChunk() - } + cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ + MaxBlockNumPerChunk: 255, + MaxTxNumPerChunk: math.MaxUint64, + MaxL2GasPerChunk: math.MaxUint64, + ChunkTimeoutSec: math.MaxUint32, + }, encoding.CodecV7, chainConfig, db, nil) - chunkOrm := orm.NewChunk(db) - chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 0, 0) - assert.NoError(t, err) + for i := 0; i < 2; i++ { + cp.TryProposeChunk() + } - var expectedNumChunks int = 2 - var numBlocksMultiplier uint64 - if codecVersion == encoding.CodecV4 { - numBlocksMultiplier = 255 - } else { - assert.Fail(t, "unsupported codec version, expected CodecV4") - } - assert.Len(t, chunks, expectedNumChunks) + chunkOrm = orm.NewChunk(db) + chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 1, 0) + assert.NoError(t, err) - for i, chunk := range chunks { - expected := numBlocksMultiplier * (uint64(i) + 1) - if expected > 2000 { - expected = 2000 - } - assert.Equal(t, expected, chunk.EndBlockNumber) + var expectedNumChunks int = 2 + var numBlocksMultiplier uint64 = 255 + assert.Len(t, chunks, expectedNumChunks) + + for i, chunk := range chunks { + expected := numBlocksMultiplier * (uint64(i) + 1) + if expected > 2000 { + expected = 2000 } - database.CloseDB(db) + assert.Equal(t, expected, chunk.EndBlockNumber) } } diff --git a/rollup/internal/controller/watcher/l2_watcher.go b/rollup/internal/controller/watcher/l2_watcher.go index 7c75a31981..59e225c7de 100644 --- a/rollup/internal/controller/watcher/l2_watcher.go +++ b/rollup/internal/controller/watcher/l2_watcher.go @@ -92,10 +92,6 @@ func (w *L2WatcherClient) getAndStoreBlocks(ctx context.Context, from, to uint64 if err != nil { return fmt.Errorf("failed to GetBlockByNumberOrHash: %v. number: %v", err, number) } - if block.RowConsumption == nil && !w.chainCfg.IsEuclid(block.Time()) { - w.metrics.fetchNilRowConsumptionBlockTotal.Inc() - return fmt.Errorf("fetched block does not contain RowConsumption. number: %v", number) - } var count int for _, tx := range block.Transactions() { @@ -110,10 +106,9 @@ func (w *L2WatcherClient) getAndStoreBlocks(ctx context.Context, from, to uint64 return fmt.Errorf("failed to get withdrawRoot: %v. number: %v", err3, number) } blocks = append(blocks, &encoding.Block{ - Header: block.Header(), - Transactions: encoding.TxsToTxsData(block.Transactions()), - WithdrawRoot: common.BytesToHash(withdrawRoot), - RowConsumption: block.RowConsumption, + Header: block.Header(), + Transactions: encoding.TxsToTxsData(block.Transactions()), + WithdrawRoot: common.BytesToHash(withdrawRoot), }) } @@ -123,11 +118,6 @@ func (w *L2WatcherClient) getAndStoreBlocks(ctx context.Context, from, to uint64 if codec == nil { return fmt.Errorf("failed to retrieve codec for block number %v and time %v", block.Header.Number, block.Header.Time) } - blockL1CommitCalldataSize, err := codec.EstimateBlockL1CommitCalldataSize(block) - if err != nil { - return fmt.Errorf("failed to estimate block L1 commit calldata size: %v", err) - } - w.metrics.rollupL2BlockL1CommitCalldataSize.Set(float64(blockL1CommitCalldataSize)) w.metrics.rollupL2WatcherSyncThroughput.Add(float64(block.Header.GasUsed)) } if err := w.l2BlockOrm.InsertL2Blocks(w.ctx, blocks); err != nil { diff --git a/rollup/internal/controller/watcher/l2_watcher_metrics.go b/rollup/internal/controller/watcher/l2_watcher_metrics.go index bf7e37a954..5058db9ff8 100644 --- a/rollup/internal/controller/watcher/l2_watcher_metrics.go +++ b/rollup/internal/controller/watcher/l2_watcher_metrics.go @@ -8,11 +8,9 @@ import ( ) type l2WatcherMetrics struct { - fetchRunningMissingBlocksTotal prometheus.Counter - fetchRunningMissingBlocksHeight prometheus.Gauge - rollupL2BlocksFetchedGap prometheus.Gauge - rollupL2BlockL1CommitCalldataSize prometheus.Gauge - fetchNilRowConsumptionBlockTotal prometheus.Counter + fetchRunningMissingBlocksTotal prometheus.Counter + fetchRunningMissingBlocksHeight prometheus.Gauge + rollupL2BlocksFetchedGap prometheus.Gauge rollupL2WatcherSyncThroughput prometheus.Counter } @@ -37,14 +35,6 @@ func initL2WatcherMetrics(reg prometheus.Registerer) *l2WatcherMetrics { Name: "rollup_l2_watcher_blocks_fetched_gap", Help: "The gap of l2 fetch", }), - rollupL2BlockL1CommitCalldataSize: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_l2_block_l1_commit_calldata_size", - Help: "The l1 commitBatch calldata size of the l2 block", - }), - fetchNilRowConsumptionBlockTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ - Name: "rollup_l2_watcher_fetch_nil_row_consumption_block_total", - Help: "The total number of occurrences where a fetched block has nil RowConsumption", - }), rollupL2WatcherSyncThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_l2_watcher_sync_throughput", Help: "The cumulative gas used in blocks that L2 watcher sync", diff --git a/rollup/internal/controller/watcher/watcher_test.go b/rollup/internal/controller/watcher/watcher_test.go index 4787b17767..26e3499f6e 100644 --- a/rollup/internal/controller/watcher/watcher_test.go +++ b/rollup/internal/controller/watcher/watcher_test.go @@ -101,17 +101,16 @@ func TestFunction(t *testing.T) { t.Run("TestFetchRunningMissingBlocks", testFetchRunningMissingBlocks) // Run chunk proposer test cases. - t.Run("TestChunkProposerLimitsCodecV4", testChunkProposerLimitsCodecV4) - t.Run("TestChunkProposerBlobSizeLimitCodecV4", testChunkProposerBlobSizeLimitCodecV4) + t.Run("TestChunkProposerLimitsCodecV7", testChunkProposerLimitsCodecV7) + t.Run("TestChunkProposerBlobSizeLimitCodecV7", testChunkProposerBlobSizeLimitCodecV7) // Run batch proposer test cases. - t.Run("TestBatchProposerLimitsCodecV4", testBatchProposerLimitsCodecV4) - t.Run("TestBatchCommitGasAndCalldataSizeEstimationCodecV4", testBatchCommitGasAndCalldataSizeEstimationCodecV4) - t.Run("TestBatchProposerBlobSizeLimitCodecV4", testBatchProposerBlobSizeLimitCodecV4) - t.Run("TestBatchProposerMaxChunkNumPerBatchLimitCodecV4", testBatchProposerMaxChunkNumPerBatchLimitCodecV4) + t.Run("TestBatchProposerLimitsCodecV7", testBatchProposerLimitsCodecV7) + t.Run("TestBatchProposerBlobSizeLimitCodecV7", testBatchProposerBlobSizeLimitCodecV7) + t.Run("TestBatchProposerMaxChunkNumPerBatchLimitCodecV7", testBatchProposerMaxChunkNumPerBatchLimitCodecV7) // Run bundle proposer test cases. - t.Run("TestBundleProposerLimitsCodecV4", testBundleProposerLimitsCodecV4) + t.Run("TestBundleProposerLimitsCodecV7", testBundleProposerLimitsCodecV7) } func readBlockFromJSON(t *testing.T, filename string) *encoding.Block { diff --git a/rollup/internal/orm/batch.go b/rollup/internal/orm/batch.go index 95f5a7bf82..7cd5b72b7a 100644 --- a/rollup/internal/orm/batch.go +++ b/rollup/internal/orm/batch.go @@ -288,30 +288,28 @@ func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVer } newBatch := Batch{ - Index: batch.Index, - Hash: batchMeta.BatchHash.Hex(), - DataHash: batchMeta.BatchDataHash.Hex(), - StartChunkHash: batchMeta.StartChunkHash.Hex(), - StartChunkIndex: startChunkIndex, - EndChunkHash: batchMeta.EndChunkHash.Hex(), - EndChunkIndex: startChunkIndex + numChunks - 1, - StateRoot: batch.StateRoot().Hex(), - WithdrawRoot: batch.WithdrawRoot().Hex(), - ParentBatchHash: batch.ParentBatchHash.Hex(), - BatchHeader: batchMeta.BatchBytes, - CodecVersion: int16(codecVersion), - PrevL1MessageQueueHash: batch.PrevL1MessageQueueHash.Hex(), - PostL1MessageQueueHash: batch.PostL1MessageQueueHash.Hex(), - EnableCompress: enableCompress, - BlobBytes: batchMeta.BlobBytes, - ChallengeDigest: batchMeta.ChallengeDigest.Hex(), - ChunkProofsStatus: int16(types.ChunkProofsStatusPending), - ProvingStatus: int16(types.ProvingTaskUnassigned), - RollupStatus: int16(types.RollupPending), - TotalL1CommitGas: metrics.L1CommitGas, - TotalL1CommitCalldataSize: metrics.L1CommitCalldataSize, - BlobDataProof: batchMeta.BatchBlobDataProof, - BlobSize: metrics.L1CommitBlobSize, + Index: batch.Index, + Hash: batchMeta.BatchHash.Hex(), + DataHash: batchMeta.BatchDataHash.Hex(), + StartChunkHash: batchMeta.StartChunkHash.Hex(), + StartChunkIndex: startChunkIndex, + EndChunkHash: batchMeta.EndChunkHash.Hex(), + EndChunkIndex: startChunkIndex + numChunks - 1, + StateRoot: batch.StateRoot().Hex(), + WithdrawRoot: batch.WithdrawRoot().Hex(), + ParentBatchHash: batch.ParentBatchHash.Hex(), + BatchHeader: batchMeta.BatchBytes, + CodecVersion: int16(codecVersion), + PrevL1MessageQueueHash: batch.PrevL1MessageQueueHash.Hex(), + PostL1MessageQueueHash: batch.PostL1MessageQueueHash.Hex(), + EnableCompress: enableCompress, + BlobBytes: batchMeta.BlobBytes, + ChallengeDigest: batchMeta.ChallengeDigest.Hex(), + ChunkProofsStatus: int16(types.ChunkProofsStatusPending), + ProvingStatus: int16(types.ProvingTaskUnassigned), + RollupStatus: int16(types.RollupPending), + BlobDataProof: batchMeta.BatchBlobDataProof, + BlobSize: metrics.L1CommitBlobSize, } db := o.db diff --git a/rollup/internal/orm/chunk.go b/rollup/internal/orm/chunk.go index f8f6c0da08..720d40a519 100644 --- a/rollup/internal/orm/chunk.go +++ b/rollup/internal/orm/chunk.go @@ -50,14 +50,14 @@ type Chunk struct { BatchHash string `json:"batch_hash" gorm:"column:batch_hash;default:NULL"` // blob - CrcMax uint64 `json:"crc_max" gorm:"column:crc_max"` + CrcMax uint64 `json:"crc_max" gorm:"column:crc_max"` // deprecated BlobSize uint64 `json:"blob_size" gorm:"column:blob_size"` // metadata TotalL2TxGas uint64 `json:"total_l2_tx_gas" gorm:"column:total_l2_tx_gas"` TotalL2TxNum uint64 `json:"total_l2_tx_num" gorm:"column:total_l2_tx_num"` - TotalL1CommitCalldataSize uint64 `json:"total_l1_commit_calldata_size" gorm:"column:total_l1_commit_calldata_size"` - TotalL1CommitGas uint64 `json:"total_l1_commit_gas" gorm:"column:total_l1_commit_gas"` + TotalL1CommitCalldataSize uint64 `json:"total_l1_commit_calldata_size" gorm:"column:total_l1_commit_calldata_size"` // deprecated + TotalL1CommitGas uint64 `json:"total_l1_commit_gas" gorm:"column:total_l1_commit_gas"` // deprecated CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at;default:NULL"` @@ -246,8 +246,6 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer EndBlockHash: chunk.Blocks[numBlocks-1].Header.Hash().Hex(), TotalL2TxGas: chunk.TotalGasUsed(), TotalL2TxNum: chunk.NumL2Transactions(), - TotalL1CommitCalldataSize: metrics.L1CommitCalldataSize, - TotalL1CommitGas: metrics.L1CommitGas, StartBlockTime: chunk.Blocks[0].Header.Time, TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore, TotalL1MessagesPoppedInChunk: chunk.NumL1Messages(totalL1MessagePoppedBefore), @@ -260,7 +258,6 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer CodecVersion: int16(codecVersion), EnableCompress: enableCompress, ProvingStatus: int16(types.ProvingTaskUnassigned), - CrcMax: metrics.CrcMax, BlobSize: metrics.L1CommitBlobSize, } diff --git a/rollup/internal/orm/l2_block.go b/rollup/internal/orm/l2_block.go index 5e643e8a3a..f21c797dbf 100644 --- a/rollup/internal/orm/l2_block.go +++ b/rollup/internal/orm/l2_block.go @@ -96,11 +96,6 @@ func (o *L2Block) GetL2BlocksGEHeight(ctx context.Context, height uint64, limit } block.WithdrawRoot = common.HexToHash(v.WithdrawRoot) - - if err := json.Unmarshal([]byte(v.RowConsumption), &block.RowConsumption); err != nil { - return nil, fmt.Errorf("L2Block.GetL2BlocksGEHeight error: %w", err) - } - blocks = append(blocks, &block) } @@ -171,11 +166,6 @@ func (o *L2Block) GetL2BlocksInRange(ctx context.Context, startBlockNumber uint6 } block.WithdrawRoot = common.HexToHash(v.WithdrawRoot) - - if err := json.Unmarshal([]byte(v.RowConsumption), &block.RowConsumption); err != nil { - return nil, fmt.Errorf("L2Block.GetL2BlocksInRange error: %w, start block: %v, end block: %v", err, startBlockNumber, endBlockNumber) - } - blocks = append(blocks, &block) } @@ -198,12 +188,6 @@ func (o *L2Block) InsertL2Blocks(ctx context.Context, blocks []*encoding.Block) return fmt.Errorf("L2Block.InsertL2Blocks error: %w", err) } - rc, err := json.Marshal(block.RowConsumption) - if err != nil { - log.Error("failed to marshal RowConsumption", "hash", block.Header.Hash().String(), "err", err) - return fmt.Errorf("L2Block.InsertL2Blocks error: %w", err) - } - l2Block := L2Block{ Number: block.Header.Number.Uint64(), Hash: block.Header.Hash().String(), @@ -214,7 +198,6 @@ func (o *L2Block) InsertL2Blocks(ctx context.Context, blocks []*encoding.Block) TxNum: uint32(len(block.Transactions)), GasUsed: block.Header.GasUsed, BlockTimestamp: block.Header.Time, - RowConsumption: string(rc), Header: string(header), } l2Blocks = append(l2Blocks, l2Block) diff --git a/rollup/internal/orm/orm_test.go b/rollup/internal/orm/orm_test.go index 7b6f9496a5..b714d71670 100644 --- a/rollup/internal/orm/orm_test.go +++ b/rollup/internal/orm/orm_test.go @@ -71,12 +71,14 @@ func setupEnv(t *testing.T) { block1 = &encoding.Block{} err = json.Unmarshal(templateBlockTrace, block1) assert.NoError(t, err) + block1.RowConsumption = nil templateBlockTrace, err = os.ReadFile("../../../common/testdata/blockTrace_03.json") assert.NoError(t, err) block2 = &encoding.Block{} err = json.Unmarshal(templateBlockTrace, block2) assert.NoError(t, err) + block2.RowConsumption = nil } func tearDownEnv(t *testing.T) { diff --git a/rollup/internal/utils/utils.go b/rollup/internal/utils/utils.go index a5026a737f..65b92c32c0 100644 --- a/rollup/internal/utils/utils.go +++ b/rollup/internal/utils/utils.go @@ -13,19 +13,12 @@ type ChunkMetrics struct { NumBlocks uint64 TxNum uint64 L2Gas uint64 - CrcMax uint64 FirstBlockTimestamp uint64 - L1CommitCalldataSize uint64 - L1CommitGas uint64 - - L1CommitBlobSize uint64 - L1CommitUncompressedBatchBytesSize uint64 + L1CommitBlobSize uint64 // timing metrics - EstimateGasTime time.Duration - EstimateCalldataSizeTime time.Duration - EstimateBlobSizeTime time.Duration + EstimateBlobSizeTime time.Duration } // CalculateChunkMetrics calculates chunk metrics. @@ -42,34 +35,13 @@ func CalculateChunkMetrics(chunk *encoding.Chunk, codecVersion encoding.CodecVer } var err error - metrics.CrcMax, err = chunk.CrcMax() - if err != nil { - return nil, fmt.Errorf("failed to get crc max, version: %v, err: %w", codecVersion, err) - } - codec, err := encoding.CodecFromVersion(codecVersion) if err != nil { return nil, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err) } - metrics.EstimateGasTime, err = measureTime(func() error { - metrics.L1CommitGas, err = codec.EstimateChunkL1CommitGas(chunk) - return err - }) - if err != nil { - return nil, fmt.Errorf("failed to estimate chunk L1 commit gas, version: %v, err: %w", codecVersion, err) - } - - metrics.EstimateCalldataSizeTime, err = measureTime(func() error { - metrics.L1CommitCalldataSize, err = codec.EstimateChunkL1CommitCalldataSize(chunk) - return err - }) - if err != nil { - return nil, fmt.Errorf("failed to estimate chunk L1 commit calldata size, version: %v, err: %w", codecVersion, err) - } - metrics.EstimateBlobSizeTime, err = measureTime(func() error { - metrics.L1CommitUncompressedBatchBytesSize, metrics.L1CommitBlobSize, err = codec.EstimateChunkL1CommitBatchSizeAndBlobSize(chunk) + _, metrics.L1CommitBlobSize, err = codec.EstimateChunkL1CommitBatchSizeAndBlobSize(chunk) return err }) if err != nil { @@ -84,16 +56,10 @@ type BatchMetrics struct { NumChunks uint64 FirstBlockTimestamp uint64 - L1CommitCalldataSize uint64 - L1CommitGas uint64 - - L1CommitBlobSize uint64 - L1CommitUncompressedBatchBytesSize uint64 + L1CommitBlobSize uint64 // timing metrics - EstimateGasTime time.Duration - EstimateCalldataSizeTime time.Duration - EstimateBlobSizeTime time.Duration + EstimateBlobSizeTime time.Duration } // CalculateBatchMetrics calculates batch metrics. @@ -108,24 +74,8 @@ func CalculateBatchMetrics(batch *encoding.Batch, codecVersion encoding.CodecVer return nil, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err) } - metrics.EstimateGasTime, err = measureTime(func() error { - metrics.L1CommitGas, err = codec.EstimateBatchL1CommitGas(batch) - return err - }) - if err != nil { - return nil, fmt.Errorf("failed to estimate batch L1 commit gas, version: %v, err: %w", codecVersion, err) - } - - metrics.EstimateCalldataSizeTime, err = measureTime(func() error { - metrics.L1CommitCalldataSize, err = codec.EstimateBatchL1CommitCalldataSize(batch) - return err - }) - if err != nil { - return nil, fmt.Errorf("failed to estimate batch L1 commit calldata size, version: %v, err: %w", codecVersion, err) - } - metrics.EstimateBlobSizeTime, err = measureTime(func() error { - metrics.L1CommitUncompressedBatchBytesSize, metrics.L1CommitBlobSize, err = codec.EstimateBatchL1CommitBatchSizeAndBlobSize(batch) + _, metrics.L1CommitBlobSize, err = codec.EstimateBatchL1CommitBatchSizeAndBlobSize(batch) return err }) if err != nil { diff --git a/rollup/proposer-tool-config.json b/rollup/proposer-tool-config.json index 6c0fa7e198..df5d2836f7 100644 --- a/rollup/proposer-tool-config.json +++ b/rollup/proposer-tool-config.json @@ -5,19 +5,12 @@ "max_block_num_per_chunk": 100, "max_tx_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, - "max_l1_commit_gas_per_chunk": 5000000, - "max_l1_commit_calldata_size_per_chunk": 123740, "chunk_timeout_sec": 72000000000, - "max_row_consumption_per_chunk": 10000000000, - "gas_cost_increase_multiplier": 1.2, - "max_uncompressed_batch_bytes_size": 634693 + "gas_cost_increase_multiplier": 1.2 }, "batch_proposer_config": { - "max_l1_commit_gas_per_batch": 5000000, - "max_l1_commit_calldata_size_per_batch": 123740, "batch_timeout_sec": 72000000000, "gas_cost_increase_multiplier": 1.2, - "max_uncompressed_batch_bytes_size": 634693, "max_chunks_per_batch": 45 }, "bundle_proposer_config": { diff --git a/rollup/tests/bridge_test.go b/rollup/tests/bridge_test.go index cccd1affd4..837e1a054d 100644 --- a/rollup/tests/bridge_test.go +++ b/rollup/tests/bridge_test.go @@ -208,7 +208,6 @@ func TestFunction(t *testing.T) { // l1 rollup and watch rollup events t.Run("TestCommitAndFinalizeGenesisBatch", testCommitAndFinalizeGenesisBatch) - t.Run("testCommitBatchAndFinalizeBundleCodecV4V5V6", testCommitBatchAndFinalizeBundleCodecV4V5V6) t.Run("TestCommitBatchAndFinalizeBundleCodecV7", testCommitBatchAndFinalizeBundleCodecV7) // l1 gas oracle diff --git a/rollup/tests/gas_oracle_test.go b/rollup/tests/gas_oracle_test.go index 233c8bfb19..1cace3bd11 100644 --- a/rollup/tests/gas_oracle_test.go +++ b/rollup/tests/gas_oracle_test.go @@ -66,9 +66,8 @@ func testImportL1GasPrice(t *testing.T) { Difficulty: big.NewInt(0), BaseFee: big.NewInt(0), }, - Transactions: nil, - WithdrawRoot: common.Hash{}, - RowConsumption: &gethTypes.RowConsumption{}, + Transactions: nil, + WithdrawRoot: common.Hash{}, }, }, } @@ -141,9 +140,8 @@ func testImportDefaultL1GasPriceDueToL1GasPriceSpike(t *testing.T) { Difficulty: big.NewInt(0), BaseFee: big.NewInt(0), }, - Transactions: nil, - WithdrawRoot: common.Hash{}, - RowConsumption: &gethTypes.RowConsumption{}, + Transactions: nil, + WithdrawRoot: common.Hash{}, }, }, } diff --git a/rollup/tests/process_start_test.go b/rollup/tests/process_start_test.go index 08b9659990..1199ca3543 100644 --- a/rollup/tests/process_start_test.go +++ b/rollup/tests/process_start_test.go @@ -19,7 +19,7 @@ func testProcessStart(t *testing.T) { db := setupDB(t) defer database.CloseDB(db) rollupApp.RunApp(t, cutils.GasOracleApp, "--genesis", "../conf/genesis.json") - rollupApp.RunApp(t, cutils.RollupRelayerApp, "--genesis", "../conf/genesis.json", "--min-codec-version", "4") + rollupApp.RunApp(t, cutils.RollupRelayerApp, "--genesis", "../conf/genesis.json", "--min-codec-version", "7") rollupApp.WaitExit() } @@ -36,7 +36,7 @@ func testProcessStartEnableMetrics(t *testing.T) { port, err = rand.Int(rand.Reader, big.NewInt(10000)) assert.NoError(t, err) svrPort = strconv.FormatInt(port.Int64()+30000, 10) - rollupApp.RunApp(t, cutils.RollupRelayerApp, "--metrics", "--metrics.addr", "localhost", "--metrics.port", svrPort, "--genesis", "../conf/genesis.json", "--min-codec-version", "4") + rollupApp.RunApp(t, cutils.RollupRelayerApp, "--metrics", "--metrics.addr", "localhost", "--metrics.port", svrPort, "--genesis", "../conf/genesis.json", "--min-codec-version", "7") rollupApp.WaitExit() } diff --git a/rollup/tests/rollup_test.go b/rollup/tests/rollup_test.go index 597b8e23ef..f387f93ebb 100644 --- a/rollup/tests/rollup_test.go +++ b/rollup/tests/rollup_test.go @@ -18,7 +18,6 @@ import ( "scroll-tech/common/database" "scroll-tech/common/types" - "scroll-tech/common/types/message" "scroll-tech/rollup/internal/config" "scroll-tech/rollup/internal/controller/relayer" @@ -55,170 +54,6 @@ func testCommitAndFinalizeGenesisBatch(t *testing.T) { assert.Equal(t, types.RollupFinalized, types.RollupStatus(batch.RollupStatus)) } -func testCommitBatchAndFinalizeBundleCodecV4V5V6(t *testing.T) { - db := setupDB(t) - - prepareContracts(t) - - euclidTime := uint64(3) - chainConfig := ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: &euclidTime} - - // Create L2Relayer - l2Cfg := rollupApp.Config.L2Config - l2Relayer, err := relayer.NewLayer2Relayer(context.Background(), l2Client, db, l2Cfg.RelayerConfig, chainConfig, relayer.ServiceTypeL2RollupRelayer, nil) - assert.NoError(t, err) - - // add some blocks to db - var blocks []*encoding.Block - for i := int64(0); i < 10; i++ { - header := gethTypes.Header{ - Number: big.NewInt(i + 1), - ParentHash: common.Hash{}, - Difficulty: big.NewInt(0), - BaseFee: big.NewInt(0), - Root: common.HexToHash("0x1"), - Time: uint64(i), - } - blocks = append(blocks, &encoding.Block{ - Header: &header, - Transactions: nil, - WithdrawRoot: common.HexToHash("0x2"), - RowConsumption: &gethTypes.RowConsumption{}, - }) - } - - cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 100, - MaxTxNumPerChunk: 10000, - MaxL1CommitGasPerChunk: 50000000000, - MaxL1CommitCalldataSizePerChunk: 1000000, - MaxRowConsumptionPerChunk: 1048319, - ChunkTimeoutSec: 300, - MaxUncompressedBatchBytesSize: math.MaxUint64, - }, encoding.CodecV4, chainConfig, db, nil) - - bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: 50000000000, - MaxL1CommitCalldataSizePerBatch: 1000000, - BatchTimeoutSec: 300, - MaxUncompressedBatchBytesSize: math.MaxUint64, - MaxChunksPerBatch: math.MaxInt32, - }, encoding.CodecV4, chainConfig, db, nil) - - bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{ - MaxBatchNumPerBundle: 1000000, - BundleTimeoutSec: 300, - }, encoding.CodecV4, chainConfig, db, nil) - - l2BlockOrm := orm.NewL2Block(db) - batchOrm := orm.NewBatch(db) - bundleOrm := orm.NewBundle(db) - - err = l2BlockOrm.InsertL2Blocks(context.Background(), blocks[:5]) - assert.NoError(t, err) - - cp.TryProposeChunk() - bap.TryProposeBatch() - - err = l2BlockOrm.InsertL2Blocks(context.Background(), blocks[5:]) - assert.NoError(t, err) - - cp.TryProposeChunk() - bap.TryProposeBatch() - - l2Relayer.ProcessPendingBatches() - - // make sure that batches are committed before proposing bundles (as bundle proposing depends on batches being committed). - require.Eventually(t, func() bool { - batches, getErr := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0) - assert.NoError(t, getErr) - - assert.Len(t, batches, 3) - batches = batches[1:] - for _, batch := range batches { - if types.RollupCommitted != types.RollupStatus(batch.RollupStatus) { - return false - } - } - - // make sure that batches 1 and 2 have been committed in separate transactions - return batches[0].CommitTxHash != batches[1].CommitTxHash - }, 30*time.Second, time.Second) - - bup.TryProposeBundle() // The proposed bundle contains two batches when codec version is codecv3. - - batchProof := &message.Halo2BatchProof{ - RawProof: []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}, - 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}, - 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}, - } - batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0) - assert.NoError(t, err) - batches = batches[1:] - for _, batch := range batches { - err = batchOrm.UpdateProofByHash(context.Background(), batch.Hash, batchProof, 100) - assert.NoError(t, err) - err = batchOrm.UpdateProvingStatus(context.Background(), batch.Hash, types.ProvingTaskVerified) - assert.NoError(t, err) - } - - bundleProof := &message.Halo2BundleProof{ - RawProof: []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}, - 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}, - 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}, - } - bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{}, nil, 0) - assert.NoError(t, err) - for _, bundle := range bundles { - err = bundleOrm.UpdateProofAndProvingStatusByHash(context.Background(), bundle.Hash, bundleProof, types.ProvingTaskVerified, 100) - assert.NoError(t, err) - } - - assert.Eventually(t, func() bool { - l2Relayer.ProcessPendingBundles() - - batches, err := batchOrm.GetBatches(context.Background(), map[string]interface{}{}, nil, 0) - assert.NoError(t, err) - assert.Len(t, batches, 3) - batches = batches[1:] - for _, batch := range batches { - if types.RollupStatus(batch.RollupStatus) != types.RollupFinalized { - return false - } - - assert.NotEmpty(t, batch.FinalizeTxHash) - receipt, getErr := l1Client.TransactionReceipt(context.Background(), common.HexToHash(batch.FinalizeTxHash)) - assert.NoError(t, getErr) - assert.Equal(t, gethTypes.ReceiptStatusSuccessful, receipt.Status) - } - - bundles, err := bundleOrm.GetBundles(context.Background(), map[string]interface{}{}, nil, 0) - assert.NoError(t, err) - assert.Len(t, bundles, 1) - - bundle := bundles[0] - if types.RollupStatus(bundle.RollupStatus) != types.RollupFinalized { - return false - } - assert.NotEmpty(t, bundle.FinalizeTxHash) - receipt, err := l1Client.TransactionReceipt(context.Background(), common.HexToHash(bundle.FinalizeTxHash)) - assert.NoError(t, err) - assert.Equal(t, gethTypes.ReceiptStatusSuccessful, receipt.Status) - batches, err = batchOrm.GetBatches(context.Background(), map[string]interface{}{"bundle_hash": bundle.Hash}, nil, 0) - assert.NoError(t, err) - assert.Len(t, batches, 2) - for _, batch := range batches { - assert.Equal(t, batch.RollupStatus, bundle.RollupStatus) - assert.Equal(t, bundle.FinalizeTxHash, batch.FinalizeTxHash) - } - - return true - }, 30*time.Second, time.Second) - - l2Relayer.StopSenders() - database.CloseDB(db) -} - func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) { db := setupDB(t) @@ -275,29 +110,23 @@ func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) { } blocks = append(blocks, &encoding.Block{ - Header: &header, - Transactions: transactions, - WithdrawRoot: common.HexToHash("0x2"), - RowConsumption: &gethTypes.RowConsumption{}, + Header: &header, + Transactions: transactions, + WithdrawRoot: common.HexToHash("0x2"), }) parentHash = header.Hash() } cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ - MaxBlockNumPerChunk: 100, - MaxTxNumPerChunk: 10000, - MaxL1CommitGasPerChunk: 50000000000, - MaxL1CommitCalldataSizePerChunk: 1000000, - MaxRowConsumptionPerChunk: 1048319, - ChunkTimeoutSec: 300, - MaxUncompressedBatchBytesSize: math.MaxUint64, + MaxBlockNumPerChunk: 100, + MaxTxNumPerChunk: 10000, + MaxL2GasPerChunk: math.MaxUint64, + ChunkTimeoutSec: 300, }, encoding.CodecV7, chainConfig, db, nil) bap := watcher.NewBatchProposer(context.Background(), &config.BatchProposerConfig{ - MaxL1CommitGasPerBatch: 50000000000, - MaxL1CommitCalldataSizePerBatch: 1000000, - BatchTimeoutSec: 300, - MaxUncompressedBatchBytesSize: math.MaxUint64, + MaxChunksPerBatch: math.MaxInt32, + BatchTimeoutSec: 300, }, encoding.CodecV7, chainConfig, db, nil) bup := watcher.NewBundleProposer(context.Background(), &config.BundleProposerConfig{ From 36ed7b438308e3d58047a2c226fe50aa03e47a96 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 12 May 2025 20:33:31 +0800 Subject: [PATCH 02/13] remove max_tx_num_per_chunk --- rollup/conf/config.json | 1 - rollup/internal/config/l2.go | 1 - .../controller/watcher/batch_proposer_test.go | 3 --- .../watcher/bundle_proposer_test.go | 1 - .../controller/watcher/chunk_proposer.go | 18 ++----------- .../controller/watcher/chunk_proposer_test.go | 25 ------------------- rollup/internal/orm/chunk.go | 3 +-- rollup/internal/utils/utils.go | 2 -- rollup/proposer-tool-config.json | 1 - rollup/tests/rollup_test.go | 1 - 10 files changed, 3 insertions(+), 53 deletions(-) diff --git a/rollup/conf/config.json b/rollup/conf/config.json index e280f8018d..624ac5188d 100644 --- a/rollup/conf/config.json +++ b/rollup/conf/config.json @@ -93,7 +93,6 @@ "chunk_proposer_config": { "propose_interval_milliseconds": 100, "max_block_num_per_chunk": 100, - "max_tx_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, "chunk_timeout_sec": 300, "gas_cost_increase_multiplier": 1.2 diff --git a/rollup/internal/config/l2.go b/rollup/internal/config/l2.go index 582e96d571..5c02971d21 100644 --- a/rollup/internal/config/l2.go +++ b/rollup/internal/config/l2.go @@ -30,7 +30,6 @@ type L2Config struct { type ChunkProposerConfig struct { ProposeIntervalMilliseconds uint64 `json:"propose_interval_milliseconds"` MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"` - MaxTxNumPerChunk uint64 `json:"max_tx_num_per_chunk"` MaxL2GasPerChunk uint64 `json:"max_l2_gas_per_chunk"` ChunkTimeoutSec uint64 `json:"chunk_timeout_sec"` } diff --git a/rollup/internal/controller/watcher/batch_proposer_test.go b/rollup/internal/controller/watcher/batch_proposer_test.go index 718581e81c..3010916800 100644 --- a/rollup/internal/controller/watcher/batch_proposer_test.go +++ b/rollup/internal/controller/watcher/batch_proposer_test.go @@ -73,7 +73,6 @@ func testBatchProposerLimitsCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: 1, - MaxTxNumPerChunk: 10000, MaxL2GasPerChunk: 20000000, ChunkTimeoutSec: 300, }, encoding.CodecV7, ¶ms.ChainConfig{ @@ -154,7 +153,6 @@ func testBatchProposerBlobSizeLimitCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: math.MaxUint64, - MaxTxNumPerChunk: math.MaxUint64, MaxL2GasPerChunk: math.MaxUint64, ChunkTimeoutSec: 0, }, encoding.CodecV7, chainConfig, db, nil) @@ -226,7 +224,6 @@ func testBatchProposerMaxChunkNumPerBatchLimitCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: math.MaxUint64, - MaxTxNumPerChunk: math.MaxUint64, MaxL2GasPerChunk: math.MaxUint64, ChunkTimeoutSec: 0, }, encoding.CodecV7, chainConfig, db, nil) diff --git a/rollup/internal/controller/watcher/bundle_proposer_test.go b/rollup/internal/controller/watcher/bundle_proposer_test.go index be5edc73a5..fa1b82d087 100644 --- a/rollup/internal/controller/watcher/bundle_proposer_test.go +++ b/rollup/internal/controller/watcher/bundle_proposer_test.go @@ -94,7 +94,6 @@ func testBundleProposerLimitsCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: 1, - MaxTxNumPerChunk: math.MaxUint64, MaxL2GasPerChunk: math.MaxUint64, ChunkTimeoutSec: math.MaxUint32, }, encoding.CodecV7, chainConfig, db, nil) diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index f79e5187c9..286f6c2f53 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -27,7 +27,6 @@ type ChunkProposer struct { l2BlockOrm *orm.L2Block maxBlockNumPerChunk uint64 - maxTxNumPerChunk uint64 maxL2GasPerChunk uint64 chunkTimeoutSec uint64 @@ -39,7 +38,6 @@ type ChunkProposer struct { proposeChunkFailureTotal prometheus.Counter proposeChunkUpdateInfoTotal prometheus.Counter proposeChunkUpdateInfoFailureTotal prometheus.Counter - chunkTxNum prometheus.Gauge chunkL2Gas prometheus.Gauge totalL1CommitBlobSize prometheus.Gauge chunkBlocksNum prometheus.Gauge @@ -55,7 +53,6 @@ type ChunkProposer struct { func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *ChunkProposer { log.Info("new chunk proposer", "maxBlockNumPerChunk", cfg.MaxBlockNumPerChunk, - "maxTxNumPerChunk", cfg.MaxTxNumPerChunk, "maxL2GasPerChunk", cfg.MaxL2GasPerChunk, "chunkTimeoutSec", cfg.ChunkTimeoutSec, "maxBlobSize", maxBlobSize) @@ -66,7 +63,6 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC chunkOrm: orm.NewChunk(db), l2BlockOrm: orm.NewL2Block(db), maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk, - maxTxNumPerChunk: cfg.MaxTxNumPerChunk, maxL2GasPerChunk: cfg.MaxL2GasPerChunk, chunkTimeoutSec: cfg.ChunkTimeoutSec, replayMode: false, @@ -89,10 +85,6 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_update_info_failure_total", Help: "Total number of propose chunk update info failure total.", }), - chunkTxNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ - Name: "rollup_propose_chunk_tx_num", - Help: "The chunk tx num", - }), chunkL2Gas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_l2_gas", Help: "The chunk l2 gas", @@ -250,18 +242,13 @@ func (p *ChunkProposer) proposeChunk() error { p.recordTimerChunkMetrics(metrics) - if metrics.TxNum > p.maxTxNumPerChunk || - metrics.L2Gas > p.maxL2GasPerChunk || - metrics.L1CommitBlobSize > maxBlobSize { + if metrics.L2Gas > p.maxL2GasPerChunk || metrics.L1CommitBlobSize > maxBlobSize { if i == 0 { // The first block exceeds hard limits, which indicates a bug in the sequencer, manual fix is needed. - return fmt.Errorf("the first block exceeds limits; block number: %v, limits: %+v, maxTxNum: %v, maxBlobSize: %v", - block.Header.Number, metrics, p.maxTxNumPerChunk, maxBlobSize) + return fmt.Errorf("the first block exceeds limits; block number: %v, limits: %+v, maxBlobSize: %v", block.Header.Number, metrics, maxBlobSize) } log.Debug("breaking limit condition in chunking", - "txNum", metrics.TxNum, - "maxTxNum", p.maxTxNumPerChunk, "l2Gas", metrics.L2Gas, "maxL2Gas", p.maxL2GasPerChunk, "l1CommitBlobSize", metrics.L1CommitBlobSize, @@ -305,7 +292,6 @@ func (p *ChunkProposer) proposeChunk() error { } func (p *ChunkProposer) recordAllChunkMetrics(metrics *utils.ChunkMetrics) { - p.chunkTxNum.Set(float64(metrics.TxNum)) p.chunkBlocksNum.Set(float64(metrics.NumBlocks)) p.chunkL2Gas.Set(float64(metrics.L2Gas)) p.totalL1CommitBlobSize.Set(float64(metrics.L1CommitBlobSize)) diff --git a/rollup/internal/controller/watcher/chunk_proposer_test.go b/rollup/internal/controller/watcher/chunk_proposer_test.go index 8c125818e1..653e8cf5cd 100644 --- a/rollup/internal/controller/watcher/chunk_proposer_test.go +++ b/rollup/internal/controller/watcher/chunk_proposer_test.go @@ -22,7 +22,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { tests := []struct { name string maxBlockNum uint64 - maxTxNum uint64 maxL2Gas uint64 chunkTimeoutSec uint64 expectedChunksLen int @@ -31,7 +30,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { { name: "NoLimitReached", maxBlockNum: 100, - maxTxNum: 10000, maxL2Gas: 20_000_000, chunkTimeoutSec: 1000000000000, expectedChunksLen: 0, @@ -39,24 +37,14 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { { name: "Timeout", maxBlockNum: 100, - maxTxNum: 10000, maxL2Gas: 20_000_000, chunkTimeoutSec: 0, expectedChunksLen: 1, expectedBlocksInFirstChunk: 2, }, - { - name: "MaxTxNumPerChunkIs0", - maxBlockNum: 10, - maxTxNum: 0, - maxL2Gas: 20_000_000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 0, - }, { name: "MaxL2GasPerChunkIs0", maxBlockNum: 10, - maxTxNum: 10, maxL2Gas: 0, chunkTimeoutSec: 1000000000000, expectedChunksLen: 0, @@ -64,16 +52,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { { name: "MaxBlockNumPerChunkIs1", maxBlockNum: 1, - maxTxNum: 10000, - maxL2Gas: 20_000_000, - chunkTimeoutSec: 1000000000000, - expectedChunksLen: 1, - expectedBlocksInFirstChunk: 1, - }, - { - name: "MaxTxNumPerChunkIsFirstBlock", - maxBlockNum: 10, - maxTxNum: 2, maxL2Gas: 20_000_000, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, @@ -84,7 +62,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { // with the first block it exceeds the maxL2GasPerChunk limit. name: "MaxL2GasPerChunkIsSecondBlock", maxBlockNum: 10, - maxTxNum: 10000, maxL2Gas: 1_153_000, chunkTimeoutSec: 1000000000000, expectedChunksLen: 1, @@ -108,7 +85,6 @@ func testChunkProposerLimitsCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: tt.maxBlockNum, - MaxTxNumPerChunk: tt.maxTxNum, MaxL2GasPerChunk: tt.maxL2Gas, ChunkTimeoutSec: tt.chunkTimeoutSec, }, encoding.CodecV7, ¶ms.ChainConfig{LondonBlock: big.NewInt(0), BernoulliBlock: big.NewInt(0), CurieBlock: big.NewInt(0), DarwinTime: new(uint64), DarwinV2Time: new(uint64), EuclidTime: new(uint64), EuclidV2Time: new(uint64)}, db, nil) @@ -153,7 +129,6 @@ func testChunkProposerBlobSizeLimitCodecV7(t *testing.T) { cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: 255, - MaxTxNumPerChunk: math.MaxUint64, MaxL2GasPerChunk: math.MaxUint64, ChunkTimeoutSec: math.MaxUint32, }, encoding.CodecV7, chainConfig, db, nil) diff --git a/rollup/internal/orm/chunk.go b/rollup/internal/orm/chunk.go index 720d40a519..a5d070ec54 100644 --- a/rollup/internal/orm/chunk.go +++ b/rollup/internal/orm/chunk.go @@ -55,7 +55,7 @@ type Chunk struct { // metadata TotalL2TxGas uint64 `json:"total_l2_tx_gas" gorm:"column:total_l2_tx_gas"` - TotalL2TxNum uint64 `json:"total_l2_tx_num" gorm:"column:total_l2_tx_num"` + TotalL2TxNum uint64 `json:"total_l2_tx_num" gorm:"column:total_l2_tx_num"` // deprecated TotalL1CommitCalldataSize uint64 `json:"total_l1_commit_calldata_size" gorm:"column:total_l1_commit_calldata_size"` // deprecated TotalL1CommitGas uint64 `json:"total_l1_commit_gas" gorm:"column:total_l1_commit_gas"` // deprecated CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` @@ -298,7 +298,6 @@ func (o *Chunk) InsertTestChunkForProposerTool(ctx context.Context, chunk *encod EndBlockNumber: lastBlock.Header.Number.Uint64(), EndBlockHash: lastBlock.Header.Hash().Hex(), TotalL2TxGas: chunk.TotalGasUsed(), - TotalL2TxNum: chunk.NumL2Transactions(), StartBlockTime: firstBlock.Header.Time, TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore, StateRoot: lastBlock.Header.Root.Hex(), diff --git a/rollup/internal/utils/utils.go b/rollup/internal/utils/utils.go index 65b92c32c0..9d743b0df6 100644 --- a/rollup/internal/utils/utils.go +++ b/rollup/internal/utils/utils.go @@ -11,7 +11,6 @@ import ( // ChunkMetrics indicates the metrics for proposing a chunk. type ChunkMetrics struct { NumBlocks uint64 - TxNum uint64 L2Gas uint64 FirstBlockTimestamp uint64 @@ -24,7 +23,6 @@ type ChunkMetrics struct { // CalculateChunkMetrics calculates chunk metrics. func CalculateChunkMetrics(chunk *encoding.Chunk, codecVersion encoding.CodecVersion) (*ChunkMetrics, error) { metrics := &ChunkMetrics{ - TxNum: chunk.NumTransactions(), NumBlocks: uint64(len(chunk.Blocks)), FirstBlockTimestamp: chunk.Blocks[0].Header.Time, } diff --git a/rollup/proposer-tool-config.json b/rollup/proposer-tool-config.json index df5d2836f7..3bfe844cf0 100644 --- a/rollup/proposer-tool-config.json +++ b/rollup/proposer-tool-config.json @@ -3,7 +3,6 @@ "endpoint": "https://rpc.scroll.io", "chunk_proposer_config": { "max_block_num_per_chunk": 100, - "max_tx_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, "chunk_timeout_sec": 72000000000, "gas_cost_increase_multiplier": 1.2 diff --git a/rollup/tests/rollup_test.go b/rollup/tests/rollup_test.go index f387f93ebb..4fa71fd33f 100644 --- a/rollup/tests/rollup_test.go +++ b/rollup/tests/rollup_test.go @@ -119,7 +119,6 @@ func testCommitBatchAndFinalizeBundleCodecV7(t *testing.T) { cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{ MaxBlockNumPerChunk: 100, - MaxTxNumPerChunk: 10000, MaxL2GasPerChunk: math.MaxUint64, ChunkTimeoutSec: 300, }, encoding.CodecV7, chainConfig, db, nil) From 28fd8df526a0cda601c34f825d2b2c0c2627da4d Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 13 May 2025 19:56:55 +0800 Subject: [PATCH 03/13] remove unused configs --- rollup/conf/config.json | 5 +---- rollup/proposer-tool-config.json | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/rollup/conf/config.json b/rollup/conf/config.json index 624ac5188d..5c36da3014 100644 --- a/rollup/conf/config.json +++ b/rollup/conf/config.json @@ -94,14 +94,11 @@ "propose_interval_milliseconds": 100, "max_block_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, - "chunk_timeout_sec": 300, - "gas_cost_increase_multiplier": 1.2 + "chunk_timeout_sec": 300 }, "batch_proposer_config": { "propose_interval_milliseconds": 1000, - "max_l1_commit_gas_per_batch": 11234567, "batch_timeout_sec": 300, - "gas_cost_increase_multiplier": 1.2, "max_chunks_per_batch": 45 }, "bundle_proposer_config": { diff --git a/rollup/proposer-tool-config.json b/rollup/proposer-tool-config.json index 3bfe844cf0..42946a893a 100644 --- a/rollup/proposer-tool-config.json +++ b/rollup/proposer-tool-config.json @@ -4,12 +4,10 @@ "chunk_proposer_config": { "max_block_num_per_chunk": 100, "max_l2_gas_per_chunk": 20000000, - "chunk_timeout_sec": 72000000000, - "gas_cost_increase_multiplier": 1.2 + "chunk_timeout_sec": 72000000000 }, "batch_proposer_config": { "batch_timeout_sec": 72000000000, - "gas_cost_increase_multiplier": 1.2, "max_chunks_per_batch": 45 }, "bundle_proposer_config": { From 34a63512c01ca3f2052f310351b80dca8d1ee4c9 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 13 May 2025 21:51:36 +0800 Subject: [PATCH 04/13] add back chunkTxNum --- rollup/internal/controller/watcher/chunk_proposer.go | 7 +++++++ rollup/internal/orm/chunk.go | 1 + rollup/internal/utils/utils.go | 2 ++ 3 files changed, 10 insertions(+) diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index 286f6c2f53..08ad9271c6 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -38,6 +38,7 @@ type ChunkProposer struct { proposeChunkFailureTotal prometheus.Counter proposeChunkUpdateInfoTotal prometheus.Counter proposeChunkUpdateInfoFailureTotal prometheus.Counter + chunkTxNum prometheus.Gauge chunkL2Gas prometheus.Gauge totalL1CommitBlobSize prometheus.Gauge chunkBlocksNum prometheus.Gauge @@ -85,6 +86,10 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_update_info_failure_total", Help: "Total number of propose chunk update info failure total.", }), + chunkTxNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Name: "rollup_propose_chunk_tx_num", + Help: "The chunk tx num", + }), chunkL2Gas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_l2_gas", Help: "The chunk l2 gas", @@ -93,6 +98,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_total_l1_commit_blob_size", Help: "The total l1 commit blob size", }), + chunkBlocksNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_chunk_block_number", Help: "The number of blocks in the chunk", @@ -292,6 +298,7 @@ func (p *ChunkProposer) proposeChunk() error { } func (p *ChunkProposer) recordAllChunkMetrics(metrics *utils.ChunkMetrics) { + p.chunkTxNum.Set(float64(metrics.TxNum)) p.chunkBlocksNum.Set(float64(metrics.NumBlocks)) p.chunkL2Gas.Set(float64(metrics.L2Gas)) p.totalL1CommitBlobSize.Set(float64(metrics.L1CommitBlobSize)) diff --git a/rollup/internal/orm/chunk.go b/rollup/internal/orm/chunk.go index a5d070ec54..b0ec9c35f3 100644 --- a/rollup/internal/orm/chunk.go +++ b/rollup/internal/orm/chunk.go @@ -298,6 +298,7 @@ func (o *Chunk) InsertTestChunkForProposerTool(ctx context.Context, chunk *encod EndBlockNumber: lastBlock.Header.Number.Uint64(), EndBlockHash: lastBlock.Header.Hash().Hex(), TotalL2TxGas: chunk.TotalGasUsed(), + TotalL2TxNum: chunk.NumL2Transactions(), StartBlockTime: firstBlock.Header.Time, TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore, StateRoot: lastBlock.Header.Root.Hex(), diff --git a/rollup/internal/utils/utils.go b/rollup/internal/utils/utils.go index 9d743b0df6..65b92c32c0 100644 --- a/rollup/internal/utils/utils.go +++ b/rollup/internal/utils/utils.go @@ -11,6 +11,7 @@ import ( // ChunkMetrics indicates the metrics for proposing a chunk. type ChunkMetrics struct { NumBlocks uint64 + TxNum uint64 L2Gas uint64 FirstBlockTimestamp uint64 @@ -23,6 +24,7 @@ type ChunkMetrics struct { // CalculateChunkMetrics calculates chunk metrics. func CalculateChunkMetrics(chunk *encoding.Chunk, codecVersion encoding.CodecVersion) (*ChunkMetrics, error) { metrics := &ChunkMetrics{ + TxNum: chunk.NumTransactions(), NumBlocks: uint64(len(chunk.Blocks)), FirstBlockTimestamp: chunk.Blocks[0].Header.Time, } From 1e52cc206d8ee05010a724d59999deba54112cf2 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 13 May 2025 22:00:20 +0800 Subject: [PATCH 05/13] pass config types directly --- .../controller/watcher/batch_proposer.go | 30 ++++++++----------- .../controller/watcher/bundle_proposer.go | 26 ++++++++-------- .../controller/watcher/chunk_proposer.go | 30 ++++++++----------- 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/rollup/internal/controller/watcher/batch_proposer.go b/rollup/internal/controller/watcher/batch_proposer.go index b34248d3ec..106b375909 100644 --- a/rollup/internal/controller/watcher/batch_proposer.go +++ b/rollup/internal/controller/watcher/batch_proposer.go @@ -29,8 +29,7 @@ type BatchProposer struct { chunkOrm *orm.Chunk l2BlockOrm *orm.L2Block - batchTimeoutSec uint64 - maxChunksPerBatch int + cfg *config.BatchProposerConfig replayMode bool minCodecVersion encoding.CodecVersion @@ -55,21 +54,18 @@ type BatchProposer struct { // NewBatchProposer creates a new BatchProposer instance. func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, minCodecVersion encoding.CodecVersion, chainCfg *params.ChainConfig, db *gorm.DB, reg prometheus.Registerer) *BatchProposer { - log.Info("new batch proposer", - "batchTimeoutSec", cfg.BatchTimeoutSec, - "maxBlobSize", maxBlobSize) + log.Info("new batch proposer", "batchTimeoutSec", cfg.BatchTimeoutSec, "maxBlobSize", maxBlobSize) p := &BatchProposer{ - ctx: ctx, - db: db, - batchOrm: orm.NewBatch(db), - chunkOrm: orm.NewChunk(db), - l2BlockOrm: orm.NewL2Block(db), - batchTimeoutSec: cfg.BatchTimeoutSec, - maxChunksPerBatch: cfg.MaxChunksPerBatch, - replayMode: false, - minCodecVersion: minCodecVersion, - chainCfg: chainCfg, + ctx: ctx, + db: db, + batchOrm: orm.NewBatch(db), + chunkOrm: orm.NewChunk(db), + l2BlockOrm: orm.NewL2Block(db), + cfg: cfg, + replayMode: false, + minCodecVersion: minCodecVersion, + chainCfg: chainCfg, batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_propose_batch_circle_total", @@ -245,7 +241,7 @@ func (p *BatchProposer) proposeBatch() error { } // always take the minimum of the configured max chunks per batch and the codec's max chunks per batch - maxChunksThisBatch := min(codec.MaxNumChunksPerBatch(), p.maxChunksPerBatch) + maxChunksThisBatch := min(codec.MaxNumChunksPerBatch(), p.cfg.MaxChunksPerBatch) // select at most maxChunkNumPerBatch chunks dbChunks, err := p.chunkOrm.GetChunksGEIndex(p.ctx, firstUnbatchedChunkIndex, maxChunksThisBatch) @@ -328,7 +324,7 @@ func (p *BatchProposer) proposeBatch() error { return fmt.Errorf("failed to calculate batch metrics: %w", calcErr) } currentTimeSec := uint64(time.Now().Unix()) - if metrics.FirstBlockTimestamp+p.batchTimeoutSec < currentTimeSec || metrics.NumChunks == uint64(maxChunksThisBatch) { + if metrics.FirstBlockTimestamp+p.cfg.BatchTimeoutSec < currentTimeSec || metrics.NumChunks == uint64(maxChunksThisBatch) { log.Info("reached maximum number of chunks in batch or first block timeout", "chunk count", metrics.NumChunks, "start block number", dbChunks[0].StartBlockNumber, diff --git a/rollup/internal/controller/watcher/bundle_proposer.go b/rollup/internal/controller/watcher/bundle_proposer.go index 3633750101..27216b6fef 100644 --- a/rollup/internal/controller/watcher/bundle_proposer.go +++ b/rollup/internal/controller/watcher/bundle_proposer.go @@ -26,8 +26,7 @@ type BundleProposer struct { batchOrm *orm.Batch bundleOrm *orm.Bundle - maxBatchNumPerBundle uint64 - bundleTimeoutSec uint64 + cfg *config.BundleProposerConfig minCodecVersion encoding.CodecVersion chainCfg *params.ChainConfig @@ -46,15 +45,14 @@ func NewBundleProposer(ctx context.Context, cfg *config.BundleProposerConfig, mi log.Info("new bundle proposer", "bundleBatchesNum", cfg.MaxBatchNumPerBundle, "bundleTimeoutSec", cfg.BundleTimeoutSec) p := &BundleProposer{ - ctx: ctx, - db: db, - chunkOrm: orm.NewChunk(db), - batchOrm: orm.NewBatch(db), - bundleOrm: orm.NewBundle(db), - maxBatchNumPerBundle: cfg.MaxBatchNumPerBundle, - bundleTimeoutSec: cfg.BundleTimeoutSec, - minCodecVersion: minCodecVersion, - chainCfg: chainCfg, + ctx: ctx, + db: db, + chunkOrm: orm.NewChunk(db), + batchOrm: orm.NewBatch(db), + bundleOrm: orm.NewBundle(db), + cfg: cfg, + minCodecVersion: minCodecVersion, + chainCfg: chainCfg, bundleProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_propose_bundle_circle_total", @@ -132,7 +130,7 @@ func (p *BundleProposer) proposeBundle() error { } // select at most maxBlocksThisChunk blocks - maxBatchesThisBundle := p.maxBatchNumPerBundle + maxBatchesThisBundle := p.cfg.MaxBatchNumPerBundle batches, err := p.batchOrm.GetCommittedBatchesGEIndexGECodecVersion(p.ctx, firstUnbundledBatchIndex, p.minCodecVersion, int(maxBatchesThisBundle)) if err != nil { return err @@ -193,8 +191,8 @@ func (p *BundleProposer) proposeBundle() error { } currentTimeSec := uint64(time.Now().Unix()) - if firstChunk.StartBlockTime+p.bundleTimeoutSec < currentTimeSec { - log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "bundle timeout", p.bundleTimeoutSec, "current time", currentTimeSec) + if firstChunk.StartBlockTime+p.cfg.BundleTimeoutSec < currentTimeSec { + log.Info("first block timeout", "batch count", len(batches), "start block number", firstChunk.StartBlockNumber, "start block timestamp", firstChunk.StartBlockTime, "bundle timeout", p.cfg.BundleTimeoutSec, "current time", currentTimeSec) batches, err = p.allBatchesCommittedInSameTXIncluded(batches) if err != nil { diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index 08ad9271c6..daa0f6b282 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -26,9 +26,7 @@ type ChunkProposer struct { chunkOrm *orm.Chunk l2BlockOrm *orm.L2Block - maxBlockNumPerChunk uint64 - maxL2GasPerChunk uint64 - chunkTimeoutSec uint64 + cfg *config.ChunkProposerConfig replayMode bool minCodecVersion encoding.CodecVersion @@ -59,16 +57,14 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC "maxBlobSize", maxBlobSize) p := &ChunkProposer{ - ctx: ctx, - db: db, - chunkOrm: orm.NewChunk(db), - l2BlockOrm: orm.NewL2Block(db), - maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk, - maxL2GasPerChunk: cfg.MaxL2GasPerChunk, - chunkTimeoutSec: cfg.ChunkTimeoutSec, - replayMode: false, - minCodecVersion: minCodecVersion, - chainCfg: chainCfg, + ctx: ctx, + db: db, + chunkOrm: orm.NewChunk(db), + l2BlockOrm: orm.NewL2Block(db), + cfg: cfg, + replayMode: false, + minCodecVersion: minCodecVersion, + chainCfg: chainCfg, chunkProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "rollup_propose_chunk_circle_total", @@ -185,7 +181,7 @@ func (p *ChunkProposer) proposeChunk() error { return err } - maxBlocksThisChunk := p.maxBlockNumPerChunk + maxBlocksThisChunk := p.cfg.MaxBlockNumPerChunk // select at most maxBlocksThisChunk blocks blocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, unchunkedBlockHeight, int(maxBlocksThisChunk)) @@ -248,7 +244,7 @@ func (p *ChunkProposer) proposeChunk() error { p.recordTimerChunkMetrics(metrics) - if metrics.L2Gas > p.maxL2GasPerChunk || metrics.L1CommitBlobSize > maxBlobSize { + if metrics.L2Gas > p.cfg.MaxL2GasPerChunk || metrics.L1CommitBlobSize > maxBlobSize { if i == 0 { // The first block exceeds hard limits, which indicates a bug in the sequencer, manual fix is needed. return fmt.Errorf("the first block exceeds limits; block number: %v, limits: %+v, maxBlobSize: %v", block.Header.Number, metrics, maxBlobSize) @@ -256,7 +252,7 @@ func (p *ChunkProposer) proposeChunk() error { log.Debug("breaking limit condition in chunking", "l2Gas", metrics.L2Gas, - "maxL2Gas", p.maxL2GasPerChunk, + "maxL2Gas", p.cfg.MaxL2GasPerChunk, "l1CommitBlobSize", metrics.L1CommitBlobSize, "maxBlobSize", maxBlobSize) @@ -279,7 +275,7 @@ func (p *ChunkProposer) proposeChunk() error { } currentTimeSec := uint64(time.Now().Unix()) - if metrics.FirstBlockTimestamp+p.chunkTimeoutSec < currentTimeSec || metrics.NumBlocks == maxBlocksThisChunk { + if metrics.FirstBlockTimestamp+p.cfg.ChunkTimeoutSec < currentTimeSec || metrics.NumBlocks == maxBlocksThisChunk { log.Info("reached maximum number of blocks in chunk or first block timeout", "block count", len(chunk.Blocks), "start block number", chunk.Blocks[0].Header.Number, From 1ca29977448eb556a87cf93ad9f6b8ace80f6312 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 13 May 2025 22:10:04 +0800 Subject: [PATCH 06/13] tweak --- rollup/internal/orm/chunk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup/internal/orm/chunk.go b/rollup/internal/orm/chunk.go index b0ec9c35f3..720d40a519 100644 --- a/rollup/internal/orm/chunk.go +++ b/rollup/internal/orm/chunk.go @@ -55,7 +55,7 @@ type Chunk struct { // metadata TotalL2TxGas uint64 `json:"total_l2_tx_gas" gorm:"column:total_l2_tx_gas"` - TotalL2TxNum uint64 `json:"total_l2_tx_num" gorm:"column:total_l2_tx_num"` // deprecated + TotalL2TxNum uint64 `json:"total_l2_tx_num" gorm:"column:total_l2_tx_num"` TotalL1CommitCalldataSize uint64 `json:"total_l1_commit_calldata_size" gorm:"column:total_l1_commit_calldata_size"` // deprecated TotalL1CommitGas uint64 `json:"total_l1_commit_gas" gorm:"column:total_l1_commit_gas"` // deprecated CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` From 6a8ef2c3d387dd731d41941622b687a46f0e7789 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Wed, 14 May 2025 01:14:30 +0800 Subject: [PATCH 07/13] add back chunk compatibility check --- rollup/go.mod | 2 +- rollup/go.sum | 4 +- .../controller/watcher/chunk_proposer.go | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/rollup/go.mod b/rollup/go.mod index cb945ff486..bb29a7fb06 100644 --- a/rollup/go.mod +++ b/rollup/go.mod @@ -11,7 +11,7 @@ require ( github.com/holiman/uint256 v1.3.2 github.com/mitchellh/mapstructure v1.5.0 github.com/prometheus/client_golang v1.16.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82 + github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 github.com/smartystreets/goconvey v1.8.0 github.com/spf13/viper v1.19.0 diff --git a/rollup/go.sum b/rollup/go.sum index 273d589508..65966620b8 100644 --- a/rollup/go.sum +++ b/rollup/go.sum @@ -249,8 +249,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82 h1:8mqkSusH9qz7Hzz7MtQ9uMXX0ej2c1NyeG14W1LTCQk= -github.com/scroll-tech/da-codec v0.1.3-0.20250512054757-d0bc38e57a82/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= +github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd h1:WWpmrmvj6gizg4PJf1AMvMxfKMRiFh5PlLfqUgDJKr8= +github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index daa0f6b282..61cb45dbbe 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -44,6 +44,9 @@ type ChunkProposer struct { chunkBlocksProposeNotEnoughTotal prometheus.Counter chunkEstimateBlobSizeTime prometheus.Gauge + // total number of times that chunk proposer stops early due to compressed data compatibility breach + compressedDataCompatibilityBreachTotal prometheus.Counter + chunkProposeBlockHeight prometheus.Gauge chunkProposeThroughput prometheus.Counter } @@ -82,6 +85,10 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, minC Name: "rollup_propose_chunk_update_info_failure_total", Help: "Total number of propose chunk update info failure total.", }), + compressedDataCompatibilityBreachTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Name: "rollup_propose_chunk_due_to_compressed_data_compatibility_breach_total", + Help: "Total number of propose chunk due to compressed data compatibility breach.", + }), chunkTxNum: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "rollup_propose_chunk_tx_num", Help: "The chunk tx num", @@ -147,6 +154,45 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en return nil } + compatibilityBreachOccurred := false + + for { + compatible, err := encoding.CheckChunkCompressedDataCompatibility(chunk, codecVersion) + if err != nil { + log.Error("Failed to check chunk compressed data compatibility", "start block number", chunk.Blocks[0].Header.Number, "codecVersion", codecVersion, "err", err) + return err + } + + if compatible { + break + } + + compatibilityBreachOccurred = true + + if len(chunk.Blocks) == 1 { + log.Warn("Disable compression: cannot truncate chunk with only 1 block for compatibility", "block number", chunk.Blocks[0].Header.Number) + break + } + + chunk.Blocks = chunk.Blocks[:len(chunk.Blocks)-1] + + log.Info("Chunk not compatible with compressed data, removing last block", "start block number", chunk.Blocks[0].Header.Number, "truncated block length", len(chunk.Blocks)) + } + + if compatibilityBreachOccurred { + p.compressedDataCompatibilityBreachTotal.Inc() + + // recalculate chunk metrics after truncation + var calcErr error + metrics, calcErr = utils.CalculateChunkMetrics(chunk, codecVersion) + if calcErr != nil { + return fmt.Errorf("failed to calculate chunk metrics, start block number: %v, error: %w", chunk.Blocks[0].Header.Number, calcErr) + } + + p.recordTimerChunkMetrics(metrics) + p.recordAllChunkMetrics(metrics) + } + p.chunkProposeBlockHeight.Set(float64(chunk.Blocks[len(chunk.Blocks)-1].Header.Number.Uint64())) p.chunkProposeThroughput.Add(float64(chunk.TotalGasUsed())) From edbe6f6659f1075f9a116a7152c9211bdf73e685 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Thu, 15 May 2025 15:02:37 +0800 Subject: [PATCH 08/13] add PostL1MessageQueueHash update --- rollup/internal/controller/watcher/batch_proposer.go | 1 + rollup/internal/controller/watcher/chunk_proposer.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/rollup/internal/controller/watcher/batch_proposer.go b/rollup/internal/controller/watcher/batch_proposer.go index 106b375909..5f56bb199a 100644 --- a/rollup/internal/controller/watcher/batch_proposer.go +++ b/rollup/internal/controller/watcher/batch_proposer.go @@ -161,6 +161,7 @@ func (p *BatchProposer) updateDBBatchInfo(batch *encoding.Batch, codecVersion en } batch.Chunks = batch.Chunks[:len(batch.Chunks)-1] + batch.PostL1MessageQueueHash = batch.Chunks[len(batch.Chunks)-1].PostL1MessageQueueHash log.Info("Batch not compatible with compressed data, removing last chunk", "batch index", batch.Index, "truncated chunk length", len(batch.Chunks)) } diff --git a/rollup/internal/controller/watcher/chunk_proposer.go b/rollup/internal/controller/watcher/chunk_proposer.go index 61cb45dbbe..79f2467c40 100644 --- a/rollup/internal/controller/watcher/chunk_proposer.go +++ b/rollup/internal/controller/watcher/chunk_proposer.go @@ -175,6 +175,11 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en } chunk.Blocks = chunk.Blocks[:len(chunk.Blocks)-1] + chunk.PostL1MessageQueueHash, err = encoding.MessageQueueV2ApplyL1MessagesFromBlocks(chunk.PrevL1MessageQueueHash, chunk.Blocks) + if err != nil { + log.Error("Failed to calculate last L1 message queue hash for block", "block number", chunk.Blocks[0].Header.Number, "err", err) + return err + } log.Info("Chunk not compatible with compressed data, removing last block", "start block number", chunk.Blocks[0].Header.Number, "truncated block length", len(chunk.Blocks)) } From 29e5a63b58b42f7fb92e71e074931027cd0bae96 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Fri, 16 May 2025 16:38:13 +0000 Subject: [PATCH 09/13] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[b?= =?UTF-8?q?ot]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 1a52f93d65..56cd403002 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.10" +var tag = "v4.5.11" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { From 4890842657e63d035c9fd5ed192245391e666ff1 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Sat, 17 May 2025 00:49:17 +0800 Subject: [PATCH 10/13] fix make lint --- rollup/tests/rollup_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/rollup/tests/rollup_test.go b/rollup/tests/rollup_test.go index 60541d1ae5..4fa71fd33f 100644 --- a/rollup/tests/rollup_test.go +++ b/rollup/tests/rollup_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/agiledragon/gomonkey/v2" "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/common" gethTypes "github.com/scroll-tech/go-ethereum/core/types" From 9911d77d10706d764aece34537c047dd063272ec Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 19 May 2025 19:47:24 +0800 Subject: [PATCH 11/13] update da-codec dependency --- go.work.sum | 3 +-- rollup/go.mod | 2 +- rollup/go.sum | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go.work.sum b/go.work.sum index f252c743d6..b0190053fe 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1357,8 +1357,7 @@ github.com/scroll-tech/da-codec v0.1.1-0.20241014152913-2703f226fb0b h1:5H6V6yba github.com/scroll-tech/da-codec v0.1.1-0.20241014152913-2703f226fb0b/go.mod h1:48uxaqVgpD8ulH8p+nrBtfeLHZ9tX82bVVdPNkW3rPE= github.com/scroll-tech/da-codec v0.1.3-0.20250227072756-a1482833595f h1:YYbhuUwjowqI4oyXtECRofck7Fyj18e1tcRjuQlZpJE= github.com/scroll-tech/da-codec v0.1.3-0.20250227072756-a1482833595f/go.mod h1:xECEHZLVzbdUn+tNbRJhRIjLGTOTmnFQuTgUTeVLX58= -github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493 h1:Ioc01J0WEMxuwFvEPGJeBKXdf2KY4Yc3XbFky/IxLlI= -github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= +github.com/scroll-tech/da-codec v0.1.3-0.20250519114140-bfa7133d4ad1/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= github.com/scroll-tech/go-ethereum v1.10.14-0.20240607130425-e2becce6a1a4/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ= github.com/scroll-tech/go-ethereum v1.10.14-0.20240821074444-b3fa00861e5e/go.mod h1:swB5NSp8pKNDuYsTxfR08bHS6L56i119PBx8fxvV8Cs= github.com/scroll-tech/go-ethereum v1.10.14-0.20241010064814-3d88e870ae22/go.mod h1:r9FwtxCtybMkTbWYCyBuevT9TW3zHmOTHqD082Uh+Oo= diff --git a/rollup/go.mod b/rollup/go.mod index bb29a7fb06..27d7956dc2 100644 --- a/rollup/go.mod +++ b/rollup/go.mod @@ -11,7 +11,7 @@ require ( github.com/holiman/uint256 v1.3.2 github.com/mitchellh/mapstructure v1.5.0 github.com/prometheus/client_golang v1.16.0 - github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd + github.com/scroll-tech/da-codec v0.1.3-0.20250519114140-bfa7133d4ad1 github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 github.com/smartystreets/goconvey v1.8.0 github.com/spf13/viper v1.19.0 diff --git a/rollup/go.sum b/rollup/go.sum index 65966620b8..fa250a522d 100644 --- a/rollup/go.sum +++ b/rollup/go.sum @@ -249,8 +249,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd h1:WWpmrmvj6gizg4PJf1AMvMxfKMRiFh5PlLfqUgDJKr8= -github.com/scroll-tech/da-codec v0.1.3-0.20250513170653-750488ce7dfd/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= +github.com/scroll-tech/da-codec v0.1.3-0.20250519114140-bfa7133d4ad1 h1:6aKqJSal+QVdB5HMWMs0JTbAIZ6/iAHJx9qizz0w9dU= +github.com/scroll-tech/da-codec v0.1.3-0.20250519114140-bfa7133d4ad1/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8= github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ= github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE= From e89e09bf695ea7f364e0d2d4f5927e795724cda6 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 19 May 2025 21:07:00 +0000 Subject: [PATCH 12/13] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[b?= =?UTF-8?q?ot]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 56cd403002..887eeb45db 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.11" +var tag = "v4.5.12" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { From 448fc2b00b514f7c3c5ff1c5b66974a113adc950 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 20 May 2025 08:02:44 +0000 Subject: [PATCH 13/13] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[b?= =?UTF-8?q?ot]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 887eeb45db..10ffec2174 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.12" +var tag = "v4.5.13" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok {