diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index 52a18c05e..7eba8d452 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "path/filepath" "runtime" "strings" "sync" @@ -25,7 +24,6 @@ import ( "github.com/ledgerwatch/erigon/cmd/hack/tool/fromdb" "github.com/ledgerwatch/erigon/cmd/sentry/sentry" "github.com/ledgerwatch/erigon/consensus" - "github.com/ledgerwatch/erigon/consensus/ethash" "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core/rawdb" reset2 "github.com/ledgerwatch/erigon/core/rawdb/rawdbreset" @@ -1314,24 +1312,19 @@ func initConsensusEngine(cc *params.ChainConfig, datadir string, db kv.RwDB) (en snapshots, _ := allSnapshots(context.Background(), db) config := ethconfig.Defaults - switch { - case cc.Clique != nil: - c := params.CliqueSnapshot - c.DBPath = filepath.Join(datadir, "clique", "db") - engine = ethconsensusconfig.CreateConsensusEngine(cc, l, c, config.Miner.Notify, config.Miner.Noverify, "", true, datadir, snapshots, db.ReadOnly(), db) - case cc.Aura != nil: - consensusConfig := ¶ms.AuRaConfig{DBPath: filepath.Join(datadir, "aura")} - engine = ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, "", true, datadir, snapshots, db.ReadOnly(), db) - case cc.Parlia != nil: - // Apply special hacks for BSC params - params.ApplyBinanceSmartChainParams() - consensusConfig := ¶ms.ParliaConfig{DBPath: filepath.Join(datadir, "parlia")} - engine = ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, "", true, datadir, snapshots, db.ReadOnly(), db) - case cc.Bor != nil: - consensusConfig := &config.Bor - engine = ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, HeimdallURL, false, datadir, snapshots, db.ReadOnly(), db) - default: //ethash - engine = ethash.NewFaker() + var consensusConfig interface{} + + if cc.Clique != nil { + consensusConfig = params.CliqueSnapshot + } else if cc.Aura != nil { + config.Aura.Etherbase = config.Miner.Etherbase + consensusConfig = &config.Aura + } else if cc.Parlia != nil { + consensusConfig = &config.Parlia + } else if cc.Bor != nil { + consensusConfig = &config.Bor + } else { + consensusConfig = &config.Ethash } - return + return ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallURL, config.WithoutHeimdall, datadir, snapshots, false /* readonly */, db) } diff --git a/cmd/state/commands/erigon2.go b/cmd/state/commands/erigon2.go index 93d98fd35..ca87ec6b0 100644 --- a/cmd/state/commands/erigon2.go +++ b/cmd/state/commands/erigon2.go @@ -31,7 +31,6 @@ import ( "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/consensus" - "github.com/ledgerwatch/erigon/consensus/ethash" "github.com/ledgerwatch/erigon/consensus/misc" "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core/rawdb" @@ -624,29 +623,23 @@ func (ww *WriterWrapper) CreateContract(address common.Address) error { return nil } -func initConsensusEngine(chainConfig *params.ChainConfig, snapshots *snapshotsync.RoSnapshots) (engine consensus.Engine) { +func initConsensusEngine(cc *params.ChainConfig, snapshots *snapshotsync.RoSnapshots) (engine consensus.Engine) { l := log.New() config := ethconfig.Defaults - switch { - case chainConfig.Clique != nil: - c := params.CliqueSnapshot - c.DBPath = filepath.Join(datadirCli, "clique", "db") - engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, l, c, config.Miner.Notify, config.Miner.Noverify, "", true, datadirCli, snapshots, true /* readonly */) - case chainConfig.Aura != nil: - consensusConfig := ¶ms.AuRaConfig{DBPath: filepath.Join(datadirCli, "aura")} - engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, "", true, datadirCli, snapshots, true /* readonly */) - case chainConfig.Parlia != nil: - // Apply special hacks for BSC params - params.ApplyBinanceSmartChainParams() - consensusConfig := ¶ms.ParliaConfig{DBPath: filepath.Join(datadirCli, "parlia")} - engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, "", true, datadirCli, snapshots, true /* readonly */) - case chainConfig.Bor != nil: - consensusConfig := &config.Bor - engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallURL, false, datadirCli, snapshots, true /* readonly */) - default: //ethash - engine = ethash.NewFaker() - } + var consensusConfig interface{} - return + if cc.Clique != nil { + consensusConfig = params.CliqueSnapshot + } else if cc.Aura != nil { + config.Aura.Etherbase = config.Miner.Etherbase + consensusConfig = &config.Aura + } else if cc.Parlia != nil { + consensusConfig = &config.Parlia + } else if cc.Bor != nil { + consensusConfig = &config.Bor + } else { + consensusConfig = &config.Ethash + } + return ethconsensusconfig.CreateConsensusEngine(cc, l, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallURL, config.WithoutHeimdall, datadirCli, snapshots, true /* readonly */) } diff --git a/eth/ethconsensusconfig/config.go b/eth/ethconsensusconfig/config.go index 45bc6918b..bee5a0449 100644 --- a/eth/ethconsensusconfig/config.go +++ b/eth/ethconsensusconfig/config.go @@ -47,10 +47,16 @@ func CreateConsensusEngine(chainConfig *params.ChainConfig, logger log.Logger, c } case *params.ConsensusSnapshotConfig: if chainConfig.Clique != nil { + if consensusCfg.DBPath == "" { + consensusCfg.DBPath = filepath.Join(datadir, "clique", "db") + } eng = clique.New(chainConfig, consensusCfg, db.OpenDatabase(consensusCfg.DBPath, logger, consensusCfg.InMemory, readonly)) } case *params.AuRaConfig: if chainConfig.Aura != nil { + if consensusCfg.DBPath == "" { + consensusCfg.DBPath = filepath.Join(datadir, "aura") + } var err error eng, err = aura.NewAuRa(chainConfig.Aura, db.OpenDatabase(consensusCfg.DBPath, logger, consensusCfg.InMemory, readonly), chainConfig.Aura.Etherbase, consensusconfig.GetConfigByChain(chainConfig.ChainName)) if err != nil { @@ -59,6 +65,9 @@ func CreateConsensusEngine(chainConfig *params.ChainConfig, logger log.Logger, c } case *params.ParliaConfig: if chainConfig.Parlia != nil { + if consensusCfg.DBPath == "" { + consensusCfg.DBPath = filepath.Join(datadir, "parlia") + } eng = parlia.New(chainConfig, db.OpenDatabase(consensusCfg.DBPath, logger, consensusCfg.InMemory, readonly), snapshots, chainDb[0]) } case *params.BorConfig: