29 Commits

Author SHA1 Message Date
Dat Duong
ab876fc71c
fix: Select ctx.Done() when preprocessing to avoid blocking on cancel (#635)
Close #636 

The PR updates the send logic to use a select with ctx.Done() and
t.p.ctx.Done(), ensuring the operation terminates gracefully. A test
case reproducing the issue is included in the PR for verification.
2025-08-21 17:01:05 -07:00
Marco Munizaga
e38c340f93
Fix race when calling Preprocess and msg ID generator(#627)
Closes #624
2025-07-03 11:10:37 -07:00
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
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
Hlib Kanunnikov
68726389f2
feat: WithValidatorData publishing option (#603)
Micro optimization that helps preventing deserialization of published
messages in local subscribtions
2025-03-13 12:59:39 +02:00
Viacheslav
972f19967f
chore: ignore signing keys during WithLocalPublication publishing (#497) 2022-11-20 16:30:53 +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
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
Iulian Pascalau
0ea9140c95
Publishing option for signing a message with a custom private key (#486)
* - added PublishWithSk functionality on the Topic implementation

* - fixes after merge

* - complete refactor: used publishing options instead of a new function

* - added one more check in unit test

* - bugfix: use local variables instead of fields

* - renamed tests
2022-05-26 12:39:30 +03:00
Wondertan
957fc4f80c feat: introduce msgIdGenerator and add ID field to Message wrapper 2022-01-23 09:29:32 +02:00
Daniel Martí
5c90105738 support MinTopicSize without a discovery mechanism
That is, when MinTopicSize is used but not WithDiscovery,
Publish will keep waiting until MinTopicSize's condition is met.

At the moment, this is done by polling every 200ms.
In the future, the mechanism could be optimized to be event-based.
A TODO is left for that purpose.

Fixes #454.
2021-10-29 20:55:01 +03: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
vyzo
175d43f4e7 rename validation.Publish to PushLocal 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
d6c20b59fc remove multi-topic message support 2020-10-08 20:18:21 +03:00
vyzo
c82d664e8f prettify things 2020-09-09 16:57:36 +03:00
vyzo
5d06aa2d4f add api for dynamically setting and resetting topic score parameters 2020-09-09 16:57:36 +03:00
Louis Thibault
c5ece1d0c7 Add String() method to Topic. 2020-08-11 14:25:09 +03:00
Diederik Loerakker
99507107b6
Merge pull request #359 from protolambda/optional-sig-origin-seq
Signing policy + optional Signature, From and Seqno
2020-07-23 08:47:47 +03:00
Lukasz Zimnoch
af44f7a07d Topic relay cancelling
Implemented relay reference
cancel logic.
2020-05-01 12:22:22 +03:00
Lukasz Zimnoch
750cc66336 Topic relay support
Implemented Relay method which
allows to enable message relaying
for the given topic.
2020-05-01 12:22:22 +03:00
vyzo
8b423348a0 add ValidatorData field to Message
Useful for passing data from the validation to the application.
2019-11-15 20:16:58 +02:00
Adin Schmahmann
686c928d4e pubsub and topic methods now return error if the pubsub context has been cancelled instead of hanging 2019-11-04 03:52:39 -05:00
Adin Schmahmann
ad97d9bf17 fixed closed Topic handles still being able to perform some actions on the topic 2019-11-02 19:28:44 -04:00
Adin Schmahmann
899f9cd62b fixed Topic close error 2019-11-01 17:12:23 -04:00
Adin Schmahmann
f9c26c2e68 Added libp2p discovery capabilities to PubSub.
When the WithDiscovery option is passed to PubSub then PubSub will be able to search for more peers that are interested in our topics.

This includes the ability for Publishes (via Topic.Publish()) to block until the router is ready to publish. When a router is ready is currently defined by a combination of a user defined MinTopicSize function (passed into topic.Publish via the WithReadiness publish option) and the properties of the pubsub router used. The discovery tests show example usage.
2019-10-31 16:39:18 -04:00
Adin Schmahmann
5ef7439d71 interface: New Topic + TopicEventHandlers objects.
Added PubSub.Join(topic) that returns a Topic object. This object can be Subscribed and Published to as well as to get a TopicEventHandler for topic events. This means that the Subscription object will no longer handle PeerEvents and that PubSub's Publish and Subscribe functions are deprecated.
2019-10-31 15:37:44 -04:00