Integration: configure correct consensus engine (#6492)

This commit is contained in:
Alex Sharov 2023-01-03 12:20:18 +07:00 committed by GitHub
parent d595accc63
commit a4006ad2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 43 deletions

View File

@ -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 := &params.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 := &params.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)
}

View File

@ -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 := &params.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 := &params.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 */)
}

View File

@ -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: