mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-13 13:43:30 +00:00
Prevent Reorgs if Chain Head Does Not Change (#2548)
* revent reorgs if head does not change * lint * spacing
This commit is contained in:
parent
5fc6f2d728
commit
c1dfa2677e
@ -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",
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user