diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 2552b6411..0890b5e1f 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,7 +19,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.61.0 + version: v1.62.0 - name: notify failure if: failure() && github.ref == 'refs/heads/main' env: diff --git a/.golangci.yml b/.golangci.yml index 20a6b434a..c74cad5a2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -178,6 +178,7 @@ linters: - nonamedreturns - paralleltest - prealloc + - recvcheck # triggers a lot of false positives - tagliatelle - varnamelen - wsl diff --git a/.pre-commit/run_linter.sh b/.pre-commit/run_linter.sh index b9996f10f..2fb04107b 100755 --- a/.pre-commit/run_linter.sh +++ b/.pre-commit/run_linter.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="1.61.0" +VERSION="1.62.0" if ! command -v golangci-lint &> /dev/null then diff --git a/Dockerfile b/Dockerfile index 2fd16ed50..ca1f312da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,7 @@ RUN addgroup --gid "$GID" "$USER" \ && chmod u+x /usr/local/bin/charon WORKDIR "/opt/$USER" +RUN chown charon "/opt/$USER" USER charon ENTRYPOINT ["/usr/local/bin/charon"] diff --git a/app/obolapi/api_internal_test.go b/app/obolapi/api_internal_test.go index babcc9a84..a4f299085 100644 --- a/app/obolapi/api_internal_test.go +++ b/app/obolapi/api_internal_test.go @@ -63,7 +63,7 @@ func TestHttpPost(t *testing.T) { data, err := io.ReadAll(r.Body) require.NoError(t, err) defer r.Body.Close() - require.Equal(t, string(data), `{"test_body_key": "test_body_value"}`) + require.JSONEq(t, string(data), `{"test_body_key": "test_body_value"}`) w.WriteHeader(http.StatusOK) _, err = w.Write([]byte(`"OK"`)) diff --git a/cmd/addvalidators_internal_test.go b/cmd/addvalidators_internal_test.go index d2f21c720..0799bac65 100644 --- a/cmd/addvalidators_internal_test.go +++ b/cmd/addvalidators_internal_test.go @@ -217,9 +217,9 @@ func TestRunAddValidators(t *testing.T) { require.NoError(t, err) require.Len(t, entries, 3) - require.True(t, strings.Contains(entries[0].Name(), "cluster-manifest")) - require.True(t, strings.Contains(entries[1].Name(), "deposit-data")) - require.True(t, strings.Contains(entries[2].Name(), "validator_keys")) + require.Contains(t, entries[0].Name(), "cluster-manifest") + require.Contains(t, entries[1].Name(), "deposit-data") + require.Contains(t, entries[2].Name(), "validator_keys") }) } diff --git a/cmd/cmd.go b/cmd/cmd.go index 0b152c01d..e83b47cbc 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -49,6 +49,14 @@ func New() *cobra.Command { newAlphaCmd( newAddValidatorsCmd(runAddValidatorsSolo), newViewClusterManifestCmd(runViewClusterManifest), + newTestCmd( + newTestAllCmd(runTestAll), + newTestPeersCmd(runTestPeers), + newTestBeaconCmd(runTestBeacon), + newTestValidatorCmd(runTestValidator), + newTestMEVCmd(runTestMEV), + newTestInfraCmd(runTestInfra), + ), ), newExitCmd( newListActiveValidatorsCmd(runListActiveValidatorsCmd), @@ -57,14 +65,6 @@ func New() *cobra.Command { newFetchExitCmd(runFetchExit), ), newUnsafeCmd(newRunCmd(app.Run, true)), - newTestCmd( - newTestAllCmd(runTestAll), - newTestPeersCmd(runTestPeers), - newTestBeaconCmd(runTestBeacon), - newTestValidatorCmd(runTestValidator), - newTestMEVCmd(runTestMEV), - newTestInfraCmd(runTestInfra), - ), ) } diff --git a/cmd/duration.go b/cmd/duration.go index 8f713811d..179ab87ee 100644 --- a/cmd/duration.go +++ b/cmd/duration.go @@ -65,3 +65,16 @@ func (d *Duration) UnmarshalText(b []byte) error { return nil } + +func RoundDuration(d Duration) Duration { + switch { + case d.Duration > time.Second: + return Duration{d.Round(10 * time.Millisecond)} + case d.Duration > time.Millisecond: + return Duration{d.Round(time.Millisecond)} + case d.Duration > time.Microsecond: + return Duration{d.Round(time.Microsecond)} + default: + return d + } +} diff --git a/cmd/duration_test.go b/cmd/duration_test.go index 213113172..b43bd8965 100644 --- a/cmd/duration_test.go +++ b/cmd/duration_test.go @@ -294,3 +294,43 @@ func TestDurationUnmarshalText(t *testing.T) { }) } } + +func TestRoundDuration(t *testing.T) { + tests := []struct { + name string + in cmd.Duration + expected cmd.Duration + }{ + { + name: "15.151 milliseconds", + in: cmd.Duration{15151 * time.Microsecond}, + expected: cmd.Duration{15 * time.Millisecond}, + }, + { + name: "15.151515 milliseconds", + in: cmd.Duration{15151515 * time.Nanosecond}, + expected: cmd.Duration{15 * time.Millisecond}, + }, + { + name: "2.344444 seconds", + in: cmd.Duration{2344444 * time.Microsecond}, + expected: cmd.Duration{2340 * time.Millisecond}, + }, + { + name: "2.345555 seconds", + in: cmd.Duration{2345555 * time.Microsecond}, + expected: cmd.Duration{2350 * time.Millisecond}, + }, + { + name: "15.151 microsecond", + in: cmd.Duration{15151 * time.Nanosecond}, + expected: cmd.Duration{15 * time.Microsecond}, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + res := cmd.RoundDuration(test.in) + require.Equal(t, test.expected, res) + }) + } +} diff --git a/cmd/test.go b/cmd/test.go index dfc00901c..134c21192 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -380,7 +380,7 @@ func evaluateRTT(rtt time.Duration, testRes testResult, avg time.Duration, poor } else { testRes.Verdict = testVerdictGood } - testRes.Measurement = Duration{rtt}.String() + testRes.Measurement = RoundDuration(Duration{rtt}).String() return testRes } diff --git a/cmd/testbeacon.go b/cmd/testbeacon.go index 70b240961..61f09d98f 100644 --- a/cmd/testbeacon.go +++ b/cmd/testbeacon.go @@ -830,14 +830,7 @@ func beaconSimulationTest(ctx context.Context, conf *testBeaconConfig, target st highestRTT = sim.Max } } - if highestRTT.Duration > thresholdBeaconSimulationPoor { - testRes.Verdict = testVerdictPoor - } else if highestRTT.Duration > thresholdBeaconSimulationAvg { - testRes.Verdict = testVerdictAvg - } else { - testRes.Verdict = testVerdictGood - } - testRes.Measurement = highestRTT.String() + testRes = evaluateRTT(highestRTT.Duration, testRes, thresholdBeaconSimulationAvg, thresholdBeaconSimulationPoor) log.Info(ctx, "Validators simulation finished", z.Any("validators_count", params.TotalValidatorsCount), diff --git a/cmd/testinfra.go b/cmd/testinfra.go index 4eae88f39..968c0f7c1 100644 --- a/cmd/testinfra.go +++ b/cmd/testinfra.go @@ -267,7 +267,7 @@ func infraDiskWriteSpeedTest(ctx context.Context, conf *testInfraConfig) testRes } else { testRes.Verdict = testVerdictGood } - testRes.Measurement = strconv.FormatFloat(diskWriteMBs, 'f', 4, 64) + "MB/s" + testRes.Measurement = strconv.FormatFloat(diskWriteMBs, 'f', 2, 64) + "MB/s" return testRes } @@ -370,7 +370,7 @@ func infraDiskReadSpeedTest(ctx context.Context, conf *testInfraConfig) testResu } else { testRes.Verdict = testVerdictGood } - testRes.Measurement = strconv.FormatFloat(diskReadMBs, 'f', 4, 64) + "MB/s" + testRes.Measurement = strconv.FormatFloat(diskReadMBs, 'f', 2, 64) + "MB/s" return testRes } @@ -514,16 +514,7 @@ func infraInternetLatencyTest(ctx context.Context, conf *testInfraConfig) testRe if err != nil { return failedTestResult(testRes, err) } - latency := server.Latency - - if latency > internetLatencyPoor { - testRes.Verdict = testVerdictPoor - } else if latency > internetLatencyAvg { - testRes.Verdict = testVerdictAvg - } else { - testRes.Verdict = testVerdictGood - } - testRes.Measurement = latency.Round(time.Microsecond).String() + testRes = evaluateRTT(server.Latency, testRes, internetLatencyAvg, internetLatencyPoor) return testRes } @@ -612,6 +603,11 @@ func fioCommand(ctx context.Context, filename string, blocksize int, operation s return nil, errors.Wrap(err, "exec fio command") } + err = os.Remove(fmt.Sprintf("%v/fiotest", filename)) + if err != nil { + return nil, errors.Wrap(err, "delete fio test file") + } + return cmd, nil } diff --git a/cmd/testmev.go b/cmd/testmev.go index 248f0646b..6dff83451 100644 --- a/cmd/testmev.go +++ b/cmd/testmev.go @@ -33,7 +33,7 @@ type testMEVConfig struct { Endpoints []string BeaconNodeEndpoint string LoadTest bool - LoadTestBlocks uint + NumberOfPayloads uint } type testCaseMEV func(context.Context, *testMEVConfig, string) testResult @@ -75,6 +75,10 @@ func newTestMEVCmd(runFunc func(context.Context, io.Writer, testMEVConfig) (test return errors.New("beacon-node-endpoint should be specified when load-test is") } + if loadTest == "false" && beaconNodeEndpoint != "" { + return errors.New("beacon-node-endpoint should be used only when load-test is") + } + return nil }) @@ -82,19 +86,18 @@ func newTestMEVCmd(runFunc func(context.Context, io.Writer, testMEVConfig) (test } func bindTestMEVFlags(cmd *cobra.Command, config *testMEVConfig, flagsPrefix string) { - cmd.Flags().StringSliceVar(&config.Endpoints, flagsPrefix+"endpoints", nil, "[REQUIRED] Comma separated list of one or more MEV relay endpoint URLs.") + cmd.Flags().StringSliceVar(&config.Endpoints, flagsPrefix+"endpoints", nil, "Comma separated list of one or more MEV relay endpoint URLs.") cmd.Flags().StringVar(&config.BeaconNodeEndpoint, flagsPrefix+"beacon-node-endpoint", "", "[REQUIRED] Beacon node endpoint URL used for block creation test.") cmd.Flags().BoolVar(&config.LoadTest, flagsPrefix+"load-test", false, "Enable load test.") - cmd.Flags().UintVar(&config.LoadTestBlocks, flagsPrefix+"load-test-blocks", 3, "Amount of blocks the 'createMultipleBlocks' test will create.") + cmd.Flags().UintVar(&config.NumberOfPayloads, flagsPrefix+"number-of-payloads", 1, "Increases the accuracy of the load test by asking for multiple payloads. Increases test duration.") mustMarkFlagRequired(cmd, flagsPrefix+"endpoints") } func supportedMEVTestCases() map[testCaseName]testCaseMEV { return map[testCaseName]testCaseMEV{ - {name: "Ping", order: 1}: mevPingTest, - {name: "PingMeasure", order: 2}: mevPingMeasureTest, - {name: "CreateBlock", order: 3}: mevCreateBlockTest, - {name: "CreateMultipleBlocks", order: 4}: mevCreateMultipleBlocksTest, + {name: "Ping", order: 1}: mevPingTest, + {name: "PingMeasure", order: 2}: mevPingMeasureTest, + {name: "CreateBlock", order: 3}: mevCreateBlockTest, } } @@ -305,53 +308,8 @@ func mevCreateBlockTest(ctx context.Context, conf *testMEVConfig, target string) return failedTestResult(testRes, err) } - log.Info(ctx, "Starting attempts for block creation", z.Any("mev_relay", target)) - rtt, err := createMEVBlock(ctx, conf, target, nextSlot, latestBlock, proposerDuties) - if err != nil { - return failedTestResult(testRes, err) - } - testRes = evaluateRTT(rtt, testRes, thresholdMEVBlockAvg, thresholdMEVBlockPoor) - - return testRes -} - -func mevCreateMultipleBlocksTest(ctx context.Context, conf *testMEVConfig, target string) testResult { - testRes := testResult{Name: "CreateMultipleBlocks"} - - if !conf.LoadTest { - testRes.Verdict = testVerdictSkipped - return testRes - } - - latestBlock, err := latestBeaconBlock(ctx, conf.BeaconNodeEndpoint) - if err != nil { - return failedTestResult(testRes, err) - } - - // wait for beginning of next slot, as the block for current one might have already been proposed - latestBlockTSUnix, err := strconv.ParseInt(latestBlock.Body.ExecutionPayload.Timestamp, 10, 64) - if err != nil { - failedTestResult(testRes, err) - } - latestBlockTS := time.Unix(latestBlockTSUnix, 0) - nextBlockTS := latestBlockTS.Add(slotTime) - for time.Now().Before(nextBlockTS) && ctx.Err() == nil { - sleepWithContext(ctx, time.Millisecond) - } - - latestSlot, err := strconv.ParseInt(latestBlock.Slot, 10, 64) - if err != nil { - return failedTestResult(testRes, err) - } - nextSlot := latestSlot + 1 - epoch := nextSlot / slotsInEpoch - proposerDuties, err := fetchProposersForEpoch(ctx, conf, epoch) - if err != nil { - return failedTestResult(testRes, err) - } - allBlocksRTT := []time.Duration{} - log.Info(ctx, "Starting attempts for multiple block creation", z.Any("mev_relay", target), z.Any("blocks", conf.LoadTestBlocks)) + log.Info(ctx, "Starting attempts for block creation", z.Any("mev_relay", target), z.Any("blocks", conf.NumberOfPayloads)) for ctx.Err() == nil { startIteration := time.Now() rtt, err := createMEVBlock(ctx, conf, target, nextSlot, latestBlock, proposerDuties) @@ -359,7 +317,7 @@ func mevCreateMultipleBlocksTest(ctx context.Context, conf *testMEVConfig, targe return failedTestResult(testRes, err) } allBlocksRTT = append(allBlocksRTT, rtt) - if len(allBlocksRTT) == int(conf.LoadTestBlocks) { + if len(allBlocksRTT) == int(conf.NumberOfPayloads) { break } // wait for the next slot - time it took createMEVBlock - 1 sec diff --git a/cmd/testmev_internal_test.go b/cmd/testmev_internal_test.go index 5032d8700..0de88f077 100644 --- a/cmd/testmev_internal_test.go +++ b/cmd/testmev_internal_test.go @@ -57,7 +57,6 @@ func TestMEVTest(t *testing.T) { {Name: "Ping", Verdict: testVerdictOk, Measurement: "", Suggestion: "", Error: testResultError{}}, {Name: "PingMeasure", Verdict: testVerdictGood, Measurement: "", Suggestion: "", Error: testResultError{}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, }, }, @@ -82,7 +81,6 @@ func TestMEVTest(t *testing.T) { {Name: "Ping", Verdict: testVerdictOk, Measurement: "", Suggestion: "", Error: testResultError{}}, {Name: "PingMeasure", Verdict: testVerdictGood, Measurement: "", Suggestion: "", Error: testResultError{}}, {Name: "CreateBlock", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{}}, }, }, }, @@ -105,13 +103,11 @@ func TestMEVTest(t *testing.T) { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, endpoint2: { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, }, }, @@ -157,13 +153,11 @@ func TestMEVTest(t *testing.T) { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, endpoint2: { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, }, }, @@ -223,13 +217,11 @@ func TestMEVTest(t *testing.T) { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port1))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, endpoint2: { {Name: "Ping", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "PingMeasure", Verdict: testVerdictFail, Measurement: "", Suggestion: "", Error: testResultError{errors.New(fmt.Sprintf(`%v: connect: connection refused`, port2))}}, {Name: "CreateBlock", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, - {Name: "CreateMultipleBlocks", Verdict: testVerdictSkipped, Measurement: "", Suggestion: "", Error: testResultError{}}, }, }, Score: categoryScoreC, diff --git a/cmd/testpeers.go b/cmd/testpeers.go index 3843cfdd8..1ce351dfa 100644 --- a/cmd/testpeers.go +++ b/cmd/testpeers.go @@ -38,15 +38,15 @@ import ( type testPeersConfig struct { testConfig - ENRs []string - P2P p2p.Config - Log log.Config - DataDir string - KeepAlive time.Duration - LoadTestDuration time.Duration - DirectConnectionTimeout time.Duration - ClusterLockFilePath string - ClusterDefinitionFilePath string + ENRs []string + P2P p2p.Config + Log log.Config + DataDir string + KeepAlive time.Duration + LoadTestDuration time.Duration + DirectConnectionTimeout time.Duration + LockFile string + DefinitionFile string } type ( @@ -90,8 +90,8 @@ func newTestPeersCmd(runFunc func(context.Context, io.Writer, testPeersConfig) ( wrapPreRunE(cmd, func(cmd *cobra.Command, _ []string) error { const ( enrs = "enrs" - clusterLockFilePath = "cluster-lock-file-path" - clusterDefinitionFilePath = "cluster-definition-file-path" + clusterLockFilePath = "lock-file" + clusterDefinitionFilePath = "definition-file" ) enrsValue := cmd.Flags().Lookup(enrs).Value.String() clusterLockPathValue := cmd.Flags().Lookup(clusterLockFilePath).Value.String() @@ -120,8 +120,8 @@ func bindTestPeersFlags(cmd *cobra.Command, config *testPeersConfig, flagsPrefix cmd.Flags().DurationVar(&config.KeepAlive, flagsPrefix+"keep-alive", 30*time.Minute, "Time to keep TCP node alive after test completion, so connection is open for other peers to test on their end.") cmd.Flags().DurationVar(&config.LoadTestDuration, flagsPrefix+"load-test-duration", 30*time.Second, "Time to keep running the load tests in seconds. For each second a new continuous ping instance is spawned.") cmd.Flags().DurationVar(&config.DirectConnectionTimeout, flagsPrefix+"direct-connection-timeout", 2*time.Minute, "Time to keep trying to establish direct connection to peer.") - cmd.Flags().StringVar(&config.ClusterLockFilePath, flagsPrefix+"cluster-lock-file-path", "", "Path to cluster lock file, used to fetch peers' ENR addresses.") - cmd.Flags().StringVar(&config.ClusterDefinitionFilePath, flagsPrefix+"cluster-definition-file-path", "", "Path to cluster definition file, used to fetch peers' ENR addresses.") + cmd.Flags().StringVar(&config.LockFile, flagsPrefix+"lock-file", "", "The path to the cluster lock file defining the distributed validator cluster.") + cmd.Flags().StringVar(&config.DefinitionFile, flagsPrefix+"definition-file", "", "The path to the cluster definition file or an HTTP URL.") } func supportedPeerTestCases() map[testCaseName]testCasePeer { @@ -251,7 +251,7 @@ func testAllPeers(ctx context.Context, queuedTestCases []testCaseName, allTestCa singlePeerResCh := make(chan map[string][]testResult) group, _ := errgroup.WithContext(ctx) - enrs, err := fetchENRs(conf) + enrs, err := fetchENRs(ctx, conf) if err != nil { return err } @@ -395,14 +395,7 @@ func peerPingMeasureTest(ctx context.Context, _ *testPeersConfig, tcpNode host.H return failedTestResult(testRes, result.Error) } - if result.RTT > thresholdPeersMeasurePoor { - testRes.Verdict = testVerdictPoor - } else if result.RTT > thresholdPeersMeasureAvg { - testRes.Verdict = testVerdictAvg - } else { - testRes.Verdict = testVerdictGood - } - testRes.Measurement = Duration{result.RTT}.String() + testRes = evaluateRTT(result.RTT, testRes, thresholdPeersMeasureAvg, thresholdPeersMeasurePoor) return testRes } @@ -660,18 +653,12 @@ func relayPingMeasureTest(ctx context.Context, _ *testPeersConfig, target string // helper functions -func fetchPeersFromDefinition(path string) ([]string, error) { - f, err := os.ReadFile(path) +func fetchPeersFromDefinition(ctx context.Context, path string) ([]string, error) { + def, err := loadDefinition(ctx, path) if err != nil { return nil, errors.Wrap(err, "read definition file", z.Str("path", path)) } - var def cluster.Definition - err = json.Unmarshal(f, &def) - if err != nil { - return nil, errors.Wrap(err, "unmarshal definition json", z.Str("path", path)) - } - var enrs []string for _, o := range def.Operators { enrs = append(enrs, o.ENR) @@ -708,19 +695,19 @@ func fetchPeersFromLock(path string) ([]string, error) { return enrs, nil } -func fetchENRs(conf testPeersConfig) ([]string, error) { +func fetchENRs(ctx context.Context, conf testPeersConfig) ([]string, error) { var enrs []string var err error switch { case len(conf.ENRs) != 0: enrs = conf.ENRs - case conf.ClusterDefinitionFilePath != "": - enrs, err = fetchPeersFromDefinition(conf.ClusterDefinitionFilePath) + case conf.DefinitionFile != "": + enrs, err = fetchPeersFromDefinition(ctx, conf.DefinitionFile) if err != nil { return nil, err } - case conf.ClusterLockFilePath != "": - enrs, err = fetchPeersFromLock(conf.ClusterLockFilePath) + case conf.LockFile != "": + enrs, err = fetchPeersFromLock(conf.LockFile) if err != nil { return nil, err } @@ -730,7 +717,7 @@ func fetchENRs(conf testPeersConfig) ([]string, error) { } func startTCPNode(ctx context.Context, conf testPeersConfig) (host.Host, func(), error) { - enrs, err := fetchENRs(conf) + enrs, err := fetchENRs(ctx, conf) if err != nil { return nil, nil, err } diff --git a/cmd/testpeers_internal_test.go b/cmd/testpeers_internal_test.go index 9622c2a7d..3500cd816 100644 --- a/cmd/testpeers_internal_test.go +++ b/cmd/testpeers_internal_test.go @@ -320,7 +320,7 @@ func TestPeersTestFlags(t *testing.T) { { name: "no enrs flag", args: []string{"peers"}, - expectedErr: "--enrs, --cluster-lock-file-path or --cluster-definition-file-path must be specified.", + expectedErr: "--enrs, --lock-file or --definition-file must be specified.", }, { name: "no output json on quiet", diff --git a/core/priority/component.go b/core/priority/component.go index 04c072e48..7ccb6c28d 100644 --- a/core/priority/component.go +++ b/core/priority/component.go @@ -49,15 +49,9 @@ type ScoredPriority struct { Score int } -// coreConsensus is an interface for the core/consensus.Component. -type coreConsensus interface { - ProposePriority(context.Context, core.Duty, *pbv1.PriorityResult) error - SubscribePriority(func(context.Context, core.Duty, *pbv1.PriorityResult) error) -} - // NewComponent returns a new priority component. func NewComponent(ctx context.Context, tcpNode host.Host, peers []peer.ID, minRequired int, sendFunc p2p.SendReceiveFunc, - registerHandlerFunc p2p.RegisterHandlerFunc, consensus coreConsensus, + registerHandlerFunc p2p.RegisterHandlerFunc, consensus Consensus, exchangeTimeout time.Duration, privkey *k1.PrivateKey, deadlineFunc func(duty core.Duty) (time.Time, bool), ) (*Component, error) { verifier, err := newMsgVerifier(peers) diff --git a/go.mod b/go.mod index 2d23396f7..6190dfae0 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.10.0 github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.4.1 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 go.opentelemetry.io/otel v1.32.0 diff --git a/go.sum b/go.sum index 1c6188763..b604708b4 100644 --- a/go.sum +++ b/go.sum @@ -527,8 +527,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=