Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
92faa64c
Unverified
Commit
92faa64c
authored
May 26, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ensureChannelWithRoom to ensureChannelWithSpace
parent
a4f59e9e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
14 deletions
+19
-14
channel.go
op-batcher/batcher/channel.go
+3
-1
channel_manager.go
op-batcher/batcher/channel_manager.go
+6
-3
channel_manager_test.go
op-batcher/batcher/channel_manager_test.go
+2
-2
channel_test.go
op-batcher/batcher/channel_test.go
+8
-8
No files found.
op-batcher/batcher/channel.go
View file @
92faa64c
...
@@ -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
new
Pending
Channel
(
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
)
...
...
op-batcher/batcher/channel_manager.go
View file @
92faa64c
...
@@ -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
.
ensureChannelWith
Room
(
l1Head
);
err
!=
nil
{
if
err
:=
s
.
ensureChannelWith
Space
(
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
:=
new
Pending
Channel
(
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
)
}
}
...
...
op-batcher/batcher/channel_manager_test.go
View file @
92faa64c
...
@@ -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
.
ensureChannelWith
Room
(
l1BlockID
))
require
.
NoError
(
m
.
ensureChannelWith
Space
(
l1BlockID
))
require
.
NotNil
(
m
.
currentChannel
)
require
.
NotNil
(
m
.
currentChannel
)
require
.
Len
(
m
.
currentChannel
.
confirmedTransactions
,
0
)
require
.
Len
(
m
.
currentChannel
.
confirmedTransactions
,
0
)
...
...
op-batcher/batcher/channel_test.go
View file @
92faa64c
...
@@ -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
.
ensureChannelWith
Room
(
eth
.
BlockID
{}))
require
.
NoError
(
t
,
m
.
ensureChannelWith
Space
(
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
.
ensureChannelWith
Room
(
eth
.
BlockID
{}))
require
.
NoError
(
t
,
m
.
ensureChannelWith
Space
(
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
])
}
}
// TestChannel
Manager
TxConfirmed checks the [ChannelManager.TxConfirmed] function.
// TestChannelTxConfirmed checks the [ChannelManager.TxConfirmed] function.
func
TestChannel
Manager
TxConfirmed
(
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
.
ensureChannelWith
Room
(
eth
.
BlockID
{}))
require
.
NoError
(
t
,
m
.
ensureChannelWith
Space
(
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
])
}
}
// TestChannel
Manager
TxFailed checks the [ChannelManager.TxFailed] function.
// TestChannelTxFailed checks the [ChannelManager.TxFailed] function.
func
TestChannel
Manager
TxFailed
(
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
.
ensureChannelWith
Room
(
eth
.
BlockID
{}))
require
.
NoError
(
t
,
m
.
ensureChannelWith
Space
(
eth
.
BlockID
{}))
channelID
:=
m
.
currentChannel
.
ID
()
channelID
:=
m
.
currentChannel
.
ID
()
frame
:=
frameData
{
frame
:=
frameData
{
data
:
[]
byte
{},
data
:
[]
byte
{},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment