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
ab90a101
Commit
ab90a101
authored
Jan 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: tests and nits :test_tube:
parent
b256b358
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
2 deletions
+91
-2
node.go
op-node/node/node.go
+4
-0
types.go
op-node/rollup/types.go
+2
-2
types_test.go
op-node/rollup/types_test.go
+85
-0
No files found.
op-node/node/node.go
View file @
ab90a101
...
@@ -127,11 +127,13 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
...
@@ -127,11 +127,13 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
// Validate the L1 Client Chain ID
// Validate the L1 Client Chain ID
if
err
:=
cfg
.
Rollup
.
CheckL1ChainID
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
if
err
:=
cfg
.
Rollup
.
CheckL1ChainID
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L1 RPC chain id"
,
"err"
,
err
)
n
.
log
.
Error
(
"failed to verify L1 RPC chain id"
,
"err"
,
err
)
return
err
}
}
// Validate the Rollup L1 Genesis Blockhash
// Validate the Rollup L1 Genesis Blockhash
if
err
:=
cfg
.
Rollup
.
CheckL1GenesisBlockHash
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
if
err
:=
cfg
.
Rollup
.
CheckL1GenesisBlockHash
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L1 genesis block hash"
,
"err"
,
err
)
n
.
log
.
Error
(
"failed to verify L1 genesis block hash"
,
"err"
,
err
)
return
err
}
}
// Keep subscribed to the L1 heads, which keeps the L1 maintainer pointing to the best headers to sync
// Keep subscribed to the L1 heads, which keeps the L1 maintainer pointing to the best headers to sync
...
@@ -202,11 +204,13 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
...
@@ -202,11 +204,13 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
// Validate the L2 Client Chain ID
// Validate the L2 Client Chain ID
if
err
:=
cfg
.
Rollup
.
CheckL2ChainID
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
if
err
:=
cfg
.
Rollup
.
CheckL2ChainID
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L2 RPC chain id"
,
"err"
,
err
)
n
.
log
.
Error
(
"failed to verify L2 RPC chain id"
,
"err"
,
err
)
return
err
}
}
// Validate the Rollup L2 Genesis Blockhash
// Validate the Rollup L2 Genesis Blockhash
if
err
:=
cfg
.
Rollup
.
CheckL2GenesisBlockHash
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
if
err
:=
cfg
.
Rollup
.
CheckL2GenesisBlockHash
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L2 genesis block hash"
,
"err"
,
err
)
n
.
log
.
Error
(
"failed to verify L2 genesis block hash"
,
"err"
,
err
)
return
err
}
}
n
.
l2Driver
=
driver
.
NewDriver
(
&
cfg
.
Driver
,
&
cfg
.
Rollup
,
n
.
l2Source
,
n
.
l1Source
,
n
,
n
.
log
,
snapshotLog
,
n
.
metrics
)
n
.
l2Driver
=
driver
.
NewDriver
(
&
cfg
.
Driver
,
&
cfg
.
Rollup
,
n
.
l2Source
,
n
.
l1Source
,
n
,
n
.
log
,
snapshotLog
,
n
.
metrics
)
...
...
op-node/rollup/types.go
View file @
ab90a101
...
@@ -67,7 +67,7 @@ func (cfg *Config) CheckL1ChainID(ctx context.Context, client L1Client) error {
...
@@ -67,7 +67,7 @@ func (cfg *Config) CheckL1ChainID(ctx context.Context, client L1Client) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cfg
.
L1ChainID
!=
id
{
if
cfg
.
L1ChainID
.
Cmp
(
id
)
!=
0
{
return
fmt
.
Errorf
(
"incorrect L1 RPC chain id %d, expected %d"
,
cfg
.
L1ChainID
,
id
)
return
fmt
.
Errorf
(
"incorrect L1 RPC chain id %d, expected %d"
,
cfg
.
L1ChainID
,
id
)
}
}
return
nil
return
nil
...
@@ -96,7 +96,7 @@ func (cfg *Config) CheckL2ChainID(ctx context.Context, client L2Client) error {
...
@@ -96,7 +96,7 @@ func (cfg *Config) CheckL2ChainID(ctx context.Context, client L2Client) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cfg
.
L2ChainID
!=
id
{
if
cfg
.
L2ChainID
.
Cmp
(
id
)
!=
0
{
return
fmt
.
Errorf
(
"incorrect L2 RPC chain id %d, expected %d"
,
cfg
.
L2ChainID
,
id
)
return
fmt
.
Errorf
(
"incorrect L2 RPC chain id %d, expected %d"
,
cfg
.
L2ChainID
,
id
)
}
}
return
nil
return
nil
...
...
op-node/rollup/types_test.go
View file @
ab90a101
package
rollup
package
rollup
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"math/big"
"math/big"
"math/rand"
"math/rand"
...
@@ -55,3 +56,87 @@ func TestConfigJSON(t *testing.T) {
...
@@ -55,3 +56,87 @@ func TestConfigJSON(t *testing.T) {
assert
.
NoError
(
t
,
json
.
Unmarshal
(
data
,
&
roundTripped
))
assert
.
NoError
(
t
,
json
.
Unmarshal
(
data
,
&
roundTripped
))
assert
.
Equal
(
t
,
&
roundTripped
,
config
)
assert
.
Equal
(
t
,
&
roundTripped
,
config
)
}
}
type
mockL1Client
struct
{
chainID
*
big
.
Int
Hash
common
.
Hash
}
func
(
m
*
mockL1Client
)
L1ChainID
(
context
.
Context
)
(
*
big
.
Int
,
error
)
{
return
m
.
chainID
,
nil
}
func
(
m
*
mockL1Client
)
L1BlockRefByNumber
(
ctx
context
.
Context
,
number
uint64
)
(
eth
.
L1BlockRef
,
error
)
{
return
eth
.
L1BlockRef
{
Hash
:
m
.
Hash
,
Number
:
100
,
},
nil
}
func
TestCheckL1ChainID
(
t
*
testing
.
T
)
{
config
:=
randConfig
()
config
.
L1ChainID
=
big
.
NewInt
(
100
)
err
:=
config
.
CheckL1ChainID
(
context
.
TODO
(),
&
mockL1Client
{
chainID
:
big
.
NewInt
(
100
)})
assert
.
NoError
(
t
,
err
)
err
=
config
.
CheckL1ChainID
(
context
.
TODO
(),
&
mockL1Client
{
chainID
:
big
.
NewInt
(
101
)})
assert
.
Error
(
t
,
err
)
err
=
config
.
CheckL1ChainID
(
context
.
TODO
(),
&
mockL1Client
{
chainID
:
big
.
NewInt
(
99
)})
assert
.
Error
(
t
,
err
)
}
func
TestCheckL1BlockRefByNumber
(
t
*
testing
.
T
)
{
config
:=
randConfig
()
config
.
Genesis
.
L1
.
Number
=
100
config
.
Genesis
.
L1
.
Hash
=
[
32
]
byte
{
0x01
}
mockClient
:=
mockL1Client
{
chainID
:
big
.
NewInt
(
100
),
Hash
:
common
.
Hash
{
0x01
}}
err
:=
config
.
CheckL1GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
NoError
(
t
,
err
)
mockClient
.
Hash
=
common
.
Hash
{
0x02
}
err
=
config
.
CheckL1GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
Error
(
t
,
err
)
mockClient
.
Hash
=
common
.
Hash
{
0x00
}
err
=
config
.
CheckL1GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
Error
(
t
,
err
)
}
type
mockL2Client
struct
{
chainID
*
big
.
Int
Hash
common
.
Hash
}
func
(
m
*
mockL2Client
)
L2ChainID
(
context
.
Context
)
(
*
big
.
Int
,
error
)
{
return
m
.
chainID
,
nil
}
func
(
m
*
mockL2Client
)
L2BlockRefByNumber
(
ctx
context
.
Context
,
number
uint64
)
(
eth
.
L2BlockRef
,
error
)
{
return
eth
.
L2BlockRef
{
Hash
:
m
.
Hash
,
Number
:
100
,
},
nil
}
func
TestCheckL2ChainID
(
t
*
testing
.
T
)
{
config
:=
randConfig
()
config
.
L2ChainID
=
big
.
NewInt
(
100
)
err
:=
config
.
CheckL2ChainID
(
context
.
TODO
(),
&
mockL2Client
{
chainID
:
big
.
NewInt
(
100
)})
assert
.
NoError
(
t
,
err
)
err
=
config
.
CheckL2ChainID
(
context
.
TODO
(),
&
mockL2Client
{
chainID
:
big
.
NewInt
(
101
)})
assert
.
Error
(
t
,
err
)
err
=
config
.
CheckL2ChainID
(
context
.
TODO
(),
&
mockL2Client
{
chainID
:
big
.
NewInt
(
99
)})
assert
.
Error
(
t
,
err
)
}
func
TestCheckL2BlockRefByNumber
(
t
*
testing
.
T
)
{
config
:=
randConfig
()
config
.
Genesis
.
L2
.
Number
=
100
config
.
Genesis
.
L2
.
Hash
=
[
32
]
byte
{
0x01
}
mockClient
:=
mockL2Client
{
chainID
:
big
.
NewInt
(
100
),
Hash
:
common
.
Hash
{
0x01
}}
err
:=
config
.
CheckL2GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
NoError
(
t
,
err
)
mockClient
.
Hash
=
common
.
Hash
{
0x02
}
err
=
config
.
CheckL2GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
Error
(
t
,
err
)
mockClient
.
Hash
=
common
.
Hash
{
0x00
}
err
=
config
.
CheckL2GenesisBlockHash
(
context
.
TODO
(),
&
mockClient
)
assert
.
Error
(
t
,
err
)
}
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