support db by default. move ldb to nodeconfig

pull/539/head
Minh Doan 6 years ago committed by Minh Doan
parent fcd950e270
commit 15d134e280
  1. 24
      cmd/harmony/main.go
  2. 5
      internal/configs/node/config.go

@ -85,7 +85,6 @@ var (
ip = flag.String("ip", "127.0.0.1", "IP of the node") ip = flag.String("ip", "127.0.0.1", "IP of the node")
port = flag.String("port", "9000", "port of the node.") port = flag.String("port", "9000", "port of the node.")
logFolder = flag.String("log_folder", "latest", "the folder collecting the logs of this execution") logFolder = flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
dbSupported = flag.Bool("db_supported", true, "false means not db_supported, true means db_supported")
freshDB = flag.Bool("fresh_db", false, "true means the existing disk based db will be removed") freshDB = flag.Bool("fresh_db", false, "true means the existing disk based db will be removed")
profile = flag.Bool("profile", false, "Turn on profiling (CPU, Memory).") profile = flag.Bool("profile", false, "Turn on profiling (CPU, Memory).")
metricsReportURL = flag.String("metrics_report_url", "", "If set, reports metrics to this URL.") metricsReportURL = flag.String("metrics_report_url", "", "If set, reports metrics to this URL.")
@ -140,6 +139,11 @@ func initSetup() {
func createGlobalConfig() *nodeconfig.ConfigType { func createGlobalConfig() *nodeconfig.ConfigType {
nodeConfig := nodeconfig.GetGlobalConfig() nodeConfig := nodeconfig.GetGlobalConfig()
nodeConfig.StakingPriKey = node.LoadStakingKeyFromFile(*stakingKeyFile, *accountIndex)
// Initialize leveldb if dbSupported.
nodeConfig.MainDB, _ = InitLDBDatabase(*ip, *port, *freshDB, false)
return nodeConfig return nodeConfig
} }
@ -148,6 +152,7 @@ func main() {
flag.Parse() flag.Parse()
initSetup() initSetup()
nodeConfig := createGlobalConfig()
var shardID = "0" var shardID = "0"
var peers []p2p.Peer var peers []p2p.Peer
@ -156,8 +161,6 @@ func main() {
var clientPeer *p2p.Peer var clientPeer *p2p.Peer
var role string var role string
stakingPriKey := node.LoadStakingKeyFromFile(*stakingKeyFile, *accountIndex)
p2pPriKey, _, err := utils.LoadKeyFromFile(*keyFile) p2pPriKey, _, err := utils.LoadKeyFromFile(*keyFile)
if err != nil { if err != nil {
panic(err) panic(err)
@ -179,12 +182,6 @@ func main() {
// Init logging. // Init logging.
loggingInit(*logFolder, role, *ip, *port, *onlyLogTps) loggingInit(*logFolder, role, *ip, *port, *onlyLogTps)
// Initialize leveldb if dbSupported.
var ldb *ethdb.LDBDatabase
if *dbSupported {
ldb, _ = InitLDBDatabase(*ip, *port, *freshDB, false)
}
host, err := p2pimpl.NewHost(&selfPeer, p2pPriKey) host, err := p2pimpl.NewHost(&selfPeer, p2pPriKey)
if *logConn { if *logConn {
host.GetP2PHost().Network().Notify(utils.ConnLogger) host.GetP2PHost().Network().Notify(utils.ConnLogger)
@ -210,10 +207,10 @@ func main() {
} }
// Current node. // Current node.
currentNode := node.New(host, consensus, ldb) currentNode := node.New(host, consensus, nodeConfig.MainDB)
currentNode.Consensus.OfflinePeers = currentNode.OfflinePeers currentNode.Consensus.OfflinePeers = currentNode.OfflinePeers
currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.NodeConfig.SetRole(nodeconfig.NewNode)
currentNode.AccountKey = stakingPriKey currentNode.AccountKey = nodeConfig.StakingPriKey
// TODO: refactor the creation of blockchain out of node.New() // TODO: refactor the creation of blockchain out of node.New()
consensus.ChainReader = currentNode.Blockchain() consensus.ChainReader = currentNode.Blockchain()
@ -226,10 +223,7 @@ func main() {
} }
currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon) currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
} else { } else {
var beacondb ethdb.Database beacondb, _ := InitLDBDatabase(*ip, *port, *freshDB, true)
if *dbSupported {
beacondb, _ = InitLDBDatabase(*ip, *port, *freshDB, true)
}
currentNode.AddBeaconChainDatabase(beacondb) currentNode.AddBeaconChainDatabase(beacondb)
if *isNewNode { if *isNewNode {

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
) )
@ -62,7 +63,9 @@ type ConfigType struct {
isLeader bool // whether this node is a leader or not isLeader bool // whether this node is a leader or not
shardID uint32 // shardID of this node shardID uint32 // shardID of this node
role Role // Role of the node role Role // Role of the node
stakingKey *ecdsa.PrivateKey
StakingPriKey *ecdsa.PrivateKey
MainDB *ethdb.LDBDatabase
} }
// configs is a list of node configuration. // configs is a list of node configuration.

Loading…
Cancel
Save