165 Commits

Author SHA1 Message Date
Prem Chaitanya Prathi
fc0a0a9bb7
Merge branch 'libp2p:master' into master 2025-08-22 10:47:47 +05:30
Marco Munizaga
fedbccc0c6
fix(BatchPublishing): Make topic.AddToBatch threadsafe (#622)
topic.Publish is already thread safe. topic.AddToBatch should strive to
follow similar semantics.

Looking at how this would integrate with Prysm, they use separate
goroutines per message they'd like to batch.
2025-06-25 12:38:21 -07:00
Marco Munizaga
c405ca8028
refactor: 10x faster RPC splitting (#615)
Builds on #582. 10x faster than current master. 0 allocs.

The basic logic is the same as the old version, except we return an
`iter.Seq[RPC]` and yield `RPC` types instead of a slice of `*RPC`. This
lets us avoid allocations for heap pointers.

Please review @algorandskiy, and let me know if this improves your use
case.
2025-05-28 22:32:25 -07:00
Marco Munizaga
9e5145fb29
Send IDONTWANT before first publish (#612)
See #610 

We previously send IDONTWANT only when forwarding. This has us send
IDONTWANT on our initial publish as well. Helps in the case that one or
more peers may also publish the same thing at around the same time (see
#610 for a longer explanation) and prevents "boomerang" duplicates where
a peer sends you back the message you sent before you get a chance to
send it to them.

This also serves as a hint to a peer that you are about to send them a
certain message.
2025-05-19 17:02:21 -07:00
Marco Munizaga
0c5ee7bbfe
feat(gossipsub): Add MessageBatch (#607)
to support batch publishing messages

Replaces #602.

Batch publishing lets the system know there are multiple related
messages to be published so it can prioritize sending different messages
before sending copies of messages. For example, with the default API,
when you publish two messages A and B, under the hood A gets sent to D=8
peers first, before B gets sent out. With this MessageBatch api we can
now send one copy of A _and then_ one copy of B before sending multiple
copies.

When a node has bandwidth constraints relative to the messages it is
publishing this improves dissemination time.

For more context see this post:
https://ethresear.ch/t/improving-das-performance-with-gossipsub-batch-publishing/21713
2025-05-08 10:23:02 -07:00
Marco Munizaga
50ccc5ca90
fix(IDONTWANT)!: Do not IDONTWANT your sender (#609)
We were sending IDONTWANT to the sender of the received message. This is
pointless, as the sender should not repeat a message it already sent.
The sender could also have tracked that it had sent this peer the
message (we don't do this currently, and it's probably not necessary).

@ppopth
2025-04-30 10:58:50 +03:00
richΛrd
b0f2429ca2
Merge branch 'libp2p:master' into master 2024-08-23 10:33:42 -04:00
Pop Chunhapanya
b421b3ab05
GossipSub v1.2: IDONTWANT control message and priority queue. (#553)
## GossipSub v1.2 implementation

Specification: libp2p/specs#548

### Work Summary
Sending IDONTWANT

Implement a smart queue
Add priorities to the smart queue

    Put IDONTWANT packets into the smart priority queue as soon as the node gets the packets

Handling IDONTWANT

Use a map to remember the message ids whose IDONTWANT packets have been received
Implement max_idontwant_messages (ignore the IDONWANT packets if the max is reached)
Clear the message IDs from the cache after 3 heartbeats

    Hash the message IDs before putting them into the cache.

More requested features

    Add a feature test to not send IDONTWANT if the other side doesnt support it

### Commit Summary

* Replace sending channel with the smart rpcQueue

Since we want to implement a priority queue later, we need to replace
the normal sending channels with the new smart structures first.

* Implement UrgentPush in the smart rpcQueue

UrgentPush allows you to push an rpc packet to the front of the queue so
that it will be popped out fast.

* Add IDONTWANT to rpc.proto and trace.proto

* Send IDONTWANT right before validation step

Most importantly, this commit adds a new method called PreValidation to
the interface PubSubRouter, which will be called right before validating
the gossipsub message.

In GossipSubRouter, PreValidation will send the IDONTWANT controll
messages to all the mesh peers of the topics of the received messages.

* Test GossipSub IDONWANT sending

* Send IDONWANT only for large messages

* Handle IDONTWANT control messages

When receiving IDONTWANTs, the host should remember the message ids
contained in IDONTWANTs using a hash map.

When receiving messages with those ids, it shouldn't forward them to the
peers who already sent the IDONTWANTs.

When the maximum number of IDONTWANTs is reached for any particular
peer, the host should ignore any excessive IDONTWANTs from that peer.

* Clear expired message IDs from the IDONTWANT cache

If the messages IDs received from IDONTWANTs are older than 3
heartbeats, they should be removed from the IDONTWANT cache.

* Keep the hashes of IDONTWANT message ids instead

Rather than keeping the raw message ids, keep their hashes instead to
save memory and protect again memory DoS attacks.

* Increase GossipSubMaxIHaveMessages to 1000

* fixup! Clear expired message IDs from the IDONTWANT cache

* Not send IDONTWANT if the receiver doesn't support

* fixup! Replace sending channel with the smart rpcQueue

* Not use pointers in rpcQueue

* Simply rcpQueue by using only one mutex

* Check ctx error in rpc sending worker

Co-authored-by: Steven Allen <steven@stebalien.com>

* fixup! Simply rcpQueue by using only one mutex

* fixup! Keep the hashes of IDONTWANT message ids instead

* Use AfterFunc instead implementing our own

* Fix misc lint errors

* fixup! Fix misc lint errors

* Revert "Increase GossipSubMaxIHaveMessages to 1000"

This reverts commit 6fabcdd068a5f5238c5280a3460af9c3998418ec.

* Increase GossipSubMaxIDontWantMessages to 1000

* fixup! Handle IDONTWANT control messages

* Skip TestGossipsubConnTagMessageDeliveries

* Skip FuzzAppendOrMergeRPC

* Revert "Skip FuzzAppendOrMergeRPC"

This reverts commit f141e13234de0960d139339acb636a1afea9e219.

* fixup! Send IDONWANT only for large messages

* fixup! fixup! Keep the hashes of IDONTWANT message ids instead

* fixup! Implement UrgentPush in the smart rpcQueue

* fixup! Use AfterFunc instead implementing our own

---------

Co-authored-by: Steven Allen <steven@stebalien.com>
2024-08-16 18:16:35 +03:00
Richard Ramos
fab982a94a refactor: create MeshPeer function in Pubsub 2024-08-07 10:40:51 +05:30
richΛrd
b12b0e138b feat: expose router and mesh peers (#1) 2024-08-07 10:40:51 +05:30
Steven Allen
b23b3ee559
Switch to the new peer notify mechanism (#564)
1. Only listen for peers added and identify events.
2. Remove the old "Limited" check. Peers only show up as "Connected" if
they have non-limited connections.
3. Don't bother listening for new connections directly and/or
connectivity changes. We'll get a new identify event per new connection
regardless.

fixes #546
2024-07-11 11:46:35 +00:00
vyzo
56c0e6c5c9
Refactor timecache implementations (#523)
* reimplement timecache for sane and performant behaviour

* remove seenMessagesMx, take advantage of new tc api

* fix timecache tests

* fix typo

* store expiry, don't make life difficult

* refactor common background sweep procedure for both impls

* add godocs to TimeCache
2023-02-21 21:13:13 +02:00
RichΛrd
cda3df70f4
chore: update go version and dependencies (#516) 2023-02-15 21:48:58 +02:00
Marco Munizaga
a14aca16fa
chore: update to go-libp2p v0.25 (#517)
* Update to go-libp2p v0.25

* Use go 1.19
2023-02-10 17:27:48 +01:00
Mohsin Zaidi
973fef56e1
feat: expire messages from the cache based on last seen time (#513)
* feat: expire messages from the cache based on last seen time

* chore: minor renaming

* fix: messages should not be found after expiration

* chore: editorial

* fix: use new time cache strategy consistently

* fix: default to old time cache and add todo for background gc
2023-01-24 02:02:44 +02:00
Louis Thibault
3d2eab3572
Add docstring for WithAppSpecificRPCInspector (#510) 2022-12-01 19:56:37 +02:00
Yahya Hassanzadeh
d3f151c224
Adds Application Specific RPC Inspector (#509)
* Update go.mod

* Refactor GossipSub Construction  (#1)

* Enables non-atomic validation for peer scoring parameters (#499)

* decouples topic scoring parameters

* adds skiping atomic validation for topic parameters

* cleans up

* adds skip atomic validation to peer score threshold

* adds skip atomic validation for peer parameters

* adds test for non-atomic validation

* adds tests for peer score

* adds tests for peer score thresholds

* refactors tests

* chore: Update .github/workflows/stale.yml [skip ci]

* adds with gossipsub tracker

Co-authored-by: libp2p-mgmt-read-write[bot] <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com>

* decouples options

* fixes conflict

* reverts back module

* fixes peer score helper

* Adds send control message to gossipsub router (#2)

* adjusts libp2p version (#3)

* Update go.mod (#4)

* adds app specific rpc handler

* Create ci.yml (#5)

* Create Makefile (#7)

* Revert "Merge branch 'yahya/gossipsub-router-interface'" (#6)

This reverts commit 1c91995b7fbce0e4b9c5990c5bfda0d555267182.

* Update ci.yml (#9)

* Revert "Merge branch 'master' into yahya/adds-rpc-inspector"

This reverts commit 352d7471c58580480b7f6592001bc3e9b910fa77.

* Revert "Merge remote-tracking branch 'origin/yahya/adds-rpc-inspector' into yahya/adds-rpc-inspector"

This reverts commit 586c5cb6eb2a971a1590ea32050de139316984d2.

* Revert "Merge branch 'master' into yahya/adds-rpc-inspector"

This reverts commit 2e13ee8b95dded5a3401dd86f952fae3419bd86b.

* moves app specific inspector to pubsub

* removes option from gossipsub

* moves app specific rpc inspector up

* refactors app specific to return an error

Co-authored-by: libp2p-mgmt-read-write[bot] <104492852+libp2p-mgmt-read-write[bot]@users.noreply.github.com>
2022-12-01 08:10:07 +02:00
Marten Seemann
4f56e8f0a7
update go-libp2p to v0.22.0 (#498)
* update go-libp2p to v0.22.0

* skip TestGossipsubConnTagMessageDeliveries
2022-08-26 02:45:41 -07:00
vyzo
60cf380032
fix handling of dead peers (#492)
* fix handling of dead peers

* remove unnecessary continue
2022-07-01 19:37:38 +03:00
Hlib Kanunnikov
96efa27a1a
feat: WithLocalPublication option to enable local only publishing on a topic (#481)
* feat: WithLocalPublication option to enable local only publishing on a topic

* docs: improve comment on WithLocalPublication option
2022-07-01 18:49:12 +03:00
Yahya Hassanzadeh
06b5ba4763
Adds exponential backoff to re-spawing new streams for supposedly dead peers (#483)
* updates gitignore

* implements draft solution

* consolidates update and get

* extends test

* adds cleaner logic

* removes a redundant else case

* refactors cleanup in a goroutine

* adds a jitter to backoff

* stretches the sleep for cleanup

* reduces jitter time

* fixes a test

* adds maximum backoff attempts

* returns error for closing channel

* refactors peer status exceed backoff threshold

* converts if-else to switch

* nit

* consolidates update and maximum backoff check

* bug fix

* nit

* refactors cleanup with a ticker object
2022-05-30 19:47:08 +03:00
protolambda
566fdfa6fc fix unused GossipSubHistoryGossip, make seenMessages ttl configurable, make score params SeenMsgTTL configurable 2022-05-24 22:20:42 +03:00
Wondertan
fed393e39d chore: better name 2022-01-23 09:29:32 +02:00
Wondertan
fcbbfd8131 feat: detach WithMsgIdFunction 2022-01-23 09:29:32 +02:00
Wondertan
ec5e9b42a9 chore: go fmt and return timecache named import 2022-01-23 09:29:32 +02:00
Wondertan
6035642336 feat: new WithMsgIdFunction topic option to enable topics to have own msg id generation rules 2022-01-23 09:29:32 +02:00
Wondertan
0e687f24a6 feat: integrate msgIdGenerator 2022-01-23 09:29:32 +02:00
Wondertan
957fc4f80c feat: introduce msgIdGenerator and add ID field to Message wrapper 2022-01-23 09:29:32 +02:00
Simon Zhu
7ef0669764
remove peer filter check from subscriptions (#453) 2021-09-22 10:46:09 +03:00
Simon Zhu
628353661b Create peer filter option 2021-09-21 13:50:09 +03:00
Richard Ramos
37d36d77b1 fix: code review 2021-07-30 16:57:34 +03:00
Richard Ramos
faffd2a0bd add support for custom protocol matching function 2021-07-30 16:57:34 +03:00
Ian Davis
37ebe34352 Revert noisy newline changes 2021-07-19 15:48:58 +03:00
Ian Davis
079d8973a6 fix: avoid panic when peer is blacklisted after connection 2021-07-19 15:48:58 +03:00
vyzo
3b98004eed release priority locks early when handling batches 2021-07-14 00:43:52 +03:00
vyzo
b289ec5017 batch process dead peer notifications 2021-07-14 00:43:52 +03:00
vyzo
9d86090f42 use a priority lock instead of a semaphore
so that there is no case of infinite accumulation of pending peers in the queue.
also adds a connectedness check before adding the peer.
2021-07-14 00:43:52 +03:00
vyzo
ac4a401fd6 use a semaphore for new peer notifications so that we don't block the event loop 2021-07-14 00:43:52 +03:00
vyzo
1f8e231861 don't accumulate pending goroutines from new connections 2021-07-14 00:43:52 +03:00
Michael Muré
65f48fb2c8 rename RawTracer's DroppedInSubscribe into UndeliverableMessage 2021-07-13 08:58:00 -07:00
Michael Muré
9be1c593c6 add a new RawTracer event to track messages dropped in Subscribe 2021-07-13 08:58:00 -07:00
Michael Muré
3c7689d482 add an option to configure the Subscription output queue length 2021-07-13 08:58:00 -07:00
Michael Muré
c02d4c7179 fix some comments 2021-07-13 08:58:00 -07:00
Steven Allen
6195a09441
fix: remove deprecated and never used topic descriptors (#423)
fixes #264
2021-05-11 12:55:14 -07:00
vyzo
7a3d0ca396 demote log spam to debug 2021-04-01 19:31:07 +03:00
vyzo
84302e9633 rename checkSignature to checkSigningPolicy 2021-03-31 17:53:46 +03:00
vyzo
005ac1598c implement synchronous validation for locally published messages
So that locally published messages are never dropped because of full
validation queues.
2021-03-31 17:53:46 +03:00
vyzo
5457a2845b expose internalTracer as RawTracer 2021-03-16 08:28:02 +02:00
vyzo
05c505ef60 export rejection named string constants 2021-03-16 08:28:02 +02:00
vyzo
8676a0e25b deduplicate inbound streams 2021-01-12 17:18:00 +02:00