Skip to content
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

cmd/hivechain: add forkenv output #921

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/hivechain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Creates `accounts.json` containing accounts and corresponding private keys.
This writes the `genesis.json` file containing a go-ethereum style genesis spec. Note
this file includes the fork block numbers/timestamps.

### forkenv

This writes `forkenv.json` with fork configuration environment variables for hive tests.

### headblock

This creates `headblock.json` with a dump of the head header.
Expand Down
12 changes: 6 additions & 6 deletions cmd/hivechain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ var (

numberBasedForkNames = []string{
"homestead",
"eip150",
"eip155",
"eip158",
"tangerinewhistle",
"spuriousdragon",
"byzantium",
"constantinople",
"petersburg",
Expand Down Expand Up @@ -64,11 +63,10 @@ func (cfg *generatorConfig) createChainConfig() *params.ChainConfig {
// number-based forks
case "homestead":
chaincfg.HomesteadBlock = new(big.Int).SetUint64(b)
case "eip150":
case "tangerinewhistle":
chaincfg.EIP150Block = new(big.Int).SetUint64(b)
case "eip155":
case "spuriousdragon":
chaincfg.EIP155Block = new(big.Int).SetUint64(b)
case "eip158":
chaincfg.EIP158Block = new(big.Int).SetUint64(b)
case "byzantium":
chaincfg.ByzantiumBlock = new(big.Int).SetUint64(b)
Expand Down Expand Up @@ -98,6 +96,8 @@ func (cfg *generatorConfig) createChainConfig() *params.ChainConfig {
chaincfg.CancunTime = &timestamp
case "prague":
chaincfg.PragueTime = &timestamp
default:
panic(fmt.Sprintf("unknown fork name %q", fork))
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/hivechain/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

var outputFunctions = map[string]func(*generator) error{
"genesis": (*generator).writeGenesis,
"forkenv": (*generator).writeForkEnv,
"chain": (*generator).writeChain,
"powchain": (*generator).writePoWChain,
"headstate": (*generator).writeState,
Expand Down
43 changes: 43 additions & 0 deletions cmd/hivechain/output_forkenv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"math/big"
)

// writeForkEnv writes chain fork configuration in the form that hive expects.
func (g *generator) writeForkEnv() error {
cfg := g.genesis.Config
env := make(map[string]string)
env["HIVE_CHAIN_ID"] = fmt.Sprint(cfg.ChainID)

setNum := func(hive string, blocknum *big.Int) {
if blocknum != nil {
env[hive] = blocknum.Text(10)
}
}
setTime := func(hive string, timestamp *uint64) {
if timestamp != nil {
env[hive] = fmt.Sprintf("%d", *timestamp)
}
}
setNum("HIVE_FORK_HOMESTEAD", cfg.HomesteadBlock)
setNum("HIVE_FORK_TANGERINE", cfg.EIP150Block)
setNum("HIVE_FORK_SPURIOUS", cfg.EIP155Block)
setNum("HIVE_FORK_BYZANTIUM", cfg.ByzantiumBlock)
setNum("HIVE_FORK_CONSTANTINOPLE", cfg.ConstantinopleBlock)
setNum("HIVE_FORK_PETERSBURG", cfg.PetersburgBlock)
setNum("HIVE_FORK_ISTANBUL", cfg.IstanbulBlock)
setNum("HIVE_FORK_MUIR_GLACIER", cfg.MuirGlacierBlock)
setNum("HIVE_FORK_ARROW_GLACIER", cfg.ArrowGlacierBlock)
setNum("HIVE_FORK_GRAY_GLACIER", cfg.GrayGlacierBlock)
setNum("HIVE_FORK_BERLIN", cfg.BerlinBlock)
setNum("HIVE_FORK_LONDON", cfg.LondonBlock)
setNum("HIVE_MERGE_BLOCK_ID", cfg.MergeNetsplitBlock)
setNum("HIVE_TERMINAL_TOTAL_DIFFICULTY", cfg.TerminalTotalDifficulty)
setTime("HIVE_SHANGHAI_TIMESTAMP", cfg.ShanghaiTime)
setTime("HIVE_CANCUN_TIMESTAMP", cfg.CancunTime)
setTime("HIVE_PRAGUE_TIMESTAMP", cfg.PragueTime)

return g.writeJSON("forkenv.json", env)
}