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
93be57b9
Unverified
Commit
93be57b9
authored
May 11, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename TargetSizeCompressor to RatioCompressor, and add some comments
parent
4ccdbf0a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
21 deletions
+37
-21
channel_builder.go
op-batcher/batcher/channel_builder.go
+1
-1
ratio_compressor.go
op-batcher/batcher/ratio_compressor.go
+17
-12
ratio_compressor_test.go
op-batcher/batcher/ratio_compressor_test.go
+2
-2
shadow_compressor.go
op-batcher/batcher/shadow_compressor.go
+7
-0
flags.go
op-batcher/flags/flags.go
+9
-5
l2_batcher.go
op-e2e/actions/l2_batcher.go
+1
-1
No files found.
op-batcher/batcher/channel_builder.go
View file @
93be57b9
...
...
@@ -106,7 +106,7 @@ func (cc *ChannelConfig) NewCompressor() (derive.Compressor, error) {
cc
.
TargetNumFrames
,
)
default
:
return
New
TargetSize
Compressor
(
return
New
Ratio
Compressor
(
cc
.
TargetFrameSize
,
cc
.
TargetNumFrames
,
cc
.
ApproxComprRatio
,
...
...
op-batcher/batcher/
target_size
_compressor.go
→
op-batcher/batcher/
ratio
_compressor.go
View file @
93be57b9
...
...
@@ -7,7 +7,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
)
type
TargetSize
Compressor
struct
{
type
Ratio
Compressor
struct
{
// The frame size to target when creating channel frames. 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
...
...
@@ -27,8 +27,13 @@ type TargetSizeCompressor struct {
compress
*
zlib
.
Writer
}
func
NewTargetSizeCompressor
(
targetFrameSize
uint64
,
targetNumFrames
int
,
approxCompRatio
float64
)
(
derive
.
Compressor
,
error
)
{
c
:=
&
TargetSizeCompressor
{
// NewRatioCompressor creates a new derive.Compressor implementation that uses the target
// size and a compression ratio parameter to determine how much data can be written to
// the compressor before it's considered full. The full calculation is as follows:
//
// full = uncompressedLength * approxCompRatio >= targetFrameSize * targetNumFrames
func
NewRatioCompressor
(
targetFrameSize
uint64
,
targetNumFrames
int
,
approxCompRatio
float64
)
(
derive
.
Compressor
,
error
)
{
c
:=
&
RatioCompressor
{
TargetFrameSize
:
targetFrameSize
,
TargetNumFrames
:
targetNumFrames
,
ApproxComprRatio
:
approxCompRatio
,
...
...
@@ -43,7 +48,7 @@ func NewTargetSizeCompressor(targetFrameSize uint64, targetNumFrames int, approx
return
c
,
nil
}
func
(
t
*
TargetSize
Compressor
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
func
(
t
*
Ratio
Compressor
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
if
err
:=
t
.
FullErr
();
err
!=
nil
{
return
0
,
err
}
...
...
@@ -51,29 +56,29 @@ func (t *TargetSizeCompressor) Write(p []byte) (int, error) {
return
t
.
compress
.
Write
(
p
)
}
func
(
t
*
TargetSize
Compressor
)
Close
()
error
{
func
(
t
*
Ratio
Compressor
)
Close
()
error
{
return
t
.
compress
.
Close
()
}
func
(
t
*
TargetSize
Compressor
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
func
(
t
*
Ratio
Compressor
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
return
t
.
buf
.
Read
(
p
)
}
func
(
t
*
TargetSize
Compressor
)
Reset
()
{
func
(
t
*
Ratio
Compressor
)
Reset
()
{
t
.
buf
.
Reset
()
t
.
compress
.
Reset
(
&
t
.
buf
)
t
.
inputBytes
=
0
}
func
(
t
*
TargetSize
Compressor
)
Len
()
int
{
func
(
t
*
Ratio
Compressor
)
Len
()
int
{
return
t
.
buf
.
Len
()
}
func
(
t
*
TargetSize
Compressor
)
Flush
()
error
{
func
(
t
*
Ratio
Compressor
)
Flush
()
error
{
return
t
.
compress
.
Flush
()
}
func
(
t
*
TargetSize
Compressor
)
FullErr
()
error
{
func
(
t
*
Ratio
Compressor
)
FullErr
()
error
{
if
t
.
inputTargetReached
()
{
return
derive
.
CompressorFullErr
}
...
...
@@ -82,12 +87,12 @@ func (t *TargetSizeCompressor) FullErr() error {
// InputThreshold calculates the input data threshold in bytes from the given
// parameters.
func
(
t
*
TargetSize
Compressor
)
InputThreshold
()
uint64
{
func
(
t
*
Ratio
Compressor
)
InputThreshold
()
uint64
{
return
uint64
(
float64
(
t
.
TargetNumFrames
)
*
float64
(
t
.
TargetFrameSize
)
/
t
.
ApproxComprRatio
)
}
// inputTargetReached says whether the target amount of input data has been
// reached in this channel builder. No more blocks can be added afterwards.
func
(
t
*
TargetSize
Compressor
)
inputTargetReached
()
bool
{
func
(
t
*
Ratio
Compressor
)
inputTargetReached
()
bool
{
return
uint64
(
t
.
inputBytes
)
>=
t
.
InputThreshold
()
}
op-batcher/batcher/
target_size
_compressor_test.go
→
op-batcher/batcher/
ratio
_compressor_test.go
View file @
93be57b9
...
...
@@ -123,11 +123,11 @@ func TestInputThreshold(t *testing.T) {
TargetFrameSize
:
tt
.
input
.
TargetFrameSize
,
TargetNumFrames
:
tt
.
input
.
TargetNumFrames
,
ApproxComprRatio
:
tt
.
input
.
ApproxComprRatio
,
CompressorKind
:
flags
.
CompressorTarget
,
CompressorKind
:
flags
.
RatioCompressorKind
,
}
comp
,
err
:=
config
.
NewCompressor
()
require
.
NoError
(
t
,
err
)
got
:=
comp
.
(
*
batcher
.
TargetSize
Compressor
)
.
InputThreshold
()
got
:=
comp
.
(
*
batcher
.
Ratio
Compressor
)
.
InputThreshold
()
tt
.
assertion
(
got
)
}
}
op-batcher/batcher/shadow_compressor.go
View file @
93be57b9
...
...
@@ -26,6 +26,13 @@ type ShadowCompressor struct {
fullErr
error
}
// NewShadowCompressor creates a new derive.Compressor implementation that contains two
// compression buffers: one used for size estimation, and one used for the final
// compressed output. The first is flushed on every write, the second isn't, which means
// the final compressed data is always slightly smaller than the target. There is one
// exception to this rule: the first write to the buffer is not checked against the
// target, which allows individual blocks larger than the target to be included (and will
// be split across multiple channel frames).
func
NewShadowCompressor
(
targetFrameSize
uint64
,
targetNumFrames
int
)
(
derive
.
Compressor
,
error
)
{
c
:=
&
ShadowCompressor
{
TargetFrameSize
:
targetFrameSize
,
...
...
op-batcher/flags/flags.go
View file @
93be57b9
...
...
@@ -92,7 +92,7 @@ var (
flags
.
EnumString
[
CompressorKind
](
CompressorKinds
),
EnvVar
:
opservice
.
PrefixEnvVar
(
EnvVarPrefix
,
"COMPRESSOR"
),
Value
:
func
()
*
CompressorKind
{
out
:=
CompressorTarget
out
:=
RatioCompressorKind
return
&
out
}(),
}
...
...
@@ -152,13 +152,17 @@ func CheckRequired(ctx *cli.Context) error {
type
CompressorKind
string
const
(
CompressorTarget
CompressorKind
=
"target"
CompressorShadow
CompressorKind
=
"shadow"
// The RatioCompressorKind kind selects the batcher.RatioCompressor (see
// batcher.NewRatioCompressor for a description).
RatioCompressorKind
CompressorKind
=
"ratio"
// The ShadowCompressorKind kind selects the batcher.ShadowCompressor (see
// batcher.NewShadowCompressor for a description).
ShadowCompressorKind
CompressorKind
=
"shadow"
)
var
CompressorKinds
=
[]
CompressorKind
{
CompressorTarget
,
CompressorShadow
,
RatioCompressorKind
,
ShadowCompressorKind
,
}
func
(
kind
CompressorKind
)
String
()
string
{
...
...
op-e2e/actions/l2_batcher.go
View file @
93be57b9
...
...
@@ -134,7 +134,7 @@ func (s *L2Batcher) Buffer(t Testing) error {
if
s
.
l2BatcherCfg
.
GarbageCfg
!=
nil
{
ch
,
err
=
NewGarbageChannelOut
(
s
.
l2BatcherCfg
.
GarbageCfg
)
}
else
{
c
,
e
:=
batcher
.
New
TargetSize
Compressor
(
s
.
l2BatcherCfg
.
MaxL1TxSize
,
1
,
1
)
c
,
e
:=
batcher
.
New
Ratio
Compressor
(
s
.
l2BatcherCfg
.
MaxL1TxSize
,
1
,
1
)
require
.
NoError
(
t
,
e
,
"failed to create compressor"
)
ch
,
err
=
derive
.
NewChannelOut
(
c
)
}
...
...
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