forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
l2geth: Add OVM ETH and message passer state dump (ethereum-optimism#…
…3742) This is necessary in order to perform the mainnet OVM ETH and withdrawal hashes migration. Operates using a L2GETH_STATE_DUMP_PATH environment variable that specifies the file that addresses should be dump to. They are not deduplicated. The format of the file is: ``` ETH|<ovm eth address> MSG|<sender>|<msg> ```
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package statedumper | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ethereum-optimism/optimism/l2geth/common" | ||
"io" | ||
"os" | ||
"sync" | ||
) | ||
|
||
type StateDumper interface { | ||
WriteETH(address common.Address) | ||
WriteMessage(sender common.Address, msg []byte) | ||
} | ||
|
||
var DefaultStateDumper StateDumper | ||
|
||
func NewStateDumper() StateDumper { | ||
path := os.Getenv("L2GETH_STATE_DUMP_PATH") | ||
if path == "" { | ||
return &noopStateDumper{} | ||
} | ||
|
||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE, 0o755) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &FileStateDumper{ | ||
f: f, | ||
} | ||
} | ||
|
||
type FileStateDumper struct { | ||
f io.Writer | ||
mtx sync.Mutex | ||
} | ||
|
||
func (s *FileStateDumper) WriteETH(address common.Address) { | ||
s.mtx.Lock() | ||
defer s.mtx.Unlock() | ||
if _, err := s.f.Write([]byte(fmt.Sprintf("ETH|%s\n", address.Hex()))); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (s *FileStateDumper) WriteMessage(sender common.Address, msg []byte) { | ||
s.mtx.Lock() | ||
defer s.mtx.Unlock() | ||
if _, err := s.f.Write([]byte(fmt.Sprintf("MSG|%s|%x\n", sender.Hex(), msg))); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
type noopStateDumper struct { | ||
} | ||
|
||
func (n *noopStateDumper) WriteETH(address common.Address) { | ||
} | ||
|
||
func (n *noopStateDumper) WriteMessage(sender common.Address, msg []byte) { | ||
} | ||
|
||
func init() { | ||
DefaultStateDumper = NewStateDumper() | ||
} | ||
|
||
func WriteETH(address common.Address) { | ||
DefaultStateDumper.WriteETH(address) | ||
} | ||
|
||
func WriteMessage(sender common.Address, msg []byte) { | ||
DefaultStateDumper.WriteMessage(sender, msg) | ||
} |