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
461b2134
Unverified
Commit
461b2134
authored
Apr 18, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move compressor instantiation to ChannelConfig
parent
7a73979b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
67 deletions
+90
-67
channel_builder.go
op-batcher/batcher/channel_builder.go
+32
-10
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+16
-12
channel_manager_test.go
op-batcher/batcher/channel_manager_test.go
+27
-18
config.go
op-batcher/batcher/config.go
+0
-18
driver.go
op-batcher/batcher/driver.go
+5
-2
target_size_compressor_test.go
op-batcher/batcher/target_size_compressor_test.go
+9
-6
flags.go
op-batcher/flags/flags.go
+1
-1
No files found.
op-batcher/batcher/channel_builder.go
View file @
461b2134
...
...
@@ -7,6 +7,7 @@ import (
"io"
"math"
"github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/core/types"
)
...
...
@@ -32,8 +33,6 @@ func (e *ChannelFullError) Unwrap() error {
return
e
.
Err
}
type
CompressorFactory
func
()
(
derive
.
Compressor
,
error
)
type
ChannelConfig
struct
{
// Number of epochs (L1 blocks) per sequencing window, including the epoch
// L1 origin block itself
...
...
@@ -56,8 +55,21 @@ type ChannelConfig struct {
SubSafetyMargin
uint64
// The maximum byte-size a frame can have.
MaxFrameSize
uint64
// CompressorFactory creates Compressors used to compress frame data.
CompressorFactory
CompressorFactory
// The target number of frames to create per channel. Note that if the
// realized compression ratio is worse than the approximate, more frames may
// actually be created. This also depends on how close TargetFrameSize is to
// MaxFrameSize.
TargetFrameSize
uint64
// The target number of frames to create in this channel. If the realized
// compression ratio is worse than approxComprRatio, additional leftover
// frame(s) might get created.
TargetNumFrames
int
// Approximated compression ratio to assume. Should be slightly smaller than
// average from experiments to avoid the chances of creating a small
// additional leftover frame.
ApproxComprRatio
float64
// CompressorKind is the compressor implementation to use.
CompressorKind
flags
.
CompressorKind
}
// Check validates the [ChannelConfig] parameters.
...
...
@@ -83,14 +95,24 @@ func (cc *ChannelConfig) Check() error {
return
fmt
.
Errorf
(
"max frame size %d is less than the minimum 23"
,
cc
.
MaxFrameSize
)
}
// Compressor must be set
if
cc
.
CompressorFactory
==
nil
{
return
errors
.
New
(
"compressor factory cannot be nil"
)
}
return
nil
}
func
(
cc
*
ChannelConfig
)
NewCompressor
()
(
derive
.
Compressor
,
error
)
{
switch
cc
.
CompressorKind
{
case
flags
.
CompressorShadow
:
return
NewShadowCompressor
(
cc
.
MaxFrameSize
,
// subtract 1 byte for version
)
default
:
return
NewTargetSizeCompressor
(
cc
.
TargetFrameSize
,
// subtract 1 byte for version
cc
.
TargetNumFrames
,
cc
.
ApproxComprRatio
,
)
}
}
type
frameID
struct
{
chID
derive
.
ChannelID
frameNumber
uint16
...
...
@@ -131,7 +153,7 @@ type channelBuilder struct {
// newChannelBuilder creates a new channel builder or returns an error if the
// channel out could not be created.
func
newChannelBuilder
(
cfg
ChannelConfig
)
(
*
channelBuilder
,
error
)
{
c
,
err
:=
cfg
.
CompressorFactory
()
c
,
err
:=
cfg
.
NewCompressor
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
op-batcher/batcher/channel_builder_test.go
View file @
461b2134
...
...
@@ -28,13 +28,9 @@ var defaultTestChannelConfig = ChannelConfig{
MaxChannelDuration
:
1
,
SubSafetyMargin
:
4
,
MaxFrameSize
:
120000
,
CompressorFactory
:
newCompressorFactory
(
100000
,
1
,
0.4
),
}
func
newCompressorFactory
(
targetFrameSize
uint64
,
targetNumFrames
int
,
approxCompRatio
float64
)
CompressorFactory
{
return
func
()
(
derive
.
Compressor
,
error
)
{
return
NewTargetSizeCompressor
(
targetFrameSize
,
targetNumFrames
,
approxCompRatio
)
}
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
// TestChannelConfig_Check tests the [ChannelConfig] [Check] function.
...
...
@@ -420,7 +416,7 @@ func TestChannelBuilder_OutputWrongFramePanic(t *testing.T) {
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
c
,
err
:=
channelConfig
.
CompressorFactory
()
c
,
err
:=
channelConfig
.
NewCompressor
()
require
.
NoError
(
t
,
err
)
co
,
err
:=
derive
.
NewChannelOut
(
c
)
require
.
NoError
(
t
,
err
)
...
...
@@ -488,7 +484,9 @@ func TestChannelBuilder_OutputFramesWorks(t *testing.T) {
func
TestChannelBuilder_MaxRLPBytesPerChannel
(
t
*
testing
.
T
)
{
t
.
Parallel
()
channelConfig
:=
defaultTestChannelConfig
channelConfig
.
CompressorFactory
=
newCompressorFactory
(
derive
.
MaxRLPBytesPerChannel
*
2
,
derive
.
MaxRLPBytesPerChannel
*
2
,
1
)
channelConfig
.
MaxFrameSize
=
derive
.
MaxRLPBytesPerChannel
*
2
channelConfig
.
TargetFrameSize
=
derive
.
MaxRLPBytesPerChannel
*
2
channelConfig
.
ApproxComprRatio
=
1
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
...
...
@@ -504,7 +502,9 @@ func TestChannelBuilder_MaxRLPBytesPerChannel(t *testing.T) {
func
TestChannelBuilder_OutputFramesMaxFrameIndex
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
channelConfig
.
MaxFrameSize
=
24
channelConfig
.
CompressorFactory
=
newCompressorFactory
(
24
,
math
.
MaxInt
,
0
)
channelConfig
.
TargetNumFrames
=
math
.
MaxInt
channelConfig
.
TargetFrameSize
=
24
channelConfig
.
ApproxComprRatio
=
0
// Continuously add blocks until the max frame index is reached
// This should cause the [channelBuilder.OutputFrames] function
...
...
@@ -546,7 +546,9 @@ func TestChannelBuilder_AddBlock(t *testing.T) {
channelConfig
.
MaxFrameSize
=
30
// Configure the Input Threshold params so we observe a full channel
channelConfig
.
CompressorFactory
=
newCompressorFactory
(
30
,
2
,
1
)
channelConfig
.
TargetFrameSize
=
30
channelConfig
.
TargetNumFrames
=
2
channelConfig
.
ApproxComprRatio
=
1
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
...
...
@@ -701,8 +703,10 @@ func TestChannelBuilder_OutputBytes(t *testing.T) {
require
:=
require
.
New
(
t
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
cfg
:=
defaultTestChannelConfig
cfg
.
TargetFrameSize
=
1000
cfg
.
MaxFrameSize
=
1000
cfg
.
CompressorFactory
=
newCompressorFactory
(
1000
,
16
,
1
)
cfg
.
TargetNumFrames
=
16
cfg
.
ApproxComprRatio
=
1.0
cb
,
err
:=
newChannelBuilder
(
cfg
)
require
.
NoError
(
err
,
"newChannelBuilder"
)
...
...
op-batcher/batcher/channel_manager_test.go
View file @
461b2134
...
...
@@ -98,8 +98,9 @@ func TestChannelManagerReturnsErrReorgWhenDrained(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetFrameSize
:
1
,
MaxFrameSize
:
120
_000
,
CompressorFactory
:
newCompressorFactory
(
1
,
1
,
1
)
,
ApproxComprRatio
:
1.0
,
})
a
:=
newMiniL2Block
(
0
)
...
...
@@ -170,7 +171,8 @@ func TestChannelManager_Clear(t *testing.T) {
// Have to set the max frame size here otherwise the channel builder would not
// be able to output any frames
MaxFrameSize
:
24
,
CompressorFactory
:
newCompressorFactory
(
24
,
1
,
1
),
TargetFrameSize
:
24
,
ApproxComprRatio
:
1.0
,
})
// Channel Manager state should be empty by default
...
...
@@ -329,8 +331,9 @@ func TestChannelManager_TxResend(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlError
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetFrameSize
:
1
,
MaxFrameSize
:
120
_000
,
CompressorFactory
:
newCompressorFactory
(
1
,
1
,
1
)
,
ApproxComprRatio
:
1.0
,
})
a
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
4
)
...
...
@@ -369,8 +372,9 @@ func TestChannelManagerCloseBeforeFirstUse(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetFrameSize
:
1
,
MaxFrameSize
:
100
,
CompressorFactory
:
newCompressorFactory
(
0
,
1
,
1
)
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
...
...
@@ -393,8 +397,9 @@ func TestChannelManagerCloseNoPendingChannel(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
MaxFrameSize
:
1000
,
CompressorFactory
:
newCompressorFactory
(
1
,
1
,
1
),
TargetFrameSize
:
1
,
MaxFrameSize
:
100
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
a
:=
newMiniL2Block
(
0
)
...
...
@@ -428,8 +433,10 @@ func TestChannelManagerClosePendingChannel(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetNumFrames
:
100
,
TargetFrameSize
:
1000
,
MaxFrameSize
:
1000
,
CompressorFactory
:
newCompressorFactory
(
1000
,
100
,
1
)
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
...
...
@@ -469,8 +476,10 @@ func TestChannelManagerCloseAllTxsFailed(t *testing.T) {
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetNumFrames
:
100
,
TargetFrameSize
:
1000
,
MaxFrameSize
:
1000
,
CompressorFactory
:
newCompressorFactory
(
1000
,
100
,
1
)
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
...
...
op-batcher/batcher/config.go
View file @
461b2134
...
...
@@ -12,7 +12,6 @@ import (
"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-batcher/rpc"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/sources"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
opmetrics
"github.com/ethereum-optimism/optimism/op-service/metrics"
...
...
@@ -153,20 +152,3 @@ func NewConfig(ctx *cli.Context) CLIConfig {
PprofConfig
:
oppprof
.
ReadCLIConfig
(
ctx
),
}
}
func
(
c
CLIConfig
)
NewCompressorFactory
()
CompressorFactory
{
return
func
()
(
derive
.
Compressor
,
error
)
{
switch
c
.
CompressorKind
{
case
flags
.
CompressorTarget
:
return
NewTargetSizeCompressor
(
c
.
TargetL1TxSize
-
1
,
// subtract 1 byte for version
c
.
TargetNumFrames
,
c
.
ApproxComprRatio
,
)
default
:
return
NewShadowCompressor
(
c
.
MaxL1TxSize
-
1
,
// subtract 1 byte for version
)
}
}
}
op-batcher/batcher/driver.go
View file @
461b2134
...
...
@@ -90,7 +90,10 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
MaxChannelDuration
:
cfg
.
MaxChannelDuration
,
SubSafetyMargin
:
cfg
.
SubSafetyMargin
,
MaxFrameSize
:
cfg
.
MaxL1TxSize
-
1
,
// subtract 1 byte for version
CompressorFactory
:
cfg
.
NewCompressorFactory
(),
TargetFrameSize
:
cfg
.
TargetL1TxSize
-
1
,
// subtract 1 byte for version
TargetNumFrames
:
cfg
.
TargetNumFrames
,
ApproxComprRatio
:
cfg
.
ApproxComprRatio
,
CompressorKind
:
cfg
.
CompressorKind
,
},
}
...
...
op-batcher/batcher/target_size_compressor_test.go
View file @
461b2134
package
batcher_test
import
(
"github.com/ethereum-optimism/optimism/op-batcher/flags"
"math"
"testing"
...
...
@@ -118,13 +119,15 @@ func TestInputThreshold(t *testing.T) {
// Validate each test case
for
_
,
tt
:=
range
tests
{
compressor
,
err
:=
batcher
.
NewTargetSizeCompressor
(
tt
.
input
.
TargetFrameSize
,
tt
.
input
.
TargetNumFrames
,
tt
.
input
.
ApproxComprRatio
,
)
config
:=
batcher
.
ChannelConfig
{
TargetFrameSize
:
tt
.
input
.
TargetFrameSize
,
TargetNumFrames
:
tt
.
input
.
TargetNumFrames
,
ApproxComprRatio
:
tt
.
input
.
ApproxComprRatio
,
CompressorKind
:
flags
.
CompressorTarget
,
}
comp
,
err
:=
config
.
NewCompressor
()
require
.
NoError
(
t
,
err
)
got
:=
comp
ressor
.
(
*
batcher
.
TargetSizeCompressor
)
.
InputThreshold
()
got
:=
comp
.
(
*
batcher
.
TargetSizeCompressor
)
.
InputThreshold
()
tt
.
assertion
(
got
)
}
}
op-batcher/flags/flags.go
View file @
461b2134
...
...
@@ -92,7 +92,7 @@ var (
flags
.
EnumString
[
CompressorKind
](
CompressorKinds
),
EnvVar
:
opservice
.
PrefixEnvVar
(
envVarPrefix
,
"COMPRESSOR"
),
Value
:
func
()
*
CompressorKind
{
out
:=
Compressor
Shadow
out
:=
Compressor
Target
return
&
out
}(),
}
...
...
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