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: supporting meta field in WakuMessage #2384

Merged
merged 14 commits into from
Feb 14, 2024

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented Jan 29, 2024

Description

The "meta" field is late addition to the Waku Message specification. It is currently supported in go-waku and not in nwaku. We're implementing its support in this PR.

Changes

  • adding meta field to Relay, Filter and Store Waku Messages
  • testing for correct returned fields in all 3 types of messages
  • fixed validator test that timed out early

Issue

closes #2214

Note

We also wanted to avoid responding with an error when an extra field is sent in a POST request.
There seems to be an issue in the nim-json-serialization dependency that throws an exception when this happens. Will report and track the issue to make sure it gets fixed

@gabrielmer gabrielmer changed the title supporting meta field in WakuMessage Supporting meta field in WakuMessage Jan 29, 2024
@gabrielmer gabrielmer changed the title Supporting meta field in WakuMessage feat: supporting meta field in WakuMessage Jan 29, 2024
@gabrielmer gabrielmer self-assigned this Jan 29, 2024
@gabrielmer gabrielmer changed the title feat: supporting meta field in WakuMessage feat: supporting meta field in WakuMessage [in progress] Jan 29, 2024
@gabrielmer gabrielmer changed the title feat: supporting meta field in WakuMessage [in progress] feat: supporting meta field in WakuMessage (in progress) Jan 29, 2024
Copy link

github-actions bot commented Jan 29, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2384

Built from ebbf3f5

@gabrielmer gabrielmer changed the title feat: supporting meta field in WakuMessage (in progress) feat: supporting meta field in WakuMessage (in progress) Jan 29, 2024
@gabrielmer gabrielmer force-pushed the feat-adding-support-for-meta-field-in-rest-api branch from 0401a7f to 02cb4a7 Compare February 6, 2024 14:37
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.

It looks great so far. Good work!
I just added a minor comment

tests/wakunode2/test_validators.nim Outdated Show resolved Hide resolved
@gabrielmer gabrielmer changed the title feat: supporting meta field in WakuMessage (in progress) feat: supporting meta field in WakuMessage Feb 12, 2024
@gabrielmer gabrielmer force-pushed the feat-adding-support-for-meta-field-in-rest-api branch from a822948 to 10d2bf8 Compare February 12, 2024 09:44
@gabrielmer gabrielmer marked this pull request as ready for review February 12, 2024 12:22
Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

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

LGTM!

What happens with the messages in DB do they have meta already but nwaku was discarding the field?

@gabrielmer
Copy link
Contributor Author

LGTM!

What happens with the messages in DB do they have meta already but nwaku was discarding the field?

Great question! So it seems that meta was already defined in the WakuMessage type

type WakuMessage* = object
# Data payload transmitted.
payload*: seq[byte]
# String identifier that can be used for content-based filtering.
contentTopic*: ContentTopic
# Application specific metadata.
meta*: seq[byte]
# Number to discriminate different types of payload encryption.
# Compatibility with Whisper/WakuV1.
version*: uint32
# Sender generated timestamp.
timestamp*: Timestamp
# The ephemeral attribute indicates signifies the transient nature of the
# message (if the message should be stored).
ephemeral*: bool
# Part of RFC 17: https://rfc.vac.dev/spec/17/
# The proof attribute indicates that the message is not spam. This
# attribute will be used in the rln-relay protocol.
proof*: seq[byte]

And this is the one being used in the db

HistoryResponse* = object
messages*: seq[WakuMessage]
cursor*: Option[HistoryCursor]

But apparently the field wasn't getting filled when sending neither relay, filter nor store messages

@SionoiS
Copy link
Contributor

SionoiS commented Feb 12, 2024

But apparently the field wasn't getting filled when sending neither relay, filter nor store messages

Good to know! but...

Let me rephrase my question. Are messages stored in Postgres as blobs? If not, are the messages previously created by nwaku show no value in the DB for that field? Lastly, is this a problem or not?

@gabrielmer
Copy link
Contributor Author

Good to know! but...

Let me rephrase my question. Are messages stored in Postgres as blobs? If not, are the messages previously created by nwaku show no value in the DB for that field? Lastly, is this a problem or not?

Ooh, I think there's actually an issue with that. I think it's not getting saved in the DB at all 😶
It doesn't seem to be in the schema.

proc createTableQuery(): string =
"CREATE TABLE IF NOT EXISTS messages (" &
" pubsubTopic VARCHAR NOT NULL," &
" contentTopic VARCHAR NOT NULL," &
" payload VARCHAR," &
" version INTEGER NOT NULL," &
" timestamp BIGINT NOT NULL," &
" id VARCHAR NOT NULL," &
" messageHash VARCHAR NOT NULL," &
" storedAt BIGINT NOT NULL," &
" CONSTRAINT messageIndex PRIMARY KEY (messageHash)" &
");"

What I don't understand is it working on the Store test then. Don't we use any DB in those tests? @Ivansete-status

@Ivansete-status
Copy link
Collaborator

What I don't understand is it working on the Store test then. Don't we use any DB in those tests? @Ivansete-status

Yup! We use a database in Postgres tests.

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.

LGTM! Thanks!

I think we can merge this PR, stating clearly that is missing the proper storage of this field, and submit another PR in the future where we start storing the meta field in the database.

@gabrielmer
Copy link
Contributor Author

Yup! We use a database in Postgres tests.

So in https://github.com/waku-org/nwaku/blob/0dac9f9dd49e2047f3988f4cf0332712028efd0e/tests/wakunode_rest/test_rest_store.nim, are store messages saved in memory?

If so, is it done different in a way only for testing? There's something I don't quite understand - I thought store messages were always retrieved from a db

@Ivansete-status
Copy link
Collaborator

So in https://github.com/waku-org/nwaku/blob/0dac9f9dd49e2047f3988f4cf0332712028efd0e/tests/wakunode_rest/test_rest_store.nim, are store messages saved in memory?

Yes, this particular test module stores messages in memory.


If so, is it done different in a way only for testing? There's something I don't quite understand - I thought store messages were always retrieved from a db

That represents a test gap that should be filled with a test_rest_store_postgres.nim module.

These are the test modules that interact with a local Postgres database:
https://github.com/waku-org/nwaku/blob/master/tests/waku_archive/test_driver_postgres_query.nim
https://github.com/waku-org/nwaku/blob/master/tests/waku_archive/test_driver_postgres.nim
... and notice that these are compiled in the following location:

defined(postgres):
import
./waku_archive/test_driver_postgres_query, ./waku_archive/test_driver_postgres

@gabrielmer
Copy link
Contributor Author

I think we can merge this PR, stating clearly that is missing the proper storage of this field, and submit another PR in the future where we start storing the meta field in the database.

Super, sounds good! Will merge it and implement in a different PR support for db storage of the meta field :)

@gabrielmer gabrielmer merged commit 3903f13 into master Feb 14, 2024
9 of 10 checks passed
@gabrielmer gabrielmer deleted the feat-adding-support-for-meta-field-in-rest-api branch February 14, 2024 15:30
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.

bug: relay publish fails with 400 Bad Request when message contains meta field
3 participants