mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +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"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -288,16 +289,6 @@ func (n *Node) openEndpoints() error {
|
||||||
return err
|
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.
|
// stopServices terminates running services, RPC and p2p networking.
|
||||||
// It is the inverse of Start.
|
// It is the inverse of Start.
|
||||||
func (n *Node) stopServices(running []Lifecycle) error {
|
func (n *Node) stopServices(running []Lifecycle) error {
|
||||||
|
|
@ -575,7 +566,7 @@ func (n *Node) RegisterLifecycle(lifecycle Lifecycle) {
|
||||||
if n.state != initializingState {
|
if n.state != initializingState {
|
||||||
panic("can't register lifecycle on running/stopped node")
|
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))
|
panic(fmt.Sprintf("attempt to register lifecycle %T more than once", lifecycle))
|
||||||
}
|
}
|
||||||
n.lifecycles = append(n.lifecycles, lifecycle)
|
n.lifecycles = append(n.lifecycles, lifecycle)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -116,7 +117,7 @@ func TestLifecycleRegistry_Successful(t *testing.T) {
|
||||||
noop := NewNoop()
|
noop := NewNoop()
|
||||||
stack.RegisterLifecycle(noop)
|
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)
|
t.Fatalf("lifecycle was not properly registered on the node, %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue