Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
564b0c17
Unverified
Commit
564b0c17
authored
Dec 05, 2024
by
zhiqiangxu
Committed by
GitHub
Dec 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NewChannelBuilder => newChannelBuilder, and move it into channel_builder_test.go (#13148)
parent
25972bd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
39 deletions
+40
-39
channel_builder.go
op-batcher/batcher/channel_builder.go
+0
-12
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+40
-27
No files found.
op-batcher/batcher/channel_builder.go
View file @
564b0c17
...
...
@@ -88,18 +88,6 @@ type ChannelBuilder struct {
outputBytes
int
}
// NewChannelBuilder creates a new channel builder or returns an error if the
// channel out could not be created.
// it acts as a factory for either a span or singular channel out
func
NewChannelBuilder
(
cfg
ChannelConfig
,
rollupCfg
*
rollup
.
Config
,
latestL1OriginBlockNum
uint64
)
(
*
ChannelBuilder
,
error
)
{
co
,
err
:=
NewChannelOut
(
cfg
,
rollupCfg
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"creating channel out: %w"
,
err
)
}
return
NewChannelBuilderWithChannelOut
(
cfg
,
rollupCfg
,
latestL1OriginBlockNum
,
co
),
nil
}
func
NewChannelBuilderWithChannelOut
(
cfg
ChannelConfig
,
rollupCfg
*
rollup
.
Config
,
latestL1OriginBlockNum
uint64
,
channelOut
derive
.
ChannelOut
)
*
ChannelBuilder
{
cb
:=
&
ChannelBuilder
{
cfg
:
cfg
,
...
...
op-batcher/batcher/channel_builder_test.go
View file @
564b0c17
...
...
@@ -3,6 +3,7 @@ package batcher
import
(
"bytes"
"errors"
"fmt"
"math"
"math/big"
"math/rand"
...
...
@@ -27,6 +28,18 @@ var defaultTestRollupConfig = &rollup.Config{
L2ChainID
:
big
.
NewInt
(
1234
),
}
// newChannelBuilder creates a new channel builder or returns an error if the
// channel out could not be created.
// it acts as a factory for either a span or singular channel out
func
newChannelBuilder
(
cfg
ChannelConfig
,
rollupCfg
*
rollup
.
Config
,
latestL1OriginBlockNum
uint64
)
(
*
ChannelBuilder
,
error
)
{
co
,
err
:=
NewChannelOut
(
cfg
,
rollupCfg
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"creating channel out: %w"
,
err
)
}
return
NewChannelBuilderWithChannelOut
(
cfg
,
rollupCfg
,
latestL1OriginBlockNum
,
co
),
nil
}
// addMiniBlock adds a minimal valid L2 block to the channel builder using the
// ChannelBuilder.AddBlock method.
func
addMiniBlock
(
cb
*
ChannelBuilder
)
error
{
...
...
@@ -106,7 +119,7 @@ func FuzzDurationTimeoutZeroMaxChannelDuration(f *testing.F) {
f
.
Fuzz
(
func
(
t
*
testing
.
T
,
l1BlockNum
uint64
)
{
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
MaxChannelDuration
=
0
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
cb
.
timeout
=
0
cb
.
updateDurationTimeout
(
l1BlockNum
)
...
...
@@ -129,7 +142,7 @@ func FuzzChannelBuilder_DurationZero(f *testing.F) {
// Create the channel builder
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
MaxChannelDuration
=
maxChannelDuration
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Whenever the timeout is set to 0, the channel builder should have a duration timeout
...
...
@@ -156,7 +169,7 @@ func FuzzDurationTimeoutMaxChannelDuration(f *testing.F) {
// Create the channel builder
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
MaxChannelDuration
=
maxChannelDuration
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Whenever the timeout is greater than the l1BlockNum,
...
...
@@ -190,7 +203,7 @@ func FuzzChannelCloseTimeout(f *testing.F) {
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
ChannelTimeout
=
channelTimeout
channelConfig
.
SubSafetyMargin
=
subSafetyMargin
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Check the timeout
...
...
@@ -218,7 +231,7 @@ func FuzzChannelZeroCloseTimeout(f *testing.F) {
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
ChannelTimeout
=
channelTimeout
channelConfig
.
SubSafetyMargin
=
subSafetyMargin
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Check the timeout
...
...
@@ -245,7 +258,7 @@ func FuzzSeqWindowClose(f *testing.F) {
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
SeqWindowSize
=
seqWindowSize
channelConfig
.
SubSafetyMargin
=
subSafetyMargin
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Check the timeout
...
...
@@ -273,7 +286,7 @@ func FuzzSeqWindowZeroTimeoutClose(f *testing.F) {
channelConfig
:=
defaultTestChannelConfig
()
channelConfig
.
SeqWindowSize
=
seqWindowSize
channelConfig
.
SubSafetyMargin
=
subSafetyMargin
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Check the timeout
...
...
@@ -321,7 +334,7 @@ func TestChannelBuilder_NextFrame(t *testing.T) {
channelConfig
:=
defaultTestChannelConfig
()
// Create a new channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `ChannelBuilder.outputFrame`
...
...
@@ -362,7 +375,7 @@ func ChannelBuilder_OutputWrongFramePanic(t *testing.T, batchType uint) {
channelConfig
.
BatchType
=
batchType
// Construct a channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `ChannelBuilder.outputFrame`
...
...
@@ -398,7 +411,7 @@ func TestChannelBuilder_OutputFrames(t *testing.T) {
channelConfig
.
InitNoneCompressor
()
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
cb
.
IsFull
())
require
.
Equal
(
t
,
0
,
cb
.
PendingFrames
())
...
...
@@ -452,7 +465,7 @@ func ChannelBuilder_OutputFrames_SpanBatch(t *testing.T, algo derive.Compression
channelConfig
.
InitRatioCompressor
(
1
,
algo
)
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
cb
.
IsFull
())
require
.
Equal
(
t
,
0
,
cb
.
PendingFrames
())
...
...
@@ -510,7 +523,7 @@ func ChannelBuilder_MaxRLPBytesPerChannel(t *testing.T, batchType uint) {
channelConfig
.
BatchType
=
batchType
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Add a block that overflows the [ChannelOut]
...
...
@@ -532,7 +545,7 @@ func ChannelBuilder_MaxRLPBytesPerChannelFjord(t *testing.T, batchType uint) {
channelConfig
.
BatchType
=
batchType
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Count how many a block that overflows the [ChannelOut]
...
...
@@ -553,7 +566,7 @@ func ChannelBuilder_MaxRLPBytesPerChannelFjord(t *testing.T, batchType uint) {
channelConfig
.
InitNoneCompressor
()
channelConfig
.
BatchType
=
batchType
cb
,
err
=
N
ewChannelBuilder
(
channelConfig
,
rollupConfig
,
latestL1BlockOrigin
)
cb
,
err
=
n
ewChannelBuilder
(
channelConfig
,
rollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// try add double the amount of block, it should not error
...
...
@@ -576,7 +589,7 @@ func ChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T, batchType uint) {
// Continuously add blocks until the max frame index is reached
// This should cause the [ChannelBuilder.OutputFrames] function
// to error
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
False
(
t
,
cb
.
IsFull
())
require
.
Equal
(
t
,
0
,
cb
.
PendingFrames
())
...
...
@@ -612,7 +625,7 @@ func TestChannelBuilder_FullShadowCompressor(t *testing.T) {
}
cfg
.
InitShadowCompressor
(
derive
.
Zlib
)
cb
,
err
:=
N
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
err
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
420
))
...
...
@@ -644,7 +657,7 @@ func ChannelBuilder_AddBlock(t *testing.T, batchType uint) {
channelConfig
.
InitRatioCompressor
(
1
,
derive
.
Zlib
)
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Add a nonsense block to the channel builder
...
...
@@ -670,7 +683,7 @@ func TestChannelBuilder_CheckTimeout(t *testing.T) {
channelConfig
:=
defaultTestChannelConfig
()
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Assert timeout is setup correctly
...
...
@@ -695,7 +708,7 @@ func TestChannelBuilder_CheckTimeoutZeroMaxChannelDuration(t *testing.T) {
channelConfig
.
MaxChannelDuration
=
0
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
channelConfig
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
// Without a max channel duration, timeout should not be set
...
...
@@ -718,7 +731,7 @@ func TestChannelBuilder_FramePublished(t *testing.T) {
cfg
.
SubSafetyMargin
=
100
// Construct the channel builder
cb
,
err
:=
N
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
latestL1BlockOrigin
+
cfg
.
MaxChannelDuration
,
cb
.
timeout
)
...
...
@@ -735,7 +748,7 @@ func TestChannelBuilder_FramePublished(t *testing.T) {
}
func
TestChannelBuilder_LatestL1Origin
(
t
*
testing
.
T
)
{
cb
,
err
:=
N
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
eth
.
BlockID
{},
cb
.
LatestL1Origin
())
...
...
@@ -757,7 +770,7 @@ func TestChannelBuilder_LatestL1Origin(t *testing.T) {
}
func
TestChannelBuilder_OldestL1Origin
(
t
*
testing
.
T
)
{
cb
,
err
:=
N
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
eth
.
BlockID
{},
cb
.
OldestL1Origin
())
...
...
@@ -779,7 +792,7 @@ func TestChannelBuilder_OldestL1Origin(t *testing.T) {
}
func
TestChannelBuilder_LatestL2
(
t
*
testing
.
T
)
{
cb
,
err
:=
N
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
eth
.
BlockID
{},
cb
.
LatestL2
())
...
...
@@ -801,7 +814,7 @@ func TestChannelBuilder_LatestL2(t *testing.T) {
}
func
TestChannelBuilder_OldestL2
(
t
*
testing
.
T
)
{
cb
,
err
:=
N
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
defaultTestChannelConfig
(),
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
eth
.
BlockID
{},
cb
.
OldestL2
())
...
...
@@ -831,7 +844,7 @@ func ChannelBuilder_PendingFrames_TotalFrames(t *testing.T, batchType uint) {
cfg
.
TargetNumFrames
=
tnf
cfg
.
BatchType
=
batchType
cfg
.
InitShadowCompressor
(
derive
.
Zlib
)
cb
,
err
:=
N
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
err
)
// initial builder should be empty
...
...
@@ -876,7 +889,7 @@ func ChannelBuilder_InputBytes(t *testing.T, batchType uint) {
chainId
:=
big
.
NewInt
(
1234
)
spanBatch
=
derive
.
NewSpanBatch
(
uint64
(
0
),
chainId
)
}
cb
,
err
:=
N
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
err
)
require
.
Zero
(
cb
.
InputBytes
())
...
...
@@ -913,7 +926,7 @@ func ChannelBuilder_OutputBytes(t *testing.T, batchType uint) {
cfg
.
TargetNumFrames
=
16
cfg
.
BatchType
=
batchType
cfg
.
InitRatioCompressor
(
1.0
,
derive
.
Zlib
)
cb
,
err
:=
N
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
cb
,
err
:=
n
ewChannelBuilder
(
cfg
,
defaultTestRollupConfig
,
latestL1BlockOrigin
)
require
.
NoError
(
err
,
"NewChannelBuilder"
)
require
.
Zero
(
cb
.
OutputBytes
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment