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
aae9e545
Unverified
Commit
aae9e545
authored
Apr 19, 2023
by
mergify[bot]
Committed by
GitHub
Apr 19, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into jm/nonreentrant-with-replays
parents
74586d67
85075b94
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
79 deletions
+115
-79
main_test.go
op-program/host/cmd/main_test.go
+65
-40
config.go
op-program/host/config/config.go
+45
-14
config_test.go
op-program/host/config/config_test.go
+4
-3
l2.go
op-program/host/l2/l2.go
+1
-22
No files found.
op-program/host/cmd/main_test.go
View file @
aae9e545
This diff is collapsed.
Click to expand it.
op-program/host/config/config.go
View file @
aae9e545
package
config
import
(
"encoding/json"
"errors"
"fmt"
"os"
opnode
"github.com/ethereum-optimism/optimism/op-node"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-program/host/flags"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli"
)
...
...
@@ -22,16 +27,24 @@ var (
)
type
Config
struct
{
Rollup
*
rollup
.
Config
DataDir
string
L2URL
string
L2GenesisPath
string
L1Head
common
.
Hash
L2Head
common
.
Hash
L2Claim
common
.
Hash
L1URL
string
L1TrustRPC
bool
L1RPCKind
sources
.
RPCProviderKind
Rollup
*
rollup
.
Config
// DataDir is the directory to read/write pre-image data from/to.
//If not set, an in-memory key-value store is used and fetching data must be enabled
DataDir
string
// L1Head is the block has of the L1 chain head block
L1Head
common
.
Hash
L1URL
string
L1TrustRPC
bool
L1RPCKind
sources
.
RPCProviderKind
// L2Head is the agreed L2 block to start derivation from
L2Head
common
.
Hash
L2URL
string
// L2Claim is the claimed L2 output root to verify
L2Claim
common
.
Hash
// L2ChainConfig is the op-geth chain config for the L2 execution engine
L2ChainConfig
*
params
.
ChainConfig
}
func
(
c
*
Config
)
Check
()
error
{
...
...
@@ -50,7 +63,7 @@ func (c *Config) Check() error {
if
c
.
L2Claim
==
(
common
.
Hash
{})
{
return
ErrInvalidL2Claim
}
if
c
.
L2
GenesisPath
==
""
{
if
c
.
L2
ChainConfig
==
nil
{
return
ErrMissingL2Genesis
}
if
(
c
.
L1URL
!=
""
)
!=
(
c
.
L2URL
!=
""
)
{
...
...
@@ -67,10 +80,10 @@ func (c *Config) FetchingEnabled() bool {
}
// NewConfig creates a Config with all optional values set to the CLI default value
func
NewConfig
(
rollupCfg
*
rollup
.
Config
,
l2Genesis
Path
strin
g
,
l1Head
common
.
Hash
,
l2Head
common
.
Hash
,
l2Claim
common
.
Hash
)
*
Config
{
func
NewConfig
(
rollupCfg
*
rollup
.
Config
,
l2Genesis
*
params
.
ChainConfi
g
,
l1Head
common
.
Hash
,
l2Head
common
.
Hash
,
l2Claim
common
.
Hash
)
*
Config
{
return
&
Config
{
Rollup
:
rollupCfg
,
L2
GenesisPath
:
l2GenesisPath
,
L2
ChainConfig
:
l2Genesis
,
L1Head
:
l1Head
,
L2Head
:
l2Head
,
L2Claim
:
l2Claim
,
...
...
@@ -98,11 +111,16 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
if
l1Head
==
(
common
.
Hash
{})
{
return
nil
,
ErrInvalidL1Head
}
l2GenesisPath
:=
ctx
.
GlobalString
(
flags
.
L2GenesisPath
.
Name
)
l2ChainConfig
,
err
:=
loadChainConfigFromGenesis
(
l2GenesisPath
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid genesis: %w"
,
err
)
}
return
&
Config
{
Rollup
:
rollupCfg
,
DataDir
:
ctx
.
GlobalString
(
flags
.
DataDir
.
Name
),
L2URL
:
ctx
.
GlobalString
(
flags
.
L2NodeAddr
.
Name
),
L2
GenesisPath
:
ctx
.
GlobalString
(
flags
.
L2GenesisPath
.
Name
)
,
L2
ChainConfig
:
l2ChainConfig
,
L2Head
:
l2Head
,
L2Claim
:
l2Claim
,
L1Head
:
l1Head
,
...
...
@@ -111,3 +129,16 @@ func NewConfigFromCLI(ctx *cli.Context) (*Config, error) {
L1RPCKind
:
sources
.
RPCProviderKind
(
ctx
.
GlobalString
(
flags
.
L1RPCProviderKind
.
Name
)),
},
nil
}
func
loadChainConfigFromGenesis
(
path
string
)
(
*
params
.
ChainConfig
,
error
)
{
data
,
err
:=
os
.
ReadFile
(
path
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"read l2 genesis file: %w"
,
err
)
}
var
genesis
core
.
Genesis
err
=
json
.
Unmarshal
(
data
,
&
genesis
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"parse l2 genesis file: %w"
,
err
)
}
return
genesis
.
Config
,
nil
}
op-program/host/config/config_test.go
View file @
aae9e545
...
...
@@ -6,11 +6,12 @@ import (
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)
var
validRollupConfig
=
&
chaincfg
.
Goerli
var
validL2Genesis
Path
=
"genesis.json"
var
validL2Genesis
=
params
.
GoerliChainConfig
var
validL1Head
=
common
.
Hash
{
0xaa
}
var
validL2Head
=
common
.
Hash
{
0xbb
}
var
validL2Claim
=
common
.
Hash
{
0xcc
}
...
...
@@ -60,7 +61,7 @@ func TestL2ClaimRequired(t *testing.T) {
func
TestL2GenesisRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
()
config
.
L2
GenesisPath
=
""
config
.
L2
ChainConfig
=
nil
err
:=
config
.
Check
()
require
.
ErrorIs
(
t
,
err
,
ErrMissingL2Genesis
)
}
...
...
@@ -132,7 +133,7 @@ func TestRequireDataDirInNonFetchingMode(t *testing.T) {
}
func
validConfig
()
*
Config
{
cfg
:=
NewConfig
(
validRollupConfig
,
validL2Genesis
Path
,
validL1Head
,
validL2Head
,
validL2Claim
)
cfg
:=
NewConfig
(
validRollupConfig
,
validL2Genesis
,
validL1Head
,
validL2Head
,
validL2Claim
)
cfg
.
DataDir
=
"/tmp/configTest"
return
cfg
}
op-program/host/l2/l2.go
View file @
aae9e545
...
...
@@ -2,25 +2,17 @@ package l2
import
(
"context"
"encoding/json"
"fmt"
"os"
cll2
"github.com/ethereum-optimism/optimism/op-program/client/l2"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/preimage"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)
func
NewEngine
(
logger
log
.
Logger
,
pre
preimage
.
Oracle
,
hint
preimage
.
Hinter
,
cfg
*
config
.
Config
)
(
*
cll2
.
OracleEngine
,
error
)
{
oracle
:=
cll2
.
NewCachingOracle
(
cll2
.
NewPreimageOracle
(
pre
,
hint
))
genesis
,
err
:=
loadL2Genesis
(
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
engineBackend
,
err
:=
cll2
.
NewOracleBackedL2Chain
(
logger
,
oracle
,
genesis
,
cfg
.
L2Head
)
engineBackend
,
err
:=
cll2
.
NewOracleBackedL2Chain
(
logger
,
oracle
,
cfg
.
L2ChainConfig
,
cfg
.
L2Head
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"create l2 chain: %w"
,
err
)
}
...
...
@@ -34,16 +26,3 @@ func NewFetchingOracle(ctx context.Context, logger log.Logger, cfg *config.Confi
}
return
oracle
,
nil
}
func
loadL2Genesis
(
cfg
*
config
.
Config
)
(
*
params
.
ChainConfig
,
error
)
{
data
,
err
:=
os
.
ReadFile
(
cfg
.
L2GenesisPath
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"read l2 genesis file: %w"
,
err
)
}
var
genesis
core
.
Genesis
err
=
json
.
Unmarshal
(
data
,
&
genesis
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"parse l2 genesis file: %w"
,
err
)
}
return
genesis
.
Config
,
nil
}
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