Commit 006002aa authored by Sebastian Stammler's avatar Sebastian Stammler Committed by GitHub

Rename derive.CompressorFullErr to conventional ErrCompressorFull (#9936)

parent 7340cb39
...@@ -154,7 +154,7 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro ...@@ -154,7 +154,7 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro
return l1info, fmt.Errorf("converting block to batch: %w", err) return l1info, fmt.Errorf("converting block to batch: %w", err)
} }
if _, err = c.co.AddSingularBatch(batch, l1info.SequenceNumber); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.CompressorFullErr) { if _, err = c.co.AddSingularBatch(batch, l1info.SequenceNumber); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.ErrCompressorFull) {
c.setFullErr(err) c.setFullErr(err)
return l1info, c.FullErr() return l1info, c.FullErr()
} else if err != nil { } else if err != nil {
...@@ -253,7 +253,7 @@ func (c *ChannelBuilder) IsFull() bool { ...@@ -253,7 +253,7 @@ func (c *ChannelBuilder) IsFull() bool {
// //
// It returns a ChannelFullError wrapping one of the following possible reasons // It returns a ChannelFullError wrapping one of the following possible reasons
// for the channel being full: // for the channel being full:
// - derive.CompressorFullErr if the compressor target has been reached, // - derive.ErrCompressorFull if the compressor target has been reached,
// - derive.MaxRLPBytesPerChannel if the general maximum amount of input data // - derive.MaxRLPBytesPerChannel if the general maximum amount of input data
// would have been exceeded by the latest AddBlock call, // would have been exceeded by the latest AddBlock call,
// - ErrMaxFrameIndex if the maximum number of frames has been generated // - ErrMaxFrameIndex if the maximum number of frames has been generated
......
...@@ -452,7 +452,7 @@ func TestChannelBuilder_OutputFrames_SpanBatch(t *testing.T) { ...@@ -452,7 +452,7 @@ func TestChannelBuilder_OutputFrames_SpanBatch(t *testing.T) {
// There should be no ready bytes until the channel is full // There should be no ready bytes until the channel is full
require.Equal(t, cb.co.ReadyBytes(), 0) require.Equal(t, cb.co.ReadyBytes(), 0)
} else { } else {
require.ErrorIs(t, err, derive.CompressorFullErr) require.ErrorIs(t, err, derive.ErrCompressorFull)
break break
} }
} }
...@@ -516,7 +516,7 @@ func ChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T, batchType uint) { ...@@ -516,7 +516,7 @@ func ChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T, batchType uint) {
_, err = cb.AddBlock(a) _, err = cb.AddBlock(a)
if cb.IsFull() { if cb.IsFull() {
fullErr := cb.FullErr() fullErr := cb.FullErr()
require.ErrorIs(t, fullErr, derive.CompressorFullErr) require.ErrorIs(t, fullErr, derive.ErrCompressorFull)
break break
} }
require.NoError(t, err) require.NoError(t, err)
...@@ -550,7 +550,7 @@ func TestChannelBuilder_FullShadowCompressor(t *testing.T) { ...@@ -550,7 +550,7 @@ func TestChannelBuilder_FullShadowCompressor(t *testing.T) {
_, err = cb.AddBlock(a) _, err = cb.AddBlock(a)
require.NoError(err) require.NoError(err)
_, err = cb.AddBlock(a) _, err = cb.AddBlock(a)
require.ErrorIs(err, derive.CompressorFullErr) require.ErrorIs(err, derive.ErrCompressorFull)
// without fix, adding the second block would succeed and then adding a // without fix, adding the second block would succeed and then adding a
// third block would fail with full error and the compressor would be full. // third block would fail with full error and the compressor would be full.
...@@ -593,7 +593,7 @@ func ChannelBuilder_AddBlock(t *testing.T, batchType uint) { ...@@ -593,7 +593,7 @@ func ChannelBuilder_AddBlock(t *testing.T, batchType uint) {
// Since the channel output is full, the next call to AddBlock // Since the channel output is full, the next call to AddBlock
// should return the channel out full error // should return the channel out full error
require.ErrorIs(t, addMiniBlock(cb), derive.CompressorFullErr) require.ErrorIs(t, addMiniBlock(cb), derive.ErrCompressorFull)
} }
func TestChannelBuilder_CheckTimeout(t *testing.T) { func TestChannelBuilder_CheckTimeout(t *testing.T) {
...@@ -782,7 +782,7 @@ func ChannelBuilder_OutputBytes(t *testing.T, batchType uint) { ...@@ -782,7 +782,7 @@ func ChannelBuilder_OutputBytes(t *testing.T, batchType uint) {
for { for {
block := dtest.RandomL2BlockWithChainId(rng, rng.Intn(32), defaultTestRollupConfig.L2ChainID) block := dtest.RandomL2BlockWithChainId(rng, rng.Intn(32), defaultTestRollupConfig.L2ChainID)
_, err := cb.AddBlock(block) _, err := cb.AddBlock(block)
if errors.Is(err, derive.CompressorFullErr) { if errors.Is(err, derive.ErrCompressorFull) {
break break
} }
require.NoError(err) require.NoError(err)
......
...@@ -45,7 +45,7 @@ func (t *NonCompressor) Write(p []byte) (int, error) { ...@@ -45,7 +45,7 @@ func (t *NonCompressor) Write(p []byte) (int, error) {
return 0, err return 0, err
} }
if uint64(t.buf.Len()) > t.config.TargetOutputSize { if uint64(t.buf.Len()) > t.config.TargetOutputSize {
t.fullErr = derive.CompressorFullErr t.fullErr = derive.ErrCompressorFull
} }
return n, nil return n, nil
} }
......
...@@ -66,7 +66,7 @@ func (t *RatioCompressor) Flush() error { ...@@ -66,7 +66,7 @@ func (t *RatioCompressor) Flush() error {
func (t *RatioCompressor) FullErr() error { func (t *RatioCompressor) FullErr() error {
if t.inputTargetReached() { if t.inputTargetReached() {
return derive.CompressorFullErr return derive.ErrCompressorFull
} }
return nil return nil
} }
......
...@@ -76,7 +76,7 @@ func (t *ShadowCompressor) Write(p []byte) (int, error) { ...@@ -76,7 +76,7 @@ func (t *ShadowCompressor) Write(p []byte) (int, error) {
} }
newBound = uint64(t.shadowBuf.Len()) + CloseOverheadZlib newBound = uint64(t.shadowBuf.Len()) + CloseOverheadZlib
if newBound > t.config.TargetOutputSize { if newBound > t.config.TargetOutputSize {
t.fullErr = derive.CompressorFullErr t.fullErr = derive.ErrCompressorFull
if t.Len() > 0 { if t.Len() > 0 {
// only return an error if we've already written data to this compressor before // only return an error if we've already written data to this compressor before
// (otherwise single blocks over the target would never be written) // (otherwise single blocks over the target would never be written)
......
...@@ -41,19 +41,19 @@ func TestShadowCompressor(t *testing.T) { ...@@ -41,19 +41,19 @@ func TestShadowCompressor(t *testing.T) {
targetOutputSize: 1 + derive.FrameV0OverHeadSize, targetOutputSize: 1 + derive.FrameV0OverHeadSize,
data: [][]byte{bytes.Repeat([]byte{0}, 1024)}, data: [][]byte{bytes.Repeat([]byte{0}, 1024)},
errs: []error{nil}, errs: []error{nil},
fullErr: derive.CompressorFullErr, fullErr: derive.ErrCompressorFull,
}, { }, {
name: "large second block", name: "large second block",
targetOutputSize: 1 + derive.FrameV0OverHeadSize, targetOutputSize: 1 + derive.FrameV0OverHeadSize,
data: [][]byte{bytes.Repeat([]byte{0}, 512), bytes.Repeat([]byte{0}, 1024)}, data: [][]byte{bytes.Repeat([]byte{0}, 512), bytes.Repeat([]byte{0}, 1024)},
errs: []error{nil, derive.CompressorFullErr}, errs: []error{nil, derive.ErrCompressorFull},
fullErr: derive.CompressorFullErr, fullErr: derive.ErrCompressorFull,
}, { }, {
name: "random data", name: "random data",
targetOutputSize: 1 << 17, targetOutputSize: 1 << 17,
data: [][]byte{randomBytes((1 << 17) - 1000), randomBytes(512), randomBytes(512)}, data: [][]byte{randomBytes((1 << 17) - 1000), randomBytes(512), randomBytes(512)},
errs: []error{nil, nil, derive.CompressorFullErr}, errs: []error{nil, nil, derive.ErrCompressorFull},
fullErr: derive.CompressorFullErr, fullErr: derive.ErrCompressorFull,
}} }}
for _, test := range tests { for _, test := range tests {
test := test test := test
......
...@@ -515,7 +515,7 @@ func BigL2Txs(gt *testing.T, deltaTimeOffset *hexutil.Uint64) { ...@@ -515,7 +515,7 @@ func BigL2Txs(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
sequencer.ActL2EndBlock(t) sequencer.ActL2EndBlock(t)
for batcher.l2BufferedBlock.Number < sequencer.SyncStatus().UnsafeL2.Number { for batcher.l2BufferedBlock.Number < sequencer.SyncStatus().UnsafeL2.Number {
// if we run out of space, close the channel and submit all the txs // if we run out of space, close the channel and submit all the txs
if err := batcher.Buffer(t); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.CompressorFullErr) { if err := batcher.Buffer(t); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.ErrCompressorFull) {
log.Info("flushing filled channel to batch txs", "id", batcher.l2ChannelOut.ID()) log.Info("flushing filled channel to batch txs", "id", batcher.l2ChannelOut.ID())
batcher.ActL2ChannelClose(t) batcher.ActL2ChannelClose(t)
for batcher.l2ChannelOut != nil { for batcher.l2ChannelOut != nil {
......
...@@ -13,10 +13,13 @@ import ( ...@@ -13,10 +13,13 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
var ErrMaxFrameSizeTooSmall = errors.New("maxSize is too small to fit the fixed frame overhead") var (
var ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx") ErrMaxFrameSizeTooSmall = errors.New("maxSize is too small to fit the fixed frame overhead")
var ErrTooManyRLPBytes = errors.New("batch would cause RLP bytes to go over limit") ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx")
var ErrChannelOutAlreadyClosed = errors.New("channel-out already closed") ErrTooManyRLPBytes = errors.New("batch would cause RLP bytes to go over limit")
ErrChannelOutAlreadyClosed = errors.New("channel-out already closed")
ErrCompressorFull = errors.New("compressor is full")
)
// FrameV0OverHeadSize is the absolute minimum size of a frame. // FrameV0OverHeadSize is the absolute minimum size of a frame.
// This is the fixed overhead frame size, calculated as specified // This is the fixed overhead frame size, calculated as specified
...@@ -25,11 +28,9 @@ var ErrChannelOutAlreadyClosed = errors.New("channel-out already closed") ...@@ -25,11 +28,9 @@ var ErrChannelOutAlreadyClosed = errors.New("channel-out already closed")
// [Frame Format]: https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/derivation.md#frame-format // [Frame Format]: https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/derivation.md#frame-format
const FrameV0OverHeadSize = 23 const FrameV0OverHeadSize = 23
var CompressorFullErr = errors.New("compressor is full")
type Compressor interface { type Compressor interface {
// Writer is used to write uncompressed data which will be compressed. Should return // Writer is used to write uncompressed data which will be compressed. Should return
// CompressorFullErr if the compressor is full and no more data should be written. // ErrCompressorFull if the compressor is full and no more data should be written.
io.Writer io.Writer
// Closer Close function should be called before reading any data. // Closer Close function should be called before reading any data.
io.Closer io.Closer
...@@ -43,9 +44,9 @@ type Compressor interface { ...@@ -43,9 +44,9 @@ type Compressor interface {
// Flush flushes any uncompressed data to the compression buffer. This will result in a // Flush flushes any uncompressed data to the compression buffer. This will result in a
// non-optimal compression ratio. // non-optimal compression ratio.
Flush() error Flush() error
// FullErr returns CompressorFullErr if the compressor is known to be full. Note that // FullErr returns ErrCompressorFull if the compressor is known to be full. Note that
// calls to Write will fail if an error is returned from this method, but calls to Write // calls to Write will fail if an error is returned from this method, but calls to Write
// can still return CompressorFullErr even if this does not. // can still return ErrCompressorFull even if this does not.
FullErr() error FullErr() error
} }
......
...@@ -138,7 +138,7 @@ func (co *SpanChannelOut) AddSingularBatch(batch *SingularBatch, seqNum uint64) ...@@ -138,7 +138,7 @@ func (co *SpanChannelOut) AddSingularBatch(batch *SingularBatch, seqNum uint64)
if co.compress.FullErr() != nil { if co.compress.FullErr() != nil {
err = co.compress.FullErr() err = co.compress.FullErr()
if co.spanBatchBuilder.GetBlockCount() == 1 { if co.spanBatchBuilder.GetBlockCount() == 1 {
// Do not return CompressorFullErr for the first block in the batch // Do not return ErrCompressorFull for the first block in the batch
// In this case, reader must be empty. then the contents of compressor will be copied to reader when the channel is closed. // In this case, reader must be empty. then the contents of compressor will be copied to reader when the channel is closed.
err = nil err = nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment