Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unskip E2E for V0.11 #5386

Merged
merged 14 commits into from
Apr 12, 2020
1 change: 1 addition & 0 deletions endtoend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_test(
"//beacon-chain",
"//slasher",
"//validator",
"//tools/bootnode",
"@com_github_ethereum_go_ethereum//cmd/geth",
],
shard_count = 4,
Expand Down
83 changes: 54 additions & 29 deletions endtoend/components/beacon_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@ import (
)

// StartBeaconNodes starts the requested amount of beacon nodes, passing in the deposit contract given.
func StartBeaconNodes(t *testing.T, config *types.E2EConfig) ([]string, []int) {
var multiAddrs []string
func StartBeaconNodes(t *testing.T, config *types.E2EConfig, enr string) []int {
var processIDs []int
for i := 0; i < e2e.TestParams.BeaconNodeCount; i++ {
multiAddr, pID := StartNewBeaconNode(t, config, multiAddrs)
multiAddrs = append(multiAddrs, multiAddr)
pID := StartNewBeaconNode(t, config, i, enr)
processIDs = append(processIDs, pID)
}
return multiAddrs, processIDs
return processIDs
}

// StartNewBeaconNode starts a fresh beacon node, connecting to all passed in beacon nodes.
func StartNewBeaconNode(t *testing.T, config *types.E2EConfig, multiAddrs []string) (string, int) {
index := len(multiAddrs)
func StartNewBeaconNode(t *testing.T, config *types.E2EConfig, index int, enr string) int {
binaryPath, found := bazel.FindBinary("beacon-chain", "beacon-chain")
if !found {
t.Log(binaryPath)
Expand All @@ -49,59 +46,87 @@ func StartNewBeaconNode(t *testing.T, config *types.E2EConfig, multiAddrs []stri
fmt.Sprintf("--http-web3provider=http://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort),
fmt.Sprintf("--web3provider=ws://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort+1),
fmt.Sprintf("--min-sync-peers=%d", e2e.TestParams.BeaconNodeCount-1),
fmt.Sprintf("--p2p-udp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+10), //12200
fmt.Sprintf("--p2p-tcp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+20), //13200
fmt.Sprintf("--monitoring-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+30), //8280
fmt.Sprintf("--grpc-gateway-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+40), // 3400
fmt.Sprintf("--p2p-udp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+10),
fmt.Sprintf("--p2p-tcp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+20),
fmt.Sprintf("--monitoring-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+30),
fmt.Sprintf("--grpc-gateway-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+40),
fmt.Sprintf("--contract-deployment-block=%d", 0),
fmt.Sprintf("--rpc-max-page-size=%d", params.BeaconConfig().MinGenesisActiveValidatorCount),
"--force-clear-db",
"--no-discovery",
fmt.Sprintf("--bootstrap-node=%s", enr),
}
args = append(args, featureconfig.E2EBeaconChainFlags...)
args = append(args, config.BeaconFlags...)

// After the first node is made, have all following nodes connect to all previously made nodes.
if index >= 1 {
for p := 0; p < index; p++ {
args = append(args, fmt.Sprintf("--peer=%s", multiAddrs[p]))
}
}

cmd := exec.Command(binaryPath, args...)
t.Logf("Starting beacon chain %d with flags: %s", index, strings.Join(args[2:], " "))
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start beacon node: %v", err)
}

if err = helpers.WaitForTextInFile(stdOutFile, "Node started p2p server"); err != nil {
if err = helpers.WaitForTextInFile(stdOutFile, "RPC-API listening on port"); err != nil {
t.Fatalf("could not find multiaddr for node %d, this means the node had issues starting: %v", index, err)
}

multiAddr, err := getMultiAddrFromLogFile(stdOutFile.Name())
return cmd.Process.Pid
}

// StartBootnode starts a bootnode and returns its ENR and process ID.
func StartBootnode(t *testing.T) (string, int) {
binaryPath, found := bazel.FindBinary("tools/bootnode", "bootnode")
if !found {
t.Log(binaryPath)
t.Fatal("boot node binary not found")
}

stdOutFile, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, e2e.BootNodeLogFileName)
if err != nil {
t.Fatal(err)
}

args := []string{
fmt.Sprintf("--log-file=%s", stdOutFile.Name()),
fmt.Sprintf("--discv5-port=%d", e2e.TestParams.BootNodePort),
fmt.Sprintf("--kad-port=%d", e2e.TestParams.BootNodePort+10),
fmt.Sprintf("--metrics-port=%d", e2e.TestParams.BootNodePort+20),
}

cmd := exec.Command(binaryPath, args...)
cmd.Stdout = stdOutFile
cmd.Stderr = stdOutFile
t.Logf("Starting boot node with flags: %s", strings.Join(args[1:], " "))
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start beacon node: %v", err)
}

if err = helpers.WaitForTextInFile(stdOutFile, "Running bootnode"); err != nil {
t.Fatalf("could not find enr for bootnode, this means the bootnode had issues starting: %v", err)
}

enr, err := getENRFromLogFile(stdOutFile.Name())
if err != nil {
t.Fatalf("could not get multiaddr for node %d: %v", index, err)
t.Fatalf("could not get enr for bootnode: %v", err)
}

return multiAddr, cmd.Process.Pid
return enr, cmd.Process.Pid
}

func getMultiAddrFromLogFile(name string) (string, error) {
func getENRFromLogFile(name string) (string, error) {
byteContent, err := ioutil.ReadFile(name)
if err != nil {
return "", err
}
contents := string(byteContent)

searchText := "\"Node started p2p server\" multiAddr=\""
searchText := "Running bootnode: "
startIdx := strings.Index(contents, searchText)
if startIdx == -1 {
return "", fmt.Errorf("did not find peer text in %s", contents)
return "", fmt.Errorf("did not find ENR text in %s", contents)
}
startIdx += len(searchText)
endIdx := strings.Index(contents[startIdx:], "\"")
endIdx := strings.Index(contents[startIdx:], " prefix=bootnode")
if endIdx == -1 {
return "", fmt.Errorf("did not find peer text in %s", contents)
return "", fmt.Errorf("did not find ENR text in %s", contents)
}
return contents[startIdx : startIdx+endIdx], nil
return contents[startIdx : startIdx+endIdx-1], nil
}
2 changes: 1 addition & 1 deletion endtoend/components/eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func StartEth1Node(t *testing.T) (string, int) {
"--wsaddr=0.0.0.0",
"--wsorigins=\"*\"",
"--dev",
"--dev.period=0",
"--dev.period=2",
"--ipcdisable",
}
cmd := exec.Command(binaryPath, args...)
Expand Down
16 changes: 8 additions & 8 deletions endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
t.Logf("Log Path: %s\n\n", e2e.TestParams.LogPath)

keystorePath, eth1PID := components.StartEth1Node(t)
multiAddrs, bProcessIDs := components.StartBeaconNodes(t, config)
bootnodeENR, _ := components.StartBootnode(t)
bProcessIDs := components.StartBeaconNodes(t, config, bootnodeENR)
valProcessIDs := components.StartValidators(t, config, keystorePath)
processIDs := append(valProcessIDs, bProcessIDs...)
processIDs = append(processIDs, eth1PID)
defer helpers.LogOutput(t, config)
defer helpers.KillProcesses(t, processIDs)

if config.TestSlasher {
slasherPIDs := components.StartSlashers(t)
defer helpers.KillProcesses(t, slasherPIDs)
}

beaconLogFile, err := os.Open(path.Join(e2e.TestParams.LogPath, fmt.Sprintf(e2e.BeaconNodeLogFileName, 0)))
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -73,6 +69,11 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
epochSeconds := params.BeaconConfig().SecondsPerSlot * params.BeaconConfig().SlotsPerEpoch
genesisTime := time.Unix(genesis.GenesisTime.Seconds+int64(epochSeconds/2), 0)

if config.TestSlasher {
slasherPIDs := components.StartSlashers(t)
defer helpers.KillProcesses(t, slasherPIDs)
}

ticker := helpers.GetEpochTicker(genesisTime, epochSeconds)
for currentEpoch := range ticker.C() {
for _, evaluator := range config.Evaluators {
Expand Down Expand Up @@ -100,9 +101,8 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
return
}

multiAddr, processID := components.StartNewBeaconNode(t, config, multiAddrs)
multiAddrs = append(multiAddrs, multiAddr)
index := e2e.TestParams.BeaconNodeCount
processID := components.StartNewBeaconNode(t, config, index, bootnodeENR)
syncConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", e2e.TestParams.BeaconNodeRPCPort+index), grpc.WithInsecure())
if err != nil {
t.Fatalf("Failed to dial: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion endtoend/evaluators/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/endtoend/evaluators",
visibility = ["//endtoend:__subpackages__"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//endtoend/types:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/params:go_default_library",
Expand All @@ -21,7 +22,6 @@ go_library(
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
],
)
15 changes: 12 additions & 3 deletions endtoend/evaluators/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
ptypes "github.com/gogo/protobuf/types"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/endtoend/types"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"google.golang.org/grpc"
Expand Down Expand Up @@ -79,7 +80,15 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error {
blockRoot := bytesutil.ToBytes32([]byte("muahahahaha I'm an evil validator"))
attData.BeaconBlockRoot = blockRoot[:]

dataRoot, err := ssz.HashTreeRoot(attData)
req := &eth.DomainRequest{
Epoch: chainHead.HeadEpoch,
Domain: params.BeaconConfig().DomainBeaconAttester[:],
}
resp, err := valClient.DomainData(ctx, req)
if err != nil {
return err
}
signingRoot, err := helpers.ComputeSigningRoot(attData, resp.SignatureDomain)
if err != nil {
return err
}
Expand All @@ -97,7 +106,7 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error {
att := &eth.Attestation{
AggregationBits: attBitfield,
Data: attData,
Signature: privKeys[committee[i]].Sign(dataRoot[:]).Marshal(),
Signature: privKeys[committee[i]].Sign(signingRoot[:]).Marshal(),
}
for _, conn := range conns {
client := eth.NewBeaconNodeValidatorClient(conn)
Expand Down
1 change: 0 additions & 1 deletion endtoend/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ func LogErrorOutput(t *testing.T, file io.Reader, title string, index int) {
}
t.Log(err)
}
t.Logf("===================== End of %s %d error output ====================\n", title, index)
}
4 changes: 2 additions & 2 deletions endtoend/minimal_antiflake_e2e_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
)

func TestEndToEnd_AntiFlake_MinimalConfig_1(t *testing.T) {
t.Skip("Temp skip for #5127, need proper network implementations")
testutil.ResetCache()
params.UseMinimalConfig()

minimalConfig := &types.E2EConfig{
BeaconFlags: []string{"--minimal-config", "--custom-genesis-delay=10"},
ValidatorFlags: []string{"--minimal-config"},
EpochsToRun: 3,
EpochsToRun: 4,
TestSync: false,
TestSlasher: false,
Evaluators: []types.Evaluator{
ev.PeersConnect,
ev.ValidatorsAreActive,
ev.ValidatorsParticipating,
},
}
if err := e2eParams.Init(4); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions endtoend/minimal_antiflake_e2e_2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
)

func TestEndToEnd_AntiFlake_MinimalConfig_2(t *testing.T) {
t.Skip("Temp skip for #5127, need proper network implementations")
testutil.ResetCache()
params.UseMinimalConfig()

minimalConfig := &types.E2EConfig{
BeaconFlags: []string{"--minimal-config", "--custom-genesis-delay=10"},
ValidatorFlags: []string{"--minimal-config"},
EpochsToRun: 3,
EpochsToRun: 4,
TestSync: false,
TestSlasher: false,
Evaluators: []types.Evaluator{
ev.PeersConnect,
ev.ValidatorsAreActive,
ev.ValidatorsParticipating,
},
}
if err := e2eParams.Init(4); err != nil {
Expand Down
1 change: 0 additions & 1 deletion endtoend/minimal_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func TestEndToEnd_MinimalConfig(t *testing.T) {
t.Skip("To be resolved until 5119 gets in")
testutil.ResetCache()
params.UseMinimalConfig()

Expand Down
1 change: 0 additions & 1 deletion endtoend/minimal_slashing_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestEndToEnd_Slashing_MinimalConfig(t *testing.T) {
t.Skip("To be resolved until 5119 gets in")
testutil.ResetCache()
params.UseMinimalConfig()

Expand Down
11 changes: 9 additions & 2 deletions endtoend/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package params

import (
"errors"
"fmt"
"os"
"path"
"strconv"

"github.com/bazelbuild/rules_go/go/tools/bazel"
Expand All @@ -17,6 +19,7 @@ type Params struct {
BeaconNodeCount int
Eth1RPCPort int
ContractAddress common.Address
BootNodePort int
BeaconNodeRPCPort int
BeaconNodeMetricsPort int
ValidatorMetricsPort int
Expand All @@ -27,6 +30,9 @@ type Params struct {
// TestParams is the globally accessible var for getting config elements.
var TestParams *Params

// BootNodeLogFileName is the file name used for the beacon chain node logs.
var BootNodeLogFileName = "bootnode.log"

// BeaconNodeLogFileName is the file name used for the beacon chain node logs.
var BeaconNodeLogFileName = "beacon-%d.log"

Expand Down Expand Up @@ -54,12 +60,13 @@ func Init(beaconNodeCount int) error {
}

TestParams = &Params{
TestPath: testPath,
TestPath: path.Join(testPath, fmt.Sprintf("shard-%d", testIndex)),
LogPath: logPath,
TestShardIndex: testIndex,
BeaconNodeCount: beaconNodeCount,
Eth1RPCPort: 3100 + testIndex*100, // Multiplying 100 here so the test index doesn't conflict with the other node ports.
BeaconNodeRPCPort: 4100 + testIndex*100,
BootNodePort: 4100 + testIndex*100,
BeaconNodeRPCPort: 4150 + testIndex*100,
BeaconNodeMetricsPort: 5100 + testIndex*100,
ValidatorMetricsPort: 6100 + testIndex*100,
SlasherRPCPort: 7100 + testIndex*100,
Expand Down
4 changes: 4 additions & 0 deletions tools/bootnode/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ go_image(
tags = ["manual"],
visibility = ["//visibility:private"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params:go_default_library",
"//shared/logutil:go_default_library",
"//shared/version:go_default_library",
"@com_github_btcsuite_btcd//btcec:go_default_library",
Expand All @@ -63,6 +65,8 @@ go_image(
"@com_github_libp2p_go_libp2p_kad_dht//opts:go_default_library",
"@com_github_multiformats_go_multiaddr//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@org_uber_go_automaxprocs//:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion validator/client/validator_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot uint64, pu
SlotSignature: slotSig,
})
if err != nil {
log.Errorf("Could not submit slot signature to beacon node: %v", err)
log.WithField("slot", slot).Errorf("Could not submit slot signature to beacon node: %v", err)
if v.emitAccountMetrics {
validatorAggFailVec.WithLabelValues(fmtKey).Inc()
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/validator_propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot uint64, pubKey [48]by
Graffiti: v.graffiti,
})
if err != nil {
log.WithError(err).Error("Failed to request block from beacon node")
log.WithField("blockSlot", slot).WithError(err).Error("Failed to request block from beacon node")
if v.emitAccountMetrics {
validatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
Expand Down