Skip to content

Commit

Permalink
Reverse historical detection flag for slasher (#5958)
Browse files Browse the repository at this point in the history
* Reverse historical detection flag
* Merge branch 'master' of github.com:prysmaticlabs/prysm into reverse-historical-flag
* Merge branch 'master' of github.com:prysmaticlabs/prysm into reverse-historical-flag
* Fix build
* Merge refs/heads/master into reverse-historical-flag
* Fix test
* Merge branch 'reverse-historical-flag' of github.com:prysmaticlabs/prysm into reverse-historical-flag
* Merge refs/heads/master into reverse-historical-flag
  • Loading branch information
0xKiwi committed May 23, 2020
1 parent 5a3114c commit b810243
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/rpc/beacon/attestations.go
Expand Up @@ -272,7 +272,7 @@ func (bs *Server) StreamIndexedAttestations(
log.Info("Indexed attestations stream got nil attestation or nil attestation aggregate")
continue
}
bs.CollectedAttestationsBuffer <- []*ethpb.Attestation{data.Attestation.Aggregate}
bs.ReceivedAttestationsBuffer <- data.Attestation.Aggregate
}
case atts, ok := <-bs.CollectedAttestationsBuffer:
if !ok {
Expand Down
14 changes: 7 additions & 7 deletions shared/featureconfig/config.go
Expand Up @@ -60,10 +60,10 @@ type Flags struct {
// as the chain head. UNSAFE, use with caution.
DisableForkChoice bool

// DisableBroadcastSlashings disables p2p broadcasting of proposer and attester slashings.
DisableBroadcastSlashings bool
DisableHistoricalDetection bool // DisableHistoricalDetection disables historical attestation detection and performs detection on the chain head immediately.
DisableLookback bool // DisableLookback updates slasher to not use the lookback and update validator histories until epoch 0.
// Slasher toggles.
DisableBroadcastSlashings bool // DisableBroadcastSlashings disables p2p broadcasting of proposer and attester slashings.
EnableHistoricalDetection bool // EnableHistoricalDetection disables historical attestation detection and performs detection on the chain head immediately.
DisableLookback bool // DisableLookback updates slasher to not use the lookback and update validator histories until epoch 0.

// Cache toggles.
EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558.
Expand Down Expand Up @@ -218,9 +218,9 @@ func ConfigureSlasher(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
cfg = configureConfig(ctx, cfg)
if ctx.Bool(disableHistoricalDetectionFlag.Name) {
log.Warn("Disabling historical attestation detection")
cfg.DisableHistoricalDetection = true
if ctx.Bool(enableHistoricalDetectionFlag.Name) {
log.Warn("Enabling historical attestation detection")
cfg.EnableHistoricalDetection = true
}
if ctx.Bool(disableLookbackFlag.Name) {
log.Warn("Disabling slasher lookback")
Expand Down
14 changes: 10 additions & 4 deletions shared/featureconfig/flags.go
Expand Up @@ -136,9 +136,9 @@ var (
Name: "wait-for-synced",
Usage: "Uses WaitForSynced for validator startup, to ensure a validator is able to communicate with the beacon node as quick as possible",
}
disableHistoricalDetectionFlag = &cli.BoolFlag{
Name: "disable-historical-detection",
Usage: "Disables historical attestation detection for the slasher",
enableHistoricalDetectionFlag = &cli.BoolFlag{
Name: "enable-historical-detection",
Usage: "Enables historical attestation detection for the slasher",
}
disableLookbackFlag = &cli.BoolFlag{
Name: "disable-lookback",
Expand Down Expand Up @@ -362,6 +362,11 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}
deprecatedDisableHistoricalDetectionFlag = &cli.BoolFlag{
Name: "disable-historical-detection",
Usage: deprecatedUsage,
Hidden: true,
}
)

var deprecatedFlags = []cli.Flag{
Expand Down Expand Up @@ -404,6 +409,7 @@ var deprecatedFlags = []cli.Flag{
deprecatedEnableDomainDataCacheFlag,
deprecatedEnableByteMempool,
deprecatedBroadcastSlashingFlag,
deprecatedDisableHistoricalDetectionFlag,
}

// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
Expand All @@ -418,7 +424,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{

// SlasherFlags contains a list of all the feature flags that apply to the slasher client.
var SlasherFlags = append(deprecatedFlags, []cli.Flag{
disableHistoricalDetectionFlag,
enableHistoricalDetectionFlag,
disableLookbackFlag,
}...)

Expand Down
3 changes: 2 additions & 1 deletion slasher/beaconclient/BUILD.bazel
Expand Up @@ -16,9 +16,11 @@ go_library(
visibility = ["//slasher:__subpackages__"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//shared/event:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
"//shared/slotutil:go_default_library",
"//slasher/cache:go_default_library",
"//slasher/db:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
Expand All @@ -29,7 +31,6 @@ go_library(
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
"@io_opencensus_go//trace:go_default_library",
Expand Down
8 changes: 5 additions & 3 deletions slasher/beaconclient/receivers.go
Expand Up @@ -9,7 +9,8 @@ import (

ptypes "github.com/gogo/protobuf/types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/slotutil"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (bs *Service) receiveBlocks(ctx context.Context) {
if res == nil {
continue
}
root, err := ssz.HashTreeRoot(res.Block)
root, err := stateutil.BlockRoot(res.Block)
if err != nil {
log.WithError(err).Error("Could not hash block")
return
Expand Down Expand Up @@ -135,7 +136,8 @@ func (bs *Service) collectReceivedAttestations(ctx context.Context) {
defer span.End()

var atts []*ethpb.IndexedAttestation
ticker := time.NewTicker(500 * time.Millisecond)
quarterSlot := slotutil.DivideSlotBy(4 /* 1/4 slot duration */)
ticker := time.NewTicker(quarterSlot)
for {
select {
case <-ticker.C:
Expand Down
2 changes: 1 addition & 1 deletion slasher/beaconclient/receivers_test.go
Expand Up @@ -103,7 +103,7 @@ func TestService_ReceiveAttestations_Batched(t *testing.T) {
att,
nil,
).Do(func() {
time.Sleep(2 * time.Second)
time.Sleep(4 * time.Second)
cancel()
})

Expand Down
2 changes: 1 addition & 1 deletion slasher/detection/service.go
Expand Up @@ -85,7 +85,7 @@ func (ds *Service) Start() {
<-ch
sub.Unsubscribe()

if !featureconfig.Get().DisableHistoricalDetection {
if featureconfig.Get().EnableHistoricalDetection {
// The detection service runs detection on all historical
// chain data since genesis.
go ds.detectHistoricalChainData(ds.ctx)
Expand Down

0 comments on commit b810243

Please sign in to comment.