Skip to content

Commit

Permalink
revert blockid.Key requiring the partsetheader
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Jul 2, 2021
1 parent 185eeef commit c15f05e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
10 changes: 2 additions & 8 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,14 +1611,8 @@ func (blockID BlockID) Equals(other BlockID) bool {
}

// Key returns a machine-readable string representation of the BlockID
func (blockID BlockID) Key(partSetHeader PartSetHeader) string {
pbph := partSetHeader.ToProto()
bz, err := pbph.Marshal()
if err != nil {
panic(err)
}

return string(blockID.Hash) + string(bz)
func (blockID BlockID) Key() string {
return string(blockID.Hash)
}

// ValidateBasic performs basic validation.
Expand Down
4 changes: 2 additions & 2 deletions types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *V
return nil
}

if strings.Compare(vote1.BlockID.Key(vote1.PartSetHeader), vote2.BlockID.Key(vote2.PartSetHeader)) == -1 {
if strings.Compare(vote1.BlockID.Key(), vote2.BlockID.Key()) == -1 {
voteA = vote1
voteB = vote2
} else {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (dve *DuplicateVoteEvidence) ValidateBasic() error {
return fmt.Errorf("invalid VoteB: %w", err)
}
// Enforce Votes are lexicographically sorted on blockID
if strings.Compare(dve.VoteA.BlockID.Key(dve.VoteA.PartSetHeader), dve.VoteB.BlockID.Key(dve.VoteB.PartSetHeader)) >= 0 {
if strings.Compare(dve.VoteA.BlockID.Key(), dve.VoteB.BlockID.Key()) >= 0 {
return errors.New("duplicate votes in invalid order")
}
return nil
Expand Down
1 change: 1 addition & 0 deletions types/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func VoteFromProto(pv *tmproto.Vote) (*Vote, error) {

psh, err := PartSetHeaderFromProto(pv.PartSetHeader)
if err != nil {
// todo(evan): clean up
fmt.Println("RETURNING ERROR WHILE CONVERTING TO PROTO", err)
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions types/vote_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
}
valIndex := vote.ValidatorIndex
valAddr := vote.ValidatorAddress
blockKey := vote.BlockID.Key(vote.PartSetHeader)
blockKey := vote.BlockID.Key()

// Ensure that validator index was set
if valIndex < 0 {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {

// Returns (vote, true) if vote exists for valIndex and blockKey.
func (voteSet *VoteSet) getVote(valIndex int32, blockKey string) (vote *Vote, ok bool) {
if existing := voteSet.votes[valIndex]; existing != nil && existing.BlockID.Key(existing.PartSetHeader) == blockKey {
if existing := voteSet.votes[valIndex]; existing != nil && existing.BlockID.Key() == blockKey {
return existing, true
}
if existing := voteSet.votesByBlock[blockKey].getByIndex(valIndex); existing != nil {
Expand All @@ -244,7 +244,7 @@ func (voteSet *VoteSet) addVerifiedVote(
conflicting = existing
}
// Replace vote if blockKey matches voteSet.maj23.
if voteSet.maj23 != nil && voteSet.maj23.Key(*voteSet.maj23PartSetHeader) == blockKey {
if voteSet.maj23 != nil && voteSet.maj23.Key() == blockKey {
voteSet.votes[valIndex] = vote
voteSet.votesBitArray.SetIndex(int(valIndex), true)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID, partSetHeade
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()

blockKey := blockID.Key(partSetHeader)
blockKey := blockID.Key()

// Make sure peer hasn't already told us something.
if existing, ok := voteSet.peerMaj23s[peerID]; ok {
Expand Down Expand Up @@ -360,7 +360,7 @@ func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID, partSetHeader PartSet
}
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
votesByBlock, ok := voteSet.votesByBlock[blockID.Key(partSetHeader)]
votesByBlock, ok := voteSet.votesByBlock[blockID.Key()]
if ok {
return votesByBlock.bitArray.Copy()
}
Expand Down

0 comments on commit c15f05e

Please sign in to comment.