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

feat(sds): send and receive sync messages #2293

Merged
merged 1 commit into from
Mar 13, 2025
Merged

feat(sds): send and receive sync messages #2293

merged 1 commit into from
Mar 13, 2025

Conversation

adklempner
Copy link
Member

@adklempner adklempner commented Mar 4, 2025

Problem / Description

Per the specifications, participants should periodically send sync messages. These are sent with empty content and should not be persisted.

Solution

Adds a public function for sending a sync message in the channel.
Updates other functions to properly handle sync messages (e.g. received messages that are determined to be sync messages are not persisited)

Notes


Checklist

  • Code changes are covered by unit tests.
  • Code changes are covered by e2e tests, if applicable.
  • Dogfooding has been performed, if feasible.
  • A test version has been published, if required.
  • All CI checks pass successfully.

Copy link

github-actions bot commented Mar 5, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 85.21 KB (0%) 1.8 s (0%) 11.5 s (+26.98% 🔺) 13.2 s
Waku Simple Light Node 136.22 KB (0%) 2.8 s (0%) 12.4 s (+18.79% 🔺) 15.1 s
ECIES encryption 22.92 KB (0%) 459 ms (0%) 4.7 s (+62.21% 🔺) 5.2 s
Symmetric encryption 22.35 KB (0%) 447 ms (0%) 4.8 s (+76.61% 🔺) 5.2 s
DNS discovery 70.85 KB (0%) 1.5 s (0%) 10.3 s (+8.69% 🔺) 11.7 s
Peer Exchange discovery 71.85 KB (0%) 1.5 s (0%) 6.8 s (-48.45% 🔽) 8.2 s
Local Peer Cache Discovery 65.36 KB (0%) 1.4 s (0%) 7.8 s (+35.66% 🔺) 9.1 s
Privacy preserving protocols 76.63 KB (0%) 1.6 s (0%) 10.1 s (+14.24% 🔺) 11.6 s
Waku Filter 78.3 KB (0%) 1.6 s (0%) 11.4 s (+1.39% 🔺) 13 s
Waku LightPush 75.75 KB (0%) 1.6 s (0%) 10.5 s (-4.49% 🔽) 12 s
History retrieval protocols 75.87 KB (0%) 1.6 s (0%) 8.6 s (-33.84% 🔽) 10.1 s
Deterministic Message Hashing 7.33 KB (0%) 147 ms (0%) 2.1 s (+50.89% 🔺) 2.3 s

@adklempner adklempner marked this pull request as ready for review March 11, 2025 22:39
@adklempner adklempner requested a review from a team as a code owner March 11, 2025 22:39
};

if (callback) {
return callback(message);
Copy link
Collaborator

@weboko weboko Mar 12, 2025

Choose a reason for hiding this comment

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

is thins callback intended to be used with async operations?
I see it is sync but we don't have any medium of sending message in a sync way.

I might misunderstand something but I believe it is intended to be used like:

node.sds.sendSyncMessage(async () => {
  const resp = await  node.lightPush.send();
  if (resp.success) return true;
  return false;

Copy link
Collaborator

Choose a reason for hiding this comment

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

good point, also curious

another point: this function isnt really "sending", but "preparing" the message, to be sent with lightpush, right?

perhaps doing:

public createSyncMessage(): Message { ... }

const msg = channel.createSyncMessage();
await node.lightPush.send(msg);

or if we want to keep the same API, perhaps:

withSyncMessage(callback)

Copy link
Member Author

@adklempner adklempner Mar 13, 2025

Choose a reason for hiding this comment

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

@weboko good point about async, it should support it. The example you provided is more or less how I intend for the library to be used. Updated in latest commit

@danisharora099 Ideally the library is agnostic towards what the consumer does with the message, and for the case of sync messages it's not as important. But for regular messages I do lean towards the assumption that the callback provided actually sends the message, since it gets added to the outgoing buffer.

It's a good question that deserves more consideration. We can choose to make no assumptions about whether the message was sent, and just get a basic confirmation that the consumer "accepted" it (plus generated and returned a waku message hash for non-sync messages). Then it doesn't matter what kind of retry logic is implemented on the Waku layer (so long as the message hash doesn't change) since the periodic outgoing buffer sweep in SDS will detect that the message was never acknowledged, and then notify the consumer.

Either way, I think it makes sense to stick with the callback pattern, mainly because of the retrieval hint that needs to be returned (see #2299 )

Copy link
Collaborator

@weboko weboko 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 but I don't understand the usage, let's discuss

Copy link
Collaborator

@danisharora099 danisharora099 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 to me! 🚀

};

if (callback) {
return callback(message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

good point, also curious

another point: this function isnt really "sending", but "preparing" the message, to be sent with lightpush, right?

perhaps doing:

public createSyncMessage(): Message { ... }

const msg = channel.createSyncMessage();
await node.lightPush.send(msg);

or if we want to keep the same API, perhaps:

withSyncMessage(callback)


const bloomFilter = getBloomFilter(channelA);
expect(
bloomFilter.lookup(MessageChannel.getMessageId(new Uint8Array()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

the functionality is good, however, here we check if an empty content message ID exists in the filter - perhaps we can fetch an existing message ID like:

expect(bloomFilter.lookup(someRealMessageId)).to.equal(true/false)

@adklempner adklempner merged commit 8db7690 into master Mar 13, 2025
10 of 11 checks passed
@adklempner adklempner deleted the feat/sds-sync branch March 13, 2025 18:52
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.

sds: Implement logic for sending and receiving sync messages
3 participants