-
Notifications
You must be signed in to change notification settings - Fork 78
feat: supporting meta field in store #2609
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
Changes from 13 commits
e2e392d
8b92f78
3ebda6a
b428ded
f089981
87f63f5
f32228e
f60ec3e
d39fc9e
2434f81
bc2dc8d
2dfd913
a1e2110
45a35e7
89124a8
5839555
00c2a67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| const ContentScriptVersion_4* = | ||
| """ | ||
| ALTER TABLE IF EXISTS messages_backup RENAME TO messages; | ||
| ALTER TABLE messages RENAME TO messages_backup; | ||
| ALTER TABLE messages_backup DROP CONSTRAINT messageIndex; | ||
| 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, | ||
| meta VARCHAR, | ||
| CONSTRAINT messageIndex PRIMARY KEY (messageHash, storedAt) | ||
| ) PARTITION BY RANGE (storedAt); | ||
| DO $$ | ||
| DECLARE | ||
| min_storedAt numeric; | ||
| max_storedAt numeric; | ||
| min_storedAtSeconds integer = 0; | ||
| max_storedAtSeconds integer = 0; | ||
| partition_name TEXT; | ||
| create_partition_stmt TEXT; | ||
| BEGIN | ||
| SELECT MIN(storedAt) into min_storedAt | ||
| FROM messages_backup; | ||
| SELECT MAX(storedAt) into max_storedAt | ||
| FROM messages_backup; | ||
| min_storedAtSeconds := min_storedAt / 1000000000; | ||
| max_storedAtSeconds := max_storedAt / 1000000000; | ||
| partition_name := 'messages_' || min_storedAtSeconds || '_' || max_storedAtSeconds; | ||
| create_partition_stmt := 'CREATE TABLE ' || partition_name || | ||
| ' PARTITION OF messages FOR VALUES FROM (' || | ||
| min_storedAt || ') TO (' || (max_storedAt + 1) || ')'; | ||
| IF min_storedAtSeconds > 0 AND max_storedAtSeconds > 0 THEN | ||
| EXECUTE create_partition_stmt USING partition_name, min_storedAt, max_storedAt; | ||
| END IF; | ||
| END $$; | ||
| INSERT INTO messages ( | ||
| pubsubTopic, | ||
| contentTopic, | ||
| payload, | ||
| version, | ||
| timestamp, | ||
| id, | ||
| messageHash, | ||
| storedAt | ||
| ) | ||
| SELECT pubsubTopic, | ||
| contentTopic, | ||
| payload, | ||
| version, | ||
| timestamp, | ||
| id, | ||
| messageHash, | ||
| storedAt | ||
| FROM messages_backup; | ||
| DROP TABLE messages_backup; | ||
| UPDATE version SET version = 4 WHERE version = 3; | ||
| """ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ proc msgHash*(pubSubTopic: string, msg: WakuMessage): array[32, byte] = | |
| ctx.update(msg.payload) | ||
| ctx.update(msg.contentTopic.toBytes()) | ||
| ctx.update(msg.timestamp.uint64.toBytes(Endianness.littleEndian)) | ||
| # ctx.update(msg.meta) meta is not included in the message hash, as the signature goes in the meta field | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment addresses the doubt if meta field should be included in the hash.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion there's no need to add
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm referring to the signed validators feature. In order to validate a message, looks like it expects the message hash to be signed and the signature to be attached to the WakuMessage's
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then yes indeed you can't add
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that the hash for the signed validator feature is an application-level message hash. It is different from the internal Waku Message hash. |
||
| ctx.update( | ||
| if msg.ephemeral: | ||
| @[1.byte] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the impression that it would be possible to just change the partitioned-table schema and that will automatically reflect that change in the current existing partitions. If that is the case, I think we can simplify the migration logic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it without the partition part (45a35e7) but the migration failed :/
So for now I think it's better to leave it this way