OSDN Git Service

Handle the abnormal exit situation
[bytom/vapor.git] / protocol / protocol.go
index ff61e18..59e4d1a 100644 (file)
@@ -7,6 +7,7 @@ import (
 
        "github.com/vapor/config"
        engine "github.com/vapor/consensus/consensus"
+       dpos "github.com/vapor/consensus/consensus/dpos"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -23,20 +24,26 @@ type Chain struct {
        store          Store
        processBlockCh chan *processBlockMsg
 
-       cond       sync.Cond
-       bestNode   *state.BlockNode
-       Authoritys map[string]string
-       position   uint64
-       engine     engine.Engine
+       cond     sync.Cond
+       bestNode *state.BlockNode
+       Engine   engine.Engine
 }
 
 // NewChain returns a new Chain using store as the underlying storage.
 func NewChain(store Store, txPool *TxPool) (*Chain, error) {
+
+       var engine engine.Engine
+       switch config.CommonConfig.Consensus.Type {
+       case "dpos":
+               engine = dpos.GDpos
+       }
+
        c := &Chain{
                orphanManage:   NewOrphanManage(),
                txPool:         txPool,
                store:          store,
                processBlockCh: make(chan *processBlockMsg, maxProcessBlockChSize),
+               Engine:         engine,
        }
        c.cond.L = new(sync.Mutex)
 
@@ -59,18 +66,6 @@ func NewChain(store Store, txPool *TxPool) (*Chain, error) {
        return c, nil
 }
 
-func (c *Chain) SetAuthoritys(authoritys map[string]string) {
-       c.Authoritys = authoritys
-}
-
-func (c *Chain) SetPosition(position uint64) {
-       c.position = position
-}
-
-func (c *Chain) SetConsensusEngine(engine engine.Engine) {
-       c.engine = engine
-}
-
 func (c *Chain) initChainStatus() error {
        genesisBlock := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()