Commit cd3f554a authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

op-node/rollup/derive: also mark `IsLast` as `true` when `closed &&...

op-node/rollup/derive: also mark `IsLast` as `true` when `closed && maxDataSize==readyBytes` (#9696)

* also mark IsLast as true when maxDataSize==readyBytes

* add TestOutputFrameNoEmptyLastFrame

* fix typo

* fix for review
parent ee216789
...@@ -207,10 +207,10 @@ func (co *GarbageChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) (uint1 ...@@ -207,10 +207,10 @@ func (co *GarbageChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) (uint1
// Fixed overhead: 32 + 8 + 2 + 4 + 1 = 47 bytes. // Fixed overhead: 32 + 8 + 2 + 4 + 1 = 47 bytes.
// Add one extra byte for the version byte (for the entire L1 tx though) // Add one extra byte for the version byte (for the entire L1 tx though)
maxDataSize := maxSize - 47 - 1 maxDataSize := maxSize - 47 - 1
if maxDataSize > uint64(co.buf.Len()) { if maxDataSize >= uint64(co.buf.Len()) {
maxDataSize = uint64(co.buf.Len()) maxDataSize = uint64(co.buf.Len())
// If we are closed & will not spill past the current frame // If we are closed & will not spill past the current frame
// mark it is the final frame of the channel. // mark it as the final frame of the channel.
if co.closed { if co.closed {
f.IsLast = true f.IsLast = true
} }
......
...@@ -322,10 +322,10 @@ func createEmptyFrame(id ChannelID, frame uint64, readyBytes int, closed bool, m ...@@ -322,10 +322,10 @@ func createEmptyFrame(id ChannelID, frame uint64, readyBytes int, closed bool, m
// Copy data from the local buffer into the frame data buffer // Copy data from the local buffer into the frame data buffer
maxDataSize := maxSize - FrameV0OverHeadSize maxDataSize := maxSize - FrameV0OverHeadSize
if maxDataSize > uint64(readyBytes) { if maxDataSize >= uint64(readyBytes) {
maxDataSize = uint64(readyBytes) maxDataSize = uint64(readyBytes)
// If we are closed & will not spill past the current frame // If we are closed & will not spill past the current frame
// mark it is the final frame of the channel. // mark it as the final frame of the channel.
if closed { if closed {
f.IsLast = true f.IsLast = true
} }
......
...@@ -2,7 +2,9 @@ package derive ...@@ -2,7 +2,9 @@ package derive
import ( import (
"bytes" "bytes"
"io"
"math/big" "math/big"
"math/rand"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -68,6 +70,27 @@ func TestOutputFrameSmallMaxSize(t *testing.T) { ...@@ -68,6 +70,27 @@ func TestOutputFrameSmallMaxSize(t *testing.T) {
} }
} }
func TestOutputFrameNoEmptyLastFrame(t *testing.T) {
cout, err := NewChannelOut(SingularBatchType, &nonCompressor{}, nil)
require.NoError(t, err)
rng := rand.New(rand.NewSource(0x543331))
chainID := big.NewInt(rng.Int63n(1000))
txCount := 1
singularBatch := RandomSingularBatch(rng, txCount, chainID)
written, err := cout.AddSingularBatch(singularBatch, 0)
require.NoError(t, err)
require.NoError(t, cout.Close())
var buf bytes.Buffer
// Output a frame which needs exactly `written` bytes. This frame is expected to be the last frame.
_, err = cout.OutputFrame(&buf, written+FrameV0OverHeadSize)
require.ErrorIs(t, err, io.EOF)
}
// TestRLPByteLimit ensures that stream encoder is properly limiting the length. // TestRLPByteLimit ensures that stream encoder is properly limiting the length.
// It will decode the input if `len(input) <= inputLimit`. // It will decode the input if `len(input) <= inputLimit`.
func TestRLPByteLimit(t *testing.T) { func TestRLPByteLimit(t *testing.T) {
......
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