mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 06:54:41 +00:00
consensus reactor code polish, fixed prs BitArray cache invalidation bug
This commit is contained in:
+29
-10
@@ -219,6 +219,35 @@ func (v *Validation) Round() int {
|
||||
return v.FirstPrecommit().Round
|
||||
}
|
||||
|
||||
func (v *Validation) Type() byte {
|
||||
return VoteTypePrecommit
|
||||
}
|
||||
|
||||
func (v *Validation) Size() int {
|
||||
return len(v.Precommits)
|
||||
}
|
||||
|
||||
func (v *Validation) BitArray() *BitArray {
|
||||
if v.bitArray == nil {
|
||||
v.bitArray = NewBitArray(len(v.Precommits))
|
||||
for i, precommit := range v.Precommits {
|
||||
v.bitArray.SetIndex(i, precommit != nil)
|
||||
}
|
||||
}
|
||||
return v.bitArray
|
||||
}
|
||||
|
||||
func (v *Validation) GetByIndex(index int) *Vote {
|
||||
return v.Precommits[index]
|
||||
}
|
||||
|
||||
func (v *Validation) IsCommit() bool {
|
||||
if len(v.Precommits) == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (v *Validation) ValidateBasic() error {
|
||||
if len(v.Precommits) == 0 {
|
||||
return errors.New("No precommits in validation")
|
||||
@@ -274,16 +303,6 @@ func (v *Validation) StringIndented(indent string) string {
|
||||
indent, v.hash)
|
||||
}
|
||||
|
||||
func (v *Validation) BitArray() *BitArray {
|
||||
if v.bitArray == nil {
|
||||
v.bitArray = NewBitArray(len(v.Precommits))
|
||||
for i, precommit := range v.Precommits {
|
||||
v.bitArray.SetIndex(i, precommit != nil)
|
||||
}
|
||||
}
|
||||
return v.bitArray
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type Data struct {
|
||||
|
||||
@@ -69,3 +69,17 @@ func (vote *Vote) String() string {
|
||||
|
||||
return fmt.Sprintf("Vote{%v/%02d/%v(%v) %X#%v %v}", vote.Height, vote.Round, vote.Type, typeString, Fingerprint(vote.BlockHash), vote.BlockParts, vote.Signature)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// TODO: Move blocks/Validation to here?
|
||||
|
||||
// Common interface between *consensus.VoteSet and types.Validation
|
||||
type VoteSetReader interface {
|
||||
Height() int
|
||||
Round() int
|
||||
Type() byte
|
||||
Size() int
|
||||
BitArray() *BitArray
|
||||
GetByIndex(int) *Vote
|
||||
IsCommit() bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user