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
5c6d39b6
Commit
5c6d39b6
authored
Dec 07, 2023
by
Tei Im
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use predefined clients
parent
7f57a654
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
51 deletions
+45
-51
main.go
op-chain-ops/cmd/check-derivation/main.go
+45
-51
No files found.
op-chain-ops/cmd/check-derivation/main.go
View file @
5c6d39b6
...
@@ -10,18 +10,19 @@ import (
...
@@ -10,18 +10,19 @@ import (
"os"
"os"
"time"
"time"
clients2
"github.com/ethereum-optimism/optimism/op-chain-ops/clients"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"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"
"github.com/ethereum/go-ethereum/rpc"
"github.com/mattn/go-isatty"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
)
)
...
@@ -92,61 +93,50 @@ func main() {
...
@@ -92,61 +93,50 @@ func main() {
}
}
}
}
type
clients
struct
{
func
newClientsFromContext
(
cliCtx
*
cli
.
Context
)
(
*
ethclient
.
Client
,
*
sources
.
EthClient
,
error
)
{
Client
*
ethclient
.
Client
clients
,
err
:=
clients2
.
NewClientsFromContext
(
cliCtx
)
RpcClient
*
rpc
.
Client
}
func
newClientsFromContext
(
ctx
context
.
Context
,
cliCtx
*
cli
.
Context
)
(
*
clients
,
error
)
{
url
:=
cliCtx
.
String
(
"l2-rpc-url"
)
ethClient
,
err
:=
ethclient
.
Dial
(
url
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot dial ethclient: %w"
,
err
)
return
nil
,
nil
,
err
}
}
rpcClient
,
err
:=
rpc
.
DialContext
(
ctx
,
url
)
ethClCfg
:=
sources
.
EthClientConfig
{
MaxRequestsPerBatch
:
10
,
MaxConcurrentRequests
:
10
,
ReceiptsCacheSize
:
10
,
TransactionsCacheSize
:
10
,
HeadersCacheSize
:
10
,
PayloadsCacheSize
:
10
,
TrustRPC
:
false
,
MustBePostMerge
:
true
,
RPCProviderKind
:
sources
.
RPCKindStandard
,
MethodResetDuration
:
time
.
Minute
,
}
cl
:=
ethclient
.
NewClient
(
clients
.
L2RpcClient
)
ethCl
,
err
:=
sources
.
NewEthClient
(
client
.
NewBaseRPCClient
(
clients
.
L2RpcClient
),
log
.
Root
(),
nil
,
&
ethClCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot dial rpc client: %w"
,
err
)
return
nil
,
nil
,
err
}
}
return
&
clients
{
Client
:
ethClient
,
RpcClient
:
rpcClient
}
,
nil
return
cl
,
ethCl
,
nil
}
}
func
getHead
(
ctx
context
.
Context
,
client
*
rpc
.
Client
,
info
interface
{}
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
func
getHead
(
ctx
context
.
Context
,
client
*
sources
.
EthClient
,
label
eth
.
BlockLabel
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
return
retry
.
Do2
(
ctx
,
10
,
&
retry
.
FixedStrategy
{
Dur
:
100
*
time
.
Millisecond
},
func
()
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
return
retry
.
Do2
(
ctx
,
10
,
&
retry
.
FixedStrategy
{
Dur
:
100
*
time
.
Millisecond
},
func
()
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
3
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
3
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
res
:=
make
(
map
[
string
]
interface
{})
err
:=
client
.
CallContext
(
ctx
,
&
res
,
"eth_getBlockByNumber"
,
info
,
false
)
blockInfo
,
err
:=
client
.
InfoByLabel
(
ctx
,
label
)
if
err
!=
nil
{
if
err
!=
nil
{
return
eth
.
BlockID
{},
common
.
Hash
{},
err
return
eth
.
BlockID
{},
common
.
Hash
{},
err
}
}
numStr
,
ok
:=
res
[
"number"
]
.
(
string
)
return
eth
.
BlockID
{
Hash
:
blockInfo
.
Hash
(),
Number
:
blockInfo
.
NumberU64
()},
blockInfo
.
ParentHash
(),
nil
if
!
ok
{
return
eth
.
BlockID
{},
common
.
Hash
{},
errors
.
New
(
"block number field invalid"
)
}
blockNum
,
err
:=
hexutil
.
DecodeUint64
(
numStr
)
if
err
!=
nil
{
return
eth
.
BlockID
{},
common
.
Hash
{},
fmt
.
Errorf
(
"failed to decode RPC block number: %w"
,
err
)
}
hashStr
,
ok
:=
res
[
"hash"
]
.
(
string
)
if
!
ok
{
return
eth
.
BlockID
{},
common
.
Hash
{},
errors
.
New
(
"hash field invalid"
)
}
hash
:=
common
.
HexToHash
(
hashStr
)
parentHashStr
,
ok
:=
res
[
"parentHash"
]
.
(
string
)
if
!
ok
{
return
eth
.
BlockID
{},
common
.
Hash
{},
errors
.
New
(
"parent hash field invalid"
)
}
parentHash
:=
common
.
HexToHash
(
parentHashStr
)
return
eth
.
BlockID
{
Hash
:
hash
,
Number
:
blockNum
},
parentHash
,
nil
})
})
}
}
func
getUnsafeHead
(
ctx
context
.
Context
,
client
*
rpc
.
Client
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
func
getUnsafeHead
(
ctx
context
.
Context
,
client
*
sources
.
Eth
Client
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
return
getHead
(
ctx
,
client
,
"latest"
)
return
getHead
(
ctx
,
client
,
eth
.
Unsafe
)
}
}
func
getSafeHead
(
ctx
context
.
Context
,
client
*
rpc
.
Client
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
func
getSafeHead
(
ctx
context
.
Context
,
client
*
sources
.
Eth
Client
)
(
eth
.
BlockID
,
common
.
Hash
,
error
)
{
return
getHead
(
ctx
,
client
,
"safe"
)
return
getHead
(
ctx
,
client
,
eth
.
Safe
)
}
}
func
checkReorg
(
blockMap
map
[
uint64
]
common
.
Hash
,
number
uint64
,
hash
common
.
Hash
)
{
func
checkReorg
(
blockMap
map
[
uint64
]
common
.
Hash
,
number
uint64
,
hash
common
.
Hash
)
{
...
@@ -162,16 +152,17 @@ func checkReorg(blockMap map[uint64]common.Hash, number uint64, hash common.Hash
...
@@ -162,16 +152,17 @@ func checkReorg(blockMap map[uint64]common.Hash, number uint64, hash common.Hash
// detectL2Reorg polls safe heads and detects l2 unsafe block reorg.
// detectL2Reorg polls safe heads and detects l2 unsafe block reorg.
func
detectL2Reorg
(
cliCtx
*
cli
.
Context
)
error
{
func
detectL2Reorg
(
cliCtx
*
cli
.
Context
)
error
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
clients
,
err
:=
newClientsFromContext
(
ctx
,
cliCtx
)
_
,
ethCl
,
err
:=
newClientsFromContext
(
cliCtx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
var
pollingInterval
=
time
.
Duration
(
cliCtx
.
Int
(
"polling-interval"
))
*
time
.
Millisecond
var
pollingInterval
=
time
.
Duration
(
cliCtx
.
Int
(
"polling-interval"
))
*
time
.
Millisecond
// blockMap maps blockNumber to blockHash
// blockMap maps blockNumber to blockHash
blockMap
:=
make
(
map
[
uint64
]
common
.
Hash
)
blockMap
:=
make
(
map
[
uint64
]
common
.
Hash
)
var
prevUnsafeHeadNum
uint64
var
prevUnsafeHeadNum
uint64
for
{
for
{
unsafeHeadBlockId
,
parentHash
,
err
:=
getUnsafeHead
(
ctx
,
clients
.
RpcClient
)
unsafeHeadBlockId
,
parentHash
,
err
:=
getUnsafeHead
(
ctx
,
ethCl
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch unsafe head: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to fetch unsafe head: %w"
,
err
)
}
}
...
@@ -331,7 +322,10 @@ func confirmTransaction(ctx context.Context, ethClient *ethclient.Client, l2Bloc
...
@@ -331,7 +322,10 @@ func confirmTransaction(ctx context.Context, ethClient *ethclient.Client, l2Bloc
// Then polls safe head to check unsafe blocks which includes sent tx are consolidated.
// Then polls safe head to check unsafe blocks which includes sent tx are consolidated.
func
checkConsolidation
(
cliCtx
*
cli
.
Context
)
error
{
func
checkConsolidation
(
cliCtx
*
cli
.
Context
)
error
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
clients
,
err
:=
newClientsFromContext
(
ctx
,
cliCtx
)
cl
,
ethCl
,
err
:=
newClientsFromContext
(
cliCtx
)
if
err
!=
nil
{
return
err
}
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -364,23 +358,23 @@ func checkConsolidation(cliCtx *cli.Context) error {
...
@@ -364,23 +358,23 @@ func checkConsolidation(cliCtx *cli.Context) error {
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
switch
i
%
4
{
switch
i
%
4
{
case
0
:
case
0
:
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
ients
.
Client
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
LegacyTxType
,
false
)
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
LegacyTxType
,
false
)
case
1
:
case
1
:
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
ients
.
Client
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
LegacyTxType
,
true
)
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
LegacyTxType
,
true
)
case
2
:
case
2
:
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
ients
.
Client
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
AccessListTxType
,
true
)
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
AccessListTxType
,
true
)
case
3
:
case
3
:
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
ients
.
Client
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
DynamicFeeTxType
,
true
)
tx
,
err
=
getRandomSignedTransaction
(
ctx
,
cl
,
rng
,
from
,
privateKey
,
l2ChainID
,
types
.
DynamicFeeTxType
,
true
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
cl
ients
.
Client
.
SendTransaction
(
ctx
,
tx
)
err
=
cl
.
SendTransaction
(
ctx
,
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to send transaction: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to send transaction: %w"
,
err
)
}
}
txHash
:=
tx
.
Hash
()
txHash
:=
tx
.
Hash
()
blockId
,
err
:=
confirmTransaction
(
ctx
,
cl
ients
.
Client
,
l2BlockTime
,
txHash
)
blockId
,
err
:=
confirmTransaction
(
ctx
,
cl
,
l2BlockTime
,
txHash
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -390,7 +384,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
...
@@ -390,7 +384,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
numChecked
:=
0
numChecked
:=
0
failed
:=
false
failed
:=
false
for
{
for
{
safeHeadBlockId
,
_
,
err
:=
getSafeHead
(
ctx
,
clients
.
RpcClient
)
safeHeadBlockId
,
_
,
err
:=
getSafeHead
(
ctx
,
ethCl
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch safe head: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to fetch safe head: %w"
,
err
)
}
}
...
@@ -401,7 +395,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
...
@@ -401,7 +395,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
safeBlockHash
:=
safeHeadBlockId
.
Hash
safeBlockHash
:=
safeHeadBlockId
.
Hash
if
safeHeadBlockId
.
Number
!=
blockId
.
Number
{
if
safeHeadBlockId
.
Number
!=
blockId
.
Number
{
safeBlock
,
err
:=
retry
.
Do
(
ctx
,
10
,
&
retry
.
FixedStrategy
{
Dur
:
100
*
time
.
Millisecond
},
func
()
(
*
types
.
Block
,
error
)
{
safeBlock
,
err
:=
retry
.
Do
(
ctx
,
10
,
&
retry
.
FixedStrategy
{
Dur
:
100
*
time
.
Millisecond
},
func
()
(
*
types
.
Block
,
error
)
{
return
cl
ients
.
Client
.
BlockByNumber
(
ctx
,
new
(
big
.
Int
)
.
SetUint64
(
blockId
.
Number
))
return
cl
.
BlockByNumber
(
ctx
,
new
(
big
.
Int
)
.
SetUint64
(
blockId
.
Number
))
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch block by number: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to fetch block by number: %w"
,
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