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

fix: store v3 validate cursor & remove messages #2636

Merged
merged 9 commits into from
May 1, 2024
Merged

Conversation

SionoiS
Copy link
Contributor

@SionoiS SionoiS commented Apr 26, 2024

Fixes #2635 and #2634

@SionoiS SionoiS self-assigned this Apr 26, 2024
@SionoiS SionoiS requested a review from richard-ramos April 26, 2024 12:06
@SionoiS SionoiS changed the title fix(store) validate cursor & remove messages fix: store v3 validate cursor & remove messages Apr 26, 2024
Copy link

github-actions bot commented Apr 26, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2636-rln-v2

Built from 6f4da99

Copy link

github-actions bot commented Apr 26, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2636-rln-v1

Built from 6f4da99

Copy link
Member

@richard-ramos richard-ramos left a comment

Choose a reason for hiding this comment

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

For a message that exists in the DB, the response is incorrect. It should have included a WakuMessageKeyValue with just the message hash.

REQUEST
{"request_id":"d4b573abb709d067da8afca3ec7341a8fbebee09923b4ade414e6b510bb6e24f","include_data": false, "message_hashes":["PmqobzCu78df5nprhzOUUu0e6pCFcOACjQpJistzVKM="],"pagination_forward":true,"pagination_limit":20}

RESPONSE
{"request_id":"d4b573abb709d067da8afca3ec7341a8fbebee09923b4ade414e6b510bb6e24f","status_code":200,"status_desc":"OK"}

If I change the include_data attribute to true, the response returns as expected (hash + message)

@richard-ramos
Copy link
Member

What should happen if I send a request with a valid cursor that does not exist? i.e. 0x0000000000000000000000000000000000000000000000000000000000000000:


{"request_id":"ec560c592484291ca6dfa1491507a45dba55b238c2b271cf0cb81ce1e0590fce","include_data":true,"pubsub_topic":"/waku/2/default-waku/proto","content_topics":["test"],"time_start":1714155079182460704,"time_end":1714155079285053447,"pagination_cursor":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","pagination_forward":true,"pagination_limit":20}

Currently it is returning all the records but it seems to me that this behavior is not valid, and perhaps it should return either no results, or an invalid_cursor error. I think we should do the later, and probably do a SELECT EXISTS(SELECT 1 FROM messages WHERE message_hash=?) to determine if the cursor is valid. Since the message_hash is the primary key of the table I imagine this should execute fast with no major impact on the total store query response time

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.

@SionoiS
Copy link
Contributor Author

SionoiS commented Apr 29, 2024

Currently it is returning all the records but it seems to me that this behavior is not valid, and perhaps it should return either no results, or an invalid_cursor error. I think we should do the later, and probably do a SELECT EXISTS(SELECT 1 FROM messages WHERE message_hash=?) to determine if the cursor is valid. Since the message_hash is the primary key of the table I imagine this should execute fast with no major impact on the total store query response time

Seams like the old code never validated the cursor, it's only used to order the results. I agree that we should do it though.

@richard-ramos
Copy link
Member

richard-ramos commented Apr 30, 2024

Seams like the old code never validated the cursor

I see! It can be done later in a separate PR then. Will open an issue so we don't lose track of this :)
I just tested this PR with my set of tests in go-waku and works fine!

--
EDIT:
Tracking issue in here #2653

@SionoiS SionoiS requested a review from Ivansete-status April 30, 2024 12:46
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!
Just added some comments that I hope you find useful

waku/waku_store/protocol.nim Outdated Show resolved Hide resolved
waku/waku_store/rpc_codec.nim Outdated Show resolved Hide resolved
@@ -377,7 +377,7 @@ proc getMessagesV2ArbitraryQuery(
endTime = none(Timestamp),
maxPageSize = DefaultPageSize,
ascendingOrder = true,
): Future[ArchiveDriverResult[seq[ArchiveRow]]] {.async.} =
): Future[ArchiveDriverResult[seq[ArchiveRow]]] {.async, deprecated.} =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not saying that is incorrect to label those procs as deprecated but how we should handle those? Do they still work/compile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed it would only be a visual thing but I can't find any documentation so 🤷 They do compile/work though.

waku/waku_archive/common.nim Outdated Show resolved Hide resolved
waku/waku_archive/archive.nim Outdated Show resolved Hide resolved
tests/wakunode_rest/test_rest_store.nim Outdated Show resolved Hide resolved
@SionoiS SionoiS merged commit e03d116 into master May 1, 2024
13 of 15 checks passed
@SionoiS SionoiS deleted the fix--store-v3-issues branch May 1, 2024 18:47
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: store v3 include data is ignored
3 participants