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

[Network] upgrade libp2p and libp2p-pubsub libraries #6963

Merged
merged 32 commits into from
Feb 7, 2025

Conversation

peterargue
Copy link
Contributor

@peterargue peterargue commented Jan 30, 2025

Replaces: #6821

Upgrade libp2p and libp2p-pubsub to the latest versions.

github.com/libp2p/go-libp2p v0.32.2 => v0.38.2
github.com/libp2p/go-libp2p-pubsub v0.10.0 => v0.13.0

@peterargue peterargue requested a review from a team as a code owner January 30, 2025 21:26
@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 20.00000% with 56 lines in your changes missing coverage. Please review.

Project coverage is 41.15%. Comparing base (e833530) to head (3144c07).

Files with missing lines Patch % Lines
integration/testnet/client.go 0.00% 19 Missing ⚠️
network/p2p/mock/node_builder.go 0.00% 13 Missing ⚠️
network/p2p/test/fixtures.go 12.50% 6 Missing and 1 partial ⚠️
network/p2p/builder/libp2pNodeBuilder.go 0.00% 6 Missing ⚠️
network/p2p/builder/gossipsub/gossipSubBuilder.go 16.66% 4 Missing and 1 partial ⚠️
network/p2p/mock/gossip_sub_builder.go 0.00% 2 Missing ⚠️
network/p2p/mock/pub_sub_adapter_config.go 0.00% 2 Missing ⚠️
network/p2p/node/gossipSubAdapterConfig.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6963      +/-   ##
==========================================
- Coverage   41.15%   41.15%   -0.01%     
==========================================
  Files        2131     2131              
  Lines      186855   186911      +56     
==========================================
+ Hits        76899    76919      +20     
- Misses     103516   103556      +40     
+ Partials     6440     6436       -4     
Flag Coverage Δ
unittests 41.15% <20.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -68,7 +67,7 @@ func NewGossipSubRouterSpammerWithRpcInspector(t *testing.T,
// ctlMessages is the list of spam messages to send to the victim node.
func (s *GossipSubRouterSpammer) SpamControlMessage(t *testing.T, victim p2p.LibP2PNode, ctlMessages []pb.ControlMessage, msgs ...*pb.Message) {
for _, ctlMessage := range ctlMessages {
require.True(t, s.router.Get().SendControl(victim.ID(), &ctlMessage, msgs...))
s.router.Get().SendControl(victim.ID(), &ctlMessage, msgs...)
Copy link
Contributor Author

@peterargue peterargue Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference between the mainline and forked version of pubsub was that in the fork SendControl returned a boolean. Since that was only used in this test, I'm removing the check to simplify our dependency management.

@@ -211,7 +212,7 @@ func (builder *LibP2PNodeBuilder) Build() (p2p.LibP2PNode, error) {
return nil, fmt.Errorf("could not create resolver: %w", err)
}

opts = append(opts, libp2p.MultiaddrResolver(resolver))
opts = append(opts, libp2p.MultiaddrResolver(swarm.ResolverFromMaDNS{Resolver: resolver}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was required for the libp2p/go-libp2p upgrade

@@ -199,7 +199,7 @@ func (suite *NetworkTestSuite) TestUpdateNodeAddresses() {

// create a new staked identity
ids, libP2PNodes := testutils.LibP2PNodeForNetworkFixture(suite.T(), suite.sporkId, 1)
idProvider := unittest.NewUpdatableIDProvider(ids)
idProvider := unittest.NewUpdatableIDProvider(append(suite.ids, ids...))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how this test originally worked since it was completely broken. maybe the networking logic was so slow that the message was never actually delivered. 🤷

@@ -319,7 +314,31 @@ func createConcurrentStreams(t *testing.T, ctx context.Context, nodes []p2p.LibP
// in 2 connections 1 created by each node, this happens because we are calling CreateStream concurrently.
time.Sleep(500 * time.Millisecond)
}
unittest.RequireReturnsBefore(t, wg.Wait, 3*time.Second, "could not create streams on time")
Copy link
Contributor Author

@peterargue peterargue Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test started running faster, so this check started to fail because it got here sooner and had to wait for the context timeout.

@@ -487,7 +488,7 @@ func (b *LibP2PNodeBuilder) configureRoutingSystem(
} else {
// bitswap requires a content routing system. this returns a stub instead of a full DHT
b.SetRoutingSystem(func(ctx context.Context, host host.Host) (routing.Routing, error) {
return none.ConstructNilRouting(ctx, host, nil, nil)
return routinghelpers.Null{}, nil
Copy link
Contributor Author

@peterargue peterargue Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none.ConstructNilRouting was removed. Using recommended alternative. The implementations differ in that the none version returned nil from PutValue, but the new version returns an error. Will need to see how this behaves with testing.

@janezpodhostnik
Copy link
Contributor

Are we ok with updating go-libp2p-pubsub to an unreleased version? Should we wait for a release?

@peterargue
Copy link
Contributor Author

Are we ok with updating go-libp2p-pubsub to an unreleased version? Should we wait for a release?

We needed a change that was merged after the tagged release to remove our forked version. I can poke the team about pushing a new tag.

@@ -115,7 +116,9 @@ func testGossipSubInvalidMessageDeliveryScoring(t *testing.T, spamMsgFactory fun
t.Name(),
idProvider,
p2ptest.WithRole(role),
p2ptest.OverrideFlowConfig(cfg))
p2ptest.OverrideFlowConfig(cfg),
p2ptest.WithValidateQueueSize(3000), // prevent node from dropping messages on slow CI machines
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the invalid signature test seems to run slower on the new version. Added this to prevent the victim node from dropping too many messages during the test.

network/test/cohort1/network_test.go Outdated Show resolved Hide resolved
Copy link
Member

@durkmurder durkmurder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for fixing broken tests. 🥇


spammerScore, ok := victimNode.PeerScoreExposer().GetScore(spammer.SpammerNode.ID())
require.True(t, ok)
t.Logf("spammer score: %f", spammerScore)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this or this was debugging code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not strictly. they're only logged in verbose mode and I think they are helpful to debug the test.

// when this is run against an Access node with indexing enabled, occasionally the indexed height
// lags behind the sealed height, especially after first starting up (like in a test).
// Retry using the same block until we get the account.
for {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually operations like this have an upper time limit so we don't run it indefinitely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, I left it to the context to manage that. the caller uses a 5 second timeout

// cancel the context to trigger streams to shutdown
cancel()

unittest.RequireReturnsBefore(t, wg.Wait, 1*time.Second, "could not shutdown streams on time")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice sequence

_, err = newNet.Register(channels.TestNetworkChannel, newEngine)
require.NoError(suite.T(), err)
newEngine.On("Process", channels.TestNetworkChannel, suite.ids[0].NodeID, mockery.Anything).Return(nil)

callCount := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it safe to use a non-atomic here? Do we have a guarantee that everything runs in the same goroutine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, this could cause flakiness. ee0881e

@peterargue peterargue added this pull request to the merge queue Feb 7, 2025
Merged via the queue into master with commit 8fbbd56 Feb 7, 2025
56 checks passed
@peterargue peterargue deleted the petera/upgrade-libp2p-take2 branch February 7, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants