mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-14 18:08:15 -05:00
* Ran gopls modernize to fix everything go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... * Override rules_go provided dependency for golang.org/x/tools to v0.38.0. To update this, checked out rules_go, then ran `bazel run //go/tools/releaser -- upgrade-dep -mirror=false org_golang_x_tools` and copied the patches. * Fix buildtag violations and ignore buildtag violations in external * Introduce modernize analyzer package. * Add modernize "any" analyzer. * Fix violations of any analyzer * Add modernize "appendclipped" analyzer. * Fix violations of appendclipped * Add modernize "bloop" analyzer. * Add modernize "fmtappendf" analyzer. * Add modernize "forvar" analyzer. * Add modernize "mapsloop" analyzer. * Add modernize "minmax" analyzer. * Fix violations of minmax analyzer * Add modernize "omitzero" analyzer. * Add modernize "rangeint" analyzer. * Fix violations of rangeint. * Add modernize "reflecttypefor" analyzer. * Fix violations of reflecttypefor analyzer. * Add modernize "slicescontains" analyzer. * Add modernize "slicessort" analyzer. * Add modernize "slicesdelete" analyzer. This is disabled by default for now. See https://go.dev/issue/73686. * Add modernize "stringscutprefix" analyzer. * Add modernize "stringsbuilder" analyzer. * Fix violations of stringsbuilder analyzer. * Add modernize "stringsseq" analyzer. * Add modernize "testingcontext" analyzer. * Add modernize "waitgroup" analyzer. * Changelog fragment * gofmt * gazelle * Add modernize "newexpr" analyzer. * Disable newexpr until go1.26 * Add more details in WORKSPACE on how to update the override * @nalepae feedback on min() * gofmt * Fix violations of forvar
121 lines
3.5 KiB
Go
121 lines
3.5 KiB
Go
package eth1
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/OffchainLabs/prysm/v7/testing/endtoend/helpers"
|
|
e2e "github.com/OffchainLabs/prysm/v7/testing/endtoend/params"
|
|
e2etypes "github.com/OffchainLabs/prysm/v7/testing/endtoend/types"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// NodeSet represents a set of Eth1 nodes, none of which is a mining node.
|
|
type NodeSet struct {
|
|
e2etypes.ComponentRunner
|
|
started chan struct{}
|
|
enr string
|
|
nodes []e2etypes.ComponentRunner
|
|
}
|
|
|
|
// NewNodeSet creates and returns a set of Eth1 nodes.
|
|
func NewNodeSet() *NodeSet {
|
|
return &NodeSet{
|
|
started: make(chan struct{}, 1),
|
|
}
|
|
}
|
|
|
|
// SetMinerENR sets the miner's enode, used to connect to the miner through P2P.
|
|
func (s *NodeSet) SetMinerENR(enr string) {
|
|
s.enr = enr
|
|
}
|
|
|
|
// Start starts all the execution nodes in set.
|
|
func (s *NodeSet) Start(ctx context.Context) error {
|
|
// Create Eth1 nodes. The number of nodes is the same as the number of beacon nodes.
|
|
// We want each beacon node to connect to its own Eth1 node.
|
|
// We start up one Eth1 node less than the beacon node count because the first
|
|
// beacon node will connect to the already existing Eth1 miner.
|
|
totalNodeCount := e2e.TestParams.BeaconNodeCount + e2e.TestParams.LighthouseBeaconNodeCount - 1
|
|
nodes := make([]e2etypes.ComponentRunner, totalNodeCount)
|
|
for i := range totalNodeCount {
|
|
// We start indexing nodes from 1 because the miner has an implicit 0 index.
|
|
node := NewNode(i+1, s.enr)
|
|
nodes[i] = node
|
|
}
|
|
s.nodes = nodes
|
|
|
|
// Wait for all nodes to finish their job (blocking).
|
|
// Once nodes are ready passed in handler function will be called.
|
|
return helpers.WaitOnNodes(ctx, nodes, func() {
|
|
// All nodes started, close channel, so that all services waiting on a set, can proceed.
|
|
close(s.started)
|
|
})
|
|
}
|
|
|
|
// Started checks whether execution node set is started and all nodes are ready to be queried.
|
|
func (s *NodeSet) Started() <-chan struct{} {
|
|
return s.started
|
|
}
|
|
|
|
// Pause pauses the component and its underlying process.
|
|
func (s *NodeSet) Pause() error {
|
|
for _, n := range s.nodes {
|
|
if err := n.Pause(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Resume resumes the component and its underlying process.
|
|
func (s *NodeSet) Resume() error {
|
|
for _, n := range s.nodes {
|
|
if err := n.Resume(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Stop stops the component and its underlying process.
|
|
func (s *NodeSet) Stop() error {
|
|
for _, n := range s.nodes {
|
|
if err := n.Stop(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// PauseAtIndex pauses the component and its underlying process at the desired index.
|
|
func (s *NodeSet) PauseAtIndex(i int) error {
|
|
if i >= len(s.nodes) {
|
|
return errors.Errorf("provided index exceeds slice size: %d >= %d", i, len(s.nodes))
|
|
}
|
|
return s.nodes[i].Pause()
|
|
}
|
|
|
|
// ResumeAtIndex resumes the component and its underlying process at the desired index.
|
|
func (s *NodeSet) ResumeAtIndex(i int) error {
|
|
if i >= len(s.nodes) {
|
|
return errors.Errorf("provided index exceeds slice size: %d >= %d", i, len(s.nodes))
|
|
}
|
|
return s.nodes[i].Resume()
|
|
}
|
|
|
|
// StopAtIndex stops the component and its underlying process at the desired index.
|
|
func (s *NodeSet) StopAtIndex(i int) error {
|
|
if i >= len(s.nodes) {
|
|
return errors.Errorf("provided index exceeds slice size: %d >= %d", i, len(s.nodes))
|
|
}
|
|
return s.nodes[i].Stop()
|
|
}
|
|
|
|
// ComponentAtIndex returns the component at the provided index.
|
|
func (s *NodeSet) ComponentAtIndex(i int) (e2etypes.ComponentRunner, error) {
|
|
if i >= len(s.nodes) {
|
|
return nil, errors.Errorf("provided index exceeds slice size: %d >= %d", i, len(s.nodes))
|
|
}
|
|
return s.nodes[i], nil
|
|
}
|