Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-batcher: prevent SpanChannelOut RLP bytes overflowing MaxRLPBytesPerChannel #14310

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions op-node/rollup/derive/channel_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,29 @@ func testSpanChannelOut_MaxBlocksPerSpanBatch(t *testing.T, tt maxBlocksTest) {
require.Equalf(t, batch0, batch, "iteration %d", i)
}
}

func TestSpanChannelOut_ExceedMaxRLPBytesPerChannel(t *testing.T) {
for _, algo := range CompressionAlgos {
t.Run("testSpanChannelOut_ExceedMaxRLPBytesPerChannel_"+algo.String(), func(t *testing.T) {
testSpanChannelOut_ExceedMaxRLPBytesPerChannel(t, algo)
})
}
}

func testSpanChannelOut_ExceedMaxRLPBytesPerChannel(t *testing.T, algo CompressionAlgo) {

largeBatchSize := int(rollup.NewChainSpec(&rollupCfg).MaxRLPBytesPerChannel(0))
cout, singularBatches := SpanChannelAndBatches(t, 100, 1, algo)

cout.rlp[0] = bytes.NewBuffer(make([]byte, largeBatchSize))
cout.rlp[1] = bytes.NewBuffer(make([]byte, largeBatchSize))
cout.sealedRLPBytes = largeBatchSize

for _, batch := range singularBatches {
err := cout.addSingularBatch(batch, 1)
require.ErrorIs(t, err, ErrTooManyRLPBytes)
}

require.Equal(t, cout.activeRLP().Len(), largeBatchSize)
require.Greater(t, cout.inactiveRLP().Len(), largeBatchSize)
}
1 change: 1 addition & 0 deletions op-node/rollup/derive/span_channel_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (co *SpanChannelOut) addSingularBatch(batch *SingularBatch, seqNum uint64)
// the Fjord activation.
maxRLPBytesPerChannel := co.chainSpec.MaxRLPBytesPerChannel(batch.Timestamp)
if active.Len() > int(maxRLPBytesPerChannel) {
co.swapRLP()
return fmt.Errorf("could not take %d bytes as replacement of channel of %d bytes, max is %d. err: %w",
active.Len(), co.inactiveRLP().Len(), maxRLPBytesPerChannel, ErrTooManyRLPBytes)
}
Expand Down