Skip to content

Commit 97636bf

Browse files
committed
Fixup: Add advertisement to protocol server registration
1 parent 4fb3d38 commit 97636bf

File tree

8 files changed

+13
-18
lines changed

8 files changed

+13
-18
lines changed

go/oasis-node/cmd/debug/byzantine/node.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func initializeAndRegisterByzantineNode(
155155
return nil, fmt.Errorf("initializing storage node failed: %w", err)
156156
}
157157
b.p2p.service.RegisterProtocolServer(storageP2P.NewServer(b.chainContext, b.runtimeID, storage))
158-
b.p2p.service.AdvertiseProtocol(storageP2P.ProtocolID(b.chainContext, b.runtimeID))
159158

160159
b.storage = storage
161160

go/oasis-node/cmd/node/node.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ func NewNode() (node *Node, err error) { // nolint: gocyclo
549549

550550
// Register consensus light client P2P protocol server.
551551
node.P2P.RegisterProtocolServer(consensusLightP2P.NewServer(node.P2P, node.chainContext, node.Consensus.Core()))
552-
node.P2P.AdvertiseProtocol(consensusLightP2P.ProtocolID(node.chainContext))
553552

554553
// Register the consensus service with the peer registry.
555554
if mgr := node.P2P.PeerManager(); mgr != nil {

go/p2p/api/api.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type Service interface {
6868
Publish(ctx context.Context, topic string, msg any)
6969

7070
// RegisterHandler registers a message handler for the specified runtime and topic kind.
71+
//
72+
// In addition, it triggers advertisement of the host's readiness to serve the specified topic,
73+
// allowing remote peers without existing connection to discover it.
74+
//
75+
// Ensure your server is indeed ready, to avoid advertising prematurely.
7176
RegisterHandler(topic string, handler Handler)
7277

7378
// BlockPeer blocks a specific peer from being used by the local node.
@@ -84,14 +89,11 @@ type Service interface {
8489

8590
// RegisterProtocolServer registers a protocol server for the given protocol.
8691
//
87-
// Normally, registered protocol server should be also advertised (AdvertiseProtocol),
88-
// so that remote peers find the host node.
89-
RegisterProtocolServer(srv rpc.Server)
90-
91-
// AdvertiseProtocol starts advertising the host as available for serving the specified protocol.
92+
// In addition, it triggers advertisement of the host's readiness to serve the specified protocol,
93+
// allowing remote peers without existing connection to discover it.
9294
//
93-
// It should be called only after the protocol server is running and ready to serve.
94-
AdvertiseProtocol(p core.ProtocolID)
95+
// Ensure your server is indeed ready, to avoid advertising prematurely.
96+
RegisterProtocolServer(srv rpc.Server)
9597

9698
// GetMinRepublishInterval returns the minimum republish interval that needs to be respected by
9799
// the caller when publishing the same message. If Publish is called for the same message more

go/p2p/p2p.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,13 @@ func (p *p2p) RegisterProtocolServer(srv rpc.Server) {
340340

341341
p.host.SetStreamHandler(srv.Protocol(), srv.HandleStream)
342342

343+
p.peerMgr.AdvertiseProtocol(srv.Protocol())
344+
343345
p.logger.Info("registered protocol server",
344346
"protocol_id", srv.Protocol(),
345347
)
346348
}
347349

348-
// Implements api.Service.
349-
func (p *p2p) AdvertiseProtocol(protocol core.ProtocolID) {
350-
p.peerMgr.AdvertiseProtocol(protocol)
351-
}
352-
353350
// Implements api.Service.
354351
func (p *p2p) GetMinRepublishInterval() time.Duration {
355352
return seenMessagesTTL + 5*time.Second

go/p2p/peermgmt/peermgr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func (m *PeerManager) RegisterProtocol(p core.ProtocolID, minPeers int, totalPee
196196
}
197197

198198
// AdvertiseProtocol starts advertising readiness to serve the specified protocol.
199+
//
200+
// This enables remote peers without existing connection to find the host node.
199201
func (m *PeerManager) AdvertiseProtocol(p core.ProtocolID) {
200202
m.discovery.startAdvertising(string(p))
201203
m.logger.Debug("triggered protocol advertisement",

go/worker/common/committee/node.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ func NewNode(
956956

957957
// Register transaction sync service.
958958
p2pHost.RegisterProtocolServer(txsync.NewServer(chainContext, runtime.ID(), n.TxPool))
959-
p2pHost.AdvertiseProtocol(txsync.ProtocolID(chainContext, runtime.ID()))
960959

961960
return n, nil
962961
}

go/worker/keymanager/init.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func New(
126126

127127
// Register keymanager service.
128128
commonWorker.P2P.RegisterProtocolServer(p2p.NewServer(commonWorker.ChainContext, w.runtimeID, w))
129-
commonWorker.P2P.AdvertiseProtocol(p2p.RuntimeProtocolID(commonWorker.ChainContext, w.runtimeID))
130129

131130
return w, nil
132131
}

go/worker/storage/committee/node.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,11 @@ func NewNode(
274274

275275
// Register storage sync service.
276276
commonNode.P2P.RegisterProtocolServer(storageSync.NewServer(commonNode.ChainContext, commonNode.Runtime.ID(), localStorage))
277-
commonNode.P2P.AdvertiseProtocol(storageSync.ProtocolID(commonNode.ChainContext, commonNode.Runtime.ID()))
278277
n.storageSync = storageSync.NewClient(commonNode.P2P, commonNode.ChainContext, commonNode.Runtime.ID())
279278

280279
// Register storage pub service if configured.
281280
if rpcRoleProvider != nil {
282281
commonNode.P2P.RegisterProtocolServer(storagePub.NewServer(commonNode.ChainContext, commonNode.Runtime.ID(), localStorage))
283-
commonNode.P2P.AdvertiseProtocol(storagePub.ProtocolID(commonNode.ChainContext, commonNode.Runtime.ID()))
284282
}
285283

286284
return n, nil

0 commit comments

Comments
 (0)