OSDN Git Service

fix dpos nodes less than config number (#101)
[bytom/vapor.git] / protocol / bbft.go
index 9d4de08..987397f 100644 (file)
@@ -9,12 +9,12 @@ import (
 
        "github.com/vapor/config"
        "github.com/vapor/crypto/ed25519"
+       "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/errors"
        "github.com/vapor/event"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/state"
-       "github.com/vapor/crypto/ed25519/chainkd"
 )
 
 const (
@@ -44,12 +44,17 @@ func newBbft(store Store, blockIndex *state.BlockIndex, orphanManage *OrphanMana
 }
 
 func (b *bbft) isIrreversible(block *types.Block) bool {
+       consensusNodes, err := b.consensusNodeManager.getConsensusNodesByVoteResult(&block.PreviousBlockHash)
+       if err != nil {
+               return false
+       }
+
        signNum, err := b.validateSign(block)
        if err != nil {
                return false
        }
 
-       return signNum > (NumOfConsensusNode * 2 / 3)
+       return signNum > (uint64(len(consensusNodes)) * 2 / 3)
 }
 
 // NextLeaderTime returns the start time of the specified public key as the next leader node
@@ -81,7 +86,6 @@ func (b *bbft) ProcessBlockSignature(signature []byte, xPub [64]byte, blockHeigh
                return false, err
        }
 
-
        if chainkd.XPub(xPub).Verify(blockHash.Bytes(), signature) {
                return false, errInvalidSignature
        }