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
2b57c303
Unverified
Commit
2b57c303
authored
Oct 20, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-e2e: add random withdrawals to fake-proof-of-stake
parent
73c75128
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
fakepos.go
op-e2e/e2eutils/geth/fakepos.go
+23
-2
No files found.
op-e2e/e2eutils/geth/fakepos.go
View file @
2b57c303
package
geth
import
(
"math/rand"
"time"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -12,6 +12,9 @@ import (
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/testutils"
)
// fakePoS is a testing-only utility to attach to Geth,
...
...
@@ -22,6 +25,8 @@ type fakePoS struct {
log
log
.
Logger
blockTime
uint64
withdrawalsIndex
uint64
finalizedDistance
uint64
safeDistance
uint64
...
...
@@ -33,6 +38,7 @@ func (f *fakePoS) Start() error {
if
advancing
,
ok
:=
f
.
clock
.
(
*
clock
.
AdvancingClock
);
ok
{
advancing
.
Start
()
}
withdrawalsRNG
:=
rand
.
New
(
rand
.
NewSource
(
450368975843
))
// avoid generating the same address as any test
f
.
sub
=
event
.
NewSubscription
(
func
(
quit
<-
chan
struct
{})
error
{
// poll every half a second: enough to catch up with any block time when ticks are missed
t
:=
f
.
clock
.
NewTicker
(
time
.
Second
/
2
)
...
...
@@ -64,6 +70,17 @@ func (f *fakePoS) Start() error {
// We're a long way behind, let's skip some blocks...
newBlockTime
=
uint64
(
f
.
clock
.
Now
()
.
Unix
())
}
// create some random withdrawals
withdrawals
:=
make
([]
*
types
.
Withdrawal
,
withdrawalsRNG
.
Intn
(
4
))
for
i
:=
0
;
i
<
len
(
withdrawals
);
i
++
{
withdrawals
[
i
]
=
&
types
.
Withdrawal
{
Index
:
f
.
withdrawalsIndex
+
uint64
(
i
),
Validator
:
withdrawalsRNG
.
Uint64
()
%
100
_000_000
,
// 100 million fake validators
Address
:
testutils
.
RandomAddress
(
withdrawalsRNG
),
// in gwei, consensus-layer quirk. withdraw non-zero value up to 50 ETH
Amount
:
uint64
(
withdrawalsRNG
.
Intn
(
50
_000_000_000
)
+
1
),
}
}
res
,
err
:=
f
.
engineAPI
.
ForkchoiceUpdatedV2
(
engine
.
ForkchoiceStateV1
{
HeadBlockHash
:
head
.
Hash
(),
SafeBlockHash
:
safe
.
Hash
(),
...
...
@@ -72,7 +89,7 @@ func (f *fakePoS) Start() error {
Timestamp
:
newBlockTime
,
Random
:
common
.
Hash
{},
SuggestedFeeRecipient
:
head
.
Coinbase
,
Withdrawals
:
make
([]
*
types
.
Withdrawal
,
0
)
,
Withdrawals
:
withdrawals
,
})
if
err
!=
nil
{
f
.
log
.
Error
(
"failed to start building L1 block"
,
"err"
,
err
)
...
...
@@ -109,6 +126,10 @@ func (f *fakePoS) Start() error {
f
.
log
.
Error
(
"failed to make built L1 block canonical"
,
"err"
,
err
)
continue
}
// Increment global withdrawals index in the CL.
// The EL doesn't really care about the value,
// but it's nice to mock something consistent with the CL specs.
f
.
withdrawalsIndex
+=
uint64
(
len
(
withdrawals
))
case
<-
quit
:
return
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