OSDN Git Service

fix sign block (#112)
authormuscle_boy <shenao.78@163.com>
Sun, 2 Jun 2019 14:15:12 +0000 (22:15 +0800)
committerPaladz <yzhu101@uottawa.ca>
Sun, 2 Jun 2019 14:15:12 +0000 (22:15 +0800)
* fix sign block

* rename

protocol/bbft.go
protocol/block.go

index 107334a..d026e95 100644 (file)
@@ -223,6 +223,14 @@ func (b *bbft) SignBlock(block *types.Block) ([]byte, error) {
                return nil, nil
        }
 
+       blockNodes := b.consensusNodeManager.blockIndex.NodesByHeight(block.Height)
+       for _, blockNode := range blockNodes {
+               // Has already signed the same height block
+               if ok, err := blockNode.BlockWitness.Test(uint32(node.order)); err != nil && ok {
+                       return nil, nil
+               }
+       }
+
        signature := block.Witness[node.order]
        if len(signature) == 0 {
                signature = xprv.Sign(block.Hash().Bytes())
index 8018113..8e5523b 100644 (file)
@@ -288,6 +288,14 @@ func (c *Chain) processBlock(block *types.Block) (bool, error) {
                return true, nil
        }
 
+       forkPointBlock := parent
+       for !c.index.InMainchain(forkPointBlock.Hash) {
+               forkPointBlock = forkPointBlock.Parent
+       }
+       if forkPointBlock.Height < c.bestIrreversibleNode.Height {
+               return false, errors.New("the block impossible to be block of main chain")
+       }
+
        if err := c.saveBlock(block); err != nil {
                return false, err
        }