From a0ffa454ecfa1302c6e09f532289bb5c4df34136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20M=C3=BCller?= Date: Wed, 1 Mar 2023 09:04:27 +0100 Subject: [PATCH] Remove unused code from Node struct (#6978) The server attribute was only still used in a broken, skipped unit test which we may rewrite later --- node/node.go | 16 ---------------- node/node_test.go | 21 +-------------------- node/utils_test.go | 31 ------------------------------- 3 files changed, 1 insertion(+), 67 deletions(-) diff --git a/node/node.go b/node/node.go index 888f6296a..5647a02fd 100644 --- a/node/node.go +++ b/node/node.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "net" "os" "path/filepath" "reflect" @@ -37,7 +36,6 @@ import ( "github.com/ledgerwatch/erigon-lib/kv/mdbx" "github.com/ledgerwatch/erigon-lib/kv/memdb" "github.com/ledgerwatch/erigon/migrations" - "github.com/ledgerwatch/erigon/p2p" "github.com/ledgerwatch/log/v3" ) @@ -47,7 +45,6 @@ type Node struct { log log.Logger dirLock *flock.Flock // prevents concurrent use of instance directory stop chan struct{} // Channel to wait for termination notifications - server *p2p.Server // Currently running P2P networking layer startStopLock sync.Mutex // Start/Stop are protected by an additional lock state int // Tracks state of node lifecycle @@ -97,9 +94,6 @@ func New(conf *nodecfg.Config) (*Node, error) { return node, nil } -func (n *Node) SetP2PListenFunc(listenFunc func(network, addr string) (net.Listener, error)) { -} - // Start starts all registered lifecycles, RPC services and p2p networking. // Node can only be started once. func (n *Node) Start() error { @@ -280,16 +274,6 @@ func (n *Node) RegisterLifecycle(lifecycle Lifecycle) { n.lifecycles = append(n.lifecycles, lifecycle) } -// RegisterProtocols adds backend's protocols to the node's p2p server. -func (n *Node) RegisterProtocols(protocols []p2p.Protocol) { - n.lock.Lock() - defer n.lock.Unlock() - - if n.state != initializingState { - panic("can't register protocols on running/stopped node") - } -} - // Config returns the configuration of node. func (n *Node) Config() *nodecfg.Config { return n.config diff --git a/node/node_test.go b/node/node_test.go index 620aad51d..3be75b5a4 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -134,23 +134,7 @@ func TestLifecycleRegistry_Successful(t *testing.T) { // Tests whether a service's protocols can be registered properly on the node's p2p server. func TestRegisterProtocols(t *testing.T) { t.Skip("adjust to p2p sentry") - stack, err := New(testNodeConfig(t)) - if err != nil { - t.Fatalf("failed to create protocol stack: %v", err) - } - defer stack.Close() - - fs, err := NewFullService(stack) - if err != nil { - t.Fatalf("could not create full service: %v", err) - } - - for _, protocol := range fs.Protocols() { - if !containsProtocol(stack.server.Protocols, protocol) { - t.Fatalf("protocol %v was not successfully registered", protocol) - } - } - + // TODO } // This test checks that open databases are closed with node. @@ -404,9 +388,6 @@ func TestLifecycleTerminationGuarantee(t *testing.T) { delete(started, id) delete(stopped, id) } - - stack.server = &p2p.Server{} - stack.server.PrivateKey = testNodeKey } func containsProtocol(stackProtocols []p2p.Protocol, protocol p2p.Protocol) bool { diff --git a/node/utils_test.go b/node/utils_test.go index 0a3476743..6739fa80c 100644 --- a/node/utils_test.go +++ b/node/utils_test.go @@ -19,10 +19,6 @@ package node -import ( - "github.com/ledgerwatch/erigon/p2p" -) - // NoopLifecycle is a trivial implementation of the Service interface. type NoopLifecycle struct{} @@ -61,30 +57,3 @@ func (s *InstrumentedService) Stop() error { } return s.stop } - -type FullService struct{} - -func NewFullService(stack *Node) (*FullService, error) { - fs := new(FullService) - - stack.RegisterProtocols(fs.Protocols()) - stack.RegisterLifecycle(fs) - return fs, nil -} - -func (f *FullService) Start() error { return nil } - -func (f *FullService) Stop() error { return nil } - -func (f *FullService) Protocols() []p2p.Protocol { - return []p2p.Protocol{ - { - Name: "test1", - Version: uint(1), - }, - { - Name: "test2", - Version: uint(2), - }, - } -}