Commit 92faa64c authored by Michael de Hoog's avatar Michael de Hoog

Rename ensureChannelWithRoom to ensureChannelWithSpace

parent a4f59e9e
......@@ -11,6 +11,8 @@ import (
"github.com/ethereum/go-ethereum/log"
)
// channel is a lightweight wrapper around a channelBuilder which keeps track of pending
// and confirmed transactions for a single channel.
type channel struct {
log log.Logger
metr metrics.Metricer
......@@ -24,7 +26,7 @@ type channel struct {
confirmedTransactions map[txID]eth.BlockID
}
func newPendingChannel(log log.Logger, metr metrics.Metricer, cfg ChannelConfig) (*channel, error) {
func newChannel(log log.Logger, metr metrics.Metricer, cfg ChannelConfig) (*channel, error) {
cb, err := newChannelBuilder(cfg)
if err != nil {
return nil, fmt.Errorf("creating new channel: %w", err)
......
......@@ -155,7 +155,7 @@ func (s *channelManager) TxData(l1Head eth.BlockID) (txData, error) {
return txData{}, io.EOF
}
if err := s.ensureChannelWithRoom(l1Head); err != nil {
if err := s.ensureChannelWithSpace(l1Head); err != nil {
return txData{}, err
}
......@@ -175,12 +175,15 @@ func (s *channelManager) TxData(l1Head eth.BlockID) (txData, error) {
return s.nextTxData(s.currentChannel)
}
func (s *channelManager) ensureChannelWithRoom(l1Head eth.BlockID) error {
// ensureChannelWithSpace ensures currentChannel is populated with a channel that has
// space for more data (i.e. channel.IsFull returns false). If currentChannel is nil
// or full, a new channel is created.
func (s *channelManager) ensureChannelWithSpace(l1Head eth.BlockID) error {
if s.currentChannel != nil && !s.currentChannel.IsFull() {
return nil
}
pc, err := newPendingChannel(s.log, s.metr, s.cfg)
pc, err := newChannel(s.log, s.metr, s.cfg)
if err != nil {
return fmt.Errorf("creating new channel: %w", err)
}
......
......@@ -114,8 +114,8 @@ func TestChannelManager_Clear(t *testing.T) {
}
require.NoError(m.AddL2Block(a))
// Make sure there is a channel builder
require.NoError(m.ensureChannelWithRoom(l1BlockID))
// Make sure there is a channel
require.NoError(m.ensureChannelWithSpace(l1BlockID))
require.NotNil(m.currentChannel)
require.Len(m.currentChannel.confirmedTransactions, 0)
......
......@@ -26,7 +26,7 @@ func TestChannelTimeout(t *testing.T) {
require.Nil(t, m.currentChannel)
// Set the pending channel
require.NoError(t, m.ensureChannelWithRoom(eth.BlockID{}))
require.NoError(t, m.ensureChannelWithSpace(eth.BlockID{}))
channel := m.currentChannel
require.NotNil(t, channel)
......@@ -71,7 +71,7 @@ func TestChannelNextTxData(t *testing.T) {
// Set the pending channel
// The nextTxData function should still return EOF
// since the pending channel has no frames
require.NoError(t, m.ensureChannelWithRoom(eth.BlockID{}))
require.NoError(t, m.ensureChannelWithSpace(eth.BlockID{}))
channel := m.currentChannel
require.NotNil(t, channel)
returnedTxData, err = m.nextTxData(channel)
......@@ -100,8 +100,8 @@ func TestChannelNextTxData(t *testing.T) {
require.Equal(t, expectedTxData, channel.pendingTransactions[expectedChannelID])
}
// TestChannelManagerTxConfirmed checks the [ChannelManager.TxConfirmed] function.
func TestChannelManagerTxConfirmed(t *testing.T) {
// TestChannelTxConfirmed checks the [ChannelManager.TxConfirmed] function.
func TestChannelTxConfirmed(t *testing.T) {
// Create a channel manager
log := testlog.Logger(t, log.LvlCrit)
m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{
......@@ -113,7 +113,7 @@ func TestChannelManagerTxConfirmed(t *testing.T) {
// Let's add a valid pending transaction to the channel manager
// So we can demonstrate that TxConfirmed's correctness
require.NoError(t, m.ensureChannelWithRoom(eth.BlockID{}))
require.NoError(t, m.ensureChannelWithSpace(eth.BlockID{}))
channelID := m.currentChannel.ID()
frame := frameData{
data: []byte{},
......@@ -153,15 +153,15 @@ func TestChannelManagerTxConfirmed(t *testing.T) {
require.Equal(t, blockID, m.currentChannel.confirmedTransactions[expectedChannelID])
}
// TestChannelManagerTxFailed checks the [ChannelManager.TxFailed] function.
func TestChannelManagerTxFailed(t *testing.T) {
// TestChannelTxFailed checks the [ChannelManager.TxFailed] function.
func TestChannelTxFailed(t *testing.T) {
// Create a channel manager
log := testlog.Logger(t, log.LvlCrit)
m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{})
// Let's add a valid pending transaction to the channel
// manager so we can demonstrate correctness
require.NoError(t, m.ensureChannelWithRoom(eth.BlockID{}))
require.NoError(t, m.ensureChannelWithSpace(eth.BlockID{}))
channelID := m.currentChannel.ID()
frame := frameData{
data: []byte{},
......
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