switch using disk-based db by default. logging singleton should have context of the node (ip and port)

pull/293/head
Minh Doan 6 years ago committed by Minh Doan
parent e3f09e5a29
commit 9762ab75bd
  1. 7
      cmd/harmony.go
  2. 14
      internal/utils/singleton.go
  3. 13
      node/node.go

@ -15,10 +15,10 @@ import (
"github.com/harmony-one/harmony/internal/attack"
pkg_newnode "github.com/harmony-one/harmony/internal/newnode"
"github.com/harmony-one/harmony/internal/profiler"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
peerstore "github.com/libp2p/go-libp2p-peerstore"
multiaddr "github.com/multiformats/go-multiaddr"
)
@ -82,7 +82,7 @@ func main() {
port := flag.String("port", "9000", "port of the node.")
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
attackedMode := flag.Int("attacked_mode", 0, "0 means not attacked, 1 means attacked, 2 means being open to be selected as attacked")
dbSupported := flag.Bool("db_supported", false, "false means not db_supported, true means db_supported")
dbSupported := flag.Bool("db_supported", true, "false means not db_supported, true means db_supported")
profile := flag.Bool("profile", false, "Turn on profiling (CPU, Memory).")
metricsReportURL := flag.String("metrics_report_url", "", "If set, reports metrics to this URL.")
versionFlag := flag.Bool("version", false, "Output version info")
@ -102,6 +102,9 @@ func main() {
printVersion(os.Args[0])
}
// Logging setup
utils.SetPortAndIP(*port, *ip)
// Add GOMAXPROCS to achieve max performance.
runtime.GOMAXPROCS(1024)

@ -9,6 +9,18 @@ import (
"github.com/ethereum/go-ethereum/log"
)
// Global Port and IP for logging.
var (
Port string
IP string
)
// SetPortAndIP used to print out loggings of node with Port and IP.
func SetPortAndIP(port, ip string) {
Port = port
IP = ip
}
// UniqueValidatorID defines the structure of unique validator ID
type UniqueValidatorID struct {
uniqueID uint32
@ -37,7 +49,7 @@ func (s *UniqueValidatorID) GetUniqueID() uint32 {
// GetLogInstance returns logging singleton.
func GetLogInstance() log.Logger {
onceForLog.Do(func() {
logInstance = log.New()
logInstance = log.New("port", Port, "ip", IP)
})
return logInstance
}

@ -209,7 +209,7 @@ func DeserializeNode(d []byte) *NetworkNode {
}
// New creates a new node.
func New(host host.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node {
func New(host host.Host, consensus *bft.Consensus, db ethdb.Database) *Node {
node := Node{}
if host != nil {
@ -218,15 +218,12 @@ func New(host host.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node
}
// Logger
node.log = log.New()
node.log = log.New("IP", host.GetSelfPeer().IP, "Port", host.GetSelfPeer().Port)
if host != nil && consensus != nil {
// Consensus and associated channel to communicate blocks
node.Consensus = consensus
// Initialize level db.
node.db = db
// Initialize genesis block and blockchain
genesisAlloc := node.CreateGenesisAllocWithTestingAddresses(100)
contractKey, _ := ecdsa.GenerateKey(crypto.S256(), strings.NewReader("Test contract key string stream that is fixed so that generated test key are deterministic every time"))
@ -236,7 +233,11 @@ func New(host host.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node
genesisAlloc[contractAddress] = core.GenesisAccount{Balance: contractFunds}
node.ContractKeys = append(node.ContractKeys, contractKey)
database := ethdb.NewMemDatabase()
database := db
if database == nil {
database = ethdb.NewMemDatabase()
}
chainConfig := params.TestChainConfig
chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainID as piggybacked ShardID
gspec := core.Genesis{

Loading…
Cancel
Save