Create bash scripts for initializing beacon chain and 8 validators (#1996)

* Create scripts for k8s and standard runs

* Add comment

* Create scripts to deploy contract, start beacon chain and validators

* Add placeholders

* Add more docs and remove uneeded tag
This commit is contained in:
Ivan Martinez
2019-03-15 10:42:57 -04:00
committed by Preston Van Loon
parent 04f4a7f156
commit c2d4f5b2b8
8 changed files with 200 additions and 20 deletions

View File

@@ -7,8 +7,8 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//contracts/deposit-contract:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/keystore:go_default_library",
"//shared/params:go_default_library",
"//shared/ssz:go_default_library",
"//shared/version:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
"math"
"math/big"
@@ -17,8 +18,8 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
prysmKeyStore "github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/sirupsen/logrus"
@@ -28,8 +29,13 @@ import (
"gonum.org/v1/gonum/stat/distuv"
)
var (
log = logrus.WithField("prefix", "main")
)
func main() {
var keystoreUTCPath string
var prysmKeystorePath string
var ipcPath string
var passwordFile string
var httpPath string
@@ -40,12 +46,12 @@ func main() {
var depositDelay int64
var variableTx bool
var txDeviation int64
var randomKey bool
customFormatter := new(prefixed.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
log := logrus.WithField("prefix", "main")
app := cli.NewApp()
app.Name = "sendDepositTx"
@@ -57,6 +63,11 @@ func main() {
Usage: "Location of keystore",
Destination: &keystoreUTCPath,
},
cli.StringFlag{
Name: "prysm-keystore",
Usage: "The path to the existing prysm keystore. This flag is ignored if used with --random-key",
Destination: &prysmKeystorePath,
},
cli.StringFlag{
Name: "ipcPath",
Usage: "Filename for IPC socket/pipe within the datadir",
@@ -76,7 +87,7 @@ func main() {
},
cli.StringFlag{
Name: "privKey",
Usage: "Private key to unlock account",
Usage: "Private key to send ETH transaction",
Destination: &privKeyString,
},
cli.StringFlag{
@@ -113,6 +124,11 @@ func main() {
Value: 2,
Destination: &txDeviation,
},
cli.BoolFlag{
Name: "random-key",
Usage: "Use a randomly generated keystore key",
Destination: &randomKey,
},
}
app.Action = func(c *cli.Context) {
@@ -145,16 +161,7 @@ func main() {
txOps.GasLimit = 4000000
// User inputs keystore json file, sign tx with keystore json
} else {
// #nosec - Inclusion of file via variable is OK for this tool.
file, err := os.Open(passwordFile)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanWords)
scanner.Scan()
password := scanner.Text()
password := loadTextFromFile(passwordFile)
// #nosec - Inclusion of file via variable is OK for this tool.
keyJSON, err := ioutil.ReadFile(keystoreUTCPath)
@@ -180,12 +187,28 @@ func main() {
for i := int64(0); i < numberOfDeposits; i++ {
validatorKey, err := prysmKeyStore.NewKey(rand.Reader)
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
}
}
data := &pb.DepositInput{
Pubkey: validatorKey.PublicKey.Marshal(),
ProofOfPossession: []byte("pop"),
WithdrawalCredentialsHash32: []byte("withdraw"),
data, err := prysmKeyStore.DepositInput(validatorKey, validatorKey)
if err != nil {
log.Errorf("Could not generate deposit input data: %v", err)
continue
}
serializedData := new(bytes.Buffer)
@@ -199,7 +222,7 @@ func main() {
}
log.WithFields(logrus.Fields{
"Transaction Hash": tx.Hash(),
"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
@@ -231,3 +254,16 @@ func buildStatisticalDist(depositDelay int64, numberOfDeposits int64, txDeviatio
return dist
}
func loadTextFromFile(filepath string) string {
// #nosec - Inclusion of file via variable is OK for this tool.
file, err := os.Open(filepath)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanWords)
scanner.Scan()
return scanner.Text()
}

View File

@@ -1,3 +1,17 @@
# Bash Scripts
This subproject contains useful bash scripts for working with our repository. We have a simple tool that outputs coverage, a simple tool to check for gazelle requirements, and visibility rules tools for Bazel packages.
### Instructions to run a single beacon chain node and 8 validators locally using the scripts.
1. Ensure your private key path is correct in all the files below.
2. Run `./deploy-deposit-contract.sh`
3. Put the resulting contract address in `start-beacon-chain.sh` and `setup-8-validators.sh`.
4. Run `./start-beacon-chain.sh`
5. Run `./setup-8-validators.sh`
6. You can use `tail -f /tmp/data/validator#.log` with # as a number from 1 - 8 to view the output of the validators.

12
scripts/apply-all-eth2-k8.sh Executable file
View File

@@ -0,0 +1,12 @@
#! /bin/bash
# Make sure you set your contract and private key path in the configs
kubectl apply -f k8s/priority.yaml
kubectl apply -f k8s/beacon-chain/namespace.yaml
kubectl apply -f k8s/beacon-chain/beacon-config.config.yaml
kubectl apply -f k8s/beacon-chain/beacon-chain.deploy.yaml
kubectl apply -f k8s/beacon-chain/beacon-chain.service.yaml
kubectl apply -f k8s/beacon-chain/cluster-manager.encrypted_secret.yaml
kubectl apply -f k8s/beacon-chain/cluster-manager.yaml
kubectl apply -f k8s/beacon-chain/validator.deploy.yaml

View File

@@ -0,0 +1,8 @@
#!/bin/sh
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"
$CMD

25
scripts/run-8-validators.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/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'"

73
scripts/setup-8-validators.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/sh
PRIVATE_KEY_PATH=PUTPRIVKEYPATHHERE
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
UNAME=$(echo `uname` | tr '[A-Z]' '[a-z]')
echo $PASSWORD > $PASSWORD_PATH
bazel build //validator
bazel build //contracts/deposit-contract/sendDepositTx:sendDepositTx
for i in `seq 1 8`;
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"
echo $ACCOUNTCMD
$ACCOUNTCMD
done
for i in `seq 1 8`;
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"
echo $CMD
nohup $CMD $> /tmp/validator$i.log &
done
echo "Started 8 validators"
for i in `seq 1 8`;
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"
$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 "To stop the processes, use 'pkill validator'"

12
scripts/start-beacon-chain.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
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