Skip to content

Commit 40bcc8e

Browse files
authored
Merge pull request #2327 from CortexFoundation/dev
backend & discovery fix
2 parents 74cb006 + 11822d3 commit 40bcc8e

26 files changed

Lines changed: 131 additions & 98 deletions

cmd/cortex/cvm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141

4242
"github.com/CortexFoundation/CortexTheseus/cmd/utils"
4343
"github.com/CortexFoundation/CortexTheseus/log"
44-
"github.com/CortexFoundation/CortexTheseus/p2p"
4544
)
4645

4746
func homeDir() string {
@@ -202,7 +201,7 @@ func cvmServer(ctx *cli.Context) error {
202201
return errors.New("fs start failed")
203202
}
204203

205-
err = storagefs.Start(&p2p.Server{})
204+
err = storagefs.Start()
206205
if err != nil {
207206
return err
208207
}

cmd/wnode/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func run() {
447447
return
448448
}
449449
defer server.Stop()
450-
shh.Start(&p2p.Server{})
450+
shh.Start()
451451
defer shh.Stop()
452452

453453
if !*forwarderMode {

ctxc/backend.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func New(stack *node.Node, config *Config) (*Cortex, error) {
276276

277277
ctxc.miner = miner.New(ctxc, &config.Miner, ctxc.chainConfig, ctxc.eventMux, ctxc.engine, ctxc.isLocalBlock)
278278
ctxc.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
279+
279280
ctxc.dropper = newDropper(ctxc.p2pServer.MaxDialedConns(), ctxc.p2pServer.MaxInboundConns())
280281

281282
ctxc.APIBackend = &CortexAPIBackend{stack.Config().AllowUnprotectedTxs, ctxc, nil}
@@ -287,9 +288,9 @@ func New(stack *node.Node, config *Config) (*Cortex, error) {
287288
gpoParams.Default = config.Miner.GasPrice
288289
}
289290
ctxc.APIBackend.gpo = gasprice.NewOracle(ctxc.APIBackend, gpoParams)
290-
if err != nil {
291-
return nil, err
292-
}
291+
292+
// Start the RPC service
293+
ctxc.netRPCService = ctxcapi.NewPublicNetAPI(ctxc.p2pServer, networkID)
293294

294295
//stack.RegisterProtocols(ctxc.Protocols())
295296

@@ -609,8 +610,7 @@ func (s *Cortex) Protocols() []p2p.Protocol {
609610

610611
// Start implements node.Service, starting all internal goroutines needed by the
611612
// Cortex protocol implementation.
612-
func (s *Cortex) Start(srvr *p2p.Server) error {
613-
s.startCtxcEntryUpdate(srvr.LocalNode())
613+
func (s *Cortex) Start() error {
614614
if err := s.setupDiscovery(); err != nil {
615615
return err
616616
}
@@ -620,13 +620,9 @@ func (s *Cortex) Start(srvr *p2p.Server) error {
620620
// Regularly update shutdown marker
621621
s.shutdownTracker.Start()
622622

623-
// Start the RPC service
624-
s.netRPCService = ctxcapi.NewPublicNetAPI(srvr, s.NetVersion())
625-
626623
// Figure out a max peers count based on the server limits
627-
maxPeers := srvr.MaxPeers
628624
// Start the networking layer and the light server if requested
629-
s.protocolManager.Start(maxPeers)
625+
s.protocolManager.Start(s.p2pServer.MaxPeers)
630626

631627
// Start the connection manager
632628
s.dropper.Start(s.p2pServer, func() bool { return !s.Synced() })
@@ -697,6 +693,8 @@ func (s *Cortex) updateFilterMapsHeads() {
697693
}
698694

699695
func (s *Cortex) setupDiscovery() error {
696+
s.startENRUpdater(s.p2pServer.LocalNode())
697+
700698
dnsclient := dnsdisc.NewClient(dnsdisc.Config{})
701699
if len(s.config.DiscoveryURLs) > 0 {
702700
iter, err := dnsclient.NewIterator(s.config.DiscoveryURLs...)

ctxc/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (e ctxcEntry) ENRKey() string {
3838
}
3939

4040
// startCtxcEntryUpdate starts the ENR updater loop.
41-
func (ctxc *Cortex) startCtxcEntryUpdate(ln *enode.LocalNode) {
41+
func (ctxc *Cortex) startENRUpdater(ln *enode.LocalNode) {
4242
var newHead = make(chan core.ChainHeadEvent, 10)
4343
sub := ctxc.blockchain.SubscribeChainHeadEvent(newHead)
4444

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.0
77
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250413152926-abb59313c23c
9+
github.com/CortexFoundation/torrentfs v1.0.69-0.20250415112856-b1b452a24746
1010
github.com/VictoriaMetrics/fastcache v1.12.2
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.36.3
@@ -206,7 +206,7 @@ require (
206206
github.com/pion/transport/v2 v2.2.10 // indirect
207207
github.com/pion/transport/v3 v3.0.7 // indirect
208208
github.com/pion/turn/v4 v4.0.0 // indirect
209-
github.com/pion/webrtc/v4 v4.0.14 // indirect
209+
github.com/pion/webrtc/v4 v4.0.15 // indirect
210210
github.com/pkg/errors v0.9.1 // indirect
211211
github.com/pmezard/go-difflib v1.0.0 // indirect
212212
github.com/prometheus/client_golang v1.22.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
7070
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
7171
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
7272
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
73-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250413152926-abb59313c23c h1:lpJ1OrrVq0fAz9299pdKPZPfmqopKFO+OHpCJQ9xHbo=
74-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250413152926-abb59313c23c/go.mod h1:Lf7iaFiGPvExQiyPufsbQ8hs0XkKUunTLcp0r77/IaY=
73+
github.com/CortexFoundation/torrentfs v1.0.69-0.20250415112856-b1b452a24746 h1:VP6BvIxVY1jh4UmvpJQqIzpmnYva25xVRevXHoPP/2M=
74+
github.com/CortexFoundation/torrentfs v1.0.69-0.20250415112856-b1b452a24746/go.mod h1:Lf7iaFiGPvExQiyPufsbQ8hs0XkKUunTLcp0r77/IaY=
7575
github.com/CortexFoundation/wormhole v0.0.2-0.20241128010855-a23c88842cfa h1:46VAGWxOwpoLlPNcR9etAhK0NtT215skO9Wl4i14r4o=
7676
github.com/CortexFoundation/wormhole v0.0.2-0.20241128010855-a23c88842cfa/go.mod h1:ipzmPabDgzYKUbXkGVe2gTkBEp+MsDx6pXGiuYzmP6s=
7777
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
@@ -1037,8 +1037,8 @@ github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM=
10371037
github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA=
10381038
github.com/pion/webrtc/v2 v2.2.7/go.mod h1:EfCuvKjzMgX4F/aSryRUC7L9o3u2N8WNUgnzd6wOO+8=
10391039
github.com/pion/webrtc/v2 v2.2.9/go.mod h1:TcArPDphZIBtZ+mh8J/qOREyY3ca7ihQrenulOIvfPQ=
1040-
github.com/pion/webrtc/v4 v4.0.14 h1:nyds/sFRR+HvmWoBa6wrL46sSfpArE0qR883MBW96lg=
1041-
github.com/pion/webrtc/v4 v4.0.14/go.mod h1:R3+qTnQTS03UzwDarYecgioNf7DYgTsldxnCXB821Kk=
1040+
github.com/pion/webrtc/v4 v4.0.15 h1:DWuBtTHBa9rQNqyhW+jptkq6r3zdGqr1OQ4pa2Q+Ey4=
1041+
github.com/pion/webrtc/v4 v4.0.15/go.mod h1:RXf6sJ8FUX+qwF4+AwB+A3c2Y6WpuATRTe4L/fTWNa4=
10421042
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
10431043
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
10441044
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (n *Node) Start() error {
273273
var started []reflect.Type
274274
for kind, service := range services {
275275
// Start the next service, stopping all previous upon failure
276-
if err := service.Start(running); err != nil {
276+
if err := service.Start(); err != nil {
277277
for _, kind := range started {
278278
services[kind].Stop()
279279
}

node/node_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type SampleService struct{}
3737

3838
func (s *SampleService) Protocols() []p2p.Protocol { return nil }
3939
func (s *SampleService) APIs() []rpc.API { return nil }
40-
func (s *SampleService) Start(*p2p.Server) error { fmt.Println("Service starting..."); return nil }
40+
func (s *SampleService) Start() error { fmt.Println("Service starting..."); return nil }
4141
func (s *SampleService) Stop() error { fmt.Println("Service stopping..."); return nil }
4242

4343
func ExampleService() {

node/node_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func TestServiceLifeCycle(t *testing.T) {
166166
id := id // Closure for the constructor
167167
constructor := func(*ServiceContext) (Service, error) {
168168
return &InstrumentedService{
169-
startHook: func(*p2p.Server) { started[id] = true },
169+
startHook: func() { started[id] = true },
170170
stopHook: func() { stopped[id] = true },
171171
}, nil
172172
}
@@ -214,7 +214,7 @@ func TestServiceRestarts(t *testing.T) {
214214
running = false
215215

216216
return &InstrumentedService{
217-
startHook: func(*p2p.Server) {
217+
startHook: func() {
218218
if running {
219219
panic("already running")
220220
}
@@ -266,7 +266,7 @@ func TestServiceConstructionAbortion(t *testing.T) {
266266
id := id // Closure for the constructor
267267
constructor := func(*ServiceContext) (Service, error) {
268268
return &InstrumentedService{
269-
startHook: func(*p2p.Server) { started[id] = true },
269+
startHook: func() { started[id] = true },
270270
}, nil
271271
}
272272
if err := stack.Register(maker(constructor)); err != nil {
@@ -317,7 +317,7 @@ func TestServiceStartupAbortion(t *testing.T) {
317317
id := id // Closure for the constructor
318318
constructor := func(*ServiceContext) (Service, error) {
319319
return &InstrumentedService{
320-
startHook: func(*p2p.Server) { started[id] = true },
320+
startHook: func() { started[id] = true },
321321
stopHook: func() { stopped[id] = true },
322322
}, nil
323323
}
@@ -372,7 +372,7 @@ func TestServiceTerminationGuarantee(t *testing.T) {
372372
id := id // Closure for the constructor
373373
constructor := func(*ServiceContext) (Service, error) {
374374
return &InstrumentedService{
375-
startHook: func(*p2p.Server) { started[id] = true },
375+
startHook: func() { started[id] = true },
376376
stopHook: func() { stopped[id] = true },
377377
}, nil
378378
}

node/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type Service interface {
111111

112112
// Start is called after all services have been constructed and the networking
113113
// layer was also initialized to spawn any goroutines required by the service.
114-
Start(server *p2p.Server) error
114+
Start() error
115115

116116
// Stop terminates all goroutines belonging to the service, blocking until they
117117
// are all terminated.

0 commit comments

Comments
 (0)