Fix bash scripts for initializing beacon-chain (#2080)

* Fix bash scripts for chain

* Fix flag

* Change sendDeposits.go to handle multiple keys

* Fix scripts for startup
This commit is contained in:
Ivan Martinez
2019-04-02 16:45:40 -04:00
committed by Raul Jordan
parent a057c07830
commit 89531c1667
6 changed files with 128 additions and 105 deletions

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"crypto/rand"
"encoding/hex"
"fmt"
"io/ioutil"
"math"
@@ -97,7 +98,7 @@ func main() {
},
cli.Int64Flag{
Name: "numberOfDeposits",
Value: 8,
Value: 1,
Usage: "number of deposits to send to the contract",
Destination: &numberOfDeposits,
},
@@ -185,26 +186,25 @@ func main() {
statDist := buildStatisticalDist(depositDelay, numberOfDeposits, txDeviation)
for i := int64(0); i < numberOfDeposits; i++ {
var validatorKey *prysmKeyStore.Key
if randomKey {
validatorKey, err = prysmKeyStore.NewKey(rand.Reader)
if err != nil {
log.Errorf("Could not generate random key: %v", err)
}
} else {
// Load from keystore
store := prysmKeyStore.NewKeystore(prysmKeystorePath)
rawPassword := loadTextFromFile(passwordFile)
validatorKeyPath := prysmKeystorePath + params.BeaconConfig().ValidatorPrivkeyFileName
validatorKey, err = store.GetKey(validatorKeyPath, rawPassword)
if err != nil {
log.WithField("path", validatorKeyPath).WithField("password", rawPassword).Errorf("Could not get key: %v", err)
continue
}
validatorKeys := make(map[string]*prysmKeyStore.Key)
if randomKey {
validatorKey, err := prysmKeyStore.NewKey(rand.Reader)
validatorKeys[hex.EncodeToString(validatorKey.PublicKey.Marshal())] = validatorKey
if err != nil {
log.Errorf("Could not generate random key: %v", err)
}
} else {
// Load from keystore
store := prysmKeyStore.NewKeystore(prysmKeystorePath)
rawPassword := loadTextFromFile(passwordFile)
prefix := params.BeaconConfig().ValidatorPrivkeyFileName
validatorKeys, err = store.GetKeys(prysmKeystorePath, prefix, rawPassword)
if err != nil {
log.WithField("path", prysmKeystorePath).WithField("password", rawPassword).Errorf("Could not get keys: %v", err)
}
}
for _, validatorKey := range validatorKeys {
data, err := prysmKeyStore.DepositInput(validatorKey, validatorKey)
if err != nil {
log.Errorf("Could not generate deposit input data: %v", err)
@@ -216,24 +216,25 @@ func main() {
log.Errorf("could not serialize deposit data: %v", err)
}
tx, err := depositContract.Deposit(txOps, serializedData.Bytes())
if err != nil {
log.Error("unable to send transaction to contract")
for i := int64(0); i < numberOfDeposits; i++ {
tx, err := depositContract.Deposit(txOps, serializedData.Bytes())
if err != nil {
log.Error("unable to send transaction to contract")
}
log.WithFields(logrus.Fields{
"Transaction Hash": fmt.Sprintf("%#x", tx.Hash()),
}).Infof("Deposit %d sent to contract address %v for validator with a public key %#x", i, depositContractAddr, validatorKey.PublicKey.Marshal())
// If flag is enabled make transaction times variable
if variableTx {
time.Sleep(time.Duration(math.Abs(statDist.Rand())) * time.Second)
continue
}
time.Sleep(time.Duration(depositDelay) * time.Second)
}
log.WithFields(logrus.Fields{
"Transaction Hash": fmt.Sprintf("%#x", tx.Hash()),
}).Infof("Deposit %d sent to contract for validator with a public key %#x", i, validatorKey.PublicKey.Marshal())
// If flag is enabled make transaction times variable
if variableTx {
time.Sleep(time.Duration(math.Abs(statDist.Rand())) * time.Second)
continue
}
time.Sleep(time.Duration(depositDelay) * time.Second)
}
}
err := app.Run(os.Args)
@@ -243,7 +244,6 @@ func main() {
}
func buildStatisticalDist(depositDelay int64, numberOfDeposits int64, txDeviation int64) *distuv.StudentsT {
src := rand2.NewSource(uint64(time.Now().Unix()))
dist := &distuv.StudentsT{
Mu: float64(depositDelay),

View File

@@ -2,7 +2,26 @@
PRIVATE_KEY_PATH=~/priv
CMD="bazel run //contracts/deposit-contract/deployContract -- --httpPath=https://goerli.prylabs.net"
CMD+=" --privKey=$(cat $PRIVATE_KEY_PATH) --chainStart=8 --minDeposit=100000 --maxDeposit=3200000 --customChainstartDelay 120"
while test $# -gt 0; do
case "$1" in
--privkey-path)
shift
PRIVATE_KEY_PATH=$1
shift
;;
*)
echo "$1 is not a recognized flag!"
exit 1;
;;
esac
done
CMD="bazel run //contracts/deposit-contract/deployContract --"
HTTPFLAG="--httpPath=https://goerli.prylabs.net"
PRIVFLAG="--privKey=$(cat $PRIVATE_KEY_PATH)"
CONFIGFLAGS="--chainStart=8 --minDeposit=100000 --maxDeposit=3200000 --customChainstartDelay 120"
CMD="$CMD $HTTPFLAG $PRIVFLAG $CONFIGFLAGS"
$CMD

View File

@@ -1,25 +0,0 @@
#!/bin/sh
DATA_PATH=/tmp/data
PASSWORD_PATH=$DATA_PATH/password.txt
PASSWORD="password"
echo $PASSWORD > $PASSWORD_PATH
bazel build //validator
for i in `seq 1 8`;
do
KEYSTORE=$DATA_PATH/keystore$i
UNAME=$(echo `uname` | tr '[A-Z]' '[a-z]')
CMD="bazel-bin/validator/"
CMD+=$UNAME
CMD+="_amd64_pure_stripped/validator --demo-config --password $PASSWORD_PATH --keystore-path $KEYSTORE"
nohup $CMD $> /tmp/validator$i.log &
done
echo "8 validators are running in the background. You can follow their logs at /tmp/validator#.log where # is replaced by the validator index of 1 through 8."
echo "To stop the processes, use 'pkill validator'"

View File

@@ -1,13 +1,12 @@
#!/bin/sh
#!/bin/bash
PRIVATE_KEY_PATH=PUTPRIVKEYPATHHERE
PRIVATE_KEY_PATH=~/priv
echo "clearing data"
DATA_PATH=/tmp/data
rm -rf $DATA_PATH
mkdir -p $DATA_PATH
CONTRACT=PUTDEPOSITCONTRACTHERE
PASSWORD="password"
PASSWORD_PATH=$DATA_PATH/password.txt
@@ -16,58 +15,86 @@ UNAME=$(echo `uname` | tr '[A-Z]' '[a-z]')
echo $PASSWORD > $PASSWORD_PATH
bazel build //validator
bazel build //contracts/deposit-contract/sendDepositTx:sendDepositTx
bazel build //contracts/deposit-contract/sendDepositTx
for i in `seq 1 8`;
START_INDEX=1
END_INDEX=8
while test $# -gt 0; do
case "$1" in
--deposit-contract)
shift
DEPOSIT_CONTRACT=$1
shift
;;
--end-index)
shift
END_INDEX=$1
shift
;;
--start-index)
shift
START_INDEX=$1
shift
;;
--privkey-path)
shift
PRIVATE_KEY_PATH=$1
shift
;;
*)
echo "$1 is not a recognized flag!"
exit 1;
;;
esac
done
for i in `seq $START_INDEX $END_INDEX`;
do
echo "Generating validator $i"
KEYSTORE=$DATA_PATH/keystore$i
ACCOUNTCMD="bazel-bin/validator/$UNAME"
ACCOUNTCMD+="_amd64_pure_stripped/validator accounts create --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
ACCOUNTCMD="bazel-bin/validator/${UNAME}_amd64_pure_stripped/validator accounts create --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
echo $ACCOUNTCMD
$ACCOUNTCMD
done
for i in `seq 1 8`;
for i in `seq $START_INDEX $END_INDEX`;
do
KEYSTORE=$DATA_PATH/keystore$i
CMD="bazel-bin/validator/"
CMD+=$UNAME
CMD+="_amd64_pure_stripped/validator --demo-config --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
CMD="bazel-bin/validator/${UNAME}_amd64_pure_stripped/validator --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
echo $CMD
nohup $CMD $> /tmp/validator$i.log &
done
echo "Started 8 validators"
echo "Started $END_INDEX validators"
for i in `seq 1 8`;
for i in `seq $START_INDEX $END_INDEX`;
do
echo "Sending TX for validator $i"
KEYSTORE=$DATA_PATH/keystore$i
DEPOSITCMD="bazel-bin/contracts/deposit-contract/sendDepositTx/$UNAME"
DEPOSITCMD+="_amd64_stripped/sendDepositTx"
DEPOSITCMD+=" --httpPath=https://goerli.prylabs.net"
DEPOSITCMD+=" --passwordFile=$PASSWORD_PATH"
DEPOSITCMD+=" --depositContract=$CONTRACT"
DEPOSITCMD+=" --numberOfDeposits=1"
DEPOSITCMD+=" --privKey=$(cat $PRIVATE_KEY_PATH)"
DEPOSITCMD+=" --prysm-keystore=$KEYSTORE"
DEPOSITCMD+=" --depositAmount=3200000"
HTTPFLAG="--httpPath=https://goerli.prylabs.net"
PASSFLAG="--passwordFile=$PASSWORD_PATH"
CONTRACTFLAG="--depositContract=$DEPOSIT_CONTRACT"
PRIVFLAG="--privKey=$(cat $PRIVATE_KEY_PATH)"
KEYFLAG="--prysm-keystore=$KEYSTORE"
AMOUNTFLAG="--depositAmount=3200000"
CMD="bazel-bin/contracts/deposit-contract/sendDepositTx/${UNAME}_amd64_stripped/sendDepositTx"
DEPOSITCMD="$CMD $HTTPFLAG $PASSFLAG $CONTRACTFLAG $PRIVFLAG $KEYFLAG $AMOUNTFLAG"
$DEPOSITCMD
echo $DEPOSITCMD
done
echo "8 validators are running in the background. You can follow their logs at /tmp/validator#.log where # is replaced by the validator index of 1 through 8."
echo "$END_INDEX validators are running in the background. You can follow their logs at /tmp/validator#.log where # is replaced by the validator index of $START_INDEX through $END_INDEX."
echo "To stop the processes, use 'pkill validator'"

View File

@@ -1,12 +1,16 @@
#!/bin/sh
#!/bin/bash
while test $# -gt 0; do
case "$1" in
--deposit-contract)
shift
DEPOSIT_CONTRACT=$1
shift
;;
*)
echo "$1 is not a recognized flag!"
exit 1;
;;
esac
done
DEPOSIT_CONTRACT=DEPOSITCONTRACTHERE
DATA_DIR=/tmp/beacon
rm -rf $DATA_DIR
mkdir -p $DATA_DIR
CMD="bazel run //beacon-chain -- --web3provider wss://goerli.prylabs.net/websocket"
CMD+=" --datadir $DATA_DIR --deposit-contract $DEPOSIT_CONTRACT --demo-config"
$CMD
bazel run //beacon-chain -- --clear-db --deposit-contract $DEPOSIT_CONTRACT --web3provider=wss://goerli.infura.io/ws/v3/be3fb7ed377c418087602876a40affa1

View File

@@ -21,16 +21,14 @@ func VerifyAccountNotExists(directory string, password string) error {
if directory == "" || password == "" {
return errors.New("expected a path to the validator keystore and password to be provided, received nil")
}
shardWithdrawalKeyFile := directory + params.BeaconConfig().WithdrawalPrivkeyFileName
validatorKeyFile := directory + params.BeaconConfig().ValidatorPrivkeyFileName
// First, if the keystore already exists, throws an error as there can only be
// one keystore per validator client.
ks := keystore.NewKeystore(directory)
if _, err := ks.GetKey(shardWithdrawalKeyFile, password); err == nil {
return fmt.Errorf("keystore at path already exists: %s", shardWithdrawalKeyFile)
if _, err := ks.GetKeys(directory, params.BeaconConfig().WithdrawalPrivkeyFileName, password); err == nil {
return fmt.Errorf("keystore at path already exists: %s", directory)
}
if _, err := ks.GetKey(validatorKeyFile, password); err == nil {
return fmt.Errorf("keystore at path already exists: %s", validatorKeyFile)
if _, err := ks.GetKeys(directory, params.BeaconConfig().ValidatorPrivkeyFileName, password); err == nil {
return fmt.Errorf("keystore at path already exists: %s", directory)
}
return nil
}