Commit 5651672e authored by clabby's avatar clabby

Address Mark's feedback

parent f2292db3
......@@ -16,8 +16,31 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
var ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx")
var ErrTooManyRLPBytes = errors.New("batch would cause RLP bytes to go over limit")
type GarbageKind int64
const (
STRIP_VERSION GarbageKind = iota
RANDOM
TRUNCATE_END
DIRTY_APPEND
INVALID_COMPRESSION
MALFORM_RLP
)
var GarbageKinds = []GarbageKind{
STRIP_VERSION,
RANDOM,
TRUNCATE_END,
DIRTY_APPEND,
INVALID_COMPRESSION,
MALFORM_RLP,
}
// GarbageChannelCfg is the configuration for a `GarbageChannelOut`
type GarbageChannelCfg struct {
useInvalidCompression bool
malformRLP bool
}
// WriterApi is the interface shared between `zlib.Writer` and `gzip.Writer`
type WriterApi interface {
......@@ -118,7 +141,7 @@ func (co *GarbageChannelOut) AddBlock(block *types.Block) error {
}
if co.rlpLength+buf.Len() > derive.MaxRLPBytesPerChannel {
return fmt.Errorf("could not add %d bytes to channel of %d bytes, max is %d. err: %w",
buf.Len(), co.rlpLength, derive.MaxRLPBytesPerChannel, ErrTooManyRLPBytes)
buf.Len(), co.rlpLength, derive.MaxRLPBytesPerChannel, derive.ErrTooManyRLPBytes)
}
co.rlpLength += buf.Len()
......@@ -204,7 +227,7 @@ func blockToBatch(block *types.Block) (*derive.BatchData, error) {
}
l1InfoTx := block.Transactions()[0]
if l1InfoTx.Type() != types.DepositTxType {
return nil, ErrNotDepositTx
return nil, derive.ErrNotDepositTx
}
l1Info, err := derive.L1InfoDepositTxData(l1InfoTx.Data())
if err != nil {
......
......@@ -35,16 +35,6 @@ type L1TxAPI interface {
SendTransaction(ctx context.Context, tx *types.Transaction) error
}
type ChannelOutApi interface {
ID() derive.ChannelID
Reset() error
AddBlock(block *types.Block) error
ReadyBytes() int
Flush() error
Close() error
OutputFrame(w *bytes.Buffer, maxSize uint64) error
}
type BatcherCfg struct {
// Limit the size of txs
MinL1TxSize uint64
......@@ -71,7 +61,7 @@ type L2Batcher struct {
l1Signer types.Signer
l2ChannelOut ChannelOutApi
l2ChannelOut derive.ChannelOutApi
l2Submitting bool // when the channel out is being submitted, and not safe to write to without resetting
l2BufferedBlock eth.BlockID
l2SubmittedBlock eth.BlockID
......@@ -135,7 +125,7 @@ func (s *L2Batcher) ActL2BatchBuffer(t Testing) {
}
// Create channel if we don't have one yet
if s.l2ChannelOut == nil {
var ch ChannelOutApi
var ch derive.ChannelOutApi
if s.l2BatcherCfg.GarbageCfg != nil {
ch, err = NewGarbageChannelOut(s.l2BatcherCfg.GarbageCfg)
} else {
......@@ -213,47 +203,6 @@ func (s *L2Batcher) ActL2BatchSubmit(t Testing) {
require.NoError(t, err, "need to send tx")
}
func (s *L2Batcher) ActBufferAll(t Testing) {
stat, err := s.syncStatusAPI.SyncStatus(t.Ctx())
require.NoError(t, err)
for s.l2BufferedBlock.Number < stat.UnsafeL2.Number {
s.ActL2BatchBuffer(t)
}
}
func (s *L2Batcher) ActSubmitAll(t Testing) {
s.ActBufferAll(t)
s.ActL2ChannelClose(t)
s.ActL2BatchSubmit(t)
}
// TODO: Move this to a better location
type GarbageKind int64
const (
STRIP_VERSION GarbageKind = iota
RANDOM
TRUNCATE_END
DIRTY_APPEND
INVALID_COMPRESSION
MALFORM_RLP
)
var GarbageKinds = []GarbageKind{
STRIP_VERSION,
RANDOM,
TRUNCATE_END,
DIRTY_APPEND,
INVALID_COMPRESSION,
MALFORM_RLP,
}
// Configuration for a garbage channel (`ChannelOut` in the `actions` pkg)
type GarbageChannelCfg struct {
useInvalidCompression bool
malformRLP bool
}
// ActL2BatchSubmitGarbage constructs a malformed channel frame and submits it to the
// batch inbox. This *should* cause the batch inbox to reject the blocks
// encoded within the frame, even if the blocks themselves are valid.
......@@ -336,3 +285,17 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) {
err = s.l1.SendTransaction(t.Ctx(), tx)
require.NoError(t, err, "need to send tx")
}
func (s *L2Batcher) ActBufferAll(t Testing) {
stat, err := s.syncStatusAPI.SyncStatus(t.Ctx())
require.NoError(t, err)
for s.l2BufferedBlock.Number < stat.UnsafeL2.Number {
s.ActL2BatchBuffer(t)
}
}
func (s *L2Batcher) ActSubmitAll(t Testing) {
s.ActBufferAll(t)
s.ActL2ChannelClose(t)
s.ActL2BatchSubmit(t)
}
......@@ -17,6 +17,17 @@ import (
var ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx")
var ErrTooManyRLPBytes = errors.New("batch would cause RLP bytes to go over limit")
// ChannelOutApi is the interface implemented by ChannelOut
type ChannelOutApi interface {
ID() ChannelID
Reset() error
AddBlock(block *types.Block) error
ReadyBytes() int
Flush() error
Close() error
OutputFrame(w *bytes.Buffer, maxSize uint64) error
}
type ChannelOut struct {
id ChannelID
// Frame ID of the next frame to emit. Increment after emitting
......
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