p2p: use nodeinfo less often (#8427)

This commit is contained in:
Sam Kleinman
2022-04-27 17:13:38 -04:00
committed by GitHub
parent 1121698757
commit 2a58ea3ab2
3 changed files with 1 additions and 18 deletions

View File

@@ -306,7 +306,6 @@ func (n *Node) MakeChannel(
ctx, cancel := context.WithCancel(ctx)
channel, err := n.Router.OpenChannel(ctx, chDesc)
require.NoError(t, err)
require.Contains(t, n.Router.NodeInfo().Channels, byte(chDesc.ID))
t.Cleanup(func() {
RequireEmpty(ctx, t, channel)
cancel()

View File

@@ -713,7 +713,7 @@ func (r *Router) handshakePeer(
return peerInfo, fmt.Errorf("expected to connect with peer %q, got %q",
expectID, peerInfo.NodeID)
}
if err := r.nodeInfoProducer().CompatibleWith(peerInfo); err != nil {
if err := nodeInfo.CompatibleWith(peerInfo); err != nil {
return peerInfo, ErrRejected{
err: err,
id: peerInfo.ID(),
@@ -911,11 +911,6 @@ func (r *Router) evictPeers(ctx context.Context) {
}
}
// NodeInfo returns a copy of the current NodeInfo. Used for testing.
func (r *Router) NodeInfo() types.NodeInfo {
return r.nodeInfoProducer().Copy()
}
func (r *Router) setupQueueFactory(ctx context.Context) error {
qf, err := r.createQueueFactory(ctx)
if err != nil {
@@ -936,14 +931,6 @@ func (r *Router) OnStart(ctx context.Context) error {
return err
}
nodeInfo := r.nodeInfoProducer()
r.logger.Info(
"starting router",
"node_id", nodeInfo.NodeID,
"channels", nodeInfo.Channels,
"listen_addr", nodeInfo.ListenAddr,
)
go r.dialPeers(ctx)
go r.evictPeers(ctx)
go r.acceptPeers(ctx, r.transport)

View File

@@ -128,7 +128,6 @@ func TestRouter_Channel_Basic(t *testing.T) {
channel, err := router.OpenChannel(chctx, chDesc)
require.NoError(t, err)
require.Contains(t, router.NodeInfo().Channels, byte(chDesc.ID))
require.NotNil(t, channel)
// Opening the same channel again should fail.
@@ -138,9 +137,7 @@ func TestRouter_Channel_Basic(t *testing.T) {
// Opening a different channel should work.
chDesc2 := &p2p.ChannelDescriptor{ID: 2, MessageType: &p2ptest.Message{}}
_, err = router.OpenChannel(ctx, chDesc2)
require.NoError(t, err)
require.Contains(t, router.NodeInfo().Channels, byte(chDesc2.ID))
// Closing the channel, then opening it again should be fine.
chcancel()