Prevent Reorgs if Chain Head Does Not Change (#2548)

* revent reorgs if head does not change

* lint

* spacing
This commit is contained in:
Raul Jordan 2019-05-09 11:42:24 -05:00 committed by GitHub
parent 5fc6f2d728
commit c1dfa2677e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -27,6 +27,7 @@ go_library(
"//shared/hashutil:go_default_library",
"//shared/p2p:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@ -5,6 +5,7 @@ import (
"context"
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
@ -176,7 +177,7 @@ func (c *ChainService) ApplyForkChoiceRule(
}
newState := postState
if !isDescendant {
if !isDescendant && !proto.Equal(currentHead, newHead) {
log.WithFields(logrus.Fields{
"currentSlot": currentHead.Slot - params.BeaconConfig().GenesisSlot,
"currentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(currentHeadRoot[:])),
@ -195,6 +196,13 @@ func (c *ChainService) ApplyForkChoiceRule(
reorgCount.Inc()
}
if proto.Equal(currentHead, newHead) {
log.WithFields(logrus.Fields{
"currentSlot": currentHead.Slot - params.BeaconConfig().GenesisSlot,
"currentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(currentHeadRoot[:])),
}).Warn("Head did not change after fork choice, current head has the most votes")
}
// If we receive forked blocks.
if newHead.Slot != newState.Slot {
newState, err = c.beaconDB.HistoricalStateFromSlot(ctx, newHead.Slot, newHeadRoot)