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
3acdf06a
Unverified
Commit
3acdf06a
authored
Mar 21, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-wheel: updates for geth Vana update
parent
b93874dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
cheat.go
op-wheel/cheat/cheat.go
+16
-14
No files found.
op-wheel/cheat/cheat.go
View file @
3acdf06a
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/consensus/ethash"
...
@@ -80,11 +81,11 @@ type HeadFn func(headState *state.StateDB) error
...
@@ -80,11 +81,11 @@ type HeadFn func(headState *state.StateDB) error
// and updates the blockchain headers indexes to reflect the new state-root, so geth will believe the cheat
// and updates the blockchain headers indexes to reflect the new state-root, so geth will believe the cheat
// (unless it ever re-applies the block).
// (unless it ever re-applies the block).
func
(
ch
*
Cheater
)
RunAndClose
(
fn
HeadFn
)
error
{
func
(
ch
*
Cheater
)
RunAndClose
(
fn
HeadFn
)
error
{
pre
Block
:=
ch
.
Blockchain
.
CurrentBlock
()
pre
Header
:=
ch
.
Blockchain
.
CurrentBlock
()
if
a
,
b
:=
pre
Block
.
NumberU
64
(),
ch
.
Blockchain
.
Genesis
()
.
NumberU64
();
a
<=
b
{
if
a
,
b
:=
pre
Header
.
Number
.
Uint
64
(),
ch
.
Blockchain
.
Genesis
()
.
NumberU64
();
a
<=
b
{
return
fmt
.
Errorf
(
"cheating at genesis (head block %d <= genesis block %d) is not supported"
,
a
,
b
)
return
fmt
.
Errorf
(
"cheating at genesis (head block %d <= genesis block %d) is not supported"
,
a
,
b
)
}
}
state
,
err
:=
ch
.
Blockchain
.
StateAt
(
pre
Block
.
Root
()
)
state
,
err
:=
ch
.
Blockchain
.
StateAt
(
pre
Header
.
Root
)
if
err
!=
nil
{
if
err
!=
nil
{
_
=
ch
.
Close
()
_
=
ch
.
Close
()
return
fmt
.
Errorf
(
"failed to look up head state: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to look up head state: %w"
,
err
)
...
@@ -103,7 +104,7 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
...
@@ -103,7 +104,7 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
_
=
ch
.
Close
()
_
=
ch
.
Close
()
return
fmt
.
Errorf
(
"failed to commit state change: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to commit state change: %w"
,
err
)
}
}
header
:=
pre
Block
.
Header
()
header
:=
pre
Header
// copy the header
header
.
Root
=
stateRoot
header
.
Root
=
stateRoot
blockHash
:=
header
.
Hash
()
blockHash
:=
header
.
Hash
()
...
@@ -115,14 +116,15 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
...
@@ -115,14 +116,15 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
// based on core.BlockChain.writeHeadBlock:
// based on core.BlockChain.writeHeadBlock:
// Add the block to the canonical chain number scheme and mark as the head
// Add the block to the canonical chain number scheme and mark as the head
batch
:=
ch
.
DB
.
NewBatch
()
batch
:=
ch
.
DB
.
NewBatch
()
if
ch
.
Blockchain
.
CurrentFinalizedBlock
()
.
Hash
()
==
preBlock
.
Hash
()
{
preID
:=
eth
.
BlockID
{
Hash
:
preHeader
.
Hash
(),
Number
:
preHeader
.
Number
.
Uint64
()}
if
ch
.
Blockchain
.
CurrentFinalBlock
()
.
Hash
()
==
preID
.
Hash
{
rawdb
.
WriteFinalizedBlockHash
(
batch
,
blockHash
)
rawdb
.
WriteFinalizedBlockHash
(
batch
,
blockHash
)
}
}
rawdb
.
DeleteHeaderNumber
(
batch
,
pre
Block
.
Hash
())
rawdb
.
DeleteHeaderNumber
(
batch
,
pre
Header
.
Hash
())
rawdb
.
WriteHeadHeaderHash
(
batch
,
blockHash
)
rawdb
.
WriteHeadHeaderHash
(
batch
,
blockHash
)
rawdb
.
WriteHeadFastBlockHash
(
batch
,
blockHash
)
rawdb
.
WriteHeadFastBlockHash
(
batch
,
blockHash
)
rawdb
.
WriteCanonicalHash
(
batch
,
blockHash
,
pre
Block
.
NumberU64
()
)
rawdb
.
WriteCanonicalHash
(
batch
,
blockHash
,
pre
ID
.
Number
)
rawdb
.
WriteHeaderNumber
(
batch
,
blockHash
,
pre
Block
.
NumberU64
()
)
rawdb
.
WriteHeaderNumber
(
batch
,
blockHash
,
pre
ID
.
Number
)
rawdb
.
WriteHeader
(
batch
,
header
)
rawdb
.
WriteHeader
(
batch
,
header
)
// not keyed by blockhash, and we didn't remove any txs, so we just leave this one as-is.
// not keyed by blockhash, and we didn't remove any txs, so we just leave this one as-is.
// rawdb.WriteTxLookupEntriesByBlock(batch, block)
// rawdb.WriteTxLookupEntriesByBlock(batch, block)
...
@@ -131,17 +133,17 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
...
@@ -131,17 +133,17 @@ func (ch *Cheater) RunAndClose(fn HeadFn) error {
// Geth stores the TD for each block separately from the block itself. We must update this
// Geth stores the TD for each block separately from the block itself. We must update this
// manually, otherwise Geth thinks we haven't reached TTD yet and tries to build a block
// manually, otherwise Geth thinks we haven't reached TTD yet and tries to build a block
// using Clique consensus, which causes a panic.
// using Clique consensus, which causes a panic.
rawdb
.
WriteTd
(
batch
,
blockHash
,
pre
Block
.
NumberU64
(),
ch
.
Blockchain
.
GetTd
(
preBlock
.
Hash
(),
preBlock
.
NumberU64
()
))
rawdb
.
WriteTd
(
batch
,
blockHash
,
pre
ID
.
Number
,
ch
.
Blockchain
.
GetTd
(
preID
.
Hash
,
preID
.
Number
))
// Need to copy over receipts since they are keyed by block hash.
// Need to copy over receipts since they are keyed by block hash.
receipts
:=
rawdb
.
ReadReceipts
(
ch
.
DB
,
pre
Block
.
Hash
(),
preBlock
.
NumberU64
()
,
ch
.
Blockchain
.
Config
())
receipts
:=
rawdb
.
ReadReceipts
(
ch
.
DB
,
pre
ID
.
Hash
,
preID
.
Number
,
ch
.
Blockchain
.
Config
())
rawdb
.
WriteReceipts
(
batch
,
blockHash
,
pre
Block
.
NumberU64
()
,
receipts
)
rawdb
.
WriteReceipts
(
batch
,
blockHash
,
pre
ID
.
Number
,
receipts
)
// Geth maintains an internal mapping between block bodies and their hashes. None of the database
// Geth maintains an internal mapping between block bodies and their hashes. None of the database
// accessors above update this mapping, so we need to do it manually.
// accessors above update this mapping, so we need to do it manually.
oldKey
:=
blockBodyKey
(
pre
Block
.
NumberU64
(),
preBlock
.
Hash
()
)
oldKey
:=
blockBodyKey
(
pre
ID
.
Number
,
preID
.
Hash
)
oldBody
:=
rawdb
.
ReadBodyRLP
(
ch
.
DB
,
pre
Block
.
Hash
(),
preBlock
.
NumberU64
()
)
oldBody
:=
rawdb
.
ReadBodyRLP
(
ch
.
DB
,
pre
ID
.
Hash
,
preID
.
Number
)
newKey
:=
blockBodyKey
(
pre
Block
.
NumberU64
()
,
blockHash
)
newKey
:=
blockBodyKey
(
pre
ID
.
Number
,
blockHash
)
if
err
:=
batch
.
Delete
(
oldKey
);
err
!=
nil
{
if
err
:=
batch
.
Delete
(
oldKey
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error deleting old block body key"
)
return
fmt
.
Errorf
(
"error deleting old block body key"
)
}
}
...
...
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