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
715732e7
Unverified
Commit
715732e7
authored
Jul 25, 2024
by
Adrian Sutton
Committed by
GitHub
Jul 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Extract contract binding for SystemConfig (#11227)
parent
3c1d3b87
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
13 deletions
+76
-13
cmd.go
op-node/cmd/genesis/cmd.go
+5
-13
systemconfig.go
op-node/cmd/genesis/systemconfig.go
+36
-0
systemconfig_test.go
op-node/cmd/genesis/systemconfig_test.go
+28
-0
abi_loader.go
packages/contracts-bedrock/snapshots/abi_loader.go
+7
-0
No files found.
op-node/cmd/genesis/cmd.go
View file @
715732e7
...
@@ -4,12 +4,10 @@ import (
...
@@ -4,12 +4,10 @@ import (
"context"
"context"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -165,18 +163,12 @@ var Subcommands = cli.Commands{
...
@@ -165,18 +163,12 @@ var Subcommands = cli.Commands{
return
fmt
.
Errorf
(
"cannot dial %s: %w"
,
l1RPC
,
err
)
return
fmt
.
Errorf
(
"cannot dial %s: %w"
,
l1RPC
,
err
)
}
}
funcDef
:=
"startBlock()"
caller
:=
batching
.
NewMultiCaller
(
client
.
Client
(),
batching
.
DefaultBatchSize
)
funcHash
:=
crypto
.
Keccak256Hash
([]
byte
(
funcDef
))
sysCfg
:=
NewSystemConfigContract
(
caller
,
config
.
SystemConfigProxy
)
msg
:=
ethereum
.
CallMsg
{
l1StartBlockNum
,
err
:=
sysCfg
.
StartBlock
(
context
.
Background
())
To
:
&
config
.
SystemConfigProxy
,
Data
:
funcHash
[
:
4
],
// hardcode the 4byte sig
}
result
,
err
:=
client
.
CallContract
(
context
.
Background
(),
msg
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch startBlock from SystemConfig
contract
: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to fetch startBlock from SystemConfig: %w"
,
err
)
}
}
l1StartBlockNum
:=
new
(
big
.
Int
)
.
SetBytes
(
result
)
l1StartBlock
,
err
:=
client
.
BlockByNumber
(
context
.
Background
(),
l1StartBlockNum
)
l1StartBlock
,
err
:=
client
.
BlockByNumber
(
context
.
Background
(),
l1StartBlockNum
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"cannot fetch block by number: %w"
,
err
)
return
fmt
.
Errorf
(
"cannot fetch block by number: %w"
,
err
)
...
...
op-node/cmd/genesis/systemconfig.go
0 → 100644
View file @
715732e7
package
genesis
import
(
"context"
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
var
(
methodStartBlock
=
"startBlock"
)
type
SystemConfigContract
struct
{
caller
*
batching
.
MultiCaller
contract
*
batching
.
BoundContract
}
func
NewSystemConfigContract
(
caller
*
batching
.
MultiCaller
,
addr
common
.
Address
)
*
SystemConfigContract
{
return
&
SystemConfigContract
{
caller
:
caller
,
contract
:
batching
.
NewBoundContract
(
snapshots
.
LoadSystemConfigABI
(),
addr
),
}
}
func
(
c
*
SystemConfigContract
)
StartBlock
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
result
,
err
:=
c
.
caller
.
SingleCall
(
ctx
,
rpcblock
.
Latest
,
c
.
contract
.
Call
(
methodStartBlock
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to call startBlock: %w"
,
err
)
}
return
result
.
GetBigInt
(
0
),
nil
}
op-node/cmd/genesis/systemconfig_test.go
0 → 100644
View file @
715732e7
package
genesis
import
(
"context"
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func
TestSystemConfigContract_StartBlock
(
t
*
testing
.
T
)
{
addr
:=
common
.
Address
{
0xaa
}
sysCfgAbi
:=
snapshots
.
LoadSystemConfigABI
()
stubRpc
:=
batchingTest
.
NewAbiBasedRpc
(
t
,
addr
,
sysCfgAbi
)
caller
:=
batching
.
NewMultiCaller
(
stubRpc
,
batching
.
DefaultBatchSize
)
sysCfg
:=
NewSystemConfigContract
(
caller
,
addr
)
expected
:=
big
.
NewInt
(
56
)
stubRpc
.
SetResponse
(
addr
,
methodStartBlock
,
rpcblock
.
Latest
,
nil
,
[]
interface
{}{
expected
})
result
,
err
:=
sysCfg
.
StartBlock
(
context
.
Background
())
require
.
NoError
(
t
,
err
)
require
.
Truef
(
t
,
result
.
Cmp
(
expected
)
==
0
,
"expected %v, got %v"
,
expected
,
result
)
}
packages/contracts-bedrock/snapshots/abi_loader.go
View file @
715732e7
...
@@ -22,6 +22,9 @@ var mips []byte
...
@@ -22,6 +22,9 @@ var mips []byte
//go:embed abi/DelayedWETH.json
//go:embed abi/DelayedWETH.json
var
delayedWETH
[]
byte
var
delayedWETH
[]
byte
//go:embed abi/SystemConfig.json
var
systemConfig
[]
byte
func
LoadDisputeGameFactoryABI
()
*
abi
.
ABI
{
func
LoadDisputeGameFactoryABI
()
*
abi
.
ABI
{
return
loadABI
(
disputeGameFactory
)
return
loadABI
(
disputeGameFactory
)
}
}
...
@@ -38,6 +41,10 @@ func LoadDelayedWETHABI() *abi.ABI {
...
@@ -38,6 +41,10 @@ func LoadDelayedWETHABI() *abi.ABI {
return
loadABI
(
delayedWETH
)
return
loadABI
(
delayedWETH
)
}
}
func
LoadSystemConfigABI
()
*
abi
.
ABI
{
return
loadABI
(
systemConfig
)
}
func
loadABI
(
json
[]
byte
)
*
abi
.
ABI
{
func
loadABI
(
json
[]
byte
)
*
abi
.
ABI
{
if
parsed
,
err
:=
abi
.
JSON
(
bytes
.
NewReader
(
json
));
err
!=
nil
{
if
parsed
,
err
:=
abi
.
JSON
(
bytes
.
NewReader
(
json
));
err
!=
nil
{
panic
(
err
)
panic
(
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