2020-03-22 23:04:23 +00:00
|
|
|
package components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
|
|
"github.com/prysmaticlabs/prysm/endtoend/helpers"
|
|
|
|
e2e "github.com/prysmaticlabs/prysm/endtoend/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StartSlashers starts slasher clients for use within E2E, connected to all beacon nodes.
|
|
|
|
// It returns the process IDs of the slashers.
|
|
|
|
func StartSlashers(t *testing.T) []int {
|
|
|
|
binaryPath, found := bazel.FindBinary("slasher", "slasher")
|
|
|
|
if !found {
|
|
|
|
t.Log(binaryPath)
|
|
|
|
t.Fatal("Slasher binary not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
var processIDs []int
|
|
|
|
for i := 0; i < e2e.TestParams.BeaconNodeCount; i++ {
|
|
|
|
stdOutFile, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, fmt.Sprintf(e2e.SlasherLogFileName, i))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
fmt.Sprintf("--log-file=%s", stdOutFile.Name()),
|
2020-03-30 16:10:00 +00:00
|
|
|
fmt.Sprintf("--rpc-port=%d", e2e.TestParams.SlasherRPCPort+i),
|
2020-03-22 23:04:23 +00:00
|
|
|
fmt.Sprintf("--datadir=%s/slasher-data-%d/", e2e.TestParams.TestPath, i),
|
2020-03-30 16:10:00 +00:00
|
|
|
fmt.Sprintf("--monitoring-port=%d", e2e.TestParams.SlasherMetricsPort+i),
|
2020-03-22 23:04:23 +00:00
|
|
|
fmt.Sprintf("--beacon-rpc-provider=localhost:%d", e2e.TestParams.BeaconNodeRPCPort+i),
|
|
|
|
"--force-clear-db",
|
|
|
|
"--span-map-cache",
|
|
|
|
"--verbosity=debug",
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Starting slasher %d with flags: %s", i, strings.Join(args[2:], " "))
|
|
|
|
cmd := exec.Command(binaryPath, args...)
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
t.Fatalf("Failed to start slasher client: %v", err)
|
|
|
|
}
|
|
|
|
processIDs = append(processIDs, cmd.Process.Pid)
|
|
|
|
}
|
|
|
|
|
|
|
|
stdOutFile, err := os.Open(path.Join(e2e.TestParams.LogPath, fmt.Sprintf(e2e.SlasherLogFileName, 0)))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = helpers.WaitForTextInFile(stdOutFile, "Beacon node is fully synced, starting slashing detection"); err != nil {
|
|
|
|
t.Fatalf("could not find starting logs for slasher, this means it had issues starting: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return processIDs
|
|
|
|
}
|