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
2961cf94
Unverified
Commit
2961cf94
authored
Sep 19, 2023
by
OptimismBot
Committed by
GitHub
Sep 19, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7278 from ethereum-optimism/inphi/host-chainid
op-program: Use hardcoded chain config when available
parents
0511b47b
fca6e255
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
26 deletions
+57
-26
config.go
op-program/host/config/config.go
+31
-22
config_test.go
op-program/host/config/config_test.go
+16
-1
local.go
op-program/host/kvstore/local.go
+9
-1
local_test.go
op-program/host/kvstore/local_test.go
+1
-2
No files found.
op-program/host/config/config.go
View file @
2961cf94
...
@@ -64,6 +64,9 @@ type Config struct {
...
@@ -64,6 +64,9 @@ type Config struct {
// ServerMode indicates that the program should run in pre-image server mode and wait for requests.
// ServerMode indicates that the program should run in pre-image server mode and wait for requests.
// No client program is run.
// No client program is run.
ServerMode
bool
ServerMode
bool
// IsCustomChainConfig indicates that the program uses a custom chain configuration
IsCustomChainConfig
bool
}
}
func
(
c
*
Config
)
Check
()
error
{
func
(
c
*
Config
)
Check
()
error
{
...
@@ -117,6 +120,8 @@ func NewConfig(
...
@@ -117,6 +120,8 @@ func NewConfig(
l2Claim
common
.
Hash
,
l2Claim
common
.
Hash
,
l2ClaimBlockNum
uint64
,
l2ClaimBlockNum
uint64
,
)
*
Config
{
)
*
Config
{
_
,
err
:=
params
.
LoadOPStackChainConfig
(
l2Genesis
.
ChainID
.
Uint64
())
isCustomConfig
:=
err
!=
nil
return
&
Config
{
return
&
Config
{
Rollup
:
rollupCfg
,
Rollup
:
rollupCfg
,
L2ChainConfig
:
l2Genesis
,
L2ChainConfig
:
l2Genesis
,
...
@@ -126,6 +131,7 @@ func NewConfig(
...
@@ -126,6 +131,7 @@ func NewConfig(
L2Claim
:
l2Claim
,
L2Claim
:
l2Claim
,
L2ClaimBlockNumber
:
l2ClaimBlockNum
,
L2ClaimBlockNumber
:
l2ClaimBlockNum
,
L1RPCKind
:
sources
.
RPCKindBasic
,
L1RPCKind
:
sources
.
RPCKindBasic
,
IsCustomChainConfig
:
isCustomConfig
,
}
}
}
}
...
@@ -156,6 +162,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
...
@@ -156,6 +162,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
}
}
l2GenesisPath
:=
ctx
.
String
(
flags
.
L2GenesisPath
.
Name
)
l2GenesisPath
:=
ctx
.
String
(
flags
.
L2GenesisPath
.
Name
)
var
l2ChainConfig
*
params
.
ChainConfig
var
l2ChainConfig
*
params
.
ChainConfig
var
isCustomConfig
bool
if
l2GenesisPath
==
""
{
if
l2GenesisPath
==
""
{
networkName
:=
ctx
.
String
(
flags
.
Network
.
Name
)
networkName
:=
ctx
.
String
(
flags
.
Network
.
Name
)
ch
:=
chaincfg
.
ChainByName
(
networkName
)
ch
:=
chaincfg
.
ChainByName
(
networkName
)
...
@@ -169,6 +176,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
...
@@ -169,6 +176,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
l2ChainConfig
=
cfg
l2ChainConfig
=
cfg
}
else
{
}
else
{
l2ChainConfig
,
err
=
loadChainConfigFromGenesis
(
l2GenesisPath
)
l2ChainConfig
,
err
=
loadChainConfigFromGenesis
(
l2GenesisPath
)
isCustomConfig
=
true
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid genesis: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid genesis: %w"
,
err
)
...
@@ -188,6 +196,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
...
@@ -188,6 +196,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
L1RPCKind
:
sources
.
RPCProviderKind
(
ctx
.
String
(
flags
.
L1RPCProviderKind
.
Name
)),
L1RPCKind
:
sources
.
RPCProviderKind
(
ctx
.
String
(
flags
.
L1RPCProviderKind
.
Name
)),
ExecCmd
:
ctx
.
String
(
flags
.
Exec
.
Name
),
ExecCmd
:
ctx
.
String
(
flags
.
Exec
.
Name
),
ServerMode
:
ctx
.
Bool
(
flags
.
Server
.
Name
),
ServerMode
:
ctx
.
Bool
(
flags
.
Server
.
Name
),
IsCustomChainConfig
:
isCustomConfig
,
},
nil
},
nil
}
}
...
...
op-program/host/config/config_test.go
View file @
2961cf94
package
config
package
config
import
(
import
(
"math/big"
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -12,7 +14,7 @@ import (
...
@@ -12,7 +14,7 @@ import (
var
(
var
(
validRollupConfig
=
chaincfg
.
Goerli
validRollupConfig
=
chaincfg
.
Goerli
validL2Genesis
=
params
.
GoerliChainConfig
validL2Genesis
=
chainconfig
.
OP
GoerliChainConfig
validL1Head
=
common
.
Hash
{
0xaa
}
validL1Head
=
common
.
Hash
{
0xaa
}
validL2Head
=
common
.
Hash
{
0xbb
}
validL2Head
=
common
.
Hash
{
0xbb
}
validL2Claim
=
common
.
Hash
{
0xcc
}
validL2Claim
=
common
.
Hash
{
0xcc
}
...
@@ -158,6 +160,19 @@ func TestRejectExecAndServerMode(t *testing.T) {
...
@@ -158,6 +160,19 @@ func TestRejectExecAndServerMode(t *testing.T) {
require
.
ErrorIs
(
t
,
err
,
ErrNoExecInServerMode
)
require
.
ErrorIs
(
t
,
err
,
ErrNoExecInServerMode
)
}
}
func
TestIsCustomChainConfig
(
t
*
testing
.
T
)
{
t
.
Run
(
"nonCustom"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
validConfig
()
require
.
Equal
(
t
,
cfg
.
IsCustomChainConfig
,
false
)
})
t
.
Run
(
"custom"
,
func
(
t
*
testing
.
T
)
{
customChainConfig
:=
&
params
.
ChainConfig
{
ChainID
:
big
.
NewInt
(
0x1212121212
)}
cfg
:=
NewConfig
(
validRollupConfig
,
customChainConfig
,
validL1Head
,
validL2Head
,
validL2OutputRoot
,
validL2Claim
,
validL2ClaimBlockNum
)
require
.
Equal
(
t
,
cfg
.
IsCustomChainConfig
,
true
)
})
}
func
validConfig
()
*
Config
{
func
validConfig
()
*
Config
{
cfg
:=
NewConfig
(
validRollupConfig
,
validL2Genesis
,
validL1Head
,
validL2Head
,
validL2OutputRoot
,
validL2Claim
,
validL2ClaimBlockNum
)
cfg
:=
NewConfig
(
validRollupConfig
,
validL2Genesis
,
validL1Head
,
validL2Head
,
validL2OutputRoot
,
validL2Claim
,
validL2ClaimBlockNum
)
cfg
.
DataDir
=
"/tmp/configTest"
cfg
.
DataDir
=
"/tmp/configTest"
...
...
op-program/host/kvstore/local.go
View file @
2961cf94
...
@@ -38,7 +38,15 @@ func (s *LocalPreimageSource) Get(key common.Hash) ([]byte, error) {
...
@@ -38,7 +38,15 @@ func (s *LocalPreimageSource) Get(key common.Hash) ([]byte, error) {
case
l2ClaimBlockNumberKey
:
case
l2ClaimBlockNumberKey
:
return
binary
.
BigEndian
.
AppendUint64
(
nil
,
s
.
config
.
L2ClaimBlockNumber
),
nil
return
binary
.
BigEndian
.
AppendUint64
(
nil
,
s
.
config
.
L2ClaimBlockNumber
),
nil
case
l2ChainIDKey
:
case
l2ChainIDKey
:
return
binary
.
BigEndian
.
AppendUint64
(
nil
,
client
.
CustomChainIDIndicator
),
nil
// The CustomChainIDIndicator informs the client to rely on the L2ChainConfigKey to
// read the chain config. Otherwise, it'll attempt to read a non-existent hardcoded chain config
var
chainID
uint64
if
s
.
config
.
IsCustomChainConfig
{
chainID
=
client
.
CustomChainIDIndicator
}
else
{
chainID
=
s
.
config
.
L2ChainConfig
.
ChainID
.
Uint64
()
}
return
binary
.
BigEndian
.
AppendUint64
(
nil
,
chainID
),
nil
case
l2ChainConfigKey
:
case
l2ChainConfigKey
:
return
json
.
Marshal
(
s
.
config
.
L2ChainConfig
)
return
json
.
Marshal
(
s
.
config
.
L2ChainConfig
)
case
rollupKey
:
case
rollupKey
:
...
...
op-program/host/kvstore/local_test.go
View file @
2961cf94
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/client"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
...
@@ -33,7 +32,7 @@ func TestLocalPreimageSource(t *testing.T) {
...
@@ -33,7 +32,7 @@ func TestLocalPreimageSource(t *testing.T) {
{
"L2OutputRoot"
,
l2OutputRootKey
,
cfg
.
L2OutputRoot
.
Bytes
()},
{
"L2OutputRoot"
,
l2OutputRootKey
,
cfg
.
L2OutputRoot
.
Bytes
()},
{
"L2Claim"
,
l2ClaimKey
,
cfg
.
L2Claim
.
Bytes
()},
{
"L2Claim"
,
l2ClaimKey
,
cfg
.
L2Claim
.
Bytes
()},
{
"L2ClaimBlockNumber"
,
l2ClaimBlockNumberKey
,
binary
.
BigEndian
.
AppendUint64
(
nil
,
cfg
.
L2ClaimBlockNumber
)},
{
"L2ClaimBlockNumber"
,
l2ClaimBlockNumberKey
,
binary
.
BigEndian
.
AppendUint64
(
nil
,
cfg
.
L2ClaimBlockNumber
)},
{
"L2ChainID"
,
l2ChainIDKey
,
binary
.
BigEndian
.
AppendUint64
(
nil
,
c
lient
.
CustomChainIDIndicator
)},
{
"L2ChainID"
,
l2ChainIDKey
,
binary
.
BigEndian
.
AppendUint64
(
nil
,
c
fg
.
L2ChainConfig
.
ChainID
.
Uint64
()
)},
{
"Rollup"
,
rollupKey
,
asJson
(
t
,
cfg
.
Rollup
)},
{
"Rollup"
,
rollupKey
,
asJson
(
t
,
cfg
.
Rollup
)},
{
"ChainConfig"
,
l2ChainConfigKey
,
asJson
(
t
,
cfg
.
L2ChainConfig
)},
{
"ChainConfig"
,
l2ChainConfigKey
,
asJson
(
t
,
cfg
.
L2ChainConfig
)},
{
"Unknown"
,
preimage
.
LocalIndexKey
(
1000
)
.
PreimageKey
(),
nil
},
{
"Unknown"
,
preimage
.
LocalIndexKey
(
1000
)
.
PreimageKey
(),
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