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: message.nim - set max message size to 150KiB according to spec #2298

Merged
merged 10 commits into from
Jan 3, 2024

Conversation

Ivansete-status
Copy link
Collaborator

@Ivansete-status Ivansete-status commented Dec 14, 2023

Description

Change to align the actual message limit with the one written in the spec: https://rfc.vac.dev/spec/64/#message-size

Notice that the spect states 150KB but we are setting the maximum to 150KiB because that sounds more aligned with the actual default value defined within nim-libp2p (1024 * 1024)

Issue

closes #2297

Copy link

github-actions bot commented Dec 14, 2023

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2298

Built from b966524

@fryorcraken
Copy link
Collaborator

This needs to be configurable so that the Status fleet can retain the 1MB message size for now (note they already have plans to reduce their message size).

@chaitanyaprem
Copy link
Contributor

chaitanyaprem commented Dec 15, 2023

Shouldn't this sizeCheck also be done at lightpush and respond with error in case message size crosses this limit?
Realized since lightpush message would anyways be sent via relay and hence the check would hit and fail.

Copy link

This PR may contain changes to configuration options of one of the apps.

If you are introducing a breaking change (i.e. the set of options in latest release would no longer be applicable) make sure the original option is preserved with a deprecation note for 2 following releases before it is actually removed.

Please also make sure the label release-notes is added to make sure any changes to the user interface are properly announced in changelog and release notes.

@Ivansete-status
Copy link
Collaborator Author

This needs to be configurable so that the Status fleet can retain the 1MB message size for now (note they already have plans to reduce their message size).

Hey @fryorcraken ! I've added the configurable parameter max-num-bytes-msg-size:

    maxMessageSize* {.
      desc: "Maximum message size in bytes. e.j. to set a 1 MiB, set this to 1048576 (1024*1024)."
      defaultValue: MaxWakuMessageSize
      name: "max-num-bytes-msg-size" }: int

Copy link
Contributor

@gabrielmer gabrielmer 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 so much!

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

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

lgtm. Note that some non TWN deployments would need to be updated.

@fryorcraken
Copy link
Collaborator

This needs to be configurable so that the Status fleet can retain the 1MB message size for now (note they already have plans to reduce their message size).

Hey @fryorcraken ! I've added the configurable parameter max-num-bytes-msg-size:

    maxMessageSize* {.
      desc: "Maximum message size in bytes. e.j. to set a 1 MiB, set this to 1048576 (1024*1024)."
      defaultValue: MaxWakuMessageSize
      name: "max-num-bytes-msg-size" }: int

Thanks for that. How do we ensure that we don't forget to change the config when upgrading Status fleet?

nitpick: could it accept 1MiB as input?

@Ivansete-status
Copy link
Collaborator Author

Thanks for that. How do we ensure that we don't forget to change the config when upgrading Status fleet?

Good point! We've created this issue to tackle that: #2305

nitpick: could it accept 1MiB as input?

I'll check it asap 👌

@Ivansete-status Ivansete-status changed the title chore: message.nim - set max message size to 150KB according to spec chore: message.nim - set max message size to 150KiB according to spec Dec 20, 2023
Ivansete-status added a commit to waku-org/js-waku that referenced this pull request Dec 22, 2023
… adjustment

The "Fails to push message with large meta" test used 10 ** 6 when
`nwaku` node had MaxWakuMessageSize == 1MiB ( 1*2^20 .)

`nwaku` establishes the max lightpush msg size as `const MaxRpcSize* =
MaxWakuMessageSize + 64 * 1024`
see:
https://github.com/waku-org/nwaku/blob/07beea02095035f4f4c234ec2dec1f365e6955b8/waku/waku_lightpush/rpc_codec.nim#L15

In the PR waku-org/nwaku#2298 we reduced the
MaxWakuMessageSize
from 1MiB to 150KiB. Therefore, the 105024 number comes from
substracting ( 1*2^20 - 150*2^10 )
to the original 10^6 that this test had when MaxWakuMessageSize ==
1*2^20
Ivansete-status added a commit to waku-org/js-waku that referenced this pull request Dec 22, 2023
… adjustment

The "Fails to push message with large meta" test used 10 ** 6 when
`nwaku` node had MaxWakuMessageSize == 1MiB ( 1*2^20 .)

`nwaku` establishes the max lightpush msg size as `const MaxRpcSize* =
MaxWakuMessageSize + 64 * 1024`
see:
https://github.com/waku-org/nwaku/blob/07beea02095035f4f4c234ec2dec1f365e6955b8/waku/waku_lightpush/rpc_codec.nim#L15

In the PR waku-org/nwaku#2298 we reduced the
MaxWakuMessageSize
from 1MiB to 150KiB. Therefore, the 105024 number comes from
substracting ( 1*2^20 - 150*2^10 )
to the original 10^6 that this test had when MaxWakuMessageSize ==
1*2^20
Ivansete-status added a commit to waku-org/js-waku that referenced this pull request Dec 22, 2023
… adjustment

The "Fails to push message with large meta" test used 10 ** 6 when
`nwaku` node had MaxWakuMessageSize == 1MiB ( 1*2^20 .)

`nwaku` establishes the max lightpush msg size as `const MaxRpcSize* =
MaxWakuMessageSize + 64 * 1024`
see:
https://github.com/waku-org/nwaku/blob/07beea02095035f4f4c234ec2dec1f365e6955b8/waku/waku_lightpush/rpc_codec.nim#L15

In the PR waku-org/nwaku#2298 we reduced the
MaxWakuMessageSize
from 1MiB to 150KiB. Therefore, the 105024 number comes from
substracting ( 1*2^20 - 150*2^10 )
to the original 10^6 that this test had when MaxWakuMessageSize ==
1*2^20
Copy link
Contributor

@AlejandroCabeza AlejandroCabeza left a comment

Choose a reason for hiding this comment

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

LGTM!

msg6 = fakeWakuMessage(contentTopic=contentTopic, payload=getByteSequence(3*1024*1024 + 1023*1024 + 970)) # 4MiB - 54B -> Out of Max Size
msg4 = fakeWakuMessage(contentTopic=contentTopic, payload=getByteSequence(MaxRpcSize - 1024)) # Max Size (Inclusive Limit)
msg5 = fakeWakuMessage(contentTopic=contentTopic, payload=getByteSequence(MaxRpcSize)) # Max Size (Exclusive Limit)
msg6 = fakeWakuMessage(contentTopic=contentTopic, payload=getByteSequence(MaxRpcSize)) # Out of Max Size
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is duplicated

## https://rfc.vac.dev/spec/64/#message-size
MaxWakuMessageSize* = 150 * 1024 # Remember that 1 MiB is the PubSub default

DefaultMaxWakuMessageSizeStr* = "150KiB"
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't have two sources of truth (MaxWakuMessageSize and DefaultMaxWakuMessageSizeStr). How about we use the str one as source of truth, and define the other in terms of it by calling parseMsgSize(DefaultMaxWakuMessageSizeStr)?

@Ivansete-status
Copy link
Collaborator Author

I can't quite understand why the js-waku test is failing.
I run it locally and seems to work.
command: WAKUNODE_IMAGE=quay.io/wakuorg/nwaku-pr:2298 DEBUG=waku* npm run test:node
results:
image

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

LGTM apart two little comment you may consider. Thank you.

## Parses size strings such as "1.2 KiB" or "3Kb" and returns the equivalent number of bytes
## if the parse task goes well. If not, it returns an error describing the problem.

const RegexDef = """\s*(\d+([\,\.]\d*)?)\s*([Kk]{0,1}[i]?[Bb]{1})"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not pretty sure if it would not be suitable to apply a more restrictive pattern?
Like is someone mistakenly use it "1o24 KiB" it still accepts but results in 241024. Or "l50kb" is translated to 501000. I would clearly drop trailing white space or put it under a group that should be empty at the end.
Also I may change the middle whitespace to accept zero or only 1 of it.


const
## https://rfc.vac.dev/spec/64/#message-size
DefaultMaxWakuMessageSizeStr* = "150KiB" # Remember that 1 MiB is the PubSub default
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DefaultMaxWakuMessageSizeStr* = "150KiB" # Remember that 1 MiB is the PubSub default
DefaultMaxWakuMessageSizeStr* = "150KiB" # Remember that 1024 KiB is the PubSub default

As MiB is not supported we might not refer it anywhere.

@fryorcraken
Copy link
Collaborator

I can't quite understand why the js-waku test is failing. I run it locally and seems to work. command: WAKUNODE_IMAGE=quay.io/wakuorg/nwaku-pr:2298 DEBUG=waku* npm run test:node results: image

We have some test with 1MB messages. Pretty sure @fbarbu15 or the @waku-org/js-waku-developers is already on it.

@fbarbu15
Copy link
Contributor

fbarbu15 commented Jan 3, 2024

WAKUNODE_IMAGE=quay.io/wakuorg/nwaku-pr:2298 DEBUG=waku* npm run test:node

In

I can't quite understand why the js-waku test is failing. I run it locally and seems to work. command: WAKUNODE_IMAGE=quay.io/wakuorg/nwaku-pr:2298 DEBUG=waku* npm run test:node results: image

We have some test with 1MB messages. Pretty sure @fbarbu15 or the @waku-org/js-waku-developers is already on it.

Indeed as @fryorcraken suggested, some 1MB tests are failing with quay.io/wakuorg/nwaku-pr:2298 but on interop test side (will update those).
On js-waku side, we have 1MB tests but they do not fail probably because js-waku node is doing the sending. The job was failing because of an unrelated test that is passing now on re-run and the job is green cc @Ivansete-status

@Ivansete-status Ivansete-status merged commit ed09074 into master Jan 3, 2024
10 checks passed
@Ivansete-status Ivansete-status deleted the set-max-size-to-150kb-as-spec branch January 3, 2024 12:11
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.

feat: set max message size to 150kB as per spec
9 participants