Commit e03b5073 authored by Sebastian Stammler's avatar Sebastian Stammler

op-batcher: Reorder channel builder types

parent 8d5109e7
...@@ -11,80 +11,60 @@ import ( ...@@ -11,80 +11,60 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
) )
type ( type ChannelConfig struct {
// channelBuilder uses a ChannelOut to create a channel with output frame // Number of epochs (L1 blocks) per sequencing window, including the epoch
// size approximation. // L1 origin block itself
channelBuilder struct { SeqWindowSize uint64
cfg ChannelConfig // The maximum number of L1 blocks that the inclusion transactions of a
// channel's frames can span.
// L1 block timestamp of combined channel & sequencing window timeout. 0 if ChannelTimeout uint64
// no timeout set yet. // The batcher tx submission safety margin (in #L1-blocks) to subtract from
timeout uint64 // a channel's timeout and sequencing window, to guarantee safe inclusion of
// a channel on L1.
// marked as full if a) max RLP input bytes, b) max num frames or c) max SubSafetyMargin uint64
// allowed frame index (uint16) has been reached // The maximum byte-size a frame can have.
fullErr error MaxFrameSize uint64
// current channel // The target number of frames to create per channel. Note that if the
co *derive.ChannelOut // realized compression ratio is worse than the approximate, more frames may
// list of blocks in the channel. Saved in case the channel must be rebuilt // actually be created. This also depends on how close TargetFrameSize is to
blocks []*types.Block // MaxFrameSize.
// frames data queue, to be send as txs TargetFrameSize uint64
frames []taggedData // The target number of frames to create in this channel. If the realized
} // compression ratio is worse than approxComprRatio, additional leftover
// frame(s) might get created.
ChannelConfig struct { TargetNumFrames int
// Number of epochs (L1 blocks) per sequencing window, including the epoch // Approximated compression ratio to assume. Should be slightly smaller than
// L1 origin block itself // average from experiments to avoid the chances of creating a small
SeqWindowSize uint64 // additional leftover frame.
// The maximum number of L1 blocks that the inclusion transactions of a ApproxComprRatio float64
// channel's frames can span.
ChannelTimeout uint64
// The batcher tx submission safety margin (in #L1-blocks) to subtract from
// a channel's timeout and sequencing window, to guarantee safe inclusion of
// a channel on L1.
SubSafetyMargin uint64
// The maximum byte-size a frame can have.
MaxFrameSize uint64
// The target number of frames to create per channel. 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
// MaxFrameSize.
TargetFrameSize uint64
// The target number of frames to create in this channel. If the realized
// compression ratio is worse than approxComprRatio, additional leftover
// frame(s) might get created.
TargetNumFrames int
// Approximated compression ratio to assume. Should be slightly smaller than
// average from experiments to avoid the chances of creating a small
// additional leftover frame.
ApproxComprRatio float64
}
ChannelFullError struct {
Err error
}
)
func (e *ChannelFullError) Error() string {
return "channel full: " + e.Err.Error()
} }
func (e *ChannelFullError) Unwrap() error {
return e.Err
}
var (
ErrInputTargetReached = errors.New("target amount of input data reached")
ErrMaxFrameIndex = errors.New("max frame index reached (uint16)")
ErrChannelTimedOut = errors.New("channel timed out")
)
// InputThreshold calculates the input data threshold in bytes from the given // InputThreshold calculates the input data threshold in bytes from the given
// parameters. // parameters.
func (c ChannelConfig) InputThreshold() uint64 { func (c ChannelConfig) InputThreshold() uint64 {
return uint64(float64(c.TargetNumFrames) * float64(c.TargetFrameSize) / c.ApproxComprRatio) return uint64(float64(c.TargetNumFrames) * float64(c.TargetFrameSize) / c.ApproxComprRatio)
} }
// channelBuilder uses a ChannelOut to create a channel with output frame
// size approximation.
type channelBuilder struct {
cfg ChannelConfig
// L1 block timestamp of combined channel & sequencing window timeout. 0 if
// no timeout set yet.
timeout uint64
// marked as full if a) max RLP input bytes, b) max num frames or c) max
// allowed frame index (uint16) has been reached
fullErr error
// current channel
co *derive.ChannelOut
// list of blocks in the channel. Saved in case the channel must be rebuilt
blocks []*types.Block
// frames data queue, to be send as txs
frames []taggedData
}
func newChannelBuilder(cfg ChannelConfig) (*channelBuilder, error) { func newChannelBuilder(cfg ChannelConfig) (*channelBuilder, error) {
co, err := derive.NewChannelOut() co, err := derive.NewChannelOut()
if err != nil { if err != nil {
...@@ -336,3 +316,21 @@ func (c *channelBuilder) PushFrame(id txID, frame []byte) { ...@@ -336,3 +316,21 @@ func (c *channelBuilder) PushFrame(id txID, frame []byte) {
} }
c.frames = append(c.frames, taggedData{id: id, data: frame}) c.frames = append(c.frames, taggedData{id: id, data: frame})
} }
var (
ErrInputTargetReached = errors.New("target amount of input data reached")
ErrMaxFrameIndex = errors.New("max frame index reached (uint16)")
ErrChannelTimedOut = errors.New("channel timed out")
)
type ChannelFullError struct {
Err error
}
func (e *ChannelFullError) Error() string {
return "channel full: " + e.Err.Error()
}
func (e *ChannelFullError) Unwrap() error {
return e.Err
}
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