Skip to content

Commit

Permalink
Merge branch 'addNoiseSupport' of https://github.com/prysmaticlabs/ge…
Browse files Browse the repository at this point in the history
…th-sharding into addNoiseSupport
  • Loading branch information
nisdas committed Mar 3, 2020
2 parents 2bcd2ec + e8b75b9 commit 5bb1d0b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions validator/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//proto/slashing:go_default_library",
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion validator/client/validator_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot uint64, pu
defer span.End()

span.AddAttributes(trace.StringAttribute("validator", fmt.Sprintf("%#x", pubKey)))
fmtKey := fmt.Sprintf("%#x", pubKey[:8])
fmtKey := fmt.Sprintf("%#x", pubKey[:])

duty, err := v.duty(pubKey)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions validator/client/validator_attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/validator/keymanager"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -52,7 +54,7 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot uint64, pubKey [
defer span.End()
span.AddAttributes(trace.StringAttribute("validator", fmt.Sprintf("%#x", pubKey)))

fmtKey := fmt.Sprintf("%#x", pubKey[:8])
fmtKey := fmt.Sprintf("%#x", pubKey[:])
log := log.WithField("pubKey", fmt.Sprintf("%#x", bytesutil.Trunc(pubKey[:]))).WithField("slot", slot)
duty, err := v.duty(pubKey)
if err != nil {
Expand Down Expand Up @@ -209,7 +211,12 @@ func (v *validator) signAtt(ctx context.Context, pubKey [48]byte, data *ethpb.At
return nil, err
}

sig, err := v.keyManager.Sign(pubKey, root, domain.SignatureDomain)
var sig *bls.Signature
if protectingKeymanager, supported := v.keyManager.(keymanager.ProtectingKeyManager); supported {
sig, err = protectingKeymanager.SignAttestation(pubKey, domain.SignatureDomain, data)
} else {
sig, err = v.keyManager.Sign(pubKey, root, domain.SignatureDomain)
}
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions validator/client/validator_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64)
for _, pkey := range pubKeys {
pubKey := fmt.Sprintf("%#x", pkey[:8])
log := log.WithField("pubKey", pubKey)
fmtKey := fmt.Sprintf("%#x", pkey[:])
if missingValidators[bytesutil.ToBytes48(pkey)] {
log.Info("Validator not in beacon chain")
if v.emitAccountMetrics {
validatorBalancesGaugeVec.WithLabelValues(pubKey).Set(0)
validatorBalancesGaugeVec.WithLabelValues(fmtKey).Set(0)
}
continue
}
Expand All @@ -92,7 +93,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64)
"percentChange": fmt.Sprintf("%.5f%%", percentNet*100),
}).Info("Previous epoch voting summary")
if v.emitAccountMetrics {
validatorBalancesGaugeVec.WithLabelValues(pubKey).Set(newBalance)
validatorBalancesGaugeVec.WithLabelValues(fmtKey).Set(newBalance)
}
}

Expand Down
11 changes: 9 additions & 2 deletions validator/client/validator_propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/validator/keymanager"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -54,7 +56,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot uint64, pubKey [48]by
}
ctx, span := trace.StartSpan(ctx, "validator.ProposeBlock")
defer span.End()
fmtKey := fmt.Sprintf("%#x", pubKey[:8])
fmtKey := fmt.Sprintf("%#x", pubKey[:])

span.AddAttributes(trace.StringAttribute("validator", fmt.Sprintf("%#x", pubKey)))
log := log.WithField("pubKey", fmt.Sprintf("%#x", bytesutil.Trunc(pubKey[:])))
Expand Down Expand Up @@ -196,7 +198,12 @@ func (v *validator) signBlock(ctx context.Context, pubKey [48]byte, epoch uint64
if err != nil {
return nil, errors.Wrap(err, "could not get signing root")
}
sig, err := v.keyManager.Sign(pubKey, root, domain.SignatureDomain)
var sig *bls.Signature
if protectingKeymanager, supported := v.keyManager.(keymanager.ProtectingKeyManager); supported {
sig, err = protectingKeymanager.SignProposal(pubKey, domain.SignatureDomain, b)
} else {
sig, err = v.keyManager.Sign(pubKey, root, domain.SignatureDomain)
}
if err != nil {
return nil, errors.Wrap(err, "could not get signing root")
}
Expand Down
1 change: 1 addition & 0 deletions validator/keymanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
"//shared/bytesutil:go_default_library",
"//shared/interop:go_default_library",
"//validator/accounts:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_wealdtech_go_eth2_wallet//:go_default_library",
"@com_github_wealdtech_go_eth2_wallet_store_filesystem//:go_default_library",
Expand Down
13 changes: 13 additions & 0 deletions validator/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keymanager
import (
"errors"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bls"
)

Expand All @@ -12,10 +13,22 @@ var ErrNoSuchKey = errors.New("no such key")
// ErrCannotSign is returned whenever a signing attempt fails.
var ErrCannotSign = errors.New("cannot sign")

// ErrCouldSlash is returned whenever a signing attempt is refused due to a potential slashing event.
var ErrCouldSlash = errors.New("could result in a slashing event")

// KeyManager controls access to private keys by the validator.
type KeyManager interface {
// FetchValidatingKeys fetches the list of public keys that should be used to validate with.
FetchValidatingKeys() ([][48]byte, error)
// Sign signs a message for the validator to broadcast.
Sign(pubKey [48]byte, root [32]byte, domain uint64) (*bls.Signature, error)
}

// ProtectingKeyManager provides access to a keymanager that protects its clients from slashing events.
type ProtectingKeyManager interface {
// SignProposal signs a block proposal for the validator to broadcast.
SignProposal(pubKey [48]byte, domain uint64, data *ethpb.BeaconBlock) (*bls.Signature, error)

// SignAttestation signs an attestation for the validator to broadcast.
SignAttestation(pubKey [48]byte, domain uint64, data *ethpb.AttestationData) (*bls.Signature, error)
}

0 comments on commit 5bb1d0b

Please sign in to comment.