mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Devnet macos startup and windows committed memory startup fixes (#7832)
The fixes here fix a couple of issues related to devnet start-up 1. macos threading and syscall error return where causing multi node start to both not wait and fail 2. On windows creating DB's with the default 2 TB mapsize causes the os to reserve about 4GB of committed memory per DB. This may not be used - but is reserved by the OS - so a default bor node reserves around 10GB of storage. Starting many nodes causes the OS page file to become exhausted. To fix this the consensus DB's now use the node's OpenDatabase function rather than their own, which means that the consensus DB's take notice of the config.MdbxDBSizeLimit. This fix leaves one 4GB committed memory allocation in the TX pool which needs its own MapSize setting. --------- Co-authored-by: Alex Sharp <akhounov@gmail.com>
This commit is contained in:
parent
83f5917dc8
commit
5935b11b24
@ -13,31 +13,32 @@ import (
|
||||
type Node struct {
|
||||
requests.RequestGenerator `arg:"-"`
|
||||
BuildDir string `arg:"positional" default:"./build/bin/devnet" json:"builddir"`
|
||||
DataDir string `arg:"--datadir" default:"./dev" json:"--datadir"`
|
||||
Chain string `arg:"--chain" default:"dev" json:"--chain"`
|
||||
Port int `arg:"--port" json:"--port,omitempty"`
|
||||
AllowedPorts string `arg:"--p2p.allowed-ports" json:"--p2p.allowed-ports,omitempty"`
|
||||
NAT string `arg:"--nat" default:"none" json:"--nat"`
|
||||
ConsoleVerbosity string `arg:"--log.console.verbosity" default:"0" json:"--log.console.verbosity"`
|
||||
DirVerbosity string `arg:"--log.dir.verbosity" json:"--log.dir.verbosity,omitempty"`
|
||||
LogDirPath string `arg:"--log.dir.path" json:"--log.dir.path,omitempty"`
|
||||
LogDirPrefix string `arg:"--log.dir.prefix" json:"--log.dir.prefix,omitempty"`
|
||||
P2PProtocol string `arg:"--p2p.protocol" default:"68" json:"--p2p.protocol"`
|
||||
Downloader string `arg:"--no-downloader" default:"true" json:"--no-downloader"`
|
||||
WS string `arg:"--ws" flag:"" default:"true" json:"--ws"`
|
||||
PrivateApiAddr string `arg:"--private.api.addr" default:"localhost:9090" json:"--private.api.addr"`
|
||||
HttpPort int `arg:"--http.port" default:"8545" json:"--http.port"`
|
||||
HttpVHosts string `arg:"--http.vhosts" json:"--http.vhosts"`
|
||||
AuthRpcPort int `arg:"--authrpc.port" default:"8551" json:"--authrpc.port"`
|
||||
AuthRpcVHosts string `arg:"--authrpc.vhosts" json:"--authrpc.vhosts"`
|
||||
DataDir string `arg:"--datadir" default:"./dev" json:"datadir"`
|
||||
Chain string `arg:"--chain" default:"dev" json:"chain"`
|
||||
Port int `arg:"--port" json:"port,omitempty"`
|
||||
AllowedPorts string `arg:"--p2p.allowed-ports" json:"p2p.allowed-ports,omitempty"`
|
||||
NAT string `arg:"--nat" default:"none" json:"nat"`
|
||||
ConsoleVerbosity string `arg:"--log.console.verbosity" default:"0" json:"log.console.verbosity"`
|
||||
DirVerbosity string `arg:"--log.dir.verbosity" json:"log.dir.verbosity,omitempty"`
|
||||
LogDirPath string `arg:"--log.dir.path" json:"log.dir.path,omitempty"`
|
||||
LogDirPrefix string `arg:"--log.dir.prefix" json:"log.dir.prefix,omitempty"`
|
||||
P2PProtocol string `arg:"--p2p.protocol" default:"68" json:"p2p.protocol"`
|
||||
Snapshots bool `arg:"--snapshots" flag:"" default:"false" json:"snapshots,omitempty"`
|
||||
Downloader string `arg:"--no-downloader" default:"true" json:"no-downloader"`
|
||||
WS string `arg:"--ws" flag:"" default:"true" json:"ws"`
|
||||
PrivateApiAddr string `arg:"--private.api.addr" default:"localhost:9090" json:"private.api.addr"`
|
||||
HttpPort int `arg:"--http.port" default:"8545" json:"http.port"`
|
||||
HttpVHosts string `arg:"--http.vhosts" json:"http.vhosts"`
|
||||
AuthRpcPort int `arg:"--authrpc.port" default:"8551" json:"authrpc.port"`
|
||||
AuthRpcVHosts string `arg:"--authrpc.vhosts" json:"authrpc.vhosts"`
|
||||
WSPort int `arg:"-" default:"8546" json:"-"` // flag not defined
|
||||
GRPCPort int `arg:"-" default:"8547" json:"-"` // flag not defined
|
||||
TCPPort int `arg:"-" default:"8548" json:"-"` // flag not defined
|
||||
Metrics bool `arg:"--metrics" flag:"" default:"false" json:"--metrics"`
|
||||
MetricsPort int `arg:"--metrics.port" json:"--metrics.port,omitempty"`
|
||||
MetricsAddr string `arg:"--metrics.addr" json:"--metrics.addr,omitempty"`
|
||||
StaticPeers string `arg:"--staticpeers" json:"--staticpeers,omitempty"`
|
||||
WithoutHeimdall bool `arg:"--bor.withoutheimdall" flag:"" default:"false" json:"--bor.withoutheimdall,omitempty"`
|
||||
Metrics bool `arg:"--metrics" flag:"" default:"false" json:"metrics"`
|
||||
MetricsPort int `arg:"--metrics.port" json:"metrics.port,omitempty"`
|
||||
MetricsAddr string `arg:"--metrics.addr" json:"metrics.addr,omitempty"`
|
||||
StaticPeers string `arg:"--staticpeers" json:"staticpeers,omitempty"`
|
||||
WithoutHeimdall bool `arg:"--bor.withoutheimdall" flag:"" default:"false" json:"bor.withoutheimdall,omitempty"`
|
||||
}
|
||||
|
||||
func (node *Node) configure(base Node, nodeNumber int) error {
|
||||
@ -54,6 +55,8 @@ func (node *Node) configure(base Node, nodeNumber int) error {
|
||||
node.MetricsPort = base.MetricsPort
|
||||
node.MetricsAddr = base.MetricsAddr
|
||||
|
||||
node.Snapshots = base.Snapshots
|
||||
|
||||
var err error
|
||||
|
||||
node.PrivateApiAddr, _, err = portFromBase(base.PrivateApiAddr, nodeNumber, 1)
|
||||
@ -75,12 +78,12 @@ func (node *Node) configure(base Node, nodeNumber int) error {
|
||||
|
||||
type Miner struct {
|
||||
Node
|
||||
Mine bool `arg:"--mine" flag:"true" json:"--mine"`
|
||||
DevPeriod int `arg:"--dev.period" json:"--dev.period"`
|
||||
BorPeriod int `arg:"--bor.period" json:"--bor.period"`
|
||||
BorMinBlockSize int `arg:"--bor.minblocksize" json:"--bor.minblocksize"`
|
||||
HttpApi string `arg:"--http.api" default:"admin,eth,erigon,web3,net,debug,trace,txpool,parity,ots" json:"--http.api"`
|
||||
AccountSlots int `arg:"--txpool.accountslots" default:"16" json:"--txpool.accountslots"`
|
||||
Mine bool `arg:"--mine" flag:"true" json:"mine"`
|
||||
DevPeriod int `arg:"--dev.period" json:"dev.period"`
|
||||
BorPeriod int `arg:"--bor.period" json:"bor.period"`
|
||||
BorMinBlockSize int `arg:"--bor.minblocksize" json:"bor.minblocksize"`
|
||||
HttpApi string `arg:"--http.api" default:"admin,eth,erigon,web3,net,debug,trace,txpool,parity,ots" json:"http.api"`
|
||||
AccountSlots int `arg:"--txpool.accountslots" default:"16" json:"txpool.accountslots"`
|
||||
}
|
||||
|
||||
func (m Miner) Configure(baseNode Node, nodeNumber int) (int, interface{}, error) {
|
||||
@ -106,9 +109,9 @@ func (n Miner) IsMiner() bool {
|
||||
|
||||
type NonMiner struct {
|
||||
Node
|
||||
HttpApi string `arg:"--http.api" default:"admin,eth,debug,net,trace,web3,erigon,txpool" json:"--http.api"`
|
||||
TorrentPort string `arg:"--torrent.port" default:"42070" json:"--torrent.port"`
|
||||
NoDiscover string `arg:"--nodiscover" flag:"" default:"true" json:"--nodiscover"`
|
||||
HttpApi string `arg:"--http.api" default:"admin,eth,debug,net,trace,web3,erigon,txpool" json:"http.api"`
|
||||
TorrentPort string `arg:"--torrent.port" default:"42070" json:"torrent.port"`
|
||||
NoDiscover string `arg:"--nodiscover" flag:"" default:"true" json:"nodiscover"`
|
||||
}
|
||||
|
||||
func (n NonMiner) Configure(baseNode Node, nodeNumber int) (int, interface{}, error) {
|
||||
|
@ -59,6 +59,7 @@ func (nw *Network) Start(ctx *cli.Context) error {
|
||||
Chain: nw.Chain,
|
||||
HttpPort: apiPortNo,
|
||||
PrivateApiAddr: nw.BasePrivateApiAddr,
|
||||
Snapshots: nw.Snapshots,
|
||||
}
|
||||
|
||||
metricsEnabled := ctx.Bool("metrics")
|
||||
@ -124,9 +125,11 @@ func (nw *Network) startNode(nodeAddr string, cfg interface{}, nodeNumber int) (
|
||||
nw.wg.Add(1)
|
||||
|
||||
node := node{
|
||||
sync.Mutex{},
|
||||
requests.NewRequestGenerator(nodeAddr, nw.Logger),
|
||||
cfg,
|
||||
&nw.wg,
|
||||
make(chan error),
|
||||
nil,
|
||||
}
|
||||
|
||||
@ -152,6 +155,10 @@ func (nw *Network) startNode(nodeAddr string, cfg interface{}, nodeNumber int) (
|
||||
}
|
||||
}()
|
||||
|
||||
if err = <-node.startErr; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &node, nil
|
||||
}
|
||||
|
||||
@ -176,7 +183,7 @@ func getEnode(n Node) (string, error) {
|
||||
if errors.As(urlErr.Err, &opErr) {
|
||||
var callErr *os.SyscallError
|
||||
if errors.As(opErr.Err, &callErr) {
|
||||
if callErr.Syscall == "connectex" {
|
||||
if strings.HasPrefix(callErr.Syscall, "connect") {
|
||||
reqCount++
|
||||
time.Sleep(time.Duration(devnetutils.RandomInt(5)) * time.Second)
|
||||
continue
|
||||
|
@ -30,16 +30,25 @@ func (f NodeSelectorFunc) Test(ctx go_context.Context, node Node) bool {
|
||||
}
|
||||
|
||||
type node struct {
|
||||
sync.Mutex
|
||||
requests.RequestGenerator
|
||||
args interface{}
|
||||
wg *sync.WaitGroup
|
||||
ethNode *enode.ErigonNode
|
||||
args interface{}
|
||||
wg *sync.WaitGroup
|
||||
startErr chan error
|
||||
ethNode *enode.ErigonNode
|
||||
}
|
||||
|
||||
func (n *node) Stop() {
|
||||
var toClose *enode.ErigonNode
|
||||
|
||||
n.Lock()
|
||||
if n.ethNode != nil {
|
||||
toClose := n.ethNode
|
||||
toClose = n.ethNode
|
||||
n.ethNode = nil
|
||||
}
|
||||
n.Unlock()
|
||||
|
||||
if toClose != nil {
|
||||
toClose.Close()
|
||||
}
|
||||
|
||||
@ -47,10 +56,14 @@ func (n *node) Stop() {
|
||||
}
|
||||
|
||||
func (n *node) running() bool {
|
||||
return n.ethNode != nil
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
return n.startErr == nil && n.ethNode != nil
|
||||
}
|
||||
|
||||
func (n *node) done() {
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
if n.wg != nil {
|
||||
wg := n.wg
|
||||
n.wg = nil
|
||||
@ -58,7 +71,7 @@ func (n *node) done() {
|
||||
}
|
||||
}
|
||||
|
||||
func (n node) IsMiner() bool {
|
||||
func (n *node) IsMiner() bool {
|
||||
_, isMiner := n.args.(args.Miner)
|
||||
return isMiner
|
||||
}
|
||||
@ -69,6 +82,15 @@ func (n *node) run(ctx *cli.Context) error {
|
||||
var err error
|
||||
|
||||
defer n.done()
|
||||
defer func() {
|
||||
n.Lock()
|
||||
if n.startErr != nil {
|
||||
close(n.startErr)
|
||||
n.startErr = nil
|
||||
}
|
||||
n.ethNode = nil
|
||||
n.Unlock()
|
||||
}()
|
||||
|
||||
if logger, err = debug.Setup(ctx, false /* rootLogger */); err != nil {
|
||||
return err
|
||||
@ -79,10 +101,22 @@ func (n *node) run(ctx *cli.Context) error {
|
||||
nodeCfg := enode.NewNodConfigUrfave(ctx, logger)
|
||||
ethCfg := enode.NewEthConfigUrfave(ctx, nodeCfg, logger)
|
||||
|
||||
// These are set to prevent disk and page size churn which can be excessive
|
||||
// when running multiple nodes
|
||||
// MdbxGrowthStep impacts disk usage, MdbxDBSizeLimit impacts page file usage
|
||||
nodeCfg.MdbxGrowthStep = 32 * datasize.MB
|
||||
nodeCfg.MdbxDBSizeLimit = 512 * datasize.MB
|
||||
|
||||
n.ethNode, err = enode.New(nodeCfg, ethCfg, logger)
|
||||
|
||||
n.Lock()
|
||||
if n.startErr != nil {
|
||||
n.startErr <- err
|
||||
close(n.startErr)
|
||||
n.startErr = nil
|
||||
}
|
||||
n.Unlock()
|
||||
|
||||
if err != nil {
|
||||
logger.Error("Node startup", "err", err)
|
||||
return err
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
|
||||
dbg "runtime/debug"
|
||||
"syscall"
|
||||
"time"
|
||||
@ -234,6 +235,7 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
|
||||
Logger: logger,
|
||||
BasePrivateApiAddr: "localhost:10090",
|
||||
BaseRPCAddr: "localhost:8545",
|
||||
//Snapshots: true,
|
||||
Nodes: []devnet.Node{
|
||||
args.Miner{
|
||||
Node: args.Node{
|
||||
|
@ -173,7 +173,7 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
|
||||
}
|
||||
|
||||
// Assemble the Ethereum object
|
||||
chainKv, err := node.OpenDatabase(stack.Config(), kv.ChainDB, logger)
|
||||
chainKv, err := node.OpenDatabase(stack.Config(), kv.ChainDB, "", false, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -421,8 +421,8 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
|
||||
} else {
|
||||
consensusConfig = &config.Ethash
|
||||
}
|
||||
backend.engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, consensusConfig, config.Miner.Notify, config.Miner.Noverify,
|
||||
config.HeimdallgRPCAddress, config.HeimdallURL, config.WithoutHeimdall, stack.DataDir(), false /* readonly */, logger)
|
||||
backend.engine = ethconsensusconfig.CreateConsensusEngine(stack.Config(), chainConfig, consensusConfig, config.Miner.Notify, config.Miner.Noverify,
|
||||
config.HeimdallgRPCAddress, config.HeimdallURL, config.WithoutHeimdall, false /* readonly */, logger)
|
||||
backend.forkValidator = engineapi.NewForkValidator(currentBlockNumber, inMemoryExecution, tmpdir, backend.blockReader)
|
||||
|
||||
if err != nil {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
|
||||
"github.com/ledgerwatch/erigon/node/nodecfg"
|
||||
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/ledgerwatch/secp256k1"
|
||||
@ -1603,7 +1604,7 @@ func overrideStorageMode(db kv.RwDB, logger log.Logger) error {
|
||||
})
|
||||
}
|
||||
|
||||
func initConsensusEngine(cc *chain2.Config, datadir string, db kv.RwDB, logger log.Logger) (engine consensus.Engine) {
|
||||
func initConsensusEngine(cc *chain2.Config, dir string, db kv.RwDB, logger log.Logger) (engine consensus.Engine) {
|
||||
config := ethconfig.Defaults
|
||||
|
||||
var consensusConfig interface{}
|
||||
@ -1617,6 +1618,6 @@ func initConsensusEngine(cc *chain2.Config, datadir string, db kv.RwDB, logger l
|
||||
} else {
|
||||
consensusConfig = &config.Ethash
|
||||
}
|
||||
return ethconsensusconfig.CreateConsensusEngine(cc, consensusConfig, config.Miner.Notify, config.Miner.Noverify,
|
||||
HeimdallgRPCAddress, HeimdallURL, config.WithoutHeimdall, datadir, db.ReadOnly(), logger)
|
||||
return ethconsensusconfig.CreateConsensusEngine(&nodecfg.Config{Dirs: datadir.New(dir)}, cc, consensusConfig, config.Miner.Notify, config.Miner.Noverify,
|
||||
HeimdallgRPCAddress, HeimdallURL, config.WithoutHeimdall, db.ReadOnly(), logger)
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/vm"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconsensusconfig"
|
||||
"github.com/ledgerwatch/erigon/node/nodecfg"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/turbo/debug"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
@ -616,6 +617,6 @@ func initConsensusEngine(cc *chain2.Config, snapshots *freezeblocks.RoSnapshots,
|
||||
} else {
|
||||
consensusConfig = &config.Ethash
|
||||
}
|
||||
return ethconsensusconfig.CreateConsensusEngine(cc, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallgRPCAddress,
|
||||
config.HeimdallURL, config.WithoutHeimdall, datadirCli, true /* readonly */, logger)
|
||||
return ethconsensusconfig.CreateConsensusEngine(&nodecfg.Config{Dirs: datadir.New(datadirCli)}, cc, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallgRPCAddress,
|
||||
config.HeimdallURL, config.WithoutHeimdall, true /* readonly */, logger)
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
)
|
||||
|
||||
func OpenDatabase(path string, inMem bool, readonly bool) kv.RwDB {
|
||||
opts := mdbx.NewMDBX(log.Root()).Label(kv.ConsensusDB)
|
||||
if readonly {
|
||||
opts = opts.Readonly()
|
||||
}
|
||||
if inMem {
|
||||
opts = opts.InMem("")
|
||||
} else {
|
||||
opts = opts.Path(path)
|
||||
}
|
||||
|
||||
return opts.MustOpen()
|
||||
}
|
@ -205,7 +205,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
|
||||
}
|
||||
|
||||
// Assemble the Ethereum object
|
||||
chainKv, err := node.OpenDatabase(stack.Config(), kv.ChainDB, logger)
|
||||
chainKv, err := node.OpenDatabase(stack.Config(), kv.ChainDB, "", false, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -459,8 +459,8 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
|
||||
} else {
|
||||
consensusConfig = &config.Ethash
|
||||
}
|
||||
backend.engine = ethconsensusconfig.CreateConsensusEngine(chainConfig, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallgRPCAddress, config.HeimdallURL,
|
||||
config.WithoutHeimdall, stack.DataDir(), false /* readonly */, logger)
|
||||
backend.engine = ethconsensusconfig.CreateConsensusEngine(stack.Config(), chainConfig, consensusConfig, config.Miner.Notify, config.Miner.Noverify, config.HeimdallgRPCAddress, config.HeimdallURL,
|
||||
config.WithoutHeimdall, false /* readonly */, logger)
|
||||
backend.forkValidator = engineapi.NewForkValidator(currentBlockNumber, inMemoryExecution, tmpdir, backend.blockReader)
|
||||
|
||||
backend.sentriesClient, err = sentry.NewMultiClient(
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/consensus"
|
||||
"github.com/ledgerwatch/erigon/consensus/aura"
|
||||
"github.com/ledgerwatch/erigon/consensus/bor"
|
||||
@ -16,15 +17,16 @@ import (
|
||||
"github.com/ledgerwatch/erigon/consensus/bor/heimdall/span"
|
||||
"github.com/ledgerwatch/erigon/consensus/bor/heimdallgrpc"
|
||||
"github.com/ledgerwatch/erigon/consensus/clique"
|
||||
"github.com/ledgerwatch/erigon/consensus/db"
|
||||
"github.com/ledgerwatch/erigon/consensus/ethash"
|
||||
"github.com/ledgerwatch/erigon/consensus/ethash/ethashcfg"
|
||||
"github.com/ledgerwatch/erigon/consensus/merge"
|
||||
"github.com/ledgerwatch/erigon/node"
|
||||
"github.com/ledgerwatch/erigon/node/nodecfg"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
)
|
||||
|
||||
func CreateConsensusEngine(chainConfig *chain.Config, config interface{}, notify []string, noVerify bool,
|
||||
heimdallGrpcAddress string, heimdallUrl string, withoutHeimdall bool, dataDir string, readonly bool,
|
||||
func CreateConsensusEngine(nodeConfig *nodecfg.Config, chainConfig *chain.Config, config interface{}, notify []string, noVerify bool,
|
||||
heimdallGrpcAddress string, heimdallUrl string, withoutHeimdall bool, readonly bool,
|
||||
logger log.Logger,
|
||||
) consensus.Engine {
|
||||
var eng consensus.Engine
|
||||
@ -53,16 +55,41 @@ func CreateConsensusEngine(chainConfig *chain.Config, config interface{}, notify
|
||||
}
|
||||
case *params.ConsensusSnapshotConfig:
|
||||
if chainConfig.Clique != nil {
|
||||
if consensusCfg.DBPath == "" {
|
||||
consensusCfg.DBPath = filepath.Join(dataDir, "clique", "db")
|
||||
if consensusCfg.InMemory {
|
||||
nodeConfig.Dirs.DataDir = ""
|
||||
} else {
|
||||
if consensusCfg.DBPath != "" {
|
||||
if filepath.Base(consensusCfg.DBPath) == "clique" {
|
||||
nodeConfig.Dirs.DataDir = filepath.Dir(consensusCfg.DBPath)
|
||||
} else {
|
||||
nodeConfig.Dirs.DataDir = consensusCfg.DBPath
|
||||
}
|
||||
}
|
||||
}
|
||||
eng = clique.New(chainConfig, consensusCfg, db.OpenDatabase(consensusCfg.DBPath, consensusCfg.InMemory, readonly), logger)
|
||||
|
||||
var err error
|
||||
var db kv.RwDB
|
||||
|
||||
db, err = node.OpenDatabase(nodeConfig, kv.ConsensusDB, "clique", readonly, logger)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
eng = clique.New(chainConfig, consensusCfg, db, logger)
|
||||
}
|
||||
case *chain.AuRaConfig:
|
||||
if chainConfig.Aura != nil {
|
||||
dbPath := filepath.Join(dataDir, "aura")
|
||||
var err error
|
||||
eng, err = aura.NewAuRa(chainConfig.Aura, db.OpenDatabase(dbPath, false, readonly))
|
||||
var db kv.RwDB
|
||||
|
||||
db, err = node.OpenDatabase(nodeConfig, kv.ConsensusDB, "aura", readonly, logger)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
eng, err = aura.NewAuRa(chainConfig.Aura, db)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -74,8 +101,15 @@ func CreateConsensusEngine(chainConfig *chain.Config, config interface{}, notify
|
||||
if chainConfig.Bor != nil && chainConfig.Bor.ValidatorContract != "" {
|
||||
genesisContractsClient := contract.NewGenesisContractsClient(chainConfig, chainConfig.Bor.ValidatorContract, chainConfig.Bor.StateReceiverContract, logger)
|
||||
spanner := span.NewChainSpanner(contract.ValidatorSet(), chainConfig, logger)
|
||||
borDbPath := filepath.Join(dataDir, "bor") // bor consensus path: datadir/bor
|
||||
db := db.OpenDatabase(borDbPath, false, readonly)
|
||||
|
||||
var err error
|
||||
var db kv.RwDB
|
||||
|
||||
db, err = node.OpenDatabase(nodeConfig, kv.ConsensusDB, "bor", readonly, logger)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var heimdallClient bor.IHeimdallClient
|
||||
if withoutHeimdall {
|
||||
@ -117,6 +151,6 @@ func CreateConsensusEngineBareBones(chainConfig *chain.Config, logger log.Logger
|
||||
consensusConfig = ðashCfg
|
||||
}
|
||||
|
||||
return CreateConsensusEngine(chainConfig, consensusConfig, nil /* notify */, true, /* noVerify */
|
||||
"" /* heimdallGrpcAddress */, "" /* heimdallUrl */, true /* withoutHeimdall */, "" /*dataDir*/, false /* readonly */, logger)
|
||||
return CreateConsensusEngine(&nodecfg.Config{}, chainConfig, consensusConfig, nil /* notify */, true, /* noVerify */
|
||||
"" /* heimdallGrpcAddress */, "" /* heimdallUrl */, true /* withoutHeimdall */, false /* readonly */, logger)
|
||||
}
|
||||
|
26
node/node.go
26
node/node.go
@ -283,16 +283,20 @@ func (n *Node) DataDir() string {
|
||||
return n.config.Dirs.DataDir
|
||||
}
|
||||
|
||||
func OpenDatabase(config *nodecfg.Config, label kv.Label, logger log.Logger) (kv.RwDB, error) {
|
||||
var name string
|
||||
func OpenDatabase(config *nodecfg.Config, label kv.Label, name string, readonly bool, logger log.Logger) (kv.RwDB, error) {
|
||||
switch label {
|
||||
case kv.ChainDB:
|
||||
name = "chaindata"
|
||||
case kv.TxPoolDB:
|
||||
name = "txpool"
|
||||
case kv.ConsensusDB:
|
||||
if len(name) == 0 {
|
||||
return nil, fmt.Errorf("Expected a consensus name")
|
||||
}
|
||||
default:
|
||||
name = "test"
|
||||
}
|
||||
|
||||
var db kv.RwDB
|
||||
if config.Dirs.DataDir == "" {
|
||||
db = memdb.New("")
|
||||
@ -300,9 +304,9 @@ func OpenDatabase(config *nodecfg.Config, label kv.Label, logger log.Logger) (kv
|
||||
}
|
||||
|
||||
dbPath := filepath.Join(config.Dirs.DataDir, name)
|
||||
var openFunc func(exclusive bool) (kv.RwDB, error)
|
||||
|
||||
logger.Info("Opening Database", "label", name, "path", dbPath)
|
||||
openFunc = func(exclusive bool) (kv.RwDB, error) {
|
||||
openFunc := func(exclusive bool) (kv.RwDB, error) {
|
||||
roTxLimit := int64(32)
|
||||
if config.Http.DBReadConcurrency > 0 {
|
||||
roTxLimit = int64(config.Http.DBReadConcurrency)
|
||||
@ -311,19 +315,29 @@ func OpenDatabase(config *nodecfg.Config, label kv.Label, logger log.Logger) (kv
|
||||
opts := mdbx.NewMDBX(log.Root()).
|
||||
Path(dbPath).Label(label).
|
||||
DBVerbosity(config.DatabaseVerbosity).RoTxsLimiter(roTxsLimiter)
|
||||
|
||||
if readonly {
|
||||
opts = opts.Readonly()
|
||||
}
|
||||
if exclusive {
|
||||
opts = opts.Exclusive()
|
||||
}
|
||||
if label == kv.ChainDB {
|
||||
|
||||
switch label {
|
||||
case kv.ChainDB, kv.ConsensusDB:
|
||||
if config.MdbxPageSize.Bytes() > 0 {
|
||||
opts = opts.PageSize(config.MdbxPageSize.Bytes())
|
||||
}
|
||||
if config.MdbxDBSizeLimit > 0 {
|
||||
opts = opts.MapSize(config.MdbxDBSizeLimit)
|
||||
}
|
||||
} else {
|
||||
if config.MdbxGrowthStep > 0 {
|
||||
opts = opts.GrowthStep(config.MdbxGrowthStep)
|
||||
}
|
||||
default:
|
||||
opts = opts.GrowthStep(16 * datasize.MB)
|
||||
}
|
||||
|
||||
return opts.Open()
|
||||
}
|
||||
var err error
|
||||
|
@ -147,7 +147,7 @@ func TestNodeCloseClosesDB(t *testing.T) {
|
||||
stack, _ := New(testNodeConfig(t), logger)
|
||||
defer stack.Close()
|
||||
|
||||
db, err := OpenDatabase(stack.Config(), kv.SentryDB, logger)
|
||||
db, err := OpenDatabase(stack.Config(), kv.SentryDB, "", false, logger)
|
||||
if err != nil {
|
||||
t.Fatal("can't open DB:", err)
|
||||
}
|
||||
@ -179,7 +179,7 @@ func TestNodeOpenDatabaseFromLifecycleStart(t *testing.T) {
|
||||
var db kv.RwDB
|
||||
stack.RegisterLifecycle(&InstrumentedService{
|
||||
startHook: func() {
|
||||
db, err = OpenDatabase(stack.Config(), kv.SentryDB, logger)
|
||||
db, err = OpenDatabase(stack.Config(), kv.SentryDB, "", false, logger)
|
||||
if err != nil {
|
||||
t.Fatal("can't open DB:", err)
|
||||
}
|
||||
@ -205,7 +205,7 @@ func TestNodeOpenDatabaseFromLifecycleStop(t *testing.T) {
|
||||
|
||||
stack.RegisterLifecycle(&InstrumentedService{
|
||||
stopHook: func() {
|
||||
db, err := OpenDatabase(stack.Config(), kv.ChainDB, logger)
|
||||
db, err := OpenDatabase(stack.Config(), kv.ChainDB, "", false, logger)
|
||||
if err != nil {
|
||||
t.Fatal("can't open DB:", err)
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ type Config struct {
|
||||
|
||||
MdbxPageSize datasize.ByteSize
|
||||
MdbxDBSizeLimit datasize.ByteSize
|
||||
|
||||
MdbxGrowthStep datasize.ByteSize
|
||||
// HealthCheck enables standard grpc health check
|
||||
HealthCheck bool
|
||||
|
||||
|
@ -19,10 +19,10 @@
|
||||
"0": 2
|
||||
},
|
||||
"producerDelay": {
|
||||
"0": 6
|
||||
"0": 4
|
||||
},
|
||||
"sprint": {
|
||||
"0": 64
|
||||
"0":16
|
||||
},
|
||||
"backupMultiplier": {
|
||||
"0": 5
|
||||
|
@ -61,7 +61,7 @@ func initGenesis(ctx *cli.Context) error {
|
||||
stack := MakeConfigNodeDefault(ctx, logger)
|
||||
defer stack.Close()
|
||||
|
||||
chaindb, err := node.OpenDatabase(stack.Config(), kv.ChainDB, logger)
|
||||
chaindb, err := node.OpenDatabase(stack.Config(), kv.ChainDB, "", false, logger)
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user