-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
op-batcher: adjust error handling on pending-channels after close #7683
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e76186a
op-batcher: adjust error handling on pending-channels after close
protolambda 669f30b
op-batcher: fix comment
protolambda c83b05d
Capitalize start of log messages
sebastianst ba15ac6
op-batcher: Add NonCompressor for testing purposes
sebastianst 930548c
op-node/rollup/derive: Return ErrChannelOutAlreadyClosed in SpanChann…
sebastianst 7ad152a
op-batcher: Add back outputFrames call to channelManager.Close
sebastianst 0a9ab58
op-batcher: Improve logging
sebastianst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package compressor | ||
|
||
import ( | ||
"bytes" | ||
"compress/zlib" | ||
|
||
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
) | ||
|
||
type NonCompressor struct { | ||
config Config | ||
|
||
buf bytes.Buffer | ||
compress *zlib.Writer | ||
|
||
fullErr error | ||
} | ||
|
||
// NewNonCompressor creates a new derive.Compressor implementation that doesn't | ||
// compress by using zlib.NoCompression. | ||
// It flushes to the underlying buffer any data from a prior write call. | ||
// This is very unoptimal behavior and should only be used in tests. | ||
// The NonCompressor can be used in tests to create a partially flushed channel. | ||
// If the output buffer size after a write exceeds TargetFrameSize*TargetNumFrames, | ||
// the compressor is marked as full, but the write succeeds. | ||
func NewNonCompressor(config Config) (derive.Compressor, error) { | ||
c := &NonCompressor{ | ||
config: config, | ||
} | ||
|
||
var err error | ||
c.compress, err = zlib.NewWriterLevel(&c.buf, zlib.NoCompression) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return c, nil | ||
} | ||
|
||
func (t *NonCompressor) Write(p []byte) (int, error) { | ||
if err := t.compress.Flush(); err != nil { | ||
return 0, err | ||
} | ||
n, err := t.compress.Write(p) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if uint64(t.buf.Len()) > t.config.TargetFrameSize*uint64(t.config.TargetNumFrames) { | ||
t.fullErr = derive.CompressorFullErr | ||
} | ||
return n, nil | ||
} | ||
|
||
func (t *NonCompressor) Close() error { | ||
return t.compress.Close() | ||
} | ||
|
||
func (t *NonCompressor) Read(p []byte) (int, error) { | ||
return t.buf.Read(p) | ||
} | ||
|
||
func (t *NonCompressor) Reset() { | ||
t.buf.Reset() | ||
t.compress.Reset(&t.buf) | ||
t.fullErr = nil | ||
} | ||
|
||
func (t *NonCompressor) Len() int { | ||
return t.buf.Len() | ||
} | ||
|
||
func (t *NonCompressor) Flush() error { | ||
return t.compress.Flush() | ||
} | ||
|
||
func (t *NonCompressor) FullErr() error { | ||
return t.fullErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package compressor | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNonCompressor(t *testing.T) { | ||
require := require.New(t) | ||
c, err := NewNonCompressor(Config{ | ||
TargetFrameSize: 1000, | ||
TargetNumFrames: 100, | ||
}) | ||
require.NoError(err) | ||
|
||
const dlen = 100 | ||
data := make([]byte, dlen) | ||
rng := rand.New(rand.NewSource(42)) | ||
rng.Read(data) | ||
|
||
n, err := c.Write(data) | ||
require.NoError(err) | ||
require.Equal(n, dlen) | ||
l0 := c.Len() | ||
require.Less(l0, dlen) | ||
require.Equal(7, l0) | ||
sebastianst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.Flush() | ||
l1 := c.Len() | ||
require.Greater(l1, l0) | ||
require.Greater(l1, dlen) | ||
sebastianst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
n, err = c.Write(data) | ||
require.NoError(err) | ||
require.Equal(n, dlen) | ||
l2 := c.Len() | ||
require.Equal(l1+5, l2) | ||
} | ||
sebastianst marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we're marking non-full channels as full specifically so they'll be handled in a certain way. Is that an appropriate use of the marking? I see elsewhere that we emit errors about a "error while closing full channel", and worry that will be confusing if the channel isn't actually full.