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
60ccb1de
Unverified
Commit
60ccb1de
authored
Jan 23, 2023
by
mergify[bot]
Committed by
GitHub
Jan 23, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4762 from ethereum-optimism/01-22-op-chain-ops_Use_precalculated_mint_events
op-chain-ops: Use precalculated mint events
parents
63758d82
4696c22f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
28 deletions
+5
-28
migrate.go
op-chain-ops/ether/migrate.go
+1
-2
precheck.go
op-chain-ops/ether/precheck.go
+3
-19
util.go
op-chain-ops/ether/util.go
+0
-6
db_migration.go
op-chain-ops/genesis/db_migration.go
+1
-1
No files found.
op-chain-ops/ether/migrate.go
View file @
60ccb1de
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
...
@@ -29,7 +28,7 @@ var (
...
@@ -29,7 +28,7 @@ var (
}
}
)
)
func
MigrateLegacyETH
(
ldb
ethdb
.
Database
,
db
*
state
.
StateDB
,
addresses
[]
common
.
Address
,
chainID
int
,
noCheck
bool
)
error
{
func
MigrateLegacyETH
(
db
*
state
.
StateDB
,
addresses
[]
common
.
Address
,
chainID
int
,
noCheck
bool
)
error
{
// Chain params to use for integrity checking.
// Chain params to use for integrity checking.
params
:=
migration
.
ParamsByChainID
[
chainID
]
params
:=
migration
.
ParamsByChainID
[
chainID
]
if
params
==
nil
{
if
params
==
nil
{
...
...
op-chain-ops/ether/precheck.go
View file @
60ccb1de
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis/migration"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis/migration"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -31,6 +30,8 @@ func PreCheckBalances(ldb ethdb.Database, db *state.StateDB, addresses []common.
...
@@ -31,6 +30,8 @@ func PreCheckBalances(ldb ethdb.Database, db *state.StateDB, addresses []common.
slotsInp
:=
make
(
map
[
common
.
Hash
]
int
)
slotsInp
:=
make
(
map
[
common
.
Hash
]
int
)
// For each known address, compute its balance key and add it to the list of addresses.
// For each known address, compute its balance key and add it to the list of addresses.
// Mint events are instrumented as regular ETH events in the witness data, so we no longer
// need to iterate over mint events during the migration.
for
_
,
addr
:=
range
addresses
{
for
_
,
addr
:=
range
addresses
{
addrs
=
append
(
addrs
,
addr
)
addrs
=
append
(
addrs
,
addr
)
slotsInp
[
CalcOVMETHStorageKey
(
addr
)]
=
1
slotsInp
[
CalcOVMETHStorageKey
(
addr
)]
=
1
...
@@ -48,28 +49,11 @@ func PreCheckBalances(ldb ethdb.Database, db *state.StateDB, addresses []common.
...
@@ -48,28 +49,11 @@ func PreCheckBalances(ldb ethdb.Database, db *state.StateDB, addresses []common.
addrs
=
append
(
addrs
,
sequencerEntrypointAddr
)
addrs
=
append
(
addrs
,
sequencerEntrypointAddr
)
slotsInp
[
CalcOVMETHStorageKey
(
sequencerEntrypointAddr
)]
=
1
slotsInp
[
CalcOVMETHStorageKey
(
sequencerEntrypointAddr
)]
=
1
// Also extract addresses/slots from Mint events. Our instrumentation currently only looks at
// direct balance changes inside of Geth, but Mint events mutate the ERC20 storage directly and
// therefore aren't picked up by our instrumentation. Instead of updating the instrumentation,
// we can simply iterate over every Mint event and add the address to the list of addresses.
log
.
Info
(
"Reading mint events from DB"
)
headBlock
:=
rawdb
.
ReadHeadBlock
(
ldb
)
logProgress
:=
ProgressLogger
(
100
,
"read mint events"
)
err
:=
IterateMintEvents
(
ldb
,
headBlock
.
NumberU64
(),
func
(
address
common
.
Address
,
headNum
uint64
)
error
{
addrs
=
append
(
addrs
,
address
)
slotsInp
[
CalcOVMETHStorageKey
(
address
)]
=
1
logProgress
(
"headnum"
,
headNum
)
return
nil
})
if
err
!=
nil
{
return
nil
,
wrapErr
(
err
,
"error reading mint events"
)
}
// Build a mapping of every storage slot in the LegacyERC20ETH contract, except the list of
// Build a mapping of every storage slot in the LegacyERC20ETH contract, except the list of
// slots that we know we can ignore (totalSupply, name, symbol).
// slots that we know we can ignore (totalSupply, name, symbol).
var
count
int
var
count
int
slotsAct
:=
make
(
map
[
common
.
Hash
]
common
.
Hash
)
slotsAct
:=
make
(
map
[
common
.
Hash
]
common
.
Hash
)
err
=
db
.
ForEachStorage
(
predeploys
.
LegacyERC20ETHAddr
,
func
(
key
,
value
common
.
Hash
)
bool
{
err
:
=
db
.
ForEachStorage
(
predeploys
.
LegacyERC20ETHAddr
,
func
(
key
,
value
common
.
Hash
)
bool
{
// We can safely ignore specific slots (totalSupply, name, symbol).
// We can safely ignore specific slots (totalSupply, name, symbol).
if
ignoredSlots
[
key
]
{
if
ignoredSlots
[
key
]
{
return
true
return
true
...
...
op-chain-ops/ether/util.go
View file @
60ccb1de
package
ether
package
ether
import
(
import
(
"fmt"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
func
wrapErr
(
err
error
,
msg
string
,
ctx
...
any
)
error
{
return
fmt
.
Errorf
(
"%s: %w"
,
fmt
.
Sprintf
(
msg
,
ctx
...
),
err
)
}
func
ProgressLogger
(
n
int
,
msg
string
)
func
(
...
any
)
{
func
ProgressLogger
(
n
int
,
msg
string
)
func
(
...
any
)
{
var
i
int
var
i
int
...
...
op-chain-ops/genesis/db_migration.go
View file @
60ccb1de
...
@@ -193,7 +193,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
...
@@ -193,7 +193,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m
// Finally we migrate the balances held inside the LegacyERC20ETH contract into the state trie.
// Finally we migrate the balances held inside the LegacyERC20ETH contract into the state trie.
// Note that we do NOT delete the balances from the LegacyERC20ETH contract.
// Note that we do NOT delete the balances from the LegacyERC20ETH contract.
log
.
Info
(
"Starting to migrate ERC20 ETH"
)
log
.
Info
(
"Starting to migrate ERC20 ETH"
)
err
=
ether
.
MigrateLegacyETH
(
ldb
,
db
,
addrs
,
int
(
config
.
L1ChainID
),
noCheck
)
err
=
ether
.
MigrateLegacyETH
(
db
,
addrs
,
int
(
config
.
L1ChainID
),
noCheck
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot migrate legacy eth: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"cannot migrate legacy eth: %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