Remove Deprecated Tooling (#7912)

* remove old tools

* tidy and gaz

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Raul Jordan 2020-11-22 13:07:02 -06:00 committed by GitHub
parent 7d0031ee77
commit 2a546cc50b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 0 additions and 791 deletions

3
go.mod
View File

@ -47,7 +47,6 @@ require (
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20200424224625-be1b05b0b279
github.com/influxdata/influxdb v1.8.0 // indirect
github.com/ipfs/go-ipfs-addr v0.0.1
github.com/ipfs/go-log v1.0.4
github.com/ipfs/go-log/v2 v2.1.1
github.com/joonix/log v0.0.0-20200409080653-9c1d2ceb5f1d
github.com/json-iterator/go v1.1.10
@ -58,9 +57,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-libp2p v0.10.2
github.com/libp2p/go-libp2p-blankhost v0.2.0
github.com/libp2p/go-libp2p-circuit v0.3.1
github.com/libp2p/go-libp2p-core v0.6.1
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/libp2p/go-libp2p-noise v0.1.1
github.com/libp2p/go-libp2p-pubsub v0.3.6
github.com/libp2p/go-libp2p-secio v0.2.2

View File

@ -1,42 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/prysm/tools/contract-addr",
visibility = ["//visibility:private"],
deps = ["//shared/maxprocs:go_default_library"],
)
go_binary(
name = "contract-addr",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_image(
name = "image",
base = "//tools:go_image",
binary = ":contract-addr",
tags = ["manual"],
visibility = ["//visibility:private"],
)
container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/contract-addr:latest": ":image",
"gcr.io/prysmaticlabs/prysm/contract-addr:{DOCKER_TAG}": ":image",
},
tags = ["manual"],
)
docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
)

View File

@ -1,44 +0,0 @@
/**
* This tool exists to serve currently configured contract address in k8s.
* It reads the contract address from a plain text file as provided by etcd.
*/
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
)
var address = flag.String("address-path", "", "The file path to the plain text file with the contract address")
func main() {
flag.Parse()
if *address == "" {
panic("Contract address filepath not set")
}
fmt.Println("Starting on port 8080")
log.Fatal(http.ListenAndServe(":8080", &handler{}))
}
type handler struct{}
func (h *handler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
dat, err := ioutil.ReadFile(*address)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
_, err = io.WriteString(w, string(dat))
if err != nil {
fmt.Printf("Failed to write response: %v", err)
}
}

View File

@ -1,50 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
go_library(
name = "go_default_library",
srcs = ["relaynode.go"],
importpath = "github.com/prysmaticlabs/prysm/tools/relaynode",
visibility = ["//visibility:private"],
deps = [
"//shared/maxprocs:go_default_library",
"//shared/version:go_default_library",
"@com_github_ipfs_go_log//:go_default_library",
"@com_github_libp2p_go_libp2p//:go_default_library",
"@com_github_libp2p_go_libp2p_circuit//:go_default_library",
"@com_github_libp2p_go_libp2p_crypto//:go_default_library",
"@com_github_multiformats_go_multiaddr//:go_default_library",
],
)
go_image(
name = "image",
base = "//tools:go_image",
binary = ":relaynode",
tags = ["manual"],
visibility = ["//visibility:private"],
)
go_binary(
name = "relaynode",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/relaynode:latest": ":image",
"gcr.io/prysmaticlabs/prysm/relaynode:{DOCKER_TAG}": ":image",
},
tags = ["manual"],
)
docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
)

View File

@ -1,84 +0,0 @@
/**
* Relay node
*
* A simple libp2p relay node peers to connect inbound traffic behind a NAT or
* other network restriction.
*
* Usage: Run relaynode --help for flag options.
*/
package main
import (
"context"
"flag"
"fmt"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
circuit "github.com/libp2p/go-libp2p-circuit"
crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/multiformats/go-multiaddr"
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
"github.com/prysmaticlabs/prysm/shared/version"
)
var (
privateKey = flag.String("private", "", "Private key to use for peer ID")
port = flag.Int("port", 4000, "Port to listen for connections")
debug = flag.Bool("debug", false, "Enable debug logging")
log = logging.Logger("prysm-relaynode")
)
func main() {
flag.Parse()
fmt.Printf("Starting relay node. Version: %s\n", version.GetVersion())
if *debug {
logging.SetDebugLogging()
}
ctx := context.Background()
log.Start(ctx, "main")
cleanup := func() { log.Finish(ctx) }
defer cleanup()
srcMAddr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", *port))
if err != nil {
// log.Fatalf will prevent defer from being called
cleanup()
log.Fatalf("Unable to construct multiaddr %v", err)
}
opts := []libp2p.Option{
libp2p.EnableRelay(circuit.OptHop),
libp2p.ListenAddrs(srcMAddr),
}
if *privateKey != "" {
b, err := crypto.ConfigDecodeKey(*privateKey)
if err != nil {
log.Fatalf("Failed to decode private key %v", err)
}
pk, err := crypto.UnmarshalPrivateKey(b)
if err != nil {
log.Fatalf("Failed to unmarshal private key %v", err)
}
opts = append(opts, libp2p.Identity(pk))
} else {
log.Warning("No private key provided. Using random key.")
}
h, err := libp2p.New(
ctx,
opts...,
)
if err != nil {
log.Fatalf("Failed to create host %v", err)
}
fmt.Printf("Relay available: /ip4/0.0.0.0/tcp/%v/p2p/%s\n", *port, h.ID().Pretty())
select {}
}

View File

@ -1,51 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test")
go_library(
name = "go_default_library",
srcs = ["sendDeposits.go"],
importpath = "github.com/prysmaticlabs/prysm/tools/sendDepositTx",
visibility = ["//visibility:private"],
deps = [
"//contracts/deposit-contract:go_default_library",
"//shared/depositutil:go_default_library",
"//shared/keystore:go_default_library",
"//shared/params:go_default_library",
"//shared/version:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/keystore:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
],
)
go_binary(
name = "sendDepositTx",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["sendDeposits_test.go"],
embed = [":go_default_library"],
deps = [
"//contracts/deposit-contract:go_default_library",
"//shared/interop:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"//shared/testutil/assert:go_default_library",
"//shared/testutil/require:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ethereum_go_ethereum//:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

View File

@ -1,44 +0,0 @@
## Utility to Deploy Deposit Contract
This is a utility to help users deploy deposit contract for running their own beacon chain node in a local containerized set up. The utility will deploy the validator registration contract and print out the contract address. Users will pass the contract address to the beacon chain node to monitor when they have been conducted to become an active validator.
### Usage
*Name:*
**sendDepositTx** - this is a util to send deposit transactions
*Usage:*
sendDepositTx [global options] command [command options] [arguments...]
*Flags:*
- --keystoreUTCPath value Location of keystore
- --ipcPath value Filename for IPC socket/pipe within the datadir
- --httpPath value HTTP-RPC server listening interface (default: "http://localhost:8545/")
- --passwordFile value Password file for unlock account (default: "./password.txt")
- --privKey value Private key to unlock account
- --depositContract value Address of the deposit contract
- --numberOfDeposits value number of deposits to send to the contract (default: 8)
- --depositAmount value Maximum deposit value allowed in contract(in gwei) (default: 3200)
- --depositDelay value The time delay between sending the deposits to the contract(in seconds) (default: 5)
- --variableTx This enables variable transaction latencies to simulate real-world transactions
- --txDeviation value The standard deviation between transaction times (default: 2)
- --help, -h show help
- --version, -v print the version
### Example
To use private key with default RPC:
```
bazel run //tools/sendDepositTx -- --httpPath=https://goerli.prylabs.net --keystoreUTCPath /path/to/keystore --passwordFile /path/to/password --depositDelay 2 --depositContract 0x07b39f4fde4a38bace212b546dac87c58dfe3fdc
```
### Output
```
INFO main: Deposit 7 sent to contract for validator with a public key 0x333362343964316561623337336433313433356233626330393866653262613162333631333965326235613033303933643966396238356231363566653635646166383738396164356637343035313665353563666633346665343339653038656239306236313863303962326364653036646539333435643635366437333032643961623964336163323965636336663739613137656533663333323538656436383638623161393862363738383932636334306565336634333865373031
Transaction Hash=[213 23 244 203 91 45 79 72 109 141 43 113 67 92 178 94 24 209 39 240 111 59 238 18 189 145 140 166 49 236 157 71]
```

View File

@ -1,232 +0,0 @@
package main
import (
"bufio"
"encoding/hex"
"fmt"
"io/ioutil"
"math/big"
"os"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
"github.com/prysmaticlabs/prysm/shared/depositutil"
prysmKeyStore "github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
var (
log = logrus.WithField("prefix", "main")
)
func main() {
var keystoreUTCPath string
var prysmKeystorePath string
var ipcPath string
var passwordFile string
var httpPath string
var privKeyString string
var depositContractAddr string
var numberOfDeposits int64
var depositAmount int64
var depositDelay int64
var randomKey bool
customFormatter := new(prefixed.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
logrus.SetFormatter(customFormatter)
params.UsePyrmontConfig()
app := cli.App{}
app.Name = "sendDepositTx"
app.Usage = "this is a util to send deposit transactions"
app.Version = version.GetVersion()
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "keystoreUTCPath",
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",
Destination: &ipcPath,
},
&cli.StringFlag{
Name: "httpPath",
Value: "http://localhost:8545/",
Usage: "HTTP-RPC server listening interface",
Destination: &httpPath,
},
&cli.StringFlag{
Name: "passwordFile",
Value: "./password.txt",
Usage: "Password file for unlock account",
Destination: &passwordFile,
},
&cli.StringFlag{
Name: "privKey",
Usage: "Private key to send ETH transaction",
Destination: &privKeyString,
},
&cli.StringFlag{
Name: "depositContract",
Usage: "Address of the deposit contract",
Destination: &depositContractAddr,
},
&cli.Int64Flag{
Name: "numberOfDeposits",
Value: 1,
Usage: "number of deposits to send to the contract",
Destination: &numberOfDeposits,
},
&cli.Int64Flag{
Name: "depositAmount",
Value: int64(params.BeaconConfig().MaxEffectiveBalance),
Usage: "Maximum deposit value allowed in contract(in gwei)",
Destination: &depositAmount,
},
&cli.Int64Flag{
Name: "depositDelay",
Value: 5,
Usage: "The time delay between sending the deposits to the contract(in seconds)",
Destination: &depositDelay,
},
&cli.BoolFlag{
Name: "random-key",
Usage: "Use a randomly generated keystore key",
Destination: &randomKey,
},
}
app.Action = func(c *cli.Context) error {
// Set up RPC client
var rpcClient *rpc.Client
var err error
var txOps *bind.TransactOpts
// Uses HTTP-RPC if IPC is not set
if ipcPath == "" {
rpcClient, err = rpc.Dial(httpPath)
} else {
rpcClient, err = rpc.Dial(ipcPath)
}
if err != nil {
return err
}
client := ethclient.NewClient(rpcClient)
depositAmountInGwei := uint64(depositAmount)
if privKeyString != "" {
// User inputs private key, sign tx with private key
privKey, err := crypto.HexToECDSA(privKeyString)
if err != nil {
return err
}
txOps = bind.NewKeyedTransactor(privKey)
txOps.Value = new(big.Int).Mul(big.NewInt(depositAmount), big.NewInt(1e9))
} else {
// User inputs keystore json file, sign tx with keystore json
password := loadTextFromFile(passwordFile)
// #nosec - Inclusion of file via variable is OK for this tool.
keyJSON, err := ioutil.ReadFile(keystoreUTCPath)
if err != nil {
return err
}
privKey, err := keystore.DecryptKey(keyJSON, password)
if err != nil {
return err
}
txOps = bind.NewKeyedTransactor(privKey.PrivateKey)
txOps.Value = new(big.Int).Mul(big.NewInt(depositAmount), big.NewInt(1e9))
txOps.GasLimit = 500000
}
depositContract, err := contracts.NewDepositContract(common.HexToAddress(depositContractAddr), client)
if err != nil {
return err
}
validatorKeys := make(map[string]*prysmKeyStore.Key)
if randomKey {
validatorKey, err := prysmKeyStore.NewKey()
if err != nil {
return errors.Wrap(err, "Could not generate random key")
}
validatorKeys[hex.EncodeToString(validatorKey.PublicKey.Marshal())] = validatorKey
} else {
// Load from keystore
store := prysmKeyStore.New(prysmKeystorePath)
rawPassword := loadTextFromFile(passwordFile)
prefix := params.BeaconConfig().ValidatorPrivkeyFileName
validatorKeys, err = store.GetKeys(prysmKeystorePath, prefix, rawPassword, false /* warnOnFail */)
if err != nil {
log.WithField("path", prysmKeystorePath).Errorf("Could not get keys: %v", err)
}
}
keyCounter := int64(0)
for _, validatorKey := range validatorKeys {
data, depositRoot, err := depositutil.DepositInput(validatorKey.SecretKey, validatorKey.SecretKey, depositAmountInGwei)
if err != nil {
log.Errorf("Could not generate deposit input data: %v", err)
continue
}
for j := int64(0); j < numberOfDeposits; j++ {
tx, err := depositContract.Deposit(txOps, data.PublicKey, data.WithdrawalCredentials, data.Signature, depositRoot)
if err != nil {
log.Errorf("unable to send transaction to contract: %v", err)
continue
}
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", (keyCounter*numberOfDeposits)+j, depositContractAddr, validatorKey.PublicKey.Marshal())
time.Sleep(time.Duration(depositDelay) * time.Second)
}
keyCounter++
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
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,133 +0,0 @@
package main
import (
"context"
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
"github.com/prysmaticlabs/prysm/shared/interop"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/shared/trieutil"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
}
func sendDeposits(t *testing.T, testAcc *contracts.TestAccount,
numberOfDeposits, numberOfValidators uint64) []*ethpb.Deposit {
deposits := make([]*ethpb.Deposit, 0, numberOfValidators)
depositDelay := int64(1)
depositContractAddrStr := testAcc.ContractAddr.Hex()
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0, numberOfValidators)
require.NoError(t, err, "Unable to generate keys")
depositData, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
require.NoError(t, err, "Unable to generate deposit data from keys")
for i, data := range depositData {
dataRoot := [32]byte{}
copy(dataRoot[:], depositDataRoots[i])
pubKey := pubKeys[i]
deposits = append(deposits, &ethpb.Deposit{
Data: data,
})
for j := uint64(0); j < numberOfDeposits; j++ {
tx, err := testAcc.Contract.Deposit(testAcc.TxOpts, data.PublicKey, data.WithdrawalCredentials, data.Signature, dataRoot)
require.NoError(t, err, "Unable to send transaction to contract")
testAcc.Backend.Commit()
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", j, depositContractAddrStr, pubKey.Marshal())
time.Sleep(time.Duration(depositDelay) * time.Second)
}
}
return deposits
}
func TestEndtoEndDeposits(t *testing.T) {
testutil.ResetCache()
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
testAcc.Backend.Commit()
testAcc.TxOpts.Value = contracts.Amount32Eth()
testAcc.TxOpts.GasLimit = 1000000
numberOfValidators := uint64(2)
numberOfDeposits := uint64(5)
deposits := sendDeposits(t, testAcc, numberOfDeposits, numberOfValidators)
query := ethereum.FilterQuery{
Addresses: []common.Address{
testAcc.ContractAddr,
},
}
logs, err := testAcc.Backend.FilterLogs(context.Background(), query)
require.NoError(t, err, "Unable to retrieve logs")
require.NotEqual(t, 0, len(logs), "No logs")
require.Equal(t, int(numberOfDeposits*numberOfValidators), len(logs), "No sufficient number of logs")
j := 0
for i, log := range logs {
loggedPubkey, withCreds, _, loggedSig, index, err := contracts.UnpackDepositLogData(log.Data)
require.NoError(t, err, "Unable to unpack logs")
assert.Equal(t, uint64(i), binary.LittleEndian.Uint64(index))
assert.DeepEqual(t, deposits[j].Data.PublicKey, loggedPubkey, "Pubkey is not the same as the data that was put in %v, i: %d", loggedPubkey, i)
assert.DeepEqual(t, deposits[j].Data.Signature, loggedSig, "Proof of Possession is not the same as the data that was put in %v, i: %d", loggedSig, i)
assert.DeepEqual(t, deposits[j].Data.WithdrawalCredentials, withCreds, "Withdrawal Credentials is not the same as the data that was put in %v, i: %d", withCreds, i)
if i == int(numberOfDeposits)-1 {
j++
}
}
encodedDeposits := make([][]byte, numberOfValidators*numberOfDeposits)
for i := 0; i < int(numberOfValidators); i++ {
hashedDeposit, err := deposits[i].Data.HashTreeRoot()
require.NoError(t, err, "Could not tree hash deposit data")
for j := 0; j < int(numberOfDeposits); j++ {
encodedDeposits[i*int(numberOfDeposits)+j] = hashedDeposit[:]
}
}
depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err, "Could not generate trie")
root := depositTrie.Root()
for i, encodedDeposit := range encodedDeposits {
proof, err := depositTrie.MerkleProof(i)
require.NoError(t, err, "Could not generate proof")
require.Equal(t, true, trieutil.VerifyMerkleBranch(root[:], encodedDeposit, i, proof, params.BeaconConfig().DepositContractTreeDepth),
"Unable verify deposit merkle branch of deposit root for root: %#x, encodedDeposit: %#x, i : %d", root[:], encodedDeposit, i)
}
}

View File

@ -1,21 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/prysm/tools/update-genesis-time",
visibility = ["//visibility:public"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/fileutil:go_default_library",
"//shared/timeutils:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)
go_binary(
name = "update-genesis-time",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

View File

@ -1,35 +0,0 @@
## Utility to Update Beacon State Genesis Time
This is a utility to help users update genesis time of an input beacon state
### Usage
_Name:_
**update-genesis-time** - this is a utility to update genesis time of a beacon state
_Usage:_
update-genesis-time [global options]
_Flags:_
- --input-ssz-state: Input filename of the SSZ marshaling of the genesis state
- --genesis-time: Unix timestamp used as the genesis time in the generated genesis state (defaults to now)
### Example
To use private key with default RPC:
```
bazel run //tools/update-genesis-time -- --input-ssz-state=/tmp/genesis.ssz
```
### Output
```
INFO: Elapsed time: 5.887s, Critical Path: 4.99s
INFO: 41 processes: 41 darwin-sandbox.
INFO: Build completed successfully, 44 total actions
INFO: Build completed successfully, 44 total actions
2020/04/28 11:55:21 No --genesis-time specified, defaulting to now
2020/04/28 11:55:21 Done writing to /tmp/genesis.ssz
```

View File

@ -1,52 +0,0 @@
package main
import (
"flag"
"io/ioutil"
"log"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/fileutil"
"github.com/prysmaticlabs/prysm/shared/timeutils"
)
var (
genesisTime = flag.Uint64("genesis-time", 0, "Unix timestamp used as the genesis time in the generated genesis state (defaults to now)")
inputSSZState = flag.String("input-ssz-state", "", "Input filename of the SSZ marshaling of the genesis state")
)
func main() {
flag.Parse()
if *inputSSZState == "" {
log.Fatal("Expected --input-ssz-state")
}
beaconState := &pb.BeaconState{}
if err := unmarshalFile(*inputSSZState, beaconState); err != nil {
log.Fatal(err)
}
if *genesisTime == 0 {
log.Print("No --genesis-time specified, defaulting to now")
beaconState.GenesisTime = uint64(timeutils.Now().Unix())
} else {
beaconState.GenesisTime = *genesisTime
}
encodedState, err := beaconState.MarshalSSZ()
if err != nil {
log.Fatalf("Could not ssz marshal the beacon state: %v", err)
}
if err := fileutil.WriteFile(*inputSSZState, encodedState); err != nil {
log.Fatalf("Could not write encoded beacon state to file: %v", err)
}
log.Printf("Done writing to %s", *inputSSZState)
}
func unmarshalFile(fPath string, data interface{}) error {
rawFile, err := ioutil.ReadFile(fPath)
if err != nil {
return err
}
return ssz.Unmarshal(rawFile, data)
}