}
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 {
}
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
}
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.
return c.index.InMainchain(hash)
}
+func (c *Chain) IrreversibleBlockHeight() uint64 {
+ c.cond.L.Lock()
+ defer c.cond.L.Unlock()
+ return c.bestIrreversibleNode.Height
+}
+
// This function must be called with mu lock in above level
func (c *Chain) setState(node *state.BlockNode, irreversibleNode *state.BlockNode, view *state.UtxoViewpoint, voteMap map[uint64]*state.VoteResult) error {
if err := c.store.SaveChainStatus(node, irreversibleNode, view, voteMap); err != nil {