Commit 418d7999 authored by Sebastian Stammler's avatar Sebastian Stammler

op-batcher: channelBuilder: Use ChannelOut.InputBytes

Better than replicating state.
parent 5b4c4822
...@@ -17,8 +17,6 @@ type ( ...@@ -17,8 +17,6 @@ type (
channelBuilder struct { channelBuilder struct {
cfg ChannelConfig cfg ChannelConfig
// tracks total input data rlp bytes
inputSize uint64
// marked as full if a) max RLP input bytes, b) max num frames or c) max // marked as full if a) max RLP input bytes, b) max num frames or c) max
// allowed frame index (uint16) has been reached // allowed frame index (uint16) has been reached
fullErr error fullErr error
...@@ -98,7 +96,6 @@ func (c *channelBuilder) Blocks() []*types.Block { ...@@ -98,7 +96,6 @@ func (c *channelBuilder) Blocks() []*types.Block {
} }
func (c *channelBuilder) Reset() error { func (c *channelBuilder) Reset() error {
c.inputSize = 0
c.blocks = c.blocks[:0] c.blocks = c.blocks[:0]
c.frames = c.frames[:0] c.frames = c.frames[:0]
return c.co.Reset() return c.co.Reset()
...@@ -117,14 +114,13 @@ func (c *channelBuilder) AddBlock(block *types.Block) error { ...@@ -117,14 +114,13 @@ func (c *channelBuilder) AddBlock(block *types.Block) error {
return c.FullErr() return c.FullErr()
} }
rlpsize, err := c.co.AddBlock(block) _, err := c.co.AddBlock(block)
if errors.Is(err, derive.ErrTooManyRLPBytes) { if errors.Is(err, derive.ErrTooManyRLPBytes) {
c.setFullErr(err) c.setFullErr(err)
return c.FullErr() return c.FullErr()
} else if err != nil { } else if err != nil {
return fmt.Errorf("adding block to channel out: %w", err) return fmt.Errorf("adding block to channel out: %w", err)
} }
c.inputSize += rlpsize
c.blocks = append(c.blocks, block) c.blocks = append(c.blocks, block)
if c.InputTargetReached() { if c.InputTargetReached() {
...@@ -138,7 +134,7 @@ func (c *channelBuilder) AddBlock(block *types.Block) error { ...@@ -138,7 +134,7 @@ func (c *channelBuilder) AddBlock(block *types.Block) error {
// InputTargetReached says whether the target amount of input data has been // InputTargetReached says whether the target amount of input data has been
// reached in this channel builder. No more blocks can be added afterwards. // reached in this channel builder. No more blocks can be added afterwards.
func (c *channelBuilder) InputTargetReached() bool { func (c *channelBuilder) InputTargetReached() bool {
return c.inputSize >= c.cfg.InputThreshold() return uint64(c.co.InputBytes()) >= c.cfg.InputThreshold()
} }
// IsFull returns whether the channel is full. // IsFull returns whether the channel is full.
......
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