Skip to content

Commit 3fdc30a

Browse files
committed
PR Comments
1 parent 703e194 commit 3fdc30a

File tree

9 files changed

+120
-130
lines changed

9 files changed

+120
-130
lines changed

op-batcher/batcher/channel_builder.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,11 @@ func NewChannelBuilder(cfg ChannelConfig, rollupCfg rollup.Config, latestL1Origi
8787
var co derive.ChannelOut
8888
if cfg.BatchType == derive.SpanBatchType {
8989
co, err = derive.NewSpanChannelOut(rollupCfg.Genesis.L2Time, rollupCfg.L2ChainID, cfg.CompressorConfig.TargetOutputSize)
90-
if err != nil {
91-
return nil, err
92-
}
9390
} else {
9491
co, err = derive.NewSingularChannelOut(c)
95-
if err != nil {
96-
return nil, err
97-
}
92+
}
93+
if err != nil {
94+
return nil, fmt.Errorf("creating channel out: %w", err)
9895
}
9996

10097
cb := &ChannelBuilder{
@@ -159,7 +156,7 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro
159156
return l1info, fmt.Errorf("converting block to batch: %w", err)
160157
}
161158

162-
if _, err = c.co.AddSingularBatch(batch, l1info.SequenceNumber); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.ErrCompressorFull) {
159+
if err = c.co.AddSingularBatch(batch, l1info.SequenceNumber); errors.Is(err, derive.ErrTooManyRLPBytes) || errors.Is(err, derive.ErrCompressorFull) {
163160
c.setFullErr(err)
164161
return l1info, c.FullErr()
165162
} else if err != nil {

op-batcher/batcher/channel_builder_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,10 @@ func ChannelBuilder_OutputWrongFramePanic(t *testing.T, batchType uint) {
365365

366366
// Mock the internals of `ChannelBuilder.outputFrame`
367367
// to construct a single frame
368+
// the type of batch does not matter here because we are using it to construct a broken frame
368369
c, err := channelConfig.CompressorConfig.NewCompressor()
369370
require.NoError(t, err)
370-
// co is only created to supply a random ID
371371
co, err := derive.NewSingularChannelOut(c)
372-
373372
require.NoError(t, err)
374373
var buf bytes.Buffer
375374
fn, err := co.OutputFrame(&buf, channelConfig.MaxFrameSize)

op-e2e/actions/garbage_channel_out.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Writer interface {
5454
type ChannelOutIface interface {
5555
ID() derive.ChannelID
5656
Reset() error
57-
AddBlock(rollupCfg *rollup.Config, block *types.Block) (uint64, error)
57+
AddBlock(rollupCfg *rollup.Config, block *types.Block) error
5858
ReadyBytes() int
5959
Flush() error
6060
Close() error
@@ -138,19 +138,19 @@ func (co *GarbageChannelOut) Reset() error {
138138
// error that it returns is ErrTooManyRLPBytes. If this error
139139
// is returned, the channel should be closed and a new one
140140
// should be made.
141-
func (co *GarbageChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Block) (uint64, error) {
141+
func (co *GarbageChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Block) error {
142142
if co.closed {
143-
return 0, errors.New("already closed")
143+
return errors.New("already closed")
144144
}
145145
batch, err := blockToBatch(rollupCfg, block)
146146
if err != nil {
147-
return 0, err
147+
return err
148148
}
149149
// We encode to a temporary buffer to determine the encoded length to
150150
// ensure that the total size of all RLP elements is less than or equal to MAX_RLP_BYTES_PER_CHANNEL
151151
var buf bytes.Buffer
152152
if err := rlp.Encode(&buf, batch); err != nil {
153-
return 0, err
153+
return err
154154
}
155155
if co.cfg.malformRLP {
156156
// Malform the RLP by incrementing the length prefix by 1.
@@ -160,13 +160,13 @@ func (co *GarbageChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Blo
160160
buf.Write(bufBytes)
161161
}
162162
if co.rlpLength+buf.Len() > derive.MaxRLPBytesPerChannel {
163-
return 0, fmt.Errorf("could not add %d bytes to channel of %d bytes, max is %d. err: %w",
163+
return fmt.Errorf("could not add %d bytes to channel of %d bytes, max is %d. err: %w",
164164
buf.Len(), co.rlpLength, derive.MaxRLPBytesPerChannel, derive.ErrTooManyRLPBytes)
165165
}
166166
co.rlpLength += buf.Len()
167167

168-
written, err := io.Copy(co.compress, &buf)
169-
return uint64(written), err
168+
_, err = io.Copy(co.compress, &buf)
169+
return err
170170
}
171171

172172
// ReadyBytes returns the number of bytes that the channel out can immediately output into a frame.

op-e2e/actions/l2_batcher.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,20 @@ func (s *L2Batcher) Buffer(t Testing) error {
197197

198198
if s.l2BatcherCfg.ForceSubmitSingularBatch && s.l2BatcherCfg.ForceSubmitSpanBatch {
199199
t.Fatalf("ForceSubmitSingularBatch and ForceSubmitSpanBatch cannot be set to true at the same time")
200-
} else if s.l2BatcherCfg.ForceSubmitSingularBatch {
201-
// use SingularBatchType
202-
ch, err = derive.NewSingularChannelOut(c)
203-
} else if s.l2BatcherCfg.ForceSubmitSpanBatch || s.rollupCfg.IsDelta(block.Time()) {
204-
// If both ForceSubmitSingularBatch and ForceSubmitSpanbatch are false, use SpanBatch automatically if Delta HF is activated.
205-
ch, err = derive.NewSpanChannelOut(s.rollupCfg.Genesis.L2Time, s.rollupCfg.L2ChainID, target)
206200
} else {
207-
// default to SingularBatchType if no other conditions are met
208-
ch, err = derive.NewSingularChannelOut(c)
201+
// use span batch if we're forcing it or if we're at/beyond delta
202+
if s.l2BatcherCfg.ForceSubmitSpanBatch || s.rollupCfg.IsDelta(block.Time()) {
203+
ch, err = derive.NewSpanChannelOut(s.rollupCfg.Genesis.L2Time, s.rollupCfg.L2ChainID, target)
204+
// use singular batches in all other cases
205+
} else {
206+
ch, err = derive.NewSingularChannelOut(c)
207+
}
209208
}
210209
}
211210
require.NoError(t, err, "failed to create channel")
212211
s.l2ChannelOut = ch
213212
}
214-
if _, err := s.l2ChannelOut.AddBlock(s.rollupCfg, block); err != nil {
213+
if err := s.l2ChannelOut.AddBlock(s.rollupCfg, block); err != nil {
215214
return err
216215
}
217216
ref, err := s.engCl.L2BlockRefByHash(t.Ctx(), block.Hash())

op-e2e/actions/sync_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestBackupUnsafe(gt *testing.T) {
243243
block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{})
244244
}
245245
// Add A1, B2, B3, B4, B5 into the channel
246-
_, err = channelOut.AddBlock(sd.RollupCfg, block)
246+
err = channelOut.AddBlock(sd.RollupCfg, block)
247247
require.NoError(t, err)
248248
}
249249

@@ -406,7 +406,7 @@ func TestBackupUnsafeReorgForkChoiceInputError(gt *testing.T) {
406406
block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{})
407407
}
408408
// Add A1, B2, B3, B4, B5 into the channel
409-
_, err = channelOut.AddBlock(sd.RollupCfg, block)
409+
err = channelOut.AddBlock(sd.RollupCfg, block)
410410
require.NoError(t, err)
411411
}
412412

@@ -545,7 +545,7 @@ func TestBackupUnsafeReorgForkChoiceNotInputError(gt *testing.T) {
545545
block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{})
546546
}
547547
// Add A1, B2, B3, B4, B5 into the channel
548-
_, err = channelOut.AddBlock(sd.RollupCfg, block)
548+
err = channelOut.AddBlock(sd.RollupCfg, block)
549549
require.NoError(t, err)
550550
}
551551

@@ -864,7 +864,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) {
864864
block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{})
865865
}
866866
// Add A1 ~ A12 into the channel
867-
_, err = channelOut.AddBlock(sd.RollupCfg, block)
867+
err = channelOut.AddBlock(sd.RollupCfg, block)
868868
require.NoError(t, err)
869869
}
870870

@@ -913,7 +913,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) {
913913
block = block.WithBody([]*types.Transaction{block.Transactions()[0], tx}, []*types.Header{})
914914
}
915915
// Add B1, A2 ~ A12 into the channel
916-
_, err = channelOut.AddBlock(sd.RollupCfg, block)
916+
err = channelOut.AddBlock(sd.RollupCfg, block)
917917
require.NoError(t, err)
918918
}
919919
// Submit span batch(B1, A2, ... A12)

op-node/benchmarks/batchbuilding_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212
"github.com/stretchr/testify/require"
1313
)
1414

15-
var (
15+
const (
1616
// a really large target output size to ensure that the compressors are never full
1717
targetOutput_huge = uint64(100_000_000_000)
1818
// this target size was determiend by the devnet sepolia batcher's configuration
1919
targetOuput_real = uint64(780120)
20+
)
2021

22+
var (
2123
// compressors used in the benchmark
2224
rc, _ = compressor.NewRatioCompressor(compressor.Config{
2325
TargetOutputSize: targetOutput_huge,
@@ -136,13 +138,13 @@ func BenchmarkFinalBatchChannelOut(b *testing.B) {
136138
cout, _ := channelOutByType(tc.BatchType, tc.compKey)
137139
// add all but the final batch to the channel out
138140
for i := 0; i < tc.BatchCount-1; i++ {
139-
_, err := cout.AddSingularBatch(batches[i], 0)
141+
err := cout.AddSingularBatch(batches[i], 0)
140142
require.NoError(b, err)
141143
}
142144
// measure the time to add the final batch
143145
b.StartTimer()
144146
// add the final batch to the channel out
145-
_, err := cout.AddSingularBatch(batches[tc.BatchCount-1], 0)
147+
err := cout.AddSingularBatch(batches[tc.BatchCount-1], 0)
146148
require.NoError(b, err)
147149
}
148150
})
@@ -185,7 +187,7 @@ func BenchmarkIncremental(b *testing.B) {
185187
}
186188
b.StartTimer()
187189
for i := 0; i < tc.BatchCount; i++ {
188-
_, err := cout.AddSingularBatch(batches[i], 0)
190+
err := cout.AddSingularBatch(batches[i], 0)
189191
if err != nil {
190192
done = true
191193
return
@@ -246,7 +248,7 @@ func BenchmarkAllBatchesChannelOut(b *testing.B) {
246248
b.StartTimer()
247249
// add all batches to the channel out
248250
for i := 0; i < tc.BatchCount; i++ {
249-
_, err := cout.AddSingularBatch(batches[i], 0)
251+
err := cout.AddSingularBatch(batches[i], 0)
250252
require.NoError(b, err)
251253
}
252254
}

op-node/rollup/derive/channel_out.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ type Compressor interface {
5353
type ChannelOut interface {
5454
ID() ChannelID
5555
Reset() error
56-
AddBlock(*rollup.Config, *types.Block) (uint64, error)
57-
AddSingularBatch(*SingularBatch, uint64) (uint64, error)
56+
AddBlock(*rollup.Config, *types.Block) error
57+
AddSingularBatch(*SingularBatch, uint64) error
5858
InputBytes() int
5959
ReadyBytes() int
6060
Flush() error
@@ -108,14 +108,14 @@ func (co *SingularChannelOut) Reset() error {
108108
// and an error if there is a problem adding the block. The only sentinel error
109109
// that it returns is ErrTooManyRLPBytes. If this error is returned, the channel
110110
// should be closed and a new one should be made.
111-
func (co *SingularChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Block) (uint64, error) {
111+
func (co *SingularChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Block) error {
112112
if co.closed {
113-
return 0, ErrChannelOutAlreadyClosed
113+
return ErrChannelOutAlreadyClosed
114114
}
115115

116116
batch, l1Info, err := BlockToSingularBatch(rollupCfg, block)
117117
if err != nil {
118-
return 0, err
118+
return err
119119
}
120120
return co.AddSingularBatch(batch, l1Info.SequenceNumber)
121121
}
@@ -128,26 +128,26 @@ func (co *SingularChannelOut) AddBlock(rollupCfg *rollup.Config, block *types.Bl
128128
// AddSingularBatch should be used together with BlockToBatch if you need to access the
129129
// BatchData before adding a block to the channel. It isn't possible to access
130130
// the batch data with AddBlock.
131-
func (co *SingularChannelOut) AddSingularBatch(batch *SingularBatch, _ uint64) (uint64, error) {
131+
func (co *SingularChannelOut) AddSingularBatch(batch *SingularBatch, _ uint64) error {
132132
if co.closed {
133-
return 0, ErrChannelOutAlreadyClosed
133+
return ErrChannelOutAlreadyClosed
134134
}
135135

136136
// We encode to a temporary buffer to determine the encoded length to
137137
// ensure that the total size of all RLP elements is less than or equal to MAX_RLP_BYTES_PER_CHANNEL
138138
var buf bytes.Buffer
139139
if err := rlp.Encode(&buf, NewBatchData(batch)); err != nil {
140-
return 0, err
140+
return err
141141
}
142142
if co.rlpLength+buf.Len() > MaxRLPBytesPerChannel {
143-
return 0, fmt.Errorf("could not add %d bytes to channel of %d bytes, max is %d. err: %w",
143+
return fmt.Errorf("could not add %d bytes to channel of %d bytes, max is %d. err: %w",
144144
buf.Len(), co.rlpLength, MaxRLPBytesPerChannel, ErrTooManyRLPBytes)
145145
}
146146
co.rlpLength += buf.Len()
147147

148148
// avoid using io.Copy here, because we need all or nothing
149-
written, err := co.compress.Write(buf.Bytes())
150-
return uint64(written), err
149+
_, err := co.compress.Write(buf.Bytes())
150+
return err
151151
}
152152

153153
// InputBytes returns the total amount of RLP-encoded input bytes.

0 commit comments

Comments
 (0)