Skip to content

Commit

Permalink
address @ajsutton review
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianst committed Oct 14, 2024
1 parent 59516e5 commit 625f355
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
20 changes: 11 additions & 9 deletions op-node/rollup/derive/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const (
// channel may mark itself as ready for reading once all intervening frames have been added
type Channel struct {
// id of the channel
id ChannelID
openBlock eth.L1BlockRef
holocene bool
id ChannelID
openBlock eth.L1BlockRef
requireInOrder bool

// estimated memory size, used to drop the channel if we have too much data
size uint64
Expand All @@ -47,12 +47,14 @@ type Channel struct {
highestL1InclusionBlock eth.L1BlockRef
}

func NewChannel(id ChannelID, openBlock eth.L1BlockRef, holocene bool) *Channel {
// NewChannel creates a new channel with the given id and openening block. If requireInOrder is
// true, frames must be added in order.
func NewChannel(id ChannelID, openBlock eth.L1BlockRef, requireInOrder bool) *Channel {
return &Channel{
id: id,
inputs: make(map[uint64]Frame),
openBlock: openBlock,
holocene: holocene,
id: id,
inputs: make(map[uint64]Frame),
openBlock: openBlock,
requireInOrder: requireInOrder,
}
}

Expand All @@ -73,7 +75,7 @@ func (ch *Channel) AddFrame(frame Frame, l1InclusionBlock eth.L1BlockRef) error
if ch.closed && frame.FrameNumber >= ch.endFrameNumber {
return fmt.Errorf("frame number (%d) is greater than or equal to end frame number (%d) of a closed channel", frame.FrameNumber, ch.endFrameNumber)
}
if ch.holocene && int(frame.FrameNumber) != len(ch.inputs) {
if ch.requireInOrder && int(frame.FrameNumber) != len(ch.inputs) {
return fmt.Errorf("frame out of order, expected %d, got %d", len(ch.inputs), frame.FrameNumber)
}

Expand Down
9 changes: 4 additions & 5 deletions op-node/rollup/derive/channel_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package derive

import (
"context"
"errors"
"io"

"github.com/ethereum-optimism/optimism/op-node/rollup"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (cs *ChannelStage) NextData(ctx context.Context) ([]byte, error) {
// Note that if the current channel was already completed, we would have forwarded its data
// already. So we start by reading in frames.
if cs.channel != nil && cs.channel.IsReady() {
panic("unexpected ready channel")
return nil, NewCriticalError(errors.New("unexpected ready channel"))
}

// ingest frames until we either hit an error (probably io.EOF) or complete a channel
Expand Down Expand Up @@ -109,12 +110,10 @@ func (cs *ChannelStage) NextData(ctx context.Context) ([]byte, error) {
ch := cs.channel
// Note that if we exit the frame ingestion loop, we're guaranteed to have a ready channel.
if ch == nil || !ch.IsReady() {
panic("unexpected non-ready channel")
return nil, NewCriticalError(errors.New("unexpected non-ready channel"))
}

cs.resetChannel()
r := ch.Reader()
// error always nil, as we're reading from simple bytes readers
data, _ := io.ReadAll(r)
return data, nil
return io.ReadAll(r)
}

0 comments on commit 625f355

Please sign in to comment.