-// SignBlock signing the block if current node is consensus node
-func (b *bbft) SignBlock(block *types.Block) error {
- var xprv chainkd.XPrv
- xpub := [64]byte(xprv.XPub())
- node, err := b.consensusNodeManager.getConsensusNode(block.Height, hex.EncodeToString(xpub[:]))
- if err != nil && err != errNotFoundConsensusNode {
+// ProcessBlockSignature process the received block signature messages
+// return whether a block become irreversible, if so, the chain module must update status
+func (c *Chain) ProcessBlockSignature(signature, xPub []byte, blockHash *bc.Hash) error {
+ xpubStr := hex.EncodeToString(xPub[:])
+ blockHeader, _ := c.store.GetBlockHeader(blockHash)
+
+ // save the signature if the block is not exist
+ if blockHeader == nil {
+ cacheKey := signCacheKey(blockHash.String(), xpubStr)
+ c.signatureCache.Add(cacheKey, signature)
+ return nil
+ }
+
+ consensusNode, err := c.getConsensusNode(&blockHeader.PreviousBlockHash, xpubStr)
+ if err != nil {