Skip to content

Commit

Permalink
Remove Local Protection Flag (#7543)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed Oct 15, 2020
1 parent 0b64a33 commit ec9c6f3
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 120 deletions.
7 changes: 0 additions & 7 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type Flags struct {
EnableBackupWebhook bool // EnableBackupWebhook to allow database backups to trigger from monitoring port /db/backup.
PruneEpochBoundaryStates bool // PruneEpochBoundaryStates prunes the epoch boundary state before last finalized check point.
EnableSnappyDBCompression bool // EnableSnappyDBCompression in the database.
LocalProtection bool // LocalProtection prevents the validator client from signing any messages that would be considered a slashable offense from the validators view.
SlasherProtection bool // SlasherProtection protects validator fron sending over a slashable offense over the network using external slasher.
EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer.
WaitForSynced bool // WaitForSynced uses WaitForSynced in validator startup to ensure it can communicate with the beacon node as soon as possible.
Expand Down Expand Up @@ -215,12 +214,6 @@ func ConfigureValidator(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
configureTestnet(ctx, cfg)

if ctx.Bool(enableLocalProtectionFlag.Name) {
cfg.LocalProtection = true
} else {
log.Warn("Validator slashing protection not enabled!")
}
if ctx.Bool(enableExternalSlasherProtectionFlag.Name) {
log.Warn("Enabled validator attestation and block slashing protection using an external slasher.")
cfg.SlasherProtection = true
Expand Down
7 changes: 0 additions & 7 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ var (
Name: "kafka-url",
Usage: "Stream attestations and blocks to specified kafka servers. This field is used for bootstrap.servers kafka config field.",
}
enableLocalProtectionFlag = &cli.BoolFlag{
Name: "enable-local-protection",
Usage: "Enables functionality to prevent the validator client from signing and " +
"broadcasting any messages that could be considered slashable according to its own history.",
Value: true,
}
enableExternalSlasherProtectionFlag = &cli.BoolFlag{
Name: "enable-external-slasher-protection",
Usage: "Enables the validator to connect to external slasher to prevent it from " +
Expand Down Expand Up @@ -115,7 +109,6 @@ var devModeFlags = []cli.Flag{

// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
enableLocalProtectionFlag,
enableExternalSlasherProtectionFlag,
waitForSyncedFlag,
AltonaTestnet,
Expand Down
39 changes: 18 additions & 21 deletions validator/client/attest_protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ var failedPostAttSignExternalErr = "external slasher service detected a submitte

func (v *validator) preAttSignValidations(ctx context.Context, indexedAtt *ethpb.IndexedAttestation, pubKey [48]byte) error {
fmtKey := fmt.Sprintf("%#x", pubKey[:])
if featureconfig.Get().LocalProtection {
v.attesterHistoryByPubKeyLock.RLock()
attesterHistory, ok := v.attesterHistoryByPubKey[pubKey]
v.attesterHistoryByPubKeyLock.RUnlock()
if ok && isNewAttSlashable(attesterHistory, indexedAtt.Data.Source.Epoch, indexedAtt.Data.Target.Epoch) {
if v.emitAccountMetrics {
ValidatorAttestFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPreAttSignLocalErr)
} else if !ok {
log.WithField("publicKey", fmtKey).Debug("Could not get local slashing protection data for validator")

v.attesterHistoryByPubKeyLock.RLock()
attesterHistory, ok := v.attesterHistoryByPubKey[pubKey]
v.attesterHistoryByPubKeyLock.RUnlock()
if ok && isNewAttSlashable(attesterHistory, indexedAtt.Data.Source.Epoch, indexedAtt.Data.Target.Epoch) {
if v.emitAccountMetrics {
ValidatorAttestFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPreAttSignLocalErr)
} else if !ok {
log.WithField("publicKey", fmtKey).Debug("Could not get local slashing protection data for validator")
}

if featureconfig.Get().SlasherProtection && v.protector != nil {
Expand All @@ -44,17 +43,15 @@ func (v *validator) preAttSignValidations(ctx context.Context, indexedAtt *ethpb

func (v *validator) postAttSignUpdate(ctx context.Context, indexedAtt *ethpb.IndexedAttestation, pubKey [48]byte) error {
fmtKey := fmt.Sprintf("%#x", pubKey[:])
if featureconfig.Get().LocalProtection {
v.attesterHistoryByPubKeyLock.Lock()
attesterHistory, ok := v.attesterHistoryByPubKey[pubKey]
if ok {
attesterHistory = markAttestationForTargetEpoch(attesterHistory, indexedAtt.Data.Source.Epoch, indexedAtt.Data.Target.Epoch)
v.attesterHistoryByPubKey[pubKey] = attesterHistory
} else {
log.WithField("publicKey", fmtKey).Debug("Could not get local slashing protection data for validator")
}
v.attesterHistoryByPubKeyLock.Unlock()
v.attesterHistoryByPubKeyLock.Lock()
attesterHistory, ok := v.attesterHistoryByPubKey[pubKey]
if ok {
attesterHistory = markAttestationForTargetEpoch(attesterHistory, indexedAtt.Data.Source.Epoch, indexedAtt.Data.Target.Epoch)
v.attesterHistoryByPubKey[pubKey] = attesterHistory
} else {
log.WithField("publicKey", fmtKey).Debug("Could not get local slashing protection data for validator")
}
v.attesterHistoryByPubKeyLock.Unlock()

if featureconfig.Get().SlasherProtection && v.protector != nil {
if !v.protector.CommitAttestation(ctx, indexedAtt) {
Expand Down
4 changes: 0 additions & 4 deletions validator/client/attest_protect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func TestPreSignatureValidation(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
Expand Down Expand Up @@ -51,7 +50,6 @@ func TestPreSignatureValidation(t *testing.T) {

func TestPreSignatureValidation_NilLocal(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
SlasherProtection: false,
}
reset := featureconfig.InitWithReset(config)
Expand Down Expand Up @@ -81,7 +79,6 @@ func TestPreSignatureValidation_NilLocal(t *testing.T) {

func TestPostSignatureUpdate(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
Expand Down Expand Up @@ -117,7 +114,6 @@ func TestPostSignatureUpdate(t *testing.T) {

func TestPostSignatureUpdate_NilLocal(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
SlasherProtection: false,
}
reset := featureconfig.InitWithReset(config)
Expand Down
21 changes: 0 additions & 21 deletions validator/client/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/shared/timeutils"
Expand Down Expand Up @@ -88,11 +87,6 @@ func TestAttestToBlockHead_SubmitAttestation_RequestFailure(t *testing.T) {
}

func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
validator, m, validatorKey, finish := setup(t)
defer finish()
hook := logTest.NewGlobal()
Expand Down Expand Up @@ -166,11 +160,6 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
}

func TestAttestToBlockHead_BlocksDoubleAtt(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down Expand Up @@ -214,11 +203,6 @@ func TestAttestToBlockHead_BlocksDoubleAtt(t *testing.T) {
}

func TestAttestToBlockHead_BlocksSurroundAtt(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down Expand Up @@ -263,11 +247,6 @@ func TestAttestToBlockHead_BlocksSurroundAtt(t *testing.T) {
}

func TestAttestToBlockHead_BlocksSurroundedAtt(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down
49 changes: 22 additions & 27 deletions validator/client/propose_protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ var failedPostBlockSignErr = "made a double proposal, considered slashable by re
func (v *validator) preBlockSignValidations(ctx context.Context, pubKey [48]byte, block *ethpb.BeaconBlock) error {
fmtKey := fmt.Sprintf("%#x", pubKey[:])
epoch := helpers.SlotToEpoch(block.Slot)
if featureconfig.Get().LocalProtection {
slotBits, err := v.db.ProposalHistoryForEpoch(ctx, pubKey[:], epoch)
if err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.Wrap(err, "failed to get proposal history")
slotBits, err := v.db.ProposalHistoryForEpoch(ctx, pubKey[:], epoch)
if err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}

// If the bit for the current slot is marked, do not propose.
if slotBits.BitAt(block.Slot % params.BeaconConfig().SlotsPerEpoch) {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPreBlockSignLocalErr)
return errors.Wrap(err, "failed to get proposal history")
}
// If the bit for the current slot is marked, do not propose.
if slotBits.BitAt(block.Slot % params.BeaconConfig().SlotsPerEpoch) {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPreBlockSignLocalErr)
}

if featureconfig.Get().SlasherProtection && v.protector != nil {
Expand Down Expand Up @@ -73,21 +70,19 @@ func (v *validator) postBlockSignUpdate(ctx context.Context, pubKey [48]byte, bl
}
}

if featureconfig.Get().LocalProtection {
slotBits, err := v.db.ProposalHistoryForEpoch(ctx, pubKey[:], epoch)
if err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.Wrap(err, "failed to get proposal history")
slotBits, err := v.db.ProposalHistoryForEpoch(ctx, pubKey[:], epoch)
if err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
slotBits.SetBitAt(block.Block.Slot%params.BeaconConfig().SlotsPerEpoch, true)
if err := v.db.SaveProposalHistoryForEpoch(ctx, pubKey[:], epoch, slotBits); err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.Wrap(err, "failed to save updated proposal history")
return errors.Wrap(err, "failed to get proposal history")
}
slotBits.SetBitAt(block.Block.Slot%params.BeaconConfig().SlotsPerEpoch, true)
if err := v.db.SaveProposalHistoryForEpoch(ctx, pubKey[:], epoch, slotBits); err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.Wrap(err, "failed to save updated proposal history")
}
return nil
}
2 changes: 0 additions & 2 deletions validator/client/propose_protect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

func TestPreBlockSignValidation(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: false,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
Expand All @@ -37,7 +36,6 @@ func TestPreBlockSignValidation(t *testing.T) {

func TestPostBlockSignUpdate(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: false,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
Expand Down
21 changes: 0 additions & 21 deletions validator/client/propose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/mock"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
Expand Down Expand Up @@ -185,11 +184,6 @@ func TestProposeBlock_ProposeBlockFailed(t *testing.T) {
}

func TestProposeBlock_BlocksDoubleProposal(t *testing.T) {
cfg := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(cfg)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down Expand Up @@ -225,11 +219,6 @@ func TestProposeBlock_BlocksDoubleProposal(t *testing.T) {
}

func TestProposeBlock_BlocksDoubleProposal_After54KEpochs(t *testing.T) {
cfg := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(cfg)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down Expand Up @@ -265,11 +254,6 @@ func TestProposeBlock_BlocksDoubleProposal_After54KEpochs(t *testing.T) {
}

func TestProposeBlock_AllowsPastProposals(t *testing.T) {
cfg := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(cfg)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down Expand Up @@ -314,11 +298,6 @@ func TestProposeBlock_AllowsPastProposals(t *testing.T) {
}

func TestProposeBlock_AllowsSameEpoch(t *testing.T) {
cfg := &featureconfig.Flags{
LocalProtection: true,
}
reset := featureconfig.InitWithReset(cfg)
defer reset()
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
defer finish()
Expand Down
16 changes: 6 additions & 10 deletions validator/client/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ func run(ctx context.Context, v Validator) {
continue
}

if featureconfig.Get().LocalProtection {
if err := v.UpdateProtections(ctx, slot); err != nil {
log.WithError(err).Error("Could not update validator protection")
span.End()
continue
}
if err := v.UpdateProtections(ctx, slot); err != nil {
log.WithError(err).Error("Could not update validator protection")
span.End()
continue
}

// Start fetching domain data for the next epoch.
Expand Down Expand Up @@ -157,10 +155,8 @@ func run(ctx context.Context, v Validator) {
go func() {
wg.Wait()
v.LogAttestationsSubmitted()
if featureconfig.Get().LocalProtection {
if err := v.SaveProtections(ctx); err != nil {
log.WithError(err).Error("Could not save validator protection")
}
if err := v.SaveProtections(ctx); err != nil {
log.WithError(err).Error("Could not save validator protection")
}
span.End()
}()
Expand Down

0 comments on commit ec9c6f3

Please sign in to comment.