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
53d9465e
Commit
53d9465e
authored
Mar 13, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more channel builder tests :test_tube:
parent
98a800f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
1 deletion
+152
-1
channel_builder.go
op-batcher/batcher/channel_builder.go
+1
-1
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+151
-0
No files found.
op-batcher/batcher/channel_builder.go
View file @
53d9465e
...
@@ -207,7 +207,7 @@ func (c *channelBuilder) updateTimeout(timeoutBlockNum uint64, reason error) {
...
@@ -207,7 +207,7 @@ func (c *channelBuilder) updateTimeout(timeoutBlockNum uint64, reason error) {
}
}
// checkTimeout checks if the channel is timed out at the given block number and
// checkTimeout checks if the channel is timed out at the given block number and
// in this case marks the channel as full, if it wasn't full alredy.
// in this case marks the channel as full, if it wasn't full alre
a
dy.
func
(
c
*
channelBuilder
)
checkTimeout
(
blockNum
uint64
)
{
func
(
c
*
channelBuilder
)
checkTimeout
(
blockNum
uint64
)
{
if
!
c
.
IsFull
()
&&
c
.
TimedOut
(
blockNum
)
{
if
!
c
.
IsFull
()
&&
c
.
TimedOut
(
blockNum
)
{
c
.
setFullErr
(
c
.
timeoutReason
)
c
.
setFullErr
(
c
.
timeoutReason
)
...
...
op-batcher/batcher/channel_builder_test.go
View file @
53d9465e
...
@@ -2,9 +2,15 @@ package batcher
...
@@ -2,9 +2,15 @@ package batcher
import
(
import
(
"bytes"
"bytes"
"math/big"
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/suite"
)
)
...
@@ -91,3 +97,148 @@ func (testSuite *ChannelBuilderTestSuite) TestBuilderWrongFramePanic() {
...
@@ -91,3 +97,148 @@ func (testSuite *ChannelBuilderTestSuite) TestBuilderWrongFramePanic() {
// If we get here, `PushFrame` did not panic as expected
// If we get here, `PushFrame` did not panic as expected
testSuite
.
T
()
.
Errorf
(
"did not panic"
)
testSuite
.
T
()
.
Errorf
(
"did not panic"
)
}
}
func
addNonsenseBlock
(
cb
*
channelBuilder
)
error
{
lBlock
:=
types
.
NewBlock
(
&
types
.
Header
{
BaseFee
:
big
.
NewInt
(
10
),
Difficulty
:
common
.
Big0
,
Number
:
big
.
NewInt
(
100
),
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
lBlock
,
eth
.
SystemConfig
{},
false
)
if
err
!=
nil
{
return
err
}
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
a
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
0
),
},
txs
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
err
=
cb
.
AddBlock
(
a
)
return
err
}
// TestOutputFrames tests the OutputFrames function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestOutputFrames
()
{
// Lower the max frame size so that we can test
testSuite
.
channelConfig
.
MaxFrameSize
=
2
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
testSuite
.
NoError
(
err
)
testSuite
.
False
(
cb
.
IsFull
())
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
// Calling OutputFrames without having called [AddBlock]
// should return `nil`.
testSuite
.
Nil
(
cb
.
OutputFrames
())
// There should be no ready bytes yet
readyBytes
:=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
0
,
readyBytes
)
// Let's add a block
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
// Check how many ready bytes
readyBytes
=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
2
,
readyBytes
)
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
// The channel should not be full
// but we want to output the frames for testing anyways
isFull
:=
cb
.
IsFull
()
testSuite
.
False
(
isFull
)
// Since we manually set the max frame size to 2,
// we should be able to compress the two frames now
err
=
cb
.
OutputFrames
()
testSuite
.
NoError
(
err
)
// There should be one frame in the channel builder now
testSuite
.
Equal
(
1
,
cb
.
NumFrames
())
// There should no longer be any ready bytes
readyBytes
=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
0
,
readyBytes
)
}
// TestBuilderAddBlock tests the AddBlock function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderAddBlock
()
{
// Lower the max frame size so that we can batch
testSuite
.
channelConfig
.
MaxFrameSize
=
2
// Configure the Input Threshold params so we observe a full channel
// In reality, we only need the input bytes (74) below to be greater than
// or equal to the input threshold (3 * 2) / 1 = 6
testSuite
.
channelConfig
.
TargetFrameSize
=
3
testSuite
.
channelConfig
.
TargetNumFrames
=
2
testSuite
.
channelConfig
.
ApproxComprRatio
=
1
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
testSuite
.
NoError
(
err
)
// Add a nonsense block to the channel builder
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
// Check the fields reset in the AddBlock function
testSuite
.
Equal
(
74
,
cb
.
co
.
InputBytes
())
testSuite
.
Equal
(
1
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
testSuite
.
True
(
cb
.
IsFull
())
// Since the channel output is full, the next call to AddBlock
// should return the channel out full error
err
=
addNonsenseBlock
(
cb
)
testSuite
.
ErrorIs
(
err
,
ErrInputTargetReached
)
}
// TestBuilderReset tests the Reset function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderReset
()
{
// Lower the max frame size so that we can batch
testSuite
.
channelConfig
.
MaxFrameSize
=
2
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
testSuite
.
NoError
(
err
)
// Add a nonsense block to the channel builder
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
// Check the fields reset in the Reset function
testSuite
.
Equal
(
1
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
// Timeout should be updated in the AddBlock internal call to `updateSwTimeout`
timeout
:=
uint64
(
100
)
+
cb
.
cfg
.
SeqWindowSize
-
cb
.
cfg
.
SubSafetyMargin
testSuite
.
Equal
(
timeout
,
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
// Output frames so we can set the channel builder frames
err
=
cb
.
OutputFrames
()
testSuite
.
NoError
(
err
)
// Add another block to increment the block count
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
// Check the fields reset in the Reset function
testSuite
.
Equal
(
2
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
1
,
len
(
cb
.
frames
))
testSuite
.
Equal
(
timeout
,
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
// Reset the channel builder
err
=
cb
.
Reset
()
testSuite
.
NoError
(
err
)
// Check the fields reset in the Reset function
testSuite
.
Equal
(
0
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
testSuite
.
Equal
(
uint64
(
0
),
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
testSuite
.
Equal
(
0
,
cb
.
co
.
InputBytes
())
testSuite
.
Equal
(
0
,
cb
.
co
.
ReadyBytes
())
}
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