OSDN Git Service

fix next leader time (#98)
[bytom/vapor.git] / protocol / protocol.go
index 2ad9d6e..0f4026b 100644 (file)
@@ -6,6 +6,7 @@ import (
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/config"
+       "github.com/vapor/event"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/state"
@@ -28,7 +29,7 @@ type Chain struct {
 }
 
 // NewChain returns a new Chain using store as the underlying storage.
-func NewChain(store Store, txPool *TxPool) (*Chain, error) {
+func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*Chain, error) {
        c := &Chain{
                orphanManage:   NewOrphanManage(),
                txPool:         txPool,
@@ -51,8 +52,9 @@ func NewChain(store Store, txPool *TxPool) (*Chain, error) {
        }
 
        c.bestNode = c.index.GetNode(storeStatus.Hash)
+       c.bestIrreversibleNode = c.index.GetNode(storeStatus.IrreversibleHash)
        c.index.SetMainChain(c.bestNode)
-       c.bbft = newBbft(store, c.index, c.orphanManage)
+       c.bbft = newBbft(store, c.index, c.orphanManage, eventDispatcher)
        go c.blockProcesser()
        return c, nil
 }
@@ -80,6 +82,7 @@ func (c *Chain) initChainStatus() error {
        if err != nil {
                return err
        }
+
        return c.store.SaveChainStatus(node, node, utxoView, map[uint64]*state.VoteResult{})
 }
 
@@ -117,10 +120,6 @@ func (c *Chain) setState(node *state.BlockNode, irreversibleNode *state.BlockNod
        c.cond.L.Lock()
        defer c.cond.L.Unlock()
 
-       if err := c.bbft.UpdateConsensusNodes(node.Height); err != nil {
-               return err
-       }
-
        c.index.SetMainChain(node)
        c.bestNode = node
        c.bestIrreversibleNode = irreversibleNode
@@ -149,3 +148,8 @@ func (c *Chain) BlockWaiter(height uint64) <-chan struct{} {
 func (c *Chain) GetTxPool() *TxPool {
        return c.txPool
 }
+
+// GetBBFT return chain bbft
+func (c *Chain) GetBBFT() *bbft {
+       return c.bbft
+}