Skip to content

Commit 58dfa9d

Browse files
committed
Embed Compressor Logic directly to Span Channel Out
1 parent c70c69d commit 58dfa9d

File tree

7 files changed

+168
-105
lines changed

7 files changed

+168
-105
lines changed

op-batcher/compressor/blind_compressor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func NewBlindCompressor(config Config) (derive.Compressor, error) {
3333
return c, nil
3434
}
3535

36+
func (t *BlindCompressor) TargetOutputSize() uint64 {
37+
return t.config.TargetOutputSize
38+
}
39+
3640
func (t *BlindCompressor) Write(p []byte) (int, error) {
3741
if err := t.FullErr(); err != nil {
3842
return 0, err

op-batcher/compressor/non_compressor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func NewNonCompressor(config Config) (derive.Compressor, error) {
3636
return c, nil
3737
}
3838

39+
func (t *NonCompressor) TargetOutputSize() uint64 {
40+
return t.config.TargetOutputSize
41+
}
42+
3943
func (t *NonCompressor) Write(p []byte) (int, error) {
4044
if err := t.compress.Flush(); err != nil {
4145
return 0, err

op-batcher/compressor/ratio_compressor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func NewRatioCompressor(config Config) (derive.Compressor, error) {
3434
return c, nil
3535
}
3636

37+
func (t *RatioCompressor) TargetOutputSize() uint64 {
38+
return t.config.TargetOutputSize
39+
}
40+
3741
func (t *RatioCompressor) Write(p []byte) (int, error) {
3842
if err := t.FullErr(); err != nil {
3943
return 0, err

op-batcher/compressor/shadow_compressor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func NewShadowCompressor(config Config) (derive.Compressor, error) {
5858
return c, nil
5959
}
6060

61+
func (t *ShadowCompressor) TargetOutputSize() uint64 {
62+
return t.config.TargetOutputSize
63+
}
64+
6165
func (t *ShadowCompressor) Write(p []byte) (int, error) {
6266
if t.fullErr != nil {
6367
return 0, t.fullErr

op-node/rollup/derive/channel_out.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type Compressor interface {
4848
// calls to Write will fail if an error is returned from this method, but calls to Write
4949
// can still return ErrCompressorFull even if this does not.
5050
FullErr() error
51+
// TargetOutputSize returns the target size of the compressed output
52+
TargetOutputSize() uint64
5153
}
5254

5355
type ChannelOut interface {
@@ -68,7 +70,7 @@ func NewChannelOut(batchType uint, compress Compressor, spanBatch *SpanBatch) (C
6870
case SingularBatchType:
6971
return NewSingularChannelOut(compress)
7072
case SpanBatchType:
71-
return NewSpanChannelOut(compress, spanBatch)
73+
return NewSpanChannelOut(spanBatch.GenesisTimestamp, spanBatch.ChainID, compress.TargetOutputSize())
7274
default:
7375
return nil, fmt.Errorf("unrecognized batch type: %d", batchType)
7476
}

op-node/rollup/derive/channel_out_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func (s *nonCompressor) FullErr() error {
3636
return nil
3737
}
3838

39+
func (t *nonCompressor) TargetOutputSize() uint64 {
40+
return 0
41+
}
42+
3943
func TestChannelOutAddBlock(t *testing.T) {
4044
cout, err := NewChannelOut(SingularBatchType, &nonCompressor{}, nil)
4145
require.NoError(t, err)

0 commit comments

Comments
 (0)