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
9ea1b53b
Commit
9ea1b53b
authored
Jan 23, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: separation of concerns
parent
776fea22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
36 deletions
+67
-36
node.go
op-node/node/node.go
+8
-36
types.go
op-node/rollup/types.go
+59
-0
No files found.
op-node/node/node.go
View file @
9ea1b53b
...
@@ -125,27 +125,13 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
...
@@ -125,27 +125,13 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
}
}
// Validate the L1 Client Chain ID
// Validate the L1 Client Chain ID
id
,
err
:=
n
.
l1Source
.
L1ChainID
(
ctx
)
if
err
:=
cfg
.
Rollup
.
CheckL1ChainID
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L1 RPC chain id"
,
"err"
,
err
)
n
.
log
.
Warn
(
"failed to verify L1 RPC chain id"
,
"err"
,
err
)
}
else
{
if
cfg
.
Rollup
.
L1ChainID
!=
id
{
n
.
log
.
Warn
(
"incorrect L1 RPC chain id"
,
"expected"
,
cfg
.
Rollup
.
L1ChainID
,
"actual"
,
id
)
}
else
{
n
.
log
.
Info
(
"L1 RPC chain id verified"
,
"id"
,
id
)
}
}
}
// Validate the Rollup L1 Genesis Blockhash
// Validate the Rollup L1 Genesis Blockhash
l1GenesisBlockRef
,
err
:=
n
.
l1Source
.
L1BlockRefByNumber
(
ctx
,
cfg
.
Rollup
.
Genesis
.
L1
.
Number
)
if
err
:=
cfg
.
Rollup
.
CheckL1GenesisBlockHash
(
ctx
,
n
.
l1Source
);
err
!=
nil
{
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L1 genesis block hash"
,
"err"
,
err
)
n
.
log
.
Warn
(
"failed to validate L1 genesis block"
,
"err"
,
err
)
}
else
{
if
l1GenesisBlockRef
.
Hash
!=
cfg
.
Rollup
.
Genesis
.
L1
.
Hash
{
n
.
log
.
Warn
(
"incorrect L1 genesis block"
,
"expected"
,
cfg
.
Rollup
.
Genesis
.
L1
.
Hash
,
"actual"
,
l1GenesisBlockRef
.
Hash
)
}
else
{
n
.
log
.
Info
(
"L1 genesis block verified"
,
"hash"
,
l1GenesisBlockRef
.
Hash
)
}
}
}
// 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
...
@@ -214,27 +200,13 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
...
@@ -214,27 +200,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
id
,
err
:=
n
.
l2Source
.
L2ChainID
(
ctx
)
if
err
:=
cfg
.
Rollup
.
CheckL2ChainID
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L2 RPC chain id"
,
"err"
,
err
)
n
.
log
.
Warn
(
"failed to verify L2 RPC chain id"
,
"err"
,
err
)
}
else
{
if
cfg
.
Rollup
.
L2ChainID
!=
id
{
n
.
log
.
Warn
(
"incorrect L2 RPC chain id"
,
"expected"
,
cfg
.
Rollup
.
L2ChainID
,
"actual"
,
id
)
}
else
{
n
.
log
.
Info
(
"L2 RPC chain id verified"
,
"id"
,
id
)
}
}
}
// Validate the Rollup L2 Genesis Blockhash
// Validate the Rollup L2 Genesis Blockhash
l2GenesisBlockRef
,
err
:=
n
.
l2Source
.
L2BlockRefByNumber
(
ctx
,
cfg
.
Rollup
.
Genesis
.
L2
.
Number
)
if
err
:=
cfg
.
Rollup
.
CheckL2GenesisBlockHash
(
ctx
,
n
.
l2Source
);
err
!=
nil
{
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to verify L2 genesis block hash"
,
"err"
,
err
)
n
.
log
.
Warn
(
"failed to validate L2 genesis block"
,
"err"
,
err
)
}
else
{
if
l2GenesisBlockRef
.
Hash
!=
cfg
.
Rollup
.
Genesis
.
L2
.
Hash
{
n
.
log
.
Warn
(
"incorrect L2 genesis block"
,
"expected"
,
cfg
.
Rollup
.
Genesis
.
L2
.
Hash
,
"actual"
,
l2GenesisBlockRef
.
Hash
)
}
else
{
n
.
log
.
Info
(
"L2 genesis block verified"
,
"hash"
,
l2GenesisBlockRef
.
Hash
)
}
}
}
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 @
9ea1b53b
package
rollup
package
rollup
import
(
import
(
"context"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -55,6 +56,64 @@ type Config struct {
...
@@ -55,6 +56,64 @@ type Config struct {
L1SystemConfigAddress
common
.
Address
`json:"l1_system_config_address"`
L1SystemConfigAddress
common
.
Address
`json:"l1_system_config_address"`
}
}
type
L1Client
interface
{
L1ChainID
(
context
.
Context
)
(
*
big
.
Int
,
error
)
L1BlockRefByNumber
(
context
.
Context
,
uint64
)
(
eth
.
L1BlockRef
,
error
)
}
// CheckL1ChainID checks that the configured L1 chain ID matches the client's chain ID.
func
(
cfg
*
Config
)
CheckL1ChainID
(
ctx
context
.
Context
,
client
L1Client
)
error
{
id
,
err
:=
client
.
L1ChainID
(
ctx
)
if
err
!=
nil
{
return
err
}
if
cfg
.
L1ChainID
!=
id
{
return
fmt
.
Errorf
(
"incorrect L1 RPC chain id %d, expected %d"
,
cfg
.
L1ChainID
,
id
)
}
return
nil
}
// CheckL1GenesisBlockHash checks that the configured L1 genesis block hash is valid for the given client.
func
(
cfg
*
Config
)
CheckL1GenesisBlockHash
(
ctx
context
.
Context
,
client
L1Client
)
error
{
l1GenesisBlockRef
,
err
:=
client
.
L1BlockRefByNumber
(
ctx
,
cfg
.
Genesis
.
L1
.
Number
)
if
err
!=
nil
{
return
err
}
if
l1GenesisBlockRef
.
Hash
!=
cfg
.
Genesis
.
L1
.
Hash
{
return
fmt
.
Errorf
(
"incorrect L1 genesis block hash %d, expected %d"
,
cfg
.
Genesis
.
L1
.
Hash
,
l1GenesisBlockRef
.
Hash
)
}
return
nil
}
type
L2Client
interface
{
L2ChainID
(
context
.
Context
)
(
*
big
.
Int
,
error
)
L2BlockRefByNumber
(
context
.
Context
,
uint64
)
(
eth
.
L2BlockRef
,
error
)
}
// CheckL2ChainID checks that the configured L2 chain ID matches the client's chain ID.
func
(
cfg
*
Config
)
CheckL2ChainID
(
ctx
context
.
Context
,
client
L2Client
)
error
{
id
,
err
:=
client
.
L2ChainID
(
ctx
)
if
err
!=
nil
{
return
err
}
if
cfg
.
L2ChainID
!=
id
{
return
fmt
.
Errorf
(
"incorrect L2 RPC chain id %d, expected %d"
,
cfg
.
L2ChainID
,
id
)
}
return
nil
}
// CheckL2GenesisBlockHash checks that the configured L2 genesis block hash is valid for the given client.
func
(
cfg
*
Config
)
CheckL2GenesisBlockHash
(
ctx
context
.
Context
,
client
L2Client
)
error
{
l2GenesisBlockRef
,
err
:=
client
.
L2BlockRefByNumber
(
ctx
,
cfg
.
Genesis
.
L2
.
Number
)
if
err
!=
nil
{
return
err
}
if
l2GenesisBlockRef
.
Hash
!=
cfg
.
Genesis
.
L2
.
Hash
{
return
fmt
.
Errorf
(
"incorrect L2 genesis block hash %d, expected %d"
,
cfg
.
Genesis
.
L2
.
Hash
,
l2GenesisBlockRef
.
Hash
)
}
return
nil
}
// Check verifies that the given configuration makes sense
// Check verifies that the given configuration makes sense
func
(
cfg
*
Config
)
Check
()
error
{
func
(
cfg
*
Config
)
Check
()
error
{
if
cfg
.
BlockTime
==
0
{
if
cfg
.
BlockTime
==
0
{
...
...
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