OSDN Git Service

Accumulate vote (#104)
[bytom/vapor.git] / protocol / protocol.go
index 0f4026b..1331d7f 100644 (file)
@@ -38,6 +38,7 @@ func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*
        }
        c.cond.L = new(sync.Mutex)
 
+       c.bbft = newBbft(store, nil, c.orphanManage, eventDispatcher)
        storeStatus := store.GetStoreStatus()
        if storeStatus == nil {
                if err := c.initChainStatus(); err != nil {
@@ -54,7 +55,7 @@ func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*
        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, eventDispatcher)
+       c.bbft.SetBlockIndex(c.index)
        go c.blockProcesser()
        return c, nil
 }
@@ -78,12 +79,17 @@ func (c *Chain) initChainStatus() error {
                return err
        }
 
+       voteResultMap := make(map[uint64]*state.VoteResult)
+       if err := c.bbft.ApplyBlock(voteResultMap, genesisBlock); err != nil {
+               return err
+       }
+
        node, err := state.NewBlockNode(&genesisBlock.BlockHeader, nil)
        if err != nil {
                return err
        }
 
-       return c.store.SaveChainStatus(node, node, utxoView, map[uint64]*state.VoteResult{})
+       return c.store.SaveChainStatus(node, node, utxoView, voteResultMap)
 }
 
 // BestBlockHeight returns the current height of the blockchain.