Fix Miscellaneous Deep Source Issues (#8007)

* deep source fixes

* sh fixes

* fix import

* test err

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
This commit is contained in:
Raul Jordan 2020-11-30 19:55:30 -06:00 committed by GitHub
parent 645931802f
commit 01bf97293f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 36 additions and 47 deletions

View File

@ -2,7 +2,6 @@ package stategen
import "errors"
var errUnknownStateSummary = errors.New("unknown state summary")
var errUnknownBoundaryState = errors.New("unknown boundary state")
var errUnknownState = errors.New("unknown state")
var errUnknownBlock = errors.New("unknown block")

View File

@ -109,7 +109,7 @@ func SendAndMineDeposits(t *testing.T, keystorePath string, validatorNum, offset
}
// sendDeposits uses the passed in web3 and keystore bytes to send the requested deposits.
func sendDeposits(web3 *ethclient.Client, keystoreBytes []byte, num int, offset int, partial bool) error {
func sendDeposits(web3 *ethclient.Client, keystoreBytes []byte, num, offset int, partial bool) error {
txOps, err := bind.NewTransactor(bytes.NewReader(keystoreBytes), "" /*password*/)
if err != nil {
return err

View File

@ -11,7 +11,7 @@ fi
while read -r line ; do
linenum=`expr $line : '^\([0-9]*:\)'`
linenum=$(expr $line : '^\([0-9]*:\)')
issueNum=${line//$linenum}
issueState=$(curl https://api.github.com/repos/prysmaticlabs/prysm/issues/$issueNum | grep -o '"state":"closed"');
@ -21,4 +21,4 @@ then
echo "Issue Number: $issueNum" >&2;
exit 1;
fi
done < <(grep -PrinH -o -h '(?<!context\.)todo\(#{0,1}\K(\d+)' --include \*.go *)
done < <(grep -PrinH -o -h '(?<!context\.)todo\(#{0,1}\K(\d+)' --include \*.go *)

View File

@ -43,7 +43,7 @@ do
IDENTITY=$VALUE
;;
--peers)
[ ! -z "$PEERS"] && PEERS+=","
[ -z "$PEERS" ] && PEERS+=","
PEERS+="$VALUE"
;;
--validator-keys)

View File

@ -15,7 +15,7 @@ arraylength=${#file_list[@]}
searchstring="prysmaticlabs/prysm/"
# Copy pb.go files from bazel-bin to original folder where .proto is.
for ((i = 0; i < ${arraylength}; i++)); do
for ((i = 0; i < arraylength; i++)); do
color "34" $destination
destination=${file_list[i]#*$searchstring}
chmod 755 "$destination"

View File

@ -16,7 +16,7 @@ arraylength=${#file_list[@]}
searchstring="/bin/"
# Copy ssz.go files from bazel-bin to original folder where the target is located.
for ((i = 0; i < ${arraylength}; i++)); do
for ((i = 0; i < arraylength; i++)); do
destination=${file_list[i]#*$searchstring}
color "34" $destination
chmod 755 "$destination"

View File

@ -32,44 +32,44 @@ type Lock struct {
unlock chan byte
}
func (self *Lock) Lock() {
self.lock <- 1
func (lk *Lock) Lock() {
lk.lock <- 1
// get the channels and attempt to acquire them
self.chans = make([]chan byte, 0, len(self.keys))
for i := 0; i < len(self.keys); {
ch := getChan(self.keys[i])
lk.chans = make([]chan byte, 0, len(lk.keys))
for i := 0; i < len(lk.keys); {
ch := getChan(lk.keys[i])
_, ok := <-ch
if ok {
self.chans = append(self.chans, ch)
lk.chans = append(lk.chans, ch)
i++
}
}
self.unlock <- 1
lk.unlock <- 1
}
// Unlocks this lock. Must be called after Lock.
// Can only be invoked if there is a previous call to Lock.
func (self *Lock) Unlock() {
<-self.unlock
func (lk *Lock) Unlock() {
<-lk.unlock
if self.chans != nil {
for _, ch := range self.chans {
if lk.chans != nil {
for _, ch := range lk.chans {
ch <- 1
}
self.chans = nil
lk.chans = nil
}
// Clean unused channels after the unlock.
Clean()
<-self.lock
<-lk.lock
}
// Temporarily unlocks, gives up the cpu time to other goroutine, and attempts to lock again.
func (self *Lock) Yield() {
self.Unlock()
func (lk *Lock) Yield() {
lk.Unlock()
runtime.Gosched()
self.Lock()
lk.Lock()
}
// Creates a new multilock for the specified keys

View File

@ -19,7 +19,7 @@ const (
var (
errIncorrectPhrase = errors.New("input does not match wanted phrase")
passwordReqsError = errors.New("password must have at least 8 characters, at least 1 alphabetical character, 1 unicode symbol, and 1 number")
errPasswordWeak = errors.New("password must have at least 8 characters, at least 1 alphabetical character, 1 unicode symbol, and 1 number")
)
// NotEmpty is a validation function to make sure the input given isn't empty and is valid unicode.
@ -104,7 +104,7 @@ func ValidatePasswordInput(input string) error {
}
}
if !(hasMinLen && hasLetter && hasNumber && hasSpecial) {
return passwordReqsError
return errPasswordWeak
}
strength := strongPasswords.PasswordStrength(input, nil)
if strength.Score < minPasswordScore {

View File

@ -18,17 +18,17 @@ func TestValidatePasswordInput(t *testing.T) {
{
name: "no numbers nor special characters",
input: "abcdefghijklmnopqrs",
wantedErr: passwordReqsError.Error(),
wantedErr: errPasswordWeak.Error(),
},
{
name: "number and letters but no special characters",
input: "abcdefghijklmnopqrs2020",
wantedErr: passwordReqsError.Error(),
wantedErr: errPasswordWeak.Error(),
},
{
name: "numbers, letters, special characters, but too short",
input: "abc2$",
wantedErr: passwordReqsError.Error(),
wantedErr: errPasswordWeak.Error(),
},
{
name: "proper length and strong password",
@ -54,7 +54,7 @@ func TestValidatePasswordInput(t *testing.T) {
{
name: "only numbers and symbols should fail",
input: "123493489223423_23923929",
wantedErr: passwordReqsError.Error(),
wantedErr: errPasswordWeak.Error(),
},
}
for _, tt := range tests {

View File

@ -158,7 +158,7 @@ func DepositsWithBalance(balances []uint64) ([]*ethpb.Deposit, *trieutil.SparseM
func signedDeposit(
secretKey bls.SecretKey,
publicKey []byte,
publicKey,
withdrawalKey []byte,
balance uint64,
) (*ethpb.Deposit, error) {

View File

@ -25,7 +25,7 @@ TERMS AND CONDITIONS: https://github.com/prysmaticlabs/prysm/blob/master/TERMS_O
Type "accept" to accept this terms and conditions [accept/decline]:`
acceptTosPromptErrText = `Could not scan text input, if you are trying to run in non-interactive environment, you
acceptTosPromptErrText = `could not scan text input, if you are trying to run in non-interactive environment, you
can use the --accept-terms-of-use flag after reading the terms and conditions here:
https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md`
)

View File

@ -72,9 +72,7 @@ func (s *SpanDetector) DetectSlashingsForAttestation(
if sourceEpoch > targetEpoch { //Prevent underflow and handle source > target slashable cases.
dis = sourceEpoch - targetEpoch
tmp := sourceEpoch
sourceEpoch = targetEpoch
targetEpoch = tmp
sourceEpoch, targetEpoch = targetEpoch, sourceEpoch
sourceLargerThenTargetObserved.Inc()
}
@ -241,9 +239,7 @@ func (s *SpanDetector) updateMinSpan(ctx context.Context, att *ethpb.IndexedAtte
}
// handle source > target well
if source > target {
tmp := source
source = target
target = tmp
source, target = target, source
}
valIndices := make([]uint64, len(att.AttestingIndices))
copy(valIndices, att.AttestingIndices)
@ -319,9 +315,7 @@ func (s *SpanDetector) updateMaxSpan(ctx context.Context, att *ethpb.IndexedAtte
target := att.Data.Target.Epoch
// handle source > target well
if source > target {
tmp := source
source = target
target = tmp
source, target = target, source
}
latestMaxSpanDistanceObserved.Set(float64(target - source))
valIndices := make([]uint64, len(att.AttestingIndices))

View File

@ -129,11 +129,7 @@ func (v *validator) postAttSignUpdate(ctx context.Context, indexedAtt *ethpb.Ind
if err := v.db.SaveLowestSignedSourceEpoch(ctx, pubKey, indexedAtt.Data.Source.Epoch); err != nil {
return err
}
if err := v.db.SaveLowestSignedTargetEpoch(ctx, pubKey, indexedAtt.Data.Target.Epoch); err != nil {
return err
}
return nil
return v.db.SaveLowestSignedTargetEpoch(ctx, pubKey, indexedAtt.Data.Target.Epoch)
}
// isNewAttSlashable uses the attestation history to determine if an attestation of sourceEpoch

View File

@ -62,7 +62,7 @@ func (dr *Keymanager) ImportKeystores(
}
// ImportKeypairs directly into the keymanager.
func (dr *Keymanager) ImportKeypairs(ctx context.Context, privKeys [][]byte, pubKeys [][]byte) error {
func (dr *Keymanager) ImportKeypairs(ctx context.Context, privKeys, pubKeys [][]byte) error {
// Write the accounts to disk into a single keystore.
accountsKeystore, err := dr.createAccountsKeystore(ctx, privKeys, pubKeys)
if err != nil {

View File

@ -282,7 +282,7 @@ func (s *Server) initializeWallet(ctx context.Context, cfg *wallet.Config) error
return nil
}
func writeWalletPasswordToDisk(walletDir string, password string) error {
func writeWalletPasswordToDisk(walletDir, password string) error {
if !featureconfig.Get().WriteWalletPasswordOnWebOnboarding {
return nil
}