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
98a800f8
Commit
98a800f8
authored
Mar 13, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
channel builder test suite
parent
e80cfdb2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
30 deletions
+84
-30
channel_builder.go
op-batcher/batcher/channel_builder.go
+2
-2
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+41
-27
channel_config_test.go
op-batcher/batcher/channel_config_test.go
+40
-0
channel_manager.go
op-batcher/batcher/channel_manager.go
+1
-1
No files found.
op-batcher/batcher/channel_builder.go
View file @
98a800f8
...
@@ -79,9 +79,9 @@ type channelBuilder struct {
...
@@ -79,9 +79,9 @@ type channelBuilder struct {
frames
[]
taggedData
frames
[]
taggedData
}
}
//
N
ewChannelBuilder creates a new channel builder or returns an error if the
//
n
ewChannelBuilder creates a new channel builder or returns an error if the
// channel out could not be created.
// channel out could not be created.
func
N
ewChannelBuilder
(
cfg
ChannelConfig
)
(
*
channelBuilder
,
error
)
{
func
n
ewChannelBuilder
(
cfg
ChannelConfig
)
(
*
channelBuilder
,
error
)
{
co
,
err
:=
derive
.
NewChannelOut
()
co
,
err
:=
derive
.
NewChannelOut
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
op-batcher/batcher/channel_builder_test.go
View file @
98a800f8
...
@@ -5,31 +5,45 @@ import (
...
@@ -5,31 +5,45 @@ import (
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/stretchr/testify/
requir
e"
"github.com/stretchr/testify/
suit
e"
)
)
var
defaultTestConfig
=
ChannelConfig
{
// ChannelBuilderTestSuite encapsulates testing on the ChannelBuilder.
SeqWindowSize
:
15
,
type
ChannelBuilderTestSuite
struct
{
ChannelTimeout
:
40
,
suite
.
Suite
MaxChannelDuration
:
1
,
channelConfig
ChannelConfig
SubSafetyMargin
:
4
,
}
MaxFrameSize
:
120000
,
TargetFrameSize
:
100000
,
// SetupTest sets up the test suite.
TargetNumFrames
:
1
,
func
(
testSuite
*
ChannelBuilderTestSuite
)
SetupTest
()
{
ApproxComprRatio
:
0.4
,
testSuite
.
channelConfig
=
ChannelConfig
{
SeqWindowSize
:
15
,
ChannelTimeout
:
40
,
MaxChannelDuration
:
1
,
SubSafetyMargin
:
4
,
MaxFrameSize
:
120000
,
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
}
// TestChannelBuilder runs the ChannelBuilderTestSuite.
func
TestChannelBuilder
(
t
*
testing
.
T
)
{
suite
.
Run
(
t
,
new
(
ChannelBuilderTestSuite
))
}
}
// TestBuilderNextFrame tests calling NextFrame on a ChannelBuilder with only one frame
// TestBuilderNextFrame tests calling NextFrame on a ChannelBuilder with only one frame
func
TestBuilderNextFrame
(
t
*
testing
.
T
)
{
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderNextFrame
(
)
{
cb
,
err
:=
NewChannelBuilder
(
defaultTest
Config
)
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channel
Config
)
require
.
NoError
(
t
,
err
)
testSuite
.
NoError
(
err
)
// Mock the internals of `channelBuilder.outputFrame`
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
// to construct a single frame
co
:=
cb
.
co
co
:=
cb
.
co
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
defaultTest
Config
.
MaxFrameSize
)
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
testSuite
.
channel
Config
.
MaxFrameSize
)
require
.
NoError
(
t
,
err
)
testSuite
.
NoError
(
err
)
// Push one frame into to the channel builder
// Push one frame into to the channel builder
expectedTx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
expectedTx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
...
@@ -37,34 +51,34 @@ func TestBuilderNextFrame(t *testing.T) {
...
@@ -37,34 +51,34 @@ func TestBuilderNextFrame(t *testing.T) {
cb
.
PushFrame
(
expectedTx
,
expectedBytes
)
cb
.
PushFrame
(
expectedTx
,
expectedBytes
)
// There should only be 1 frame in the channel builder
// There should only be 1 frame in the channel builder
require
.
Equal
(
t
,
1
,
cb
.
NumFrames
())
testSuite
.
Equal
(
1
,
cb
.
NumFrames
())
// We should be able to increment to the next frame
// We should be able to increment to the next frame
constructedTx
,
constructedBytes
:=
cb
.
NextFrame
()
constructedTx
,
constructedBytes
:=
cb
.
NextFrame
()
require
.
Equal
(
t
,
expectedTx
,
constructedTx
)
testSuite
.
Equal
(
expectedTx
,
constructedTx
)
require
.
Equal
(
t
,
expectedBytes
,
constructedBytes
)
testSuite
.
Equal
(
expectedBytes
,
constructedBytes
)
require
.
Equal
(
t
,
0
,
cb
.
NumFrames
())
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
// The next call should panic since the length of frames is 0
// The next call should panic since the length of frames is 0
defer
func
()
{
_
=
recover
()
}()
defer
func
()
{
_
=
recover
()
}()
cb
.
NextFrame
()
cb
.
NextFrame
()
// If we get here, `NextFrame` did not panic as expected
// If we get here, `NextFrame` did not panic as expected
t
.
Errorf
(
"did not panic"
)
t
estSuite
.
T
()
.
Errorf
(
"did not panic"
)
}
}
// TestBuilderInvalidFrameId tests that a panic is thrown when a frame is pushed with an invalid frame id
// TestBuilderInvalidFrameId tests that a panic is thrown when a frame is pushed with an invalid frame id
func
TestBuilderWrongFramePanic
(
t
*
testing
.
T
)
{
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderWrongFramePanic
(
)
{
cb
,
err
:=
NewChannelBuilder
(
defaultTest
Config
)
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channel
Config
)
require
.
NoError
(
t
,
err
)
testSuite
.
NoError
(
err
)
// Mock the internals of `channelBuilder.outputFrame`
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
// to construct a single frame
co
,
err
:=
derive
.
NewChannelOut
()
co
,
err
:=
derive
.
NewChannelOut
()
require
.
NoError
(
t
,
err
)
testSuite
.
NoError
(
err
)
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
defaultTest
Config
.
MaxFrameSize
)
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
testSuite
.
channel
Config
.
MaxFrameSize
)
require
.
NoError
(
t
,
err
)
testSuite
.
NoError
(
err
)
// The frame push should panic since we constructed a new channel out
// The frame push should panic since we constructed a new channel out
// so the channel out id won't match
// so the channel out id won't match
...
@@ -75,5 +89,5 @@ func TestBuilderWrongFramePanic(t *testing.T) {
...
@@ -75,5 +89,5 @@ func TestBuilderWrongFramePanic(t *testing.T) {
cb
.
PushFrame
(
tx
,
buf
.
Bytes
())
cb
.
PushFrame
(
tx
,
buf
.
Bytes
())
// If we get here, `PushFrame` did not panic as expected
// If we get here, `PushFrame` did not panic as expected
t
.
Errorf
(
"did not panic"
)
t
estSuite
.
T
()
.
Errorf
(
"did not panic"
)
}
}
op-batcher/batcher/channel_config_test.go
0 → 100644
View file @
98a800f8
package
batcher_test
import
(
"math"
"testing"
"github.com/ethereum-optimism/optimism/op-batcher/batcher"
"github.com/stretchr/testify/require"
)
// TestInputThreshold tests the [ChannelConfig.InputThreshold] function.
func
TestInputThreshold
(
t
*
testing
.
T
)
{
// Construct an empty channel config
config
:=
batcher
.
ChannelConfig
{
SeqWindowSize
:
15
,
ChannelTimeout
:
40
,
MaxChannelDuration
:
1
,
SubSafetyMargin
:
4
,
MaxFrameSize
:
120000
,
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
// The input threshold is calculated as: (targetNumFrames * targetFrameSize) / approxComprRatio
// Here we see that 100,000 / 0.4 = 100,000 * 2.5 = 250,000
inputThreshold
:=
config
.
InputThreshold
()
require
.
Equal
(
t
,
uint64
(
250
_000
),
inputThreshold
)
// Set the approximate compression ratio to 0
// Logically, this represents infinite compression,
// so there is no threshold on the size of the input.
// In practice, this should never be set to 0.
config
.
ApproxComprRatio
=
0
// The input threshold will overflow to the max uint64 value
receivedThreshold
:=
config
.
InputThreshold
()
var
maxUint64
uint64
=
math
.
MaxUint64
require
.
Equal
(
t
,
maxUint64
,
receivedThreshold
)
}
op-batcher/batcher/channel_manager.go
View file @
98a800f8
...
@@ -229,7 +229,7 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.BlockID) error {
...
@@ -229,7 +229,7 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.BlockID) error {
return
nil
return
nil
}
}
cb
,
err
:=
N
ewChannelBuilder
(
s
.
cfg
)
cb
,
err
:=
n
ewChannelBuilder
(
s
.
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"creating new channel: %w"
,
err
)
return
fmt
.
Errorf
(
"creating new channel: %w"
,
err
)
}
}
...
...
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