consensus reactor code polish, fixed prs BitArray cache invalidation bug

This commit is contained in:
Jae Kwon
2015-07-05 13:40:59 -07:00
parent bc71e38bad
commit 41d04cf5b8
4 changed files with 219 additions and 138 deletions
+29 -10
View File
@@ -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 {
+14
View File
@@ -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
}