Commit 616a078e authored by George Knee's avatar George Knee Committed by GitHub

op-batcher: prevent over-assessment of DA type (#12115)

* test: assert that default config doesn't change prematurely

* test: use a better system to ensure we are not over assessing

* return io.EOF from getReadyChannel

when the current channel has no tx data

also improve godoc
parent 10a16aaf
...@@ -193,7 +193,11 @@ func (s *channelManager) TxData(l1Head eth.BlockID) (txData, error) { ...@@ -193,7 +193,11 @@ func (s *channelManager) TxData(l1Head eth.BlockID) (txData, error) {
} }
// getReadyChannel returns the next channel ready to submit data, or an error. // getReadyChannel returns the next channel ready to submit data, or an error.
// It adds blocks from the block queue to the current channel and generates frames for it. // It will create a new channel if necessary.
// If there is no data ready to send, it adds blocks from the block queue
// to the current channel and generates frames for it.
// Always returns nil and the io.EOF sentinel error when
// there is no channel with txData
func (s *channelManager) getReadyChannel(l1Head eth.BlockID) (*channel, error) { func (s *channelManager) getReadyChannel(l1Head eth.BlockID) (*channel, error) {
var firstWithTxData *channel var firstWithTxData *channel
for _, ch := range s.channelQueue { for _, ch := range s.channelQueue {
...@@ -239,7 +243,11 @@ func (s *channelManager) getReadyChannel(l1Head eth.BlockID) (*channel, error) { ...@@ -239,7 +243,11 @@ func (s *channelManager) getReadyChannel(l1Head eth.BlockID) (*channel, error) {
return nil, err return nil, err
} }
return s.currentChannel, nil if s.currentChannel.HasTxData() {
return s.currentChannel, nil
}
return nil, io.EOF
} }
// ensureChannelWithSpace ensures currentChannel is populated with a channel that has // ensureChannelWithSpace ensures currentChannel is populated with a channel that has
......
...@@ -491,9 +491,11 @@ func TestChannelManager_ChannelCreation(t *testing.T) { ...@@ -491,9 +491,11 @@ func TestChannelManager_ChannelCreation(t *testing.T) {
type FakeDynamicEthChannelConfig struct { type FakeDynamicEthChannelConfig struct {
DynamicEthChannelConfig DynamicEthChannelConfig
chooseBlobs bool chooseBlobs bool
assessments int
} }
func (f *FakeDynamicEthChannelConfig) ChannelConfig() ChannelConfig { func (f *FakeDynamicEthChannelConfig) ChannelConfig() ChannelConfig {
f.assessments++
if f.chooseBlobs { if f.chooseBlobs {
return f.blobConfig return f.blobConfig
} }
...@@ -537,13 +539,21 @@ func TestChannelManager_TxData(t *testing.T) { ...@@ -537,13 +539,21 @@ func TestChannelManager_TxData(t *testing.T) {
name string name string
chooseBlobsWhenChannelCreated bool chooseBlobsWhenChannelCreated bool
chooseBlobsWhenChannelSubmitted bool chooseBlobsWhenChannelSubmitted bool
// * One when the channelManager was created
// * One when the channel is about to be submitted
// * Potentially one more if the replacement channel is about to be submitted,
// this only happens when going from calldata->blobs because
// the channel is no longer ready to send until more data
// is added.
numExpectedAssessments int
} }
tt := []TestCase{ tt := []TestCase{
{"blobs->blobs", true, true}, {"blobs->blobs", true, true, 2},
{"calldata->calldata", false, false}, {"calldata->calldata", false, false, 2},
{"blobs->calldata", true, false}, {"blobs->calldata", true, false, 2},
{"calldata->blobs", false, true}, {"calldata->blobs", false, true, 3},
} }
for _, tc := range tt { for _, tc := range tt {
...@@ -590,6 +600,7 @@ func TestChannelManager_TxData(t *testing.T) { ...@@ -590,6 +600,7 @@ func TestChannelManager_TxData(t *testing.T) {
} }
} }
require.Equal(t, tc.numExpectedAssessments, cfg.assessments)
require.Equal(t, tc.chooseBlobsWhenChannelSubmitted, data.asBlob) require.Equal(t, tc.chooseBlobsWhenChannelSubmitted, data.asBlob)
require.Equal(t, tc.chooseBlobsWhenChannelSubmitted, m.defaultCfg.UseBlobs) require.Equal(t, tc.chooseBlobsWhenChannelSubmitted, m.defaultCfg.UseBlobs)
}) })
......
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