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
57d3c50e
Unverified
Commit
57d3c50e
authored
Mar 21, 2023
by
Brian Bland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up tests
parent
c16a3cd0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
66 deletions
+40
-66
channel_manager.go
op-batcher/batcher/channel_manager.go
+4
-4
channel_manager_test.go
op-batcher/batcher/channel_manager_test.go
+36
-62
No files found.
op-batcher/batcher/channel_manager.go
View file @
57d3c50e
...
...
@@ -360,9 +360,9 @@ func l2BlockRefFromBlockAndL1Info(block *types.Block, l1info derive.L1BlockInfo)
// creation of any new channels.
// This ensures that no new frames will be produced, but there may be any number
// of pending frames produced before this call which should still be published.
func
(
s
*
channelManager
)
Close
()
error
{
func
(
s
*
channelManager
)
Close
()
{
if
s
.
closed
{
return
nil
return
}
s
.
closed
=
true
...
...
@@ -373,9 +373,9 @@ func (s *channelManager) Close() error {
}
if
s
.
pendingChannel
==
nil
{
return
nil
return
}
s
.
pendingChannel
.
Close
()
return
nil
return
}
op-batcher/batcher/channel_manager_test.go
View file @
57d3c50e
...
...
@@ -15,7 +15,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/stretchr/testify/require"
)
...
...
@@ -368,6 +367,7 @@ func TestChannelManager_TxResend(t *testing.T) {
// TestChannelManagerCloseBeforeFirstUse ensures that the channel manager
// will not produce any frames if closed immediately.
func
TestChannelManagerCloseBeforeFirstUse
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
...
...
@@ -380,20 +380,20 @@ func TestChannelManagerCloseBeforeFirstUse(t *testing.T) {
a
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
4
)
err
:=
m
.
Close
()
require
.
NoError
(
t
,
err
)
m
.
Close
()
err
=
m
.
AddL2Block
(
a
)
require
.
NoError
(
t
,
err
)
err
:
=
m
.
AddL2Block
(
a
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected closed channel manager to contain no tx data"
)
}
// TestChannelManagerCloseNoPendingChannel ensures that the channel manager
// can gracefully close with no pending channels, and will not emit any new
// channel frames.
func
TestChannelManagerCloseNoPendingChannel
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
...
...
@@ -402,132 +402,106 @@ func TestChannelManagerCloseNoPendingChannel(t *testing.T) {
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
lBlock
:=
types
.
NewBlock
(
&
types
.
Header
{
BaseFee
:
big
.
NewInt
(
10
),
Difficulty
:
common
.
Big0
,
Number
:
big
.
NewInt
(
100
),
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
lBlock
,
eth
.
SystemConfig
{},
false
)
require
.
NoError
(
t
,
err
)
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
a
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
0
),
},
txs
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
=
derive
.
L1InfoDeposit
(
1
,
lBlock
,
eth
.
SystemConfig
{},
false
)
require
.
NoError
(
t
,
err
)
txs
=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
b
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
1
),
ParentHash
:
a
.
Hash
(),
},
txs
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
a
:=
newMiniL2Block
(
0
)
b
:=
newMiniL2BlockWithNumberParent
(
0
,
big
.
NewInt
(
1
),
a
.
Hash
())
err
=
m
.
AddL2Block
(
a
)
require
.
NoError
(
t
,
err
)
err
:
=
m
.
AddL2Block
(
a
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
txdata
,
err
:=
m
.
TxData
(
eth
.
BlockID
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Expected channel manager to return valid tx data"
)
m
.
TxConfirmed
(
txdata
.
ID
(),
eth
.
BlockID
{})
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected channel manager to EOF"
)
err
=
m
.
Close
()
require
.
NoError
(
t
,
err
)
m
.
Close
()
err
=
m
.
AddL2Block
(
b
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected closed channel manager to return no new tx data"
)
}
// TestChannelManagerCloseNoPendingChannel ensures that the channel manager
// can gracefully close with a pending channel, and will not produce any
// new channel frames after this point.
func
TestChannelManagerClosePendingChannel
(
t
*
testing
.
T
)
{
r
ng
:=
rand
.
New
(
rand
.
NewSource
(
1
)
)
r
equire
:=
require
.
New
(
t
)
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetNumFrames
:
100
,
TargetFrameSize
:
20
_
000
,
MaxFrameSize
:
20
_
000
,
TargetFrameSize
:
1
000
,
MaxFrameSize
:
1
000
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
a
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
128
)
b
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
8
)
header
:=
b
.
Header
()
header
.
ParentHash
=
a
.
Hash
()
b
=
b
.
WithSeal
(
header
)
a
:=
newMiniL2Block
(
50
_000
)
b
:=
newMiniL2BlockWithNumberParent
(
10
,
big
.
NewInt
(
1
),
a
.
Hash
())
err
:=
m
.
AddL2Block
(
a
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
txdata
,
err
:=
m
.
TxData
(
eth
.
BlockID
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Expected channel manager to produce valid tx data"
)
m
.
TxConfirmed
(
txdata
.
ID
(),
eth
.
BlockID
{})
err
=
m
.
Close
()
require
.
NoError
(
t
,
err
)
m
.
Close
()
txdata
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Expected channel manager to produce tx data from remaining L2 block data"
)
m
.
TxConfirmed
(
txdata
.
ID
(),
eth
.
BlockID
{})
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected channel manager to have no more tx data"
)
err
=
m
.
AddL2Block
(
b
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected closed channel manager to produce no more tx data"
)
}
// TestChannelManagerCloseAllTxsFailed ensures that the channel manager
// can gracefully close after producing transaction frames if none of these
// have successfully landed on chain.
func
TestChannelManagerCloseAllTxsFailed
(
t
*
testing
.
T
)
{
r
ng
:=
rand
.
New
(
rand
.
NewSource
(
1
)
)
r
equire
:=
require
.
New
(
t
)
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
metrics
.
NoopMetrics
,
ChannelConfig
{
TargetNumFrames
:
100
,
TargetFrameSize
:
25
_
000
,
MaxFrameSize
:
40
_
000
,
TargetFrameSize
:
1
000
,
MaxFrameSize
:
1
000
,
ApproxComprRatio
:
1.0
,
ChannelTimeout
:
1000
,
})
a
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
128
)
a
:=
newMiniL2Block
(
50
_000
)
err
:=
m
.
AddL2Block
(
a
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Failed to add L2 block"
)
txdata
,
err
:=
m
.
TxData
(
eth
.
BlockID
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Expected channel manager to produce valid tx data"
)
m
.
TxFailed
(
txdata
.
ID
())
// Show that this data will continue to be emitted as long as the transaction
// fails and the channel manager is not closed
txdata
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
err
,
"Expected channel manager to re-attempt the failed transaction"
)
m
.
TxFailed
(
txdata
.
ID
())
err
=
m
.
Close
()
require
.
NoError
(
t
,
err
)
m
.
Close
()
_
,
err
=
m
.
TxData
(
eth
.
BlockID
{})
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
require
.
ErrorIs
(
err
,
io
.
EOF
,
"Expected closed channel manager to produce no more tx data"
)
}
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