mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
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:
committed by
Raul Jordan
parent
a057c07830
commit
89531c1667
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
@@ -97,7 +98,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
cli.Int64Flag{
|
cli.Int64Flag{
|
||||||
Name: "numberOfDeposits",
|
Name: "numberOfDeposits",
|
||||||
Value: 8,
|
Value: 1,
|
||||||
Usage: "number of deposits to send to the contract",
|
Usage: "number of deposits to send to the contract",
|
||||||
Destination: &numberOfDeposits,
|
Destination: &numberOfDeposits,
|
||||||
},
|
},
|
||||||
@@ -185,26 +186,25 @@ func main() {
|
|||||||
|
|
||||||
statDist := buildStatisticalDist(depositDelay, numberOfDeposits, txDeviation)
|
statDist := buildStatisticalDist(depositDelay, numberOfDeposits, txDeviation)
|
||||||
|
|
||||||
for i := int64(0); i < numberOfDeposits; i++ {
|
validatorKeys := make(map[string]*prysmKeyStore.Key)
|
||||||
|
if randomKey {
|
||||||
var validatorKey *prysmKeyStore.Key
|
validatorKey, err := prysmKeyStore.NewKey(rand.Reader)
|
||||||
if randomKey {
|
validatorKeys[hex.EncodeToString(validatorKey.PublicKey.Marshal())] = validatorKey
|
||||||
validatorKey, err = prysmKeyStore.NewKey(rand.Reader)
|
if err != nil {
|
||||||
if err != nil {
|
log.Errorf("Could not generate random key: %v", err)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} 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)
|
data, err := prysmKeyStore.DepositInput(validatorKey, validatorKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Could not generate deposit input data: %v", err)
|
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)
|
log.Errorf("could not serialize deposit data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := depositContract.Deposit(txOps, serializedData.Bytes())
|
for i := int64(0); i < numberOfDeposits; i++ {
|
||||||
if err != nil {
|
tx, err := depositContract.Deposit(txOps, serializedData.Bytes())
|
||||||
log.Error("unable to send transaction to contract")
|
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)
|
err := app.Run(os.Args)
|
||||||
@@ -243,7 +244,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildStatisticalDist(depositDelay int64, numberOfDeposits int64, txDeviation int64) *distuv.StudentsT {
|
func buildStatisticalDist(depositDelay int64, numberOfDeposits int64, txDeviation int64) *distuv.StudentsT {
|
||||||
|
|
||||||
src := rand2.NewSource(uint64(time.Now().Unix()))
|
src := rand2.NewSource(uint64(time.Now().Unix()))
|
||||||
dist := &distuv.StudentsT{
|
dist := &distuv.StudentsT{
|
||||||
Mu: float64(depositDelay),
|
Mu: float64(depositDelay),
|
||||||
|
|||||||
@@ -2,7 +2,26 @@
|
|||||||
|
|
||||||
PRIVATE_KEY_PATH=~/priv
|
PRIVATE_KEY_PATH=~/priv
|
||||||
|
|
||||||
CMD="bazel run //contracts/deposit-contract/deployContract -- --httpPath=https://goerli.prylabs.net"
|
while test $# -gt 0; do
|
||||||
CMD+=" --privKey=$(cat $PRIVATE_KEY_PATH) --chainStart=8 --minDeposit=100000 --maxDeposit=3200000 --customChainstartDelay 120"
|
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
|
$CMD
|
||||||
@@ -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'"
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
PRIVATE_KEY_PATH=PUTPRIVKEYPATHHERE
|
PRIVATE_KEY_PATH=~/priv
|
||||||
|
|
||||||
echo "clearing data"
|
echo "clearing data"
|
||||||
DATA_PATH=/tmp/data
|
DATA_PATH=/tmp/data
|
||||||
rm -rf $DATA_PATH
|
rm -rf $DATA_PATH
|
||||||
mkdir -p $DATA_PATH
|
mkdir -p $DATA_PATH
|
||||||
|
|
||||||
CONTRACT=PUTDEPOSITCONTRACTHERE
|
|
||||||
PASSWORD="password"
|
PASSWORD="password"
|
||||||
PASSWORD_PATH=$DATA_PATH/password.txt
|
PASSWORD_PATH=$DATA_PATH/password.txt
|
||||||
|
|
||||||
@@ -16,58 +15,86 @@ UNAME=$(echo `uname` | tr '[A-Z]' '[a-z]')
|
|||||||
echo $PASSWORD > $PASSWORD_PATH
|
echo $PASSWORD > $PASSWORD_PATH
|
||||||
|
|
||||||
bazel build //validator
|
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
|
do
|
||||||
echo "Generating validator $i"
|
echo "Generating validator $i"
|
||||||
|
|
||||||
KEYSTORE=$DATA_PATH/keystore$i
|
KEYSTORE=$DATA_PATH/keystore$i
|
||||||
|
|
||||||
ACCOUNTCMD="bazel-bin/validator/$UNAME"
|
ACCOUNTCMD="bazel-bin/validator/${UNAME}_amd64_pure_stripped/validator accounts create --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
|
||||||
ACCOUNTCMD+="_amd64_pure_stripped/validator accounts create --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
|
|
||||||
|
|
||||||
echo $ACCOUNTCMD
|
echo $ACCOUNTCMD
|
||||||
|
|
||||||
$ACCOUNTCMD
|
$ACCOUNTCMD
|
||||||
done
|
done
|
||||||
|
|
||||||
for i in `seq 1 8`;
|
for i in `seq $START_INDEX $END_INDEX`;
|
||||||
do
|
do
|
||||||
KEYSTORE=$DATA_PATH/keystore$i
|
KEYSTORE=$DATA_PATH/keystore$i
|
||||||
|
|
||||||
CMD="bazel-bin/validator/"
|
CMD="bazel-bin/validator/${UNAME}_amd64_pure_stripped/validator --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
|
||||||
CMD+=$UNAME
|
|
||||||
CMD+="_amd64_pure_stripped/validator --demo-config --password $(cat $PASSWORD_PATH) --keystore-path $KEYSTORE"
|
|
||||||
|
|
||||||
echo $CMD
|
echo $CMD
|
||||||
|
|
||||||
nohup $CMD $> /tmp/validator$i.log &
|
nohup $CMD $> /tmp/validator$i.log &
|
||||||
done
|
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
|
do
|
||||||
echo "Sending TX for validator $i"
|
echo "Sending TX for validator $i"
|
||||||
|
|
||||||
KEYSTORE=$DATA_PATH/keystore$i
|
KEYSTORE=$DATA_PATH/keystore$i
|
||||||
|
|
||||||
DEPOSITCMD="bazel-bin/contracts/deposit-contract/sendDepositTx/$UNAME"
|
HTTPFLAG="--httpPath=https://goerli.prylabs.net"
|
||||||
DEPOSITCMD+="_amd64_stripped/sendDepositTx"
|
PASSFLAG="--passwordFile=$PASSWORD_PATH"
|
||||||
DEPOSITCMD+=" --httpPath=https://goerli.prylabs.net"
|
CONTRACTFLAG="--depositContract=$DEPOSIT_CONTRACT"
|
||||||
DEPOSITCMD+=" --passwordFile=$PASSWORD_PATH"
|
PRIVFLAG="--privKey=$(cat $PRIVATE_KEY_PATH)"
|
||||||
DEPOSITCMD+=" --depositContract=$CONTRACT"
|
KEYFLAG="--prysm-keystore=$KEYSTORE"
|
||||||
DEPOSITCMD+=" --numberOfDeposits=1"
|
AMOUNTFLAG="--depositAmount=3200000"
|
||||||
DEPOSITCMD+=" --privKey=$(cat $PRIVATE_KEY_PATH)"
|
|
||||||
DEPOSITCMD+=" --prysm-keystore=$KEYSTORE"
|
CMD="bazel-bin/contracts/deposit-contract/sendDepositTx/${UNAME}_amd64_stripped/sendDepositTx"
|
||||||
DEPOSITCMD+=" --depositAmount=3200000"
|
|
||||||
|
DEPOSITCMD="$CMD $HTTPFLAG $PASSFLAG $CONTRACTFLAG $PRIVFLAG $KEYFLAG $AMOUNTFLAG"
|
||||||
|
|
||||||
$DEPOSITCMD
|
$DEPOSITCMD
|
||||||
|
|
||||||
echo $DEPOSITCMD
|
|
||||||
done
|
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'"
|
echo "To stop the processes, use 'pkill validator'"
|
||||||
@@ -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
|
bazel run //beacon-chain -- --clear-db --deposit-contract $DEPOSIT_CONTRACT --web3provider=wss://goerli.infura.io/ws/v3/be3fb7ed377c418087602876a40affa1
|
||||||
|
|
||||||
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
|
|
||||||
@@ -21,16 +21,14 @@ func VerifyAccountNotExists(directory string, password string) error {
|
|||||||
if directory == "" || password == "" {
|
if directory == "" || password == "" {
|
||||||
return errors.New("expected a path to the validator keystore and password to be provided, received nil")
|
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
|
// First, if the keystore already exists, throws an error as there can only be
|
||||||
// one keystore per validator client.
|
// one keystore per validator client.
|
||||||
ks := keystore.NewKeystore(directory)
|
ks := keystore.NewKeystore(directory)
|
||||||
if _, err := ks.GetKey(shardWithdrawalKeyFile, password); err == nil {
|
if _, err := ks.GetKeys(directory, params.BeaconConfig().WithdrawalPrivkeyFileName, password); err == nil {
|
||||||
return fmt.Errorf("keystore at path already exists: %s", shardWithdrawalKeyFile)
|
return fmt.Errorf("keystore at path already exists: %s", directory)
|
||||||
}
|
}
|
||||||
if _, err := ks.GetKey(validatorKeyFile, password); err == nil {
|
if _, err := ks.GetKeys(directory, params.BeaconConfig().ValidatorPrivkeyFileName, password); err == nil {
|
||||||
return fmt.Errorf("keystore at path already exists: %s", validatorKeyFile)
|
return fmt.Errorf("keystore at path already exists: %s", directory)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user