Skip to content

Commit

Permalink
Drop Default from GenesisBlock* functions (erigontech#7147)
Browse files Browse the repository at this point in the history
Small cosmetic changes and clean-ups
  • Loading branch information
yperbasis authored and calmbeing committed Apr 24, 2023
1 parent 07dfa00 commit 0531964
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 97 deletions.
38 changes: 5 additions & 33 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/RoaringBitmap/roaring/roaring64"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/common/length"
Expand All @@ -31,12 +30,8 @@ import (
"github.com/ledgerwatch/erigon-lib/recsplit"
"github.com/ledgerwatch/erigon-lib/recsplit/eliasfano32"
librlp "github.com/ledgerwatch/erigon-lib/rlp"
"golang.org/x/exp/slices"

"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/logging"

"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

hackdb "github.com/ledgerwatch/erigon/cmd/hack/db"
"github.com/ledgerwatch/erigon/cmd/hack/flow"
Expand All @@ -55,6 +50,8 @@ import (
"github.com/ledgerwatch/erigon/ethdb/cbor"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/logging"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
)

Expand Down Expand Up @@ -1103,33 +1100,8 @@ func devTx(chaindata string) error {
}

func chainConfig(name string) error {
var chainConfig *chain.Config
switch name {
case "mainnet":
chainConfig = params.MainnetChainConfig
case "sepolia":
chainConfig = params.SepoliaChainConfig
case "rinkeby":
chainConfig = params.RinkebyChainConfig
case "goerli":
chainConfig = params.GoerliChainConfig
case "bsc":
chainConfig = params.BSCChainConfig
case "sokol":
chainConfig = params.SokolChainConfig
case "chapel":
chainConfig = params.ChapelChainConfig
case "rialto":
chainConfig = params.RialtoChainConfig
case "mumbai":
chainConfig = params.MumbaiChainConfig
case "bor-mainnet":
chainConfig = params.BorMainnetChainConfig
case "gnosis":
chainConfig = params.GnosisChainConfig
case "chiado":
chainConfig = params.ChiadoChainConfig
default:
chainConfig := params.ChainConfigByChainName(name)
if chainConfig == nil {
return fmt.Errorf("unknown name: %s", name)
}
f, err := os.Create(filepath.Join("params", "chainspecs", fmt.Sprintf("%s.json", name)))
Expand Down
10 changes: 5 additions & 5 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func stageExec(db kv.RwDB, ctx context.Context) error {
syncCfg.ExecWorkerCount = int(workers)
syncCfg.ReconWorkerCount = int(reconWorkers)

genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
cfg := stagedsync.StageExecuteBlocksCfg(db, pm, batchSize, nil, chainConfig, engine, vmConfig, nil,
/*stateStream=*/ false,
/*badBlockHalt=*/ false, historyV3, dirs, getBlockReader(db), nil, genesis, syncCfg, agg)
Expand Down Expand Up @@ -1282,7 +1282,7 @@ func allDomains(ctx context.Context, db kv.RoDB, stepSize uint64, mode libstate.
func newDomains(ctx context.Context, db kv.RwDB, stepSize uint64, mode libstate.CommitmentMode, trie commitment.TrieVariant) (consensus.Engine, ethconfig.Config, *snapshotsync.RoSnapshots, *libstate.Aggregator) {
historyV3, pm := kvcfg.HistoryV3.FromDB(db), fromdb.PruneMode(db)
//events := shards.NewEvents()
genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)

chainConfig, genesisBlock, genesisErr := core.CommitGenesisBlock(db, genesis, "")
_ = genesisBlock // TODO apply if needed here
Expand All @@ -1305,7 +1305,7 @@ func newDomains(ctx context.Context, db kv.RwDB, stepSize uint64, mode libstate.
cfg.Prune = pm
cfg.BatchSize = batchSize
cfg.DeprecatedTxPool.Disable = true
cfg.Genesis = core.DefaultGenesisBlockByChainName(chain)
cfg.Genesis = core.GenesisBlockByChainName(chain)
//if miningConfig != nil {
// cfg.Miner = *miningConfig
//}
Expand All @@ -1325,7 +1325,7 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig)

events := shards.NewEvents()

genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
chainConfig, genesisBlock, genesisErr := core.CommitGenesisBlock(db, genesis, "")
if _, ok := genesisErr.(*chain2.ConfigCompatError); genesisErr != nil && !ok {
panic(genesisErr)
Expand All @@ -1345,7 +1345,7 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig)
cfg.Prune = pm
cfg.BatchSize = batchSize
cfg.DeprecatedTxPool.Disable = true
cfg.Genesis = core.DefaultGenesisBlockByChainName(chain)
cfg.Genesis = core.GenesisBlockByChainName(chain)
if miningConfig != nil {
cfg.Miner = *miningConfig
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var readDomains = &cobra.Command{
cfg := &nodecfg.DefaultConfig
utils.SetNodeConfigCobra(cmd, cfg)
ethConfig := &ethconfig.Defaults
ethConfig.Genesis = core.DefaultGenesisBlockByChainName(chain)
ethConfig.Genesis = core.GenesisBlockByChainName(chain)
erigoncli.ApplyFlagsForEthConfigCobra(cmd.Flags(), ethConfig)

var readFromDomain string
Expand Down Expand Up @@ -220,7 +220,7 @@ var stateDomains = &cobra.Command{
cfg := &nodecfg.DefaultConfig
utils.SetNodeConfigCobra(cmd, cfg)
ethConfig := &ethconfig.Defaults
ethConfig.Genesis = core.DefaultGenesisBlockByChainName(chain)
ethConfig.Genesis = core.GenesisBlockByChainName(chain)
erigoncli.ApplyFlagsForEthConfigCobra(cmd.Flags(), ethConfig)

dirs := datadir.New(datadirCli)
Expand Down Expand Up @@ -309,7 +309,7 @@ func loopProcessDomains(chainDb, stateDb kv.RwDB, ctx context.Context) error {
go proc.PrintStatsLoop(ctx, 30*time.Second)

if proc.startTxNum == 0 {
genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
if err := proc.ApplyGenesis(genesis); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Examples:
cfg := &nodecfg.DefaultConfig
utils.SetNodeConfigCobra(cmd, cfg)
ethConfig := &ethconfig.Defaults
ethConfig.Genesis = core.DefaultGenesisBlockByChainName(chain)
ethConfig.Genesis = core.GenesisBlockByChainName(chain)
erigoncli.ApplyFlagsForEthConfigCobra(cmd.Flags(), ethConfig)
miningConfig := params.MiningConfig{}
utils.SetupMinerCobra(cmd, &miningConfig)
Expand Down Expand Up @@ -195,7 +195,7 @@ func syncBySmallSteps(db kv.RwDB, miningConfig params.MiningConfig, ctx context.
stateStages.DisableStages(stages.Snapshots, stages.Headers, stages.BlockHashes, stages.Bodies, stages.Senders)
changesAcc := shards.NewAccumulator()

genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
syncCfg := ethconfig.Defaults.Sync
syncCfg.ExecWorkerCount = int(workers)
syncCfg.ReconWorkerCount = int(reconWorkers)
Expand Down Expand Up @@ -525,7 +525,7 @@ func loopExec(db kv.RwDB, ctx context.Context, unwind uint64) error {
from := progress(tx, stages.Execution)
to := from + unwind

genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
syncCfg := ethconfig.Defaults.Sync
syncCfg.ExecWorkerCount = int(workers)
syncCfg.ReconWorkerCount = int(reconWorkers)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/get_chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestGetChainConfig(t *testing.T) {
db := memdb.NewTestDB(t)
config, _, err := core.CommitGenesisBlock(db, core.DefaultGenesisBlock(), "")
config, _, err := core.CommitGenesisBlock(db, core.MainnetGenesisBlock(), "")
if err != nil {
t.Fatalf("setting up genensis block: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/state/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func genesisFromFile(genesisPath string) *core.Genesis {

func getChainGenesisAndConfig() (genesis *core.Genesis, chainConfig *chain2.Config) {
if chain == "" {
genesis, chainConfig = core.DefaultGenesisBlock(), params.MainnetChainConfig
genesis, chainConfig = core.MainnetGenesisBlock(), params.MainnetChainConfig
} else {
genesis, chainConfig = core.DefaultGenesisBlockByChainName(chain), params.ChainConfigByChainName(chain)
genesis, chainConfig = core.GenesisBlockByChainName(chain), params.ChainConfigByChainName(chain)
}
return genesis, chainConfig
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C

switch chain {
default:
genesis := core.DefaultGenesisBlockByChainName(chain)
genesis := core.GenesisBlockByChainName(chain)
genesisHash := params.GenesisHashByChainName(chain)
if (genesis == nil) || (genesisHash == nil) {
Fatalf("ChainDB name is not recognized: %s", chain)
Expand Down
4 changes: 2 additions & 2 deletions consensus/aura/aura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestRewardContract(t *testing.T) {
auraDB, require := memdb.NewTestDB(t), require.New(t)
engine, err := aura.NewAuRa(nil, auraDB, libcommon.Address{}, test.AuthorityRoundBlockRewardContract)
require.NoError(err)
m := stages.MockWithGenesisEngine(t, core.DefaultSokolGenesisBlock(), engine, false)
m := stages.MockWithGenesisEngine(t, core.SokolGenesisBlock(), engine, false)
m.EnableLogs()

var accBefore *accounts.Account
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestEmptyBlock(t *testing.T) {
}

require := require.New(t)
genesis := core.DefaultGnosisGenesisBlock()
genesis := core.GnosisGenesisBlock()
genesisBlock, _, err := genesis.ToBlock("")
require.NoError(err)

Expand Down
Loading

0 comments on commit 0531964

Please sign in to comment.