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
e648cc2d
Unverified
Commit
e648cc2d
authored
Aug 14, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-e2e: Move withdrawal wait helpers to op-e2e
Avoids op-node depending on test code.
parent
c5e5eef8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
65 deletions
+77
-65
withdrawals.go
op-e2e/e2eutils/wait/withdrawals.go
+71
-0
system_tob_test.go
op-e2e/system_tob_test.go
+3
-2
withdrawal_helper.go
op-e2e/withdrawal_helper.go
+3
-2
utils.go
op-node/withdrawals/utils.go
+0
-61
No files found.
op-e2e/e2eutils/wait/withdrawals.go
0 → 100644
View file @
e648cc2d
package
wait
import
(
"context"
"fmt"
"math/big"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
// ForOutputRootPublished waits until there is an output published for an L2 block number larger than the supplied l2BlockNumber
// This function polls and can block for a very long time if used on mainnet.
// This returns the block number to use for proof generation.
func
ForOutputRootPublished
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
l2OutputOracleAddr
common
.
Address
,
l2BlockNumber
*
big
.
Int
)
(
uint64
,
error
)
{
l2BlockNumber
=
new
(
big
.
Int
)
.
Set
(
l2BlockNumber
)
// Don't clobber caller owned l2BlockNumber
opts
:=
&
bind
.
CallOpts
{
Context
:
ctx
}
l2OO
,
err
:=
bindings
.
NewL2OutputOracleCaller
(
l2OutputOracleAddr
,
client
)
if
err
!=
nil
{
return
0
,
err
}
getL2BlockFromLatestOutput
:=
func
()
(
*
big
.
Int
,
error
)
{
return
l2OO
.
LatestBlockNumber
(
opts
)
}
outputBlockNum
,
err
:=
AndGet
(
ctx
,
time
.
Second
,
getL2BlockFromLatestOutput
,
func
(
latest
*
big
.
Int
)
bool
{
return
latest
.
Cmp
(
l2BlockNumber
)
>=
0
})
if
err
!=
nil
{
return
0
,
err
}
return
outputBlockNum
.
Uint64
(),
nil
}
// ForFinalizationPeriod waits until the L1 chain has progressed far enough that l1ProvingBlockNum has completed
// the finalization period.
// This functions polls and can block for a very long time if used on mainnet.
func
ForFinalizationPeriod
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
l1ProvingBlockNum
*
big
.
Int
,
l2OutputOracleAddr
common
.
Address
)
error
{
l1ProvingBlockNum
=
new
(
big
.
Int
)
.
Set
(
l1ProvingBlockNum
)
// Don't clobber caller owned l1ProvingBlockNum
opts
:=
&
bind
.
CallOpts
{
Context
:
ctx
}
// Load finalization period
l2OO
,
err
:=
bindings
.
NewL2OutputOracleCaller
(
l2OutputOracleAddr
,
client
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"create L2OOCaller: %w"
,
err
)
}
finalizationPeriod
,
err
:=
l2OO
.
FINALIZATIONPERIODSECONDS
(
opts
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"get finalization period: %w"
,
err
)
}
provingHeader
,
err
:=
client
.
HeaderByNumber
(
ctx
,
l1ProvingBlockNum
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"retrieve proving header: %w"
,
err
)
}
targetTimestamp
:=
new
(
big
.
Int
)
.
Add
(
new
(
big
.
Int
)
.
SetUint64
(
provingHeader
.
Time
),
finalizationPeriod
)
targetTime
:=
time
.
Unix
(
targetTimestamp
.
Int64
(),
0
)
// Assume clock is relatively correct
time
.
Sleep
(
time
.
Until
(
targetTime
))
// Poll for L1 Block to have a time greater than the target time
return
For
(
ctx
,
time
.
Second
,
func
()
(
bool
,
error
)
{
header
,
err
:=
client
.
HeaderByNumber
(
ctx
,
nil
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"retrieve latest header: %w"
,
err
)
}
return
header
.
Time
>
targetTimestamp
.
Uint64
(),
nil
})
}
op-e2e/system_tob_test.go
View file @
e648cc2d
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/testutils/fuzzerutils"
"github.com/ethereum-optimism/optimism/op-node/testutils/fuzzerutils"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts"
...
@@ -534,7 +535,7 @@ func TestMixedWithdrawalValidity(t *testing.T) {
...
@@ -534,7 +535,7 @@ func TestMixedWithdrawalValidity(t *testing.T) {
// Wait for the finalization period, then we can finalize this withdrawal.
// Wait for the finalization period, then we can finalize this withdrawal.
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
40
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
40
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
NotEqual
(
t
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
,
common
.
Address
{})
require
.
NotEqual
(
t
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
,
common
.
Address
{})
blockNumber
,
err
:=
w
ithdrawals
.
Wait
ForOutputRootPublished
(
ctx
,
l1Client
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
,
receipt
.
BlockNumber
)
blockNumber
,
err
:=
w
ait
.
ForOutputRootPublished
(
ctx
,
l1Client
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
,
receipt
.
BlockNumber
)
cancel
()
cancel
()
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
...
@@ -662,7 +663,7 @@ func TestMixedWithdrawalValidity(t *testing.T) {
...
@@ -662,7 +663,7 @@ func TestMixedWithdrawalValidity(t *testing.T) {
// Wait for finalization and then create the Finalized Withdrawal Transaction
// Wait for finalization and then create the Finalized Withdrawal Transaction
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
45
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
45
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
err
=
w
ithdrawals
.
Wait
ForFinalizationPeriod
(
ctx
,
l1Client
,
header
.
Number
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
)
err
=
w
ait
.
ForFinalizationPeriod
(
ctx
,
l1Client
,
header
.
Number
,
cfg
.
L1Deployments
.
L2OutputOracleProxy
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
// Finalize withdrawal
// Finalize withdrawal
...
...
op-e2e/withdrawal_helper.go
View file @
e648cc2d
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -89,7 +90,7 @@ func ProveWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client,
...
@@ -89,7 +90,7 @@ func ProveWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client,
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
40
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
40
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
blockNumber
,
err
:=
w
ithdrawals
.
Wait
ForOutputRootPublished
(
ctx
,
l1Client
,
config
.
L1Deployments
.
L2OutputOracleProxy
,
l2WithdrawalReceipt
.
BlockNumber
)
blockNumber
,
err
:=
w
ait
.
ForOutputRootPublished
(
ctx
,
l1Client
,
config
.
L1Deployments
.
L2OutputOracleProxy
,
l2WithdrawalReceipt
.
BlockNumber
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
rpcClient
,
err
:=
rpc
.
Dial
(
l2Node
.
WSEndpoint
())
rpcClient
,
err
:=
rpc
.
Dial
(
l2Node
.
WSEndpoint
())
...
@@ -145,7 +146,7 @@ func FinalizeWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Clie
...
@@ -145,7 +146,7 @@ func FinalizeWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Clie
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
err
:=
w
ithdrawals
.
Wait
ForFinalizationPeriod
(
ctx
,
l1Client
,
withdrawalProofReceipt
.
BlockNumber
,
config
.
L1Deployments
.
L2OutputOracleProxy
)
err
:=
w
ait
.
ForFinalizationPeriod
(
ctx
,
l1Client
,
withdrawalProofReceipt
.
BlockNumber
,
config
.
L1Deployments
.
L2OutputOracleProxy
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
privKey
,
cfg
.
L1ChainIDBig
())
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
privKey
,
cfg
.
L1ChainIDBig
())
...
...
op-node/withdrawals/utils.go
View file @
e648cc2d
...
@@ -6,15 +6,12 @@ import (
...
@@ -6,15 +6,12 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
"time"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"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/gethclient"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
...
@@ -23,64 +20,6 @@ import (
...
@@ -23,64 +20,6 @@ import (
var
MessagePassedTopic
=
crypto
.
Keccak256Hash
([]
byte
(
"MessagePassed(uint256,address,address,uint256,uint256,bytes,bytes32)"
))
var
MessagePassedTopic
=
crypto
.
Keccak256Hash
([]
byte
(
"MessagePassed(uint256,address,address,uint256,uint256,bytes,bytes32)"
))
// WaitForOutputRootPublished waits until there is an output published for an L2 block number larger than the supplied l2BlockNumber
// This function polls and can block for a very long time if used on mainnet.
// This returns the block number to use for proof generation.
func
WaitForOutputRootPublished
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
l2OutputOracleAddr
common
.
Address
,
l2BlockNumber
*
big
.
Int
)
(
uint64
,
error
)
{
l2BlockNumber
=
new
(
big
.
Int
)
.
Set
(
l2BlockNumber
)
// Don't clobber caller owned l2BlockNumber
opts
:=
&
bind
.
CallOpts
{
Context
:
ctx
}
l2OO
,
err
:=
bindings
.
NewL2OutputOracleCaller
(
l2OutputOracleAddr
,
client
)
if
err
!=
nil
{
return
0
,
err
}
getL2BlockFromLatestOutput
:=
func
()
(
*
big
.
Int
,
error
)
{
return
l2OO
.
LatestBlockNumber
(
opts
)
}
outputBlockNum
,
err
:=
wait
.
AndGet
(
ctx
,
time
.
Second
,
getL2BlockFromLatestOutput
,
func
(
latest
*
big
.
Int
)
bool
{
return
latest
.
Cmp
(
l2BlockNumber
)
>=
0
})
if
err
!=
nil
{
return
0
,
err
}
return
outputBlockNum
.
Uint64
(),
nil
}
// WaitForFinalizationPeriod waits until the L1 chain has progressed far enough that l1ProvingBlockNum has completed
// the finalization period.
// This functions polls and can block for a very long time if used on mainnet.
func
WaitForFinalizationPeriod
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
l1ProvingBlockNum
*
big
.
Int
,
l2OutputOracleAddr
common
.
Address
)
error
{
l1ProvingBlockNum
=
new
(
big
.
Int
)
.
Set
(
l1ProvingBlockNum
)
// Don't clobber caller owned l1ProvingBlockNum
opts
:=
&
bind
.
CallOpts
{
Context
:
ctx
}
// Load finalization period
l2OO
,
err
:=
bindings
.
NewL2OutputOracleCaller
(
l2OutputOracleAddr
,
client
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"create L2OOCaller: %w"
,
err
)
}
finalizationPeriod
,
err
:=
l2OO
.
FINALIZATIONPERIODSECONDS
(
opts
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"get finalization period: %w"
,
err
)
}
provingHeader
,
err
:=
client
.
HeaderByNumber
(
ctx
,
l1ProvingBlockNum
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"retrieve proving header: %w"
,
err
)
}
targetTimestamp
:=
new
(
big
.
Int
)
.
Add
(
new
(
big
.
Int
)
.
SetUint64
(
provingHeader
.
Time
),
finalizationPeriod
)
targetTime
:=
time
.
Unix
(
targetTimestamp
.
Int64
(),
0
)
// Assume clock is relatively correct
time
.
Sleep
(
time
.
Until
(
targetTime
))
// Poll for L1 Block to have a time greater than the target time
return
wait
.
For
(
ctx
,
time
.
Second
,
func
()
(
bool
,
error
)
{
header
,
err
:=
client
.
HeaderByNumber
(
ctx
,
nil
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"retrieve latest header: %w"
,
err
)
}
return
header
.
Time
>
targetTimestamp
.
Uint64
(),
nil
})
}
type
ProofClient
interface
{
type
ProofClient
interface
{
GetProof
(
context
.
Context
,
common
.
Address
,
[]
string
,
*
big
.
Int
)
(
*
gethclient
.
AccountResult
,
error
)
GetProof
(
context
.
Context
,
common
.
Address
,
[]
string
,
*
big
.
Int
)
(
*
gethclient
.
AccountResult
,
error
)
}
}
...
...
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