"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"
miningEnable bool
newBlockCh chan *bc.Hash
-
- engine engine.Engine
}
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))
}
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
}
func (n *Node) OnStop() {
- if err := n.engine.Finish(); err != nil {
+ if err := n.chain.Engine.Finish(); err != nil {
log.Errorf("OnStop: %v", err)
}
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))
}