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
58d7067d
Commit
58d7067d
authored
Oct 12, 2023
by
Adrian Sutton
Committed by
Joshua Gutow
Oct 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Fix channel ordering
parent
af2bc484
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
16 deletions
+101
-16
channel_bank.go
op-node/rollup/derive/channel_bank.go
+32
-12
channel_bank_test.go
op-node/rollup/derive/channel_bank_test.go
+69
-4
No files found.
op-node/rollup/derive/channel_bank.go
View file @
58d7067d
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/exp/slices"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/eth"
...
@@ -116,6 +117,8 @@ func (cb *ChannelBank) IngestFrame(f Frame) {
...
@@ -116,6 +117,8 @@ func (cb *ChannelBank) IngestFrame(f Frame) {
// Read the raw data of the first channel, if it's timed-out or closed.
// Read the raw data of the first channel, if it's timed-out or closed.
// Read returns io.EOF if there is nothing new to read.
// Read returns io.EOF if there is nothing new to read.
func
(
cb
*
ChannelBank
)
Read
()
(
data
[]
byte
,
err
error
)
{
func
(
cb
*
ChannelBank
)
Read
()
(
data
[]
byte
,
err
error
)
{
// Common Code. By returning `nil,nil`, we call back into this to make sure that all timed
// out channels at the front of the queue will eventually be removed.
if
len
(
cb
.
channelQueue
)
==
0
{
if
len
(
cb
.
channelQueue
)
==
0
{
return
nil
,
io
.
EOF
return
nil
,
io
.
EOF
}
}
...
@@ -127,23 +130,40 @@ func (cb *ChannelBank) Read() (data []byte, err error) {
...
@@ -127,23 +130,40 @@ func (cb *ChannelBank) Read() (data []byte, err error) {
cb
.
metrics
.
RecordChannelTimedOut
()
cb
.
metrics
.
RecordChannelTimedOut
()
delete
(
cb
.
channels
,
first
)
delete
(
cb
.
channels
,
first
)
cb
.
channelQueue
=
cb
.
channelQueue
[
1
:
]
cb
.
channelQueue
=
cb
.
channelQueue
[
1
:
]
// There is a new head channel if there is a channel after we have removed the first channel
if
len
(
cb
.
channelQueue
)
>
0
{
cb
.
metrics
.
RecordHeadChannelOpened
()
}
return
nil
,
nil
// multiple different channels may all be timed out
return
nil
,
nil
// multiple different channels may all be timed out
}
}
if
!
ch
.
IsReady
()
{
// At the point we have removed all timed out channels from the front of the channelQueue.
// Pre-Canyon we simply check the first index.
// Post-Canyon we read the entire channelQueue for the first ready channel. If no channel is
// available, we return `nil, io.EOF`.
if
!
cb
.
cfg
.
IsCanyon
(
cb
.
Origin
()
.
Time
)
{
return
cb
.
readIndex
(
0
)
}
for
i
:=
0
;
i
<
len
(
cb
.
channelQueue
);
i
++
{
if
data
,
err
:=
cb
.
readIndex
(
i
);
err
==
nil
{
return
data
,
nil
}
}
return
nil
,
io
.
EOF
}
// readIndex attempts to read the channel at the specified index. If the channel is
// not ready (or timed out), it will return io.EOF.
// If the channel read was successful, it will remove the channel from the channelQueue.
func
(
cb
*
ChannelBank
)
readIndex
(
i
int
)
(
data
[]
byte
,
err
error
)
{
chanID
:=
cb
.
channelQueue
[
i
]
ch
:=
cb
.
channels
[
chanID
]
timedOut
:=
ch
.
OpenBlockNumber
()
+
cb
.
cfg
.
ChannelTimeout
<
cb
.
Origin
()
.
Number
if
timedOut
||
!
ch
.
IsReady
()
{
return
nil
,
io
.
EOF
return
nil
,
io
.
EOF
}
}
cb
.
log
.
Info
(
"Reading channel"
,
"channel"
,
first
,
"frames"
,
len
(
ch
.
inputs
))
cb
.
log
.
Info
(
"Reading channel"
,
"channel"
,
chanID
,
"frames"
,
len
(
ch
.
inputs
))
delete
(
cb
.
channels
,
first
)
delete
(
cb
.
channels
,
chanID
)
cb
.
channelQueue
=
cb
.
channelQueue
[
1
:
]
cb
.
channelQueue
=
slices
.
Delete
(
cb
.
channelQueue
,
i
,
i
+
1
)
// There is a new head channel if there is a channel after we have removed the first channel
if
len
(
cb
.
channelQueue
)
>
0
{
cb
.
metrics
.
RecordHeadChannelOpened
()
cb
.
metrics
.
RecordHeadChannelOpened
()
}
r
:=
ch
.
Reader
()
r
:=
ch
.
Reader
()
// Suppress error here. io.ReadAll does return nil instead of io.EOF though.
// Suppress error here. io.ReadAll does return nil instead of io.EOF though.
data
,
_
=
io
.
ReadAll
(
r
)
data
,
_
=
io
.
ReadAll
(
r
)
...
...
op-node/rollup/derive/channel_bank_test.go
View file @
58d7067d
...
@@ -130,10 +130,10 @@ func TestChannelBankSimple(t *testing.T) {
...
@@ -130,10 +130,10 @@ func TestChannelBankSimple(t *testing.T) {
require
.
Equal
(
t
,
io
.
EOF
,
err
)
require
.
Equal
(
t
,
io
.
EOF
,
err
)
}
}
// TestChannelBankInterleaved ensure that the channel bank can handle frames from multiple channels
// TestChannelBankInterleaved
PreCanyon
ensure that the channel bank can handle frames from multiple channels
// that arrive out of order. Per the specs, the first channel to arrive (not the first to be completed)
// that arrive out of order. Per the specs, the first channel to arrive (not the first to be completed)
// is returned first
.
// is returned first
prior to the Canyon network upgrade
func
TestChannelBankInterleaved
(
t
*
testing
.
T
)
{
func
TestChannelBankInterleaved
PreCanyon
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
))
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
))
a
:=
testutils
.
RandomBlockRef
(
rng
)
a
:=
testutils
.
RandomBlockRef
(
rng
)
...
@@ -144,7 +144,7 @@ func TestChannelBankInterleaved(t *testing.T) {
...
@@ -144,7 +144,7 @@ func TestChannelBankInterleaved(t *testing.T) {
input
.
AddFrames
(
"a:1:second"
)
input
.
AddFrames
(
"a:1:second"
)
input
.
AddFrame
(
Frame
{},
io
.
EOF
)
input
.
AddFrame
(
Frame
{},
io
.
EOF
)
cfg
:=
&
rollup
.
Config
{
ChannelTimeout
:
10
}
cfg
:=
&
rollup
.
Config
{
ChannelTimeout
:
10
,
CanyonTime
:
nil
}
cb
:=
NewChannelBank
(
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
cfg
,
input
,
nil
,
metrics
.
NoopMetrics
)
cb
:=
NewChannelBank
(
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
cfg
,
input
,
nil
,
metrics
.
NoopMetrics
)
...
@@ -194,6 +194,71 @@ func TestChannelBankInterleaved(t *testing.T) {
...
@@ -194,6 +194,71 @@ func TestChannelBankInterleaved(t *testing.T) {
require
.
Equal
(
t
,
io
.
EOF
,
err
)
require
.
Equal
(
t
,
io
.
EOF
,
err
)
}
}
// TestChannelBankInterleaved ensure that the channel bank can handle frames from multiple channels
// that arrive out of order. Per the specs (post Canyon), the first channel to be complete should be
// returned
func
TestChannelBankInterleaved
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
))
a
:=
testutils
.
RandomBlockRef
(
rng
)
input
:=
&
fakeChannelBankInput
{
origin
:
a
}
input
.
AddFrames
(
"a:0:first"
,
"b:2:trois!"
)
input
.
AddFrames
(
"b:1:deux"
,
"a:2:third!"
)
input
.
AddFrames
(
"b:0:premiere"
)
input
.
AddFrames
(
"a:1:second"
)
input
.
AddFrame
(
Frame
{},
io
.
EOF
)
ct
:=
uint64
(
0
)
cfg
:=
&
rollup
.
Config
{
ChannelTimeout
:
10
,
CanyonTime
:
&
ct
}
cb
:=
NewChannelBank
(
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
cfg
,
input
,
nil
,
metrics
.
NoopMetrics
)
// Load a:0
out
,
err
:=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Load b:2
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Load b:1
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Load a:2
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Load b:0 & Channel b is complete. Channel a was opened first but isn't ready
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Pull out the channel b because it's ready first.
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
"premieredeuxtrois"
,
string
(
out
))
// Load a:1
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
ErrorIs
(
t
,
err
,
NotEnoughData
)
require
.
Equal
(
t
,
[]
byte
(
nil
),
out
)
// Pull out the channel a
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
"firstsecondthird"
,
string
(
out
))
// No more data
out
,
err
=
cb
.
NextData
(
context
.
Background
())
require
.
Nil
(
t
,
out
)
require
.
Equal
(
t
,
io
.
EOF
,
err
)
}
func
TestChannelBankDuplicates
(
t
*
testing
.
T
)
{
func
TestChannelBankDuplicates
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
))
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
))
a
:=
testutils
.
RandomBlockRef
(
rng
)
a
:=
testutils
.
RandomBlockRef
(
rng
)
...
...
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