Handle voting ties in BestFinalized() (#7622)

This commit is contained in:
Victor Farazdagi 2020-10-23 07:43:35 +03:00 committed by GitHub
parent 6eb022ffa1
commit e5e51e66e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -452,7 +452,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) (uint64,
var targetEpoch uint64
var mostVotes uint64
for epoch, count := range finalizedEpochVotes {
if count > mostVotes {
if count > mostVotes || (count == mostVotes && epoch > targetEpoch) {
mostVotes = count
targetEpoch = epoch
}

View File

@ -651,6 +651,22 @@ func TestStatus_BestPeer(t *testing.T) {
targetEpoch: 6,
targetEpochSupport: 4,
},
{
name: "handle epoch ties",
peers: []*peerConfig{
{finalizedEpoch: 6, headSlot: 6 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 6, headSlot: 6 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 6, headSlot: 6 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 7, headSlot: 7 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 8, headSlot: 8 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 8, headSlot: 8 * params.BeaconConfig().SlotsPerEpoch},
{finalizedEpoch: 8, headSlot: 8 * params.BeaconConfig().SlotsPerEpoch},
},
ourFinalizedEpoch: 5,
limitPeers: 15,
targetEpoch: 8,
targetEpochSupport: 3,
},
}
for _, tt := range tests {