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: sending msg hash as string on libwaku message event #3234

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented Jan 8, 2025

Description

As previously discussed, it makes more sense for application clients to use message hashes as hex strings instead of a string representation of a byte array.

In this PR, we're modifying the usage of message hashes in libwaku and in the REST API to receive and return the message hashes as hex strings. This change only applies for the interactions with the message hashes and with pagination cursors (which are themselves message hashes). Everything else remains untouched and other fields such as payload and meta are still sent as base64 strings.

Changes

  • creating WakuMessageKeyValueHex and StoreQueryResponseHex types to be used when interacting with application clients
  • returning message hashes in libwaku's JsonMessageEvent and waku_store_query as hex strings
  • returning message hashes in Store REST API as hex strings
  • updating tests

A PR updating the REST API's docs will be opened once this PR is merged. Or shall we define a new endpoint for backward compatibility? Another option is to accept both byte arrays and hex strings in the API and check in the endpoint which one it is

Issue

#3076

@gabrielmer gabrielmer requested review from richard-ramos and Ivansete-status and removed request for richard-ramos January 8, 2025 17:51
Copy link

github-actions bot commented Jan 8, 2025

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3234

Built from 9fda9e4

@Ivansete-status
Copy link
Collaborator

@gabrielmer - ah, sorry but I can't approve that one now, unless you convince me hehe. I think is fine passing the msg_hash as byte array because is more efficient than dealing with string. On the other hand, the host code (Go, Rust, etc) should easily show the msg_hash representation in a readable format. Let me know if that causes a big trouble somewhere :)

@gabrielmer
Copy link
Contributor Author

gabrielmer commented Jan 9, 2025

@gabrielmer - ah, sorry but I can't approve that one now, unless you convince me hehe. I think is fine passing the msg_hash as byte array because is more efficient than dealing with string. On the other hand, the host code (Go, Rust, etc) should easily show the msg_hash representation in a readable format. Let me know if that causes a big trouble somewhere :)

Well, I don't know if I can convince you about the change itself, but at least I might be able to convince you that the opposite is true of what you mentioned - dealing with a string is more efficient than dealing with the byte array lol.

If you see, the events are not serialized and deserialized, they are sent as a json-string:

proc onReceivedMessage(ctx: ptr WakuContext): WakuRelayHandler =
return proc(pubsubTopic: PubsubTopic, msg: WakuMessage) {.async.} =
callEventCallback(ctx, "onReceivedMessage"):
$JsonMessageEvent.new(pubsubTopic, msg)

In other words, when we send that byte-array, we are sending the string representation of a byte array, not the bytes directly.

The host has to then parse that string, convert it to an actual byte array and then convert it to the string representation of the hash. It's both less efficient and it adds extra/unnecessary work from the host's code to have to parse the string representation of a byte array

@Ivansete-status
Copy link
Collaborator

@gabrielmer - you are absolutely right my friend. I think I'm starting to get convinced ;P

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

Approving after the agreement to focus on retrieving all the information from libwaku in the most readable format, by default :)

@gabrielmer
Copy link
Contributor Author

Moving this PR back to draft, will reopen it for review once the hex string format is used all across libwaku and REST

@gabrielmer gabrielmer marked this pull request as draft January 10, 2025 14:00
@gabrielmer gabrielmer force-pushed the chore-send-wakumsg-hash-string-in-libwaku-event branch from 90658a6 to 79a69a7 Compare January 15, 2025 16:02
@gabrielmer gabrielmer force-pushed the chore-send-wakumsg-hash-string-in-libwaku-event branch from 6ac0948 to e0e9f18 Compare January 16, 2025 15:12
@gabrielmer gabrielmer marked this pull request as ready for review January 16, 2025 19:18
@@ -59,7 +59,7 @@ proc `%`*(value: Base64String): JsonNode =

type JsonMessageEvent* = ref object of JsonEvent
pubsubTopic*: string
messageHash*: WakuMessageHash
messageHash*: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's better to define a WakuMessageHashHex or HexString type and use it instead of just string?

LMK if it makes sense and if it adds value

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.

3 participants