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: messageHash attaribute added in SQLite + migration script ready #2159

Closed
wants to merge 3 commits into from

Conversation

ABresting
Copy link
Contributor

@ABresting ABresting commented Oct 25, 2023

Description

messageHash attribute added to SQLite, which removes the id attribute. An associated test case also added. A migration script also added.

Also also unifies the use of computeDigest as per the RFC. Since it was inconsistent with the remaining code. All the instances of id attribute replaced by messageHash which includes data types, testcases and library code.

It has to be done using a single PR to avoid adding another migration script to remove the legacy id attribute related code.
Wherever possible digest is replaced by messageHash for uniformity.

Adding folks from goWaku and jsWaku as well since this PR also modifies the nodeRestAPIs and some associated types.

Changes

  • id attribute replaced by messageHash
  • id/messageHash computation made uniform protocol wide.
  • all instances of id attribute replaced by messageHash
  • migration script added for id to messageHash replacement
  • primary key of SQLite updated

Issue

#2112

@ABresting ABresting self-assigned this Oct 25, 2023
@ABresting ABresting added the release-notes Issue/PR needs to be evaluated for inclusion in release notes highlights or upgrade instructions label Oct 25, 2023
@github-actions
Copy link

This PR may contain changes to database schema of one of the drivers.

If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues.

Please make sure the label release-notes is added to make sure upgrade instructions properly highlight this change.

@github-actions
Copy link

github-actions bot commented Oct 25, 2023

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2159

Built from 9644a6c

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's getting a good shape indeed!
I added a few comments that we need to resolve.
Especially interesting is the one around the "version 7" issue, where we should emphasize the upgrade correctness. i.e. we need to make sure the database gets well updated from sqlite files created in version 0.15.0, for example.

tests/waku_store/test_resume.nim Outdated Show resolved Hide resolved
waku/waku_api/rest/store/types.nim Outdated Show resolved Hide resolved
waku/waku_archive/archive.nim Show resolved Hide resolved
waku/waku_archive/driver/sqlite_driver/migrations.nim Outdated Show resolved Hide resolved
waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim Outdated Show resolved Hide resolved
waku/waku_store/common.nim Outdated Show resolved Hide resolved
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.

Apologies that I didn't realize that before but I think it is better to stick to the "digest" concept. Trying to modify so many files to accommodate the name to messageHash isn't great because we would need also to change the Store protocol itself.

Therefore I think it is better to keep using the digest name for that field in the Message database.

@jm-clius - wdyt about naming the new field messageDigest instead of messageHash? I think that would make it more aligned with our current code base. Maybe easier to just rename the "message_hash" to "messageDigest" in https://rfc.vac.dev/spec/14 :)

@@ -48,7 +48,7 @@ proc isSchemaVersion7*(db: SqliteDatabase): DatabaseResult[bool] =
return ok(true)

else:
info "Not considered schema version 7"
info "Not considered schema version 8"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be kept to 7. As a reminder, we will keep that until 0.30.0.

Suggested change
info "Not considered schema version 8"
info "Not considered schema version 7"

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

I think this introduces significant breaking changes. All Store clients operate currently with a view of how the cursors work and should be computed and this will cause queries to fail, afaics.

I don't see the need for introducing breaking changes. The main idea is to make sure that we introduce the authoritative deterministic message hash as set out in RFC 14 (https://rfc.vac.dev/spec/14/#deterministic-message-hashing) and implemented in https://github.com/waku-org/nwaku/blob/master/waku/waku_core/message/digest.nim as a queryable "column" (at least for postgresql, but it probably makes sense in the other archive impls too). To not break backwards compatibility, this should be a new column (I'm happy with messageHash). Since the deterministic message hash is used to populate this column, it MUST be unique and can serve as the (only) primary key. The computeDigest and other functions will indeed eventually be deprecated once we extend the Store protocol itself, but should remain untouched for now.


proc computeDigest*(msg: WakuMessage): MessageDigest =
proc computeDigest*(msg: WakuMessage, pubSubTopic: string): MessageHash =
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be what's used to compute the message hash - this function exists for various historical reasons that I can't fully remember. It must indeed eventually be deprecated, but the authoritative message digest computation is: https://github.com/waku-org/nwaku/blob/master/waku/waku_core/message/digest.nim

Copy link
Contributor

Choose a reason for hiding this comment

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

In other words, changing this function is unnecessarily going to break backwards compatibility. We simply want to add the message digest as defined in the RFC and implemented in https://github.com/waku-org/nwaku/blob/master/waku/waku_core/message/digest.nim as the primary key index column. This will allow us to extend the Store protocol in future to operate on these unique message digests. These will also replace our current cursors, but we'll do so in a way that doesn't break backwards compatbility. IMO for now the existing query behaviour, and especially cursors, shouldn't change as it will be very high-impact, unless I'm missing something?

@ABresting
Copy link
Contributor Author

closing this since as per new research direction, a new PR with targeted scope is drafted.

@ABresting ABresting closed this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Issue/PR needs to be evaluated for inclusion in release notes highlights or upgrade instructions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants