Skip to content

Commit

Permalink
fix vote aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Sep 10, 2023
1 parent c82028a commit 43e7341
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions indexer/votes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func aggregateEpochVotes(blockMap map[uint64]*CacheBlock, epoch uint64, epochSta
ActivityMap: map[uint64]bool{},
VoteCounts: epochStats.validatorStats == nil,
}
votedBitsets := make(map[string][]byte)

for slot := firstSlot; slot <= lastSlot; slot++ {
block := blockMap[slot]
Expand All @@ -64,15 +63,13 @@ func aggregateEpochVotes(blockMap map[uint64]*CacheBlock, epoch uint64, epochSta
attKey := fmt.Sprintf("%v-%v", uint64(att.Data.Slot), uint64(att.Data.Index))
voteAmount := uint64(0)
voteBitset := att.AggregationBits
votedBitset := votedBitsets[attKey]
if epochStats.attestorAssignments != nil {
voteValidators := epochStats.attestorAssignments[attKey]
for bitIdx, validatorIdx := range voteValidators {
if votedBitset != nil && utils.BitAtVector(votedBitset, bitIdx) {
// don't "double count" votes, if a attestation aggregation has been extended and re-included
continue
}
if utils.BitAtVector(voteBitset, bitIdx) {
if votes.ActivityMap[validatorIdx] {
continue
}
if epochStats.validatorStats != nil {
voteAmount += uint64(epochStats.validatorStats.ValidatorBalances[validatorIdx])
} else {
Expand All @@ -83,17 +80,6 @@ func aggregateEpochVotes(blockMap map[uint64]*CacheBlock, epoch uint64, epochSta
}
}

if votedBitset != nil {
// merge bitsets
for i := 0; i < len(votedBitset); i++ {
votedBitset[i] |= voteBitset[i]
}
} else {
votedBitset = make([]byte, len(voteBitset))
copy(votedBitset, voteBitset)
votedBitsets[attKey] = voteBitset
}

if bytes.Equal(att.Data.Target.Root, targetRoot) {
if isNextEpoch {
votes.nextEpoch.targetVoteAmount += voteAmount
Expand Down

0 comments on commit 43e7341

Please sign in to comment.