Skip to content

Commit e75d6c1

Browse files
authored
feat: propose chunk at hardfork boundary (#1767)
1 parent 752e4e1 commit e75d6c1

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.7.6"
8+
var tag = "v4.7.7"
99

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

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,13 @@ func (p *ChunkProposer) ProposeChunk() error {
245245
// Ensure all blocks in the same chunk use the same hardfork name
246246
// If a different hardfork name is found, truncate the blocks slice at that point
247247
hardforkName := encoding.GetHardforkName(p.chainCfg, blocks[0].Header.Number.Uint64(), blocks[0].Header.Time)
248+
hardforkBoundary := false
248249
for i := 1; i < len(blocks); i++ {
249250
currentHardfork := encoding.GetHardforkName(p.chainCfg, blocks[i].Header.Number.Uint64(), blocks[i].Header.Time)
250251
if currentHardfork != hardforkName {
251-
blocks = blocks[:i]
252252
// Truncate blocks at hardfork boundary
253+
blocks = blocks[:i]
254+
hardforkBoundary = true
253255
break
254256
}
255257
}
@@ -321,6 +323,19 @@ func (p *ChunkProposer) ProposeChunk() error {
321323
return fmt.Errorf("failed to calculate chunk metrics: %w", calcErr)
322324
}
323325

326+
// No breaking condition met, but hardfork boundary reached
327+
if hardforkBoundary {
328+
log.Info("hardfork boundary reached, proposing chunk",
329+
"block count", len(chunk.Blocks),
330+
"codec version", codecVersion,
331+
"start block number", chunk.Blocks[0].Header.Number,
332+
"end block number", chunk.Blocks[len(chunk.Blocks)-1].Header.Number)
333+
334+
p.recordAllChunkMetrics(metrics)
335+
return p.updateDBChunkInfo(&chunk, codecVersion, metrics)
336+
}
337+
338+
// No breaking condition met, check for timeout
324339
currentTimeSec := uint64(time.Now().Unix())
325340
if metrics.FirstBlockTimestamp+p.cfg.ChunkTimeoutSec < currentTimeSec {
326341
log.Info("first block timeout reached",

rollup/internal/controller/watcher/chunk_proposer_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import (
1919
"scroll-tech/rollup/internal/utils"
2020
)
2121

22+
func newUint64(val uint64) *uint64 { return &val }
23+
2224
func testChunkProposerLimitsCodecV7(t *testing.T) {
2325
tests := []struct {
2426
name string
2527
maxL2Gas uint64
2628
chunkTimeoutSec uint64
2729
expectedChunksLen int
2830
expectedBlocksInFirstChunk int // only be checked when expectedChunksLen > 0
31+
GalileoTime *uint64
2932
}{
3033
{
3134
name: "NoLimitReached",
@@ -62,6 +65,14 @@ func testChunkProposerLimitsCodecV7(t *testing.T) {
6265
expectedChunksLen: 1,
6366
expectedBlocksInFirstChunk: 1,
6467
},
68+
{
69+
name: "SingleBlockByForkBoundary",
70+
maxL2Gas: 20_000_000,
71+
chunkTimeoutSec: 1000000000000,
72+
expectedChunksLen: 1,
73+
expectedBlocksInFirstChunk: 1,
74+
GalileoTime: newUint64(1669364525), // timestamp of `block2`
75+
},
6576
}
6677

6778
for _, tt := range tests {
@@ -78,11 +89,26 @@ func testChunkProposerLimitsCodecV7(t *testing.T) {
7889
_, err = chunkOrm.InsertChunk(context.Background(), &encoding.Chunk{Blocks: []*encoding.Block{{Header: &gethTypes.Header{Number: big.NewInt(0)}}}}, encoding.CodecV0, utils.ChunkMetrics{})
7990
assert.NoError(t, err)
8091

92+
// Initialize the chunk proposer.
93+
chainConfig := &params.ChainConfig{
94+
LondonBlock: big.NewInt(0),
95+
BernoulliBlock: big.NewInt(0),
96+
CurieBlock: big.NewInt(0),
97+
DarwinTime: new(uint64),
98+
DarwinV2Time: new(uint64),
99+
EuclidTime: new(uint64),
100+
EuclidV2Time: new(uint64),
101+
FeynmanTime: new(uint64),
102+
GalileoTime: tt.GalileoTime,
103+
}
104+
81105
cp := NewChunkProposer(context.Background(), &config.ChunkProposerConfig{
82106
MaxL2GasPerChunk: tt.maxL2Gas,
83107
ChunkTimeoutSec: tt.chunkTimeoutSec,
84108
MaxUncompressedBatchBytesSize: math.MaxUint64,
85-
}, encoding.CodecV7, &params.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)
109+
}, encoding.CodecV7, chainConfig, db, nil)
110+
111+
// Run one round of chunk proposing.
86112
cp.TryProposeChunk()
87113

88114
chunks, err := chunkOrm.GetChunksGEIndex(context.Background(), 1, 0)

0 commit comments

Comments
 (0)