mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
Add few tests
This commit is contained in:
@@ -341,3 +341,10 @@ func TestBlockMaxDataBytesUnknownEvidence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilBlock(t *testing.T) {
|
||||
nilBlock := BlockID{nil, PartSetHeader{}}
|
||||
t.Log(nilBlock)
|
||||
t.Log(len(nilBlock.Hash))
|
||||
t.Log(nilBlock.IsZero())
|
||||
}
|
||||
|
||||
+18
-20
@@ -62,9 +62,9 @@ func NewValidatorSet(valz []*Validator) *ValidatorSet {
|
||||
round: 0,
|
||||
}
|
||||
|
||||
if len(valz) > 0 {
|
||||
vals.IncrementProposerPriority(1)
|
||||
}
|
||||
//if len(valz) > 0 {
|
||||
// vals.IncrementProposerPriority(1)
|
||||
//}
|
||||
|
||||
return vals
|
||||
}
|
||||
@@ -93,11 +93,11 @@ func (vals *ValidatorSet) FindProposer(round int) *Validator {
|
||||
val.ProposerPriority = initialValSet.initProposerPriorities[i]
|
||||
}
|
||||
for i := initialValSet.round; i <= round; i++ {
|
||||
proposer = vals.updateProposerPriority()
|
||||
proposer = vals.UpdateProposerPriority()
|
||||
}
|
||||
} else {
|
||||
for i := vals.round; i <= round; i++ {
|
||||
proposer = vals.updateProposerPriority()
|
||||
proposer = vals.UpdateProposerPriority()
|
||||
}
|
||||
vals.round = round
|
||||
}
|
||||
@@ -127,24 +127,22 @@ func (vals *ValidatorSet) IncrementProposerPriority(times int) {
|
||||
vals.Proposer = proposer
|
||||
}
|
||||
|
||||
func (vals *ValidatorSet) UpdateProposerPriority() *Validator {
|
||||
for _, val := range vals.Validators {
|
||||
func (vals *ValidatorSet) UpdateProposerPriority() *ValidatorSet {
|
||||
nValSet := vals.Copy()
|
||||
|
||||
// just pick the proposer with the highest proposer priority
|
||||
// without any modification to it
|
||||
proposer := vals.FindProposer(0) // maybe use getProposer here
|
||||
|
||||
// update proposer priority
|
||||
for _, val := range nValSet.Validators {
|
||||
// Check for overflow for sum.
|
||||
val.ProposerPriority = safeAddClip(val.ProposerPriority, val.VotingPower)
|
||||
if bytes.Equal(proposer.Address, val.Address) {
|
||||
val.ProposerPriority = safeSubClip(val.ProposerPriority, nValSet.TotalVotingPower())
|
||||
}
|
||||
}
|
||||
|
||||
validatorsHeap := cmn.NewHeap()
|
||||
// just update the heap
|
||||
for _, val := range vals.Validators {
|
||||
validatorsHeap.PushComparable(val, proposerPriorityComparable{val})
|
||||
}
|
||||
|
||||
// Decrement the validator with most ProposerPriority:
|
||||
mostest := validatorsHeap.Peek().(*Validator)
|
||||
// mind underflow
|
||||
mostest.ProposerPriority = safeSubClip(mostest.ProposerPriority, vals.TotalVotingPower())
|
||||
|
||||
return mostest
|
||||
return nValSet
|
||||
}
|
||||
|
||||
func (vals *ValidatorSet) incrementProposerPriority(subAvg bool) *Validator {
|
||||
|
||||
Reference in New Issue
Block a user