import (
log "github.com/sirupsen/logrus"
+ "github.com/vapor/config"
"github.com/vapor/errors"
"github.com/vapor/event"
- "github.com/vapor/config"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
"github.com/vapor/protocol/state"
}
voteResultMap := make(map[uint64]*state.VoteResult)
- if err := c.bbft.ApplyBlock(voteResultMap, block); err != nil {
+ if err := c.consensusNodeManager.applyBlock(voteResultMap, block); err != nil {
return err
}
node := c.index.GetNode(&bcBlock.ID)
- if c.bbft.isIrreversible(block) && block.Height > irreversibleNode.Height {
+ if c.isIrreversible(node) && block.Height > irreversibleNode.Height {
irreversibleNode = node
}
return err
}
- if err := c.bbft.DetachBlock(voteResultMap, b); err != nil {
+ if err := c.consensusNodeManager.detachBlock(voteResultMap, b); err != nil {
return err
}
return err
}
- if err := c.bbft.ApplyBlock(voteResultMap, b); err != nil {
+ if err := c.consensusNodeManager.applyBlock(voteResultMap, b); err != nil {
return err
}
- if c.bbft.isIrreversible(b) && b.Height > irreversibleNode.Height {
+ if c.isIrreversible(attachNode) && b.Height > irreversibleNode.Height {
irreversibleNode = attachNode
}
// SaveBlock will validate and save block into storage
func (c *Chain) saveBlock(block *types.Block) error {
- if err := c.bbft.ValidateBlock(block); err != nil {
+ if _, err := c.validateSign(block); err != nil {
return errors.Sub(ErrBadBlock, err)
}
return errors.Sub(ErrBadBlock, err)
}
- signature, err := c.bbft.SignBlock(block)
+ signature, err := c.SignBlock(block)
if err != nil {
return errors.Sub(ErrBadBlock, err)
}
if len(signature) != 0 {
xPub := config.CommonConfig.PrivateKey().XPub()
- if err := c.bbft.eventDispatcher.Post(event.BlockSignatureEvent{BlockHash: block.Hash(), Signature: signature, XPub: xPub}); err != nil {
+ if err := c.eventDispatcher.Post(event.BlockSignatureEvent{BlockHash: block.Hash(), Signature: signature, XPub: xPub}); err != nil {
return err
}
}
return c.orphanManage.BlockExist(&blockHash), nil
}
- parent := c.index.GetNode(&block.PreviousBlockHash)
- if parent == nil {
+ if parent := c.index.GetNode(&block.PreviousBlockHash); parent == nil {
c.orphanManage.Add(block)
return true, nil
}
}
return false, nil
}
-
-func (c *Chain) ProcessBlockSignature(signature, pubKey []byte, blockHeight uint64, blockHash *bc.Hash) error {
- var xPub [64]byte
- for i := 0; i < 64; i++ {
- xPub[i] = pubKey[i]
- }
-
- isIrreversible, err := c.bbft.ProcessBlockSignature(signature, xPub, blockHeight, blockHash)
- if err != nil {
- return err
- }
-
- if isIrreversible && blockHeight > c.bestIrreversibleNode.Height {
- bestIrreversibleNode := c.index.GetNode(blockHash)
- if err := c.store.SaveChainNodeStatus(c.bestNode, bestIrreversibleNode); err != nil {
- return err
- }
-
- c.bestIrreversibleNode = bestIrreversibleNode
- }
- return nil
-}