Adding Basic Private Key Management (#671)

* adding flags

* adding modified key utils

* adding more funcs

* more changes

* more changes

* documentation

* changes to node

* gazelle

* fixing bazel build

* gazelle

* adding tests

* more tests

* addressing terence's feedback

* adding geth header

* test

* changes

* fixedd it

* fixed marshalling

* adding more to tests

* gazelle

* adding more tests

* lint

* add cov

* cov

* fix imports
This commit is contained in:
Nishant Das
2018-11-08 11:22:31 +08:00
committed by GitHub
parent 6476fb54af
commit 37bc1c67be
23 changed files with 833 additions and 36 deletions

View File

@@ -69,6 +69,8 @@ VERSION:
cmd.EnableTracingFlag,
cmd.TracingEndpointFlag,
cmd.TraceSampleFractionFlag,
cmd.KeystorePasswordFlag,
cmd.KeystoreDirectoryFlag,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,

View File

@@ -4,11 +4,7 @@ go_test(
name = "go_default_test",
srcs = ["node_test.go"],
embed = [":go_default_library"],
deps = [
"//shared/testutil:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
deps = ["@com_github_urfave_cli//:go_default_library"],
)
go_library(
@@ -25,6 +21,7 @@ go_library(
"//shared/cmd:go_default_library",
"//shared/database:go_default_library",
"//shared/debug:go_default_library",
"//shared/keystore:go_default_library",
"//shared/p2p:go_default_library",
"//shared/p2p/adapter/tracer:go_default_library",
"//validator/attester:go_default_library",

View File

@@ -15,6 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/database"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/validator/attester"
"github.com/prysmaticlabs/prysm/validator/beacon"
@@ -60,17 +61,15 @@ func NewValidatorClient(ctx *cli.Context) (*ValidatorClient, error) {
var pubKey []byte
inputKey := ctx.GlobalString(types.PubKeyFlag.Name)
if inputKey == "" {
var err error
pubKey, err = GeneratePubKey()
keystorePath := ctx.GlobalString(cmd.KeystoreDirectoryFlag.Name)
password := ctx.GlobalString(cmd.KeystorePasswordFlag.Name)
if keystorePath != "" && password != "" {
blspubkey, err := keystore.RetrievePubKey(keystorePath, password)
if err != nil {
return nil, err
}
log.Warnf("PublicKey not detected, generating a new one: %v", pubKey)
} else {
pubKey = []byte(inputKey)
pubKey = blspubkey.BufferedPublicKey()
}
if err := ValidatorClient.startDB(ctx); err != nil {

View File

@@ -4,24 +4,18 @@ import (
"flag"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"
"github.com/urfave/cli"
)
// Test that the sharding node can build with default flag values.
func TestNode_Builds(t *testing.T) {
hook := logTest.NewGlobal()
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
set.String("datadir", "/tmp/datadir", "the node data directory")
set.String("pukey", "f24f252", "set public key of validator")
context := cli.NewContext(app, set, nil)
_, err := NewValidatorClient(context)
if err != nil {
t.Fatalf("Failed to create ValidatorClient: %v", err)
}
testutil.AssertLogsContain(t, hook, "PublicKey not detected, generating a new one")
}

View File

@@ -2,12 +2,11 @@ package node
import (
"github.com/golang/protobuf/proto"
pb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/p2p/adapter/tracer"
"github.com/urfave/cli"
pb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1"
)
var topicMappings = map[pb.Topic]proto.Message{

View File

@@ -2,7 +2,6 @@ package types
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"