OSDN Git Service

feat: add build crosschain input (#91)
[bytom/vapor.git] / node / node.go
index 92a4593..8f05938 100644 (file)
@@ -2,6 +2,7 @@ package node
 
 import (
        "context"
+       "encoding/hex"
        "errors"
        "net"
        "net/http"
@@ -26,10 +27,9 @@ import (
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/env"
        "github.com/vapor/event"
-       "github.com/vapor/mining/cpuminer"
        "github.com/vapor/net/websocket"
        "github.com/vapor/netsync"
-       "github.com/vapor/p2p"
+       "github.com/vapor/proposal/blockproposer"
        "github.com/vapor/protocol"
        w "github.com/vapor/wallet"
 )
@@ -53,16 +53,29 @@ type Node struct {
        api             *api.API
        chain           *protocol.Chain
        txfeed          *txfeed.Tracker
-       cpuMiner        *cpuminer.CPUMiner
+       cpuMiner        *blockproposer.BlockProposer
        miningEnable    bool
 }
 
 // NewNode create bytom node
 func NewNode(config *cfg.Config) *Node {
        ctx := context.Background()
+
        if err := lockDataDirectory(config); err != nil {
                cmn.Exit("Error: " + err.Error())
        }
+
+       if err := cfg.LoadFederationFile(config.FederationFile(), config); err != nil {
+               cmn.Exit(cmn.Fmt("Failed to load federated information:[%s]", err.Error()))
+       }
+
+       log.WithFields(log.Fields{
+               "module":             logModule,
+               "fed_xpubs":          config.Federation.Xpubs,
+               "fed_quorum":         config.Federation.Quorum,
+               "fed_controlprogram": hex.EncodeToString(cfg.FederationProgrom(config)),
+       }).Info()
+
        initLogFile(config)
        initActiveNetParams(config)
        initCommonConfig(config)
@@ -79,7 +92,7 @@ func NewNode(config *cfg.Config) *Node {
 
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
-       chain, err := protocol.NewChain(store, txPool)
+       chain, err := protocol.NewChain(store, txPool, dispatcher)
        if err != nil {
                cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err))
        }
@@ -149,7 +162,7 @@ func NewNode(config *cfg.Config) *Node {
                notificationMgr: notificationMgr,
        }
 
-       node.cpuMiner = cpuminer.NewCPUMiner(chain, accounts, txPool, dispatcher)
+       node.cpuMiner = blockproposer.NewBlockProposer(chain, accounts, txPool, dispatcher)
        node.BaseService = *cmn.NewBaseService(nil, "Node", node)
        return node
 }
@@ -257,7 +270,3 @@ func (n *Node) RunForever() {
                n.Stop()
        })
 }
-
-func (n *Node) NodeInfo() *p2p.NodeInfo {
-       return n.syncManager.NodeInfo()
-}