Skip to content

Commit

Permalink
feat(rollup-relayer): add number of blocks per chunk limit
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Aug 26, 2023
1 parent 826e847 commit e35f245
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bridge/conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"finalize_sender_private_key": "1515151515151515151515151515151515151515151515151515151515151515"
},
"chunk_proposer_config": {
"max_tx_num_per_chunk": 1123,
"max_block_num_per_chunk": 100,
"max_tx_num_per_chunk": 100,
"max_l1_commit_gas_per_chunk": 11234567,
"max_l1_commit_calldata_size_per_chunk": 112345,
"chunk_timeout_sec": 300,
Expand Down
1 change: 1 addition & 0 deletions bridge/internal/config/l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type L2Config struct {

// ChunkProposerConfig loads chunk_proposer configuration items.
type ChunkProposerConfig struct {
MaxBlockNumPerChunk uint64 `json:"max_block_num_per_chunk"`
MaxTxNumPerChunk uint64 `json:"max_tx_num_per_chunk"`
MaxL1CommitGasPerChunk uint64 `json:"max_l1_commit_gas_per_chunk"`
MaxL1CommitCalldataSizePerChunk uint64 `json:"max_l1_commit_calldata_size_per_chunk"`
Expand Down
1 change: 1 addition & 0 deletions bridge/internal/controller/watcher/batch_proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func testBatchProposer(t *testing.T) {
assert.NoError(t, err)

cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
MaxBlockNumPerChunk: 100,
MaxTxNumPerChunk: 10000,
MaxL1CommitGasPerChunk: 50000000000,
MaxL1CommitCalldataSizePerChunk: 1000000,
Expand Down
12 changes: 6 additions & 6 deletions bridge/internal/controller/watcher/chunk_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"scroll-tech/bridge/internal/orm"
)

// maxNumBlockPerChunk is the maximum number of blocks we allow per chunk.
// Normally we will pack much fewer blocks because of other limits.
const maxNumBlockPerChunk int = 100

// chunkRowConsumption is map(sub-circuit name => sub-circuit row count)
type chunkRowConsumption map[string]uint64

Expand Down Expand Up @@ -55,6 +51,7 @@ type ChunkProposer struct {
chunkOrm *orm.Chunk
l2BlockOrm *orm.L2Block

maxBlockNumPerChunk uint64
maxTxNumPerChunk uint64
maxL1CommitGasPerChunk uint64
maxL1CommitCalldataSizePerChunk uint64
Expand Down Expand Up @@ -90,6 +87,7 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, db *
db: db,
chunkOrm: orm.NewChunk(db),
l2BlockOrm: orm.NewL2Block(db),
maxBlockNumPerChunk: cfg.MaxBlockNumPerChunk,
maxTxNumPerChunk: cfg.MaxTxNumPerChunk,
maxL1CommitGasPerChunk: cfg.MaxL1CommitGasPerChunk,
maxL1CommitCalldataSizePerChunk: cfg.MaxL1CommitCalldataSizePerChunk,
Expand Down Expand Up @@ -191,7 +189,7 @@ func (p *ChunkProposer) proposeChunk() (*types.Chunk, error) {
return nil, err
}

blocks, err := p.l2BlockOrm.GetL2WrappedBlocksGEHeight(p.ctx, unchunkedBlockHeight, maxNumBlockPerChunk)
blocks, err := p.l2BlockOrm.GetL2WrappedBlocksGEHeight(p.ctx, unchunkedBlockHeight, int(p.maxBlockNumPerChunk)+1)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -225,7 +223,7 @@ func (p *ChunkProposer) proposeChunk() (*types.Chunk, error) {
}
crcMax := crc.max()

if totalTxNum > p.maxTxNumPerChunk ||
if totalTxNum > p.maxTxNumPerChunk || uint64(i)+1 > p.maxBlockNumPerChunk ||
totalL1CommitCalldataSize > p.maxL1CommitCalldataSizePerChunk ||
totalOverEstimateL1CommitGas > p.maxL1CommitGasPerChunk ||
crcMax > p.maxRowConsumptionPerChunk {
Expand Down Expand Up @@ -271,6 +269,8 @@ func (p *ChunkProposer) proposeChunk() (*types.Chunk, error) {
}

log.Debug("breaking limit condition in chunking",
"totalBlockNum", i+1,
"maxBlockNumPerChunk", p.maxBlockNumPerChunk,
"totalTxNum", totalTxNum,
"maxTxNumPerChunk", p.maxTxNumPerChunk,
"currentL1CommitCalldataSize", totalL1CommitCalldataSize,
Expand Down
2 changes: 2 additions & 0 deletions bridge/internal/controller/watcher/chunk_proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func testChunkProposer(t *testing.T) {
assert.NoError(t, err)

cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
MaxBlockNumPerChunk: 100,
MaxTxNumPerChunk: 10000,
MaxL1CommitGasPerChunk: 50000000000,
MaxL1CommitCalldataSizePerChunk: 1000000,
Expand Down Expand Up @@ -53,6 +54,7 @@ func testChunkProposerRowConsumption(t *testing.T) {
assert.NoError(t, err)

cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
MaxBlockNumPerChunk: 100,
MaxTxNumPerChunk: 10000,
MaxL1CommitGasPerChunk: 50000000000,
MaxL1CommitCalldataSizePerChunk: 1000000,
Expand Down
1 change: 1 addition & 0 deletions bridge/tests/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func testCommitBatchAndFinalizeBatch(t *testing.T) {
assert.NoError(t, err)

cp := watcher.NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
MaxBlockNumPerChunk: 100,
MaxTxNumPerChunk: 10000,
MaxL1CommitGasPerChunk: 50000000000,
MaxL1CommitCalldataSizePerChunk: 1000000,
Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
)

var tag = "v4.1.117"
var tag = "v4.1.118"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down

0 comments on commit e35f245

Please sign in to comment.