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

Rename ensureChannelWithRoom to ensureChannelWithSpace

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