Commit 38bc29a5 authored by Sebastian Stammler's avatar Sebastian Stammler

op-batcher: Fix channelManager.addBlocks

The block index handling had multiple bugs.
parent 7d9a635f
...@@ -241,24 +241,27 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.L1BlockRef) error { ...@@ -241,24 +241,27 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.L1BlockRef) error {
// addBlocks adds blocks from the blocks queue to the pending channel until // addBlocks adds blocks from the blocks queue to the pending channel until
// either the queue got exhausted or the channel is full. // either the queue got exhausted or the channel is full.
func (s *channelManager) addBlocks() error { func (s *channelManager) addBlocks() error {
var ( var blocksAdded int
blockidx int var _chFullErr *ChannelFullError // throw away, just for type checking
channelFull bool for i, block := range s.blocks {
) if err := s.pendingChannel.AddBlock(block); errors.As(err, &_chFullErr) {
for ; blockidx < len(s.blocks); blockidx++ { // current block didn't get added because channel is already full
if err := s.pendingChannel.AddBlock(s.blocks[blockidx]); s.pendingChannel.IsFull() {
channelFull = true
break break
} else if err != nil { } else if err != nil {
return fmt.Errorf("adding block[%d] to channel builder: %w", blockidx, err) return fmt.Errorf("adding block[%d] to channel builder: %w", i, err)
}
blocksAdded += 1
// current block got added but channel is now full
if s.pendingChannel.IsFull() {
break
} }
} }
blocksAdded := blockidx + 1
s.log.Debug("Added blocks to channel", s.log.Debug("Added blocks to channel",
"blocks_added", blocksAdded, "blocks_added", blocksAdded,
"channel_full", channelFull, "channel_full", s.pendingChannel.IsFull(),
"blocks_pending", len(s.blocks)-blocksAdded, "blocks_pending", len(s.blocks)-blocksAdded,
"input_bytes", s.pendingChannel.InputBytes(),
) )
if blocksAdded == len(s.blocks) { if blocksAdded == len(s.blocks) {
// all blocks processed, reuse slice // all blocks processed, reuse slice
......
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