-
Notifications
You must be signed in to change notification settings - Fork 71
create cmd for dynamic genesis root #2097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: zkevm
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math/big" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/erigontech/erigon-lib/log/v3" | ||
| "github.com/erigontech/erigon/core" | ||
| "github.com/erigontech/erigon/zk/zk_config" | ||
| "github.com/erigontech/erigon/zk/zk_config/cfg_dynamic_genesis" | ||
| ) | ||
|
|
||
| func main() { | ||
| if len(os.Args) < 2 { | ||
| fmt.Fprintf(os.Stderr, "Usage: genesisroot <config-dir> [chain-name]\n") | ||
| fmt.Fprintf(os.Stderr, " config-dir: directory containing <chain>-allocs.json, <chain>-chainspec.json, <chain>-conf.json\n") | ||
| fmt.Fprintf(os.Stderr, " chain-name: chain name (default: dynamic-hermez-dev)\n") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| configDir := os.Args[1] | ||
| chain := "dynamic-hermez-dev" | ||
| if len(os.Args) > 2 { | ||
| chain = os.Args[2] | ||
| } | ||
|
|
||
| absDir, err := filepath.Abs(configDir) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "invalid config dir: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| zk_config.ZKDynamicConfigPath = absDir | ||
| zk_config.ZkUnionConfigPath = "" | ||
|
|
||
| dConf := cfg_dynamic_genesis.NewDynamicGenesisConfig(chain) | ||
|
|
||
| genesis := core.DynamicGenesisBlock(chain) | ||
|
Comment on lines
+29
to
+40
|
||
| genesis.Timestamp = dConf.Timestamp | ||
| genesis.GasLimit = dConf.GasLimit | ||
| genesis.Difficulty = big.NewInt(dConf.Difficulty) | ||
|
Comment on lines
+38
to
+43
|
||
|
|
||
| tmpDir, err := os.MkdirTemp("", "genesisroot-*") | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "failed to create temp dir: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| defer os.RemoveAll(tmpDir) | ||
|
|
||
| block, _, _, err := core.GenesisToBlock(genesis, tmpDir, log.Root()) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "GenesisToBlock failed: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Println("State Root:", block.Root().Hex()) | ||
| fmt.Println("Block Hash:", block.Hash().Hex()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage banner hard-codes the program name as
genesisroot. If the binary is renamed or invoked via a different path, the message will be inaccurate. Usingos.Args[0](orfilepath.Base(os.Args[0])) keeps the usage text correct.