OSDN Git Service

Add png dir
[bytom/vapor.git] / node / node.go
index 5774488..c30ce92 100644 (file)
@@ -27,8 +27,6 @@ import (
        "github.com/vapor/common"
        cfg "github.com/vapor/config"
        "github.com/vapor/consensus"
-       engine "github.com/vapor/consensus/consensus"
-       dpos "github.com/vapor/consensus/consensus/dpos"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database/leveldb"
        "github.com/vapor/env"
@@ -67,8 +65,6 @@ type Node struct {
        miningEnable bool
 
        newBlockCh chan *bc.Hash
-
-       engine engine.Engine
 }
 
 func NewNode(config *cfg.Config) *Node {
@@ -93,14 +89,8 @@ func NewNode(config *cfg.Config) *Node {
        tokenDB := dbm.NewDB("accesstoken", config.DBBackend, config.DBDir())
        accessTokens := accesstoken.NewStore(tokenDB)
 
-       var engine engine.Engine
-       switch config.Consensus.Type {
-       case "dpos":
-               engine = dpos.GDpos
-       }
-
        txPool := protocol.NewTxPool(store)
-       chain, err := protocol.NewChain(store, txPool, engine)
+       chain, err := protocol.NewChain(store, txPool)
        if err != nil {
                cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err))
        }
@@ -177,10 +167,9 @@ func NewNode(config *cfg.Config) *Node {
 
                newBlockCh:      newBlockCh,
                notificationMgr: notificationMgr,
-               engine:          engine,
        }
 
-       node.miner = miner.NewMiner(chain, accounts, txPool, newBlockCh, engine)
+       node.miner = miner.NewMiner(chain, accounts, txPool, newBlockCh)
        node.BaseService = *cmn.NewBaseService(nil, "Node", node)
 
        return node
@@ -305,7 +294,7 @@ func (n *Node) OnStart() error {
 }
 
 func (n *Node) OnStop() {
-       if err := n.engine.Finish(); err != nil {
+       if err := n.chain.Engine.Finish(); err != nil {
                log.Errorf("OnStop: %v", err)
        }
 
@@ -390,13 +379,17 @@ func initDpos(chain *protocol.Chain, config *cfg.Config) {
        hash := header.Hash()
        maxSignerCount := config.Consensus.MaxSignerCount
        period := config.Consensus.Period
-       if err := dpos.GDpos.Init(chain, maxSignerCount, period, height, hash); err != nil {
-               cmn.Exit(cmn.Fmt("initVote: Dpos new: %v", err))
-       }
+       err := chain.Engine.Init(chain, maxSignerCount, period, height, hash)
 
        if height > 0 {
-               oldBlockHeight := dpos.GDpos.GetOldBlockHeight()
-               oldBlockHash := dpos.GDpos.GetOldBlockHash()
+               oldBlockHeight := chain.Engine.GetOldBlockHeight()
+               oldBlockHash := chain.Engine.GetOldBlockHash()
+               if err != nil {
+                       oldBlockHeight = 0
+                       header, _ = chain.GetHeaderByHeight(oldBlockHeight)
+                       oldBlockHash = header.Hash()
+               }
+
                if err := chain.RepairDPoSData(oldBlockHeight, oldBlockHash); err != nil {
                        cmn.Exit(cmn.Fmt("initVote failed: %v", err))
                }