Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: describe topic event transition between libp2p and peer manager level #1053

Open
romanzac opened this issue Mar 14, 2024 · 0 comments
Assignees

Comments

@romanzac
Copy link
Collaborator

Background

During unit test development at #1035 was discovered unexpected behavior for events transitioning from libp2p layer to Waku layer. Within TestHandlePeerTopicEvent 5 nodes subscribed to the same pubsub topic. It is expected (w *WakuRelay) topicEventPoll(topic string, handler *pubsub.TopicEventHandler) gets executed and based on received libp2p events, new events for peer manager will get emitted and handled:

pubsub.PeerJoin - > relay.PEER_JOINED

It was not the case. topicEventPoll() either wasn't executed or not received any libp2p events.

Details - failed test:

func TestHandlePeerTopicEvent(t *testing.T) {
	log := utils.Logger()
	pubSubTopic := "/waku/2/go/pm/test"
	ctx := context.Background()

	hosts := make([]host.Host, 5)
	relays := make([]*relay.WakuRelay, 5)

	for i := 0; i < 5; i++ {
		relays[i], hosts[i], _ = makeWakuRelay(t, log)
		err := relays[i].Start(ctx)
		require.NoError(t, err)
	}

	// Create peer manager instance with the first hosts
	pm, _ := makePeerManagerWithEventBus(t, relays[0], &hosts[0])
	pm.ctx = ctx
	pm.RegisterWakuProtocol(relay.WakuRelayID_v200, relay.WakuRelayENRField)

	// Connect host[0] with all other hosts to reach 4 connections
	for i := 1; i < 5; i++ {
		pm.host.Peerstore().AddAddrs(hosts[i].ID(), hosts[i].Addrs(), peerstore.PermanentAddrTTL)
		err := pm.host.Connect(ctx, hosts[i].Peerstore().PeerInfo(hosts[i].ID()))
		require.NoError(t, err)
		err = pm.host.Peerstore().(wps.WakuPeerstore).SetDirection(hosts[i].ID(), network.DirOutbound)
		require.NoError(t, err)

	}

	// Wait for connections to settle
	time.Sleep(2 * time.Second)

	if len(pm.host.Peerstore().(*wps.WakuPeerstoreImpl).PeersByPubSubTopic(pubSubTopic)) == 0 {
		log.Info("No peers for the topic yet")
	}

	// Start event loop to listen to events
	ctxEventLoop := context.Background()
	go pm.peerEventLoop(ctxEventLoop)

	for i := 1; i < 5; i++ {
		// Subscribe to Pubsub topic on first host only
		_, err := relays[i].Subscribe(ctx, protocol.NewContentFilter(pubSubTopic))
		require.NoError(t, err)
	}
	
	// Wait for connections to settle
	time.Sleep(30 * time.Second)

	// Check four hosts have joined the topic
	require.Equal(t, 4, len(pm.host.Peerstore().(*wps.WakuPeerstoreImpl).PeersByPubSubTopic(pubSubTopic)))

	// Check all hosts have been connected
	for _, peer := range pm.host.Peerstore().(*wps.WakuPeerstoreImpl).PeersByPubSubTopic(pubSubTopic) {
		require.Equal(t, network.Connected, pm.host.Network().Connectedness(peer))
	}
	
}

Acceptance criteria

Clear explanation why peer manager related events were not emitted after the subscribe, or unsubscribe respectively. Suggest new test code. Estimate if this issue could cause problems during full node operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants