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. 21
      internal/configs/node/config.go

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

@ -8,6 +8,7 @@ import (
"fmt"
"sync"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/p2p"
)
@ -54,15 +55,17 @@ const (
// ConfigType is the structure of all node related configuration variables
type ConfigType struct {
// The three groupID design, please refer to https://github.com/harmony-one/harmony/blob/master/node/node.md#libp2p-integration
beacon p2p.GroupID // the beacon group ID
group p2p.GroupID // the group ID of the shard
client p2p.GroupID // the client group ID of the shard
isClient bool // whether this node is a client node, such as wallet/txgen
isBeacon bool // whether this node is a beacon node or not
isLeader bool // whether this node is a leader or not
shardID uint32 // shardID of this node
role Role // Role of the node
stakingKey *ecdsa.PrivateKey
beacon p2p.GroupID // the beacon group ID
group p2p.GroupID // the group ID of the shard
client p2p.GroupID // the client group ID of the shard
isClient bool // whether this node is a client node, such as wallet/txgen
isBeacon bool // whether this node is a beacon node or not
isLeader bool // whether this node is a leader or not
shardID uint32 // shardID of this node
role Role // Role of the node
StakingPriKey *ecdsa.PrivateKey
MainDB *ethdb.LDBDatabase
}
// configs is a list of node configuration.

Loading…
Cancel
Save