mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
parent
bf093348b7
commit
1dc8158ef0
2 changed files with 4 additions and 12 deletions
13
node/node.go
13
node/node.go
|
|
@ -25,6 +25,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -288,16 +289,6 @@ func (n *Node) openEndpoints() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// containsLifecycle checks if 'lfs' contains 'l'.
|
||||
func containsLifecycle(lfs []Lifecycle, l Lifecycle) bool {
|
||||
for _, obj := range lfs {
|
||||
if obj == l {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// stopServices terminates running services, RPC and p2p networking.
|
||||
// It is the inverse of Start.
|
||||
func (n *Node) stopServices(running []Lifecycle) error {
|
||||
|
|
@ -575,7 +566,7 @@ func (n *Node) RegisterLifecycle(lifecycle Lifecycle) {
|
|||
if n.state != initializingState {
|
||||
panic("can't register lifecycle on running/stopped node")
|
||||
}
|
||||
if containsLifecycle(n.lifecycles, lifecycle) {
|
||||
if slices.Contains(n.lifecycles, lifecycle) {
|
||||
panic(fmt.Sprintf("attempt to register lifecycle %T more than once", lifecycle))
|
||||
}
|
||||
n.lifecycles = append(n.lifecycles, lifecycle)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -116,7 +117,7 @@ func TestLifecycleRegistry_Successful(t *testing.T) {
|
|||
noop := NewNoop()
|
||||
stack.RegisterLifecycle(noop)
|
||||
|
||||
if !containsLifecycle(stack.lifecycles, noop) {
|
||||
if !slices.Contains(stack.lifecycles, Lifecycle(noop)) {
|
||||
t.Fatalf("lifecycle was not properly registered on the node, %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue