"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 (
}
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
return false, err
}
-
if chainkd.XPub(xPub).Verify(blockHash.Bytes(), signature) {
return false, errInvalidSignature
}
)
var (
- errNotFoundConsensusNode = errors.New("can not found consensus node")
- errNotFoundBlockNode = errors.New("can not find block node")
+ errNotFoundConsensusNode = errors.New("can not found consensus node")
+ errNotFoundBlockNode = errors.New("can not find block node")
)
type consensusNode struct {
if prevBlockNode == nil {
return nil, errNotFoundBlockNode
}
-
+
blockHeight := prevBlockNode.Height + 1
prevVoteRoundLastBlockHeight := blockHeight/roundVoteBlockNums*roundVoteBlockNums - 1
// first round
- if blockHeight / roundVoteBlockNums == 0 {
+ if blockHeight/roundVoteBlockNums == 0 {
prevVoteRoundLastBlockHeight = 0
}
sort.Sort(consensusNodeSlice(nodes))
result := make(map[string]*consensusNode)
- for i := 0; i < NumOfConsensusNode; i++ {
+ for i := 0; i < len(nodes) && i < NumOfConsensusNode; i++ {
node := nodes[i]
node.order = uint64(i)
result[node.pubkey] = node
if voteResult == nil {
voteResult = &state.VoteResult{
- Seq: voteSeq,
- NumOfVote: make(map[string]uint64),
+ Seq: voteSeq,
+ NumOfVote: make(map[string]uint64),
}
}