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

Note on valid Snowflake range #3745

Closed
wants to merge 2 commits into from
Closed

Note on valid Snowflake range #3745

wants to merge 2 commits into from

Conversation

lukellmann
Copy link
Contributor

See #3733

@7596ff
Copy link
Contributor

7596ff commented Aug 30, 2021

If a snowflake can't be zero, this note should reflect that

@Mehgugs
Copy link
Contributor

Mehgugs commented Aug 30, 2021

sure it can

@lukellmann
Copy link
Contributor Author

0 is valid and won't give you errors

@@ -108,7 +108,7 @@ All HTTP-layer services and protocols (e.g. HTTP, WebSocket) within the Discord

## Snowflakes

Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding.
Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding. Note that Discords only accepts and returns snowflakes in the range from `0` to `9223372036854775807` (both inclusive), these are all values a 63 bit unsigned integer could hold.
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
Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding. Note that Discords only accepts and returns snowflakes in the range from `0` to `9223372036854775807` (both inclusive), these are all values a 63 bit unsigned integer could hold.
Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size, they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding. Currently the largest snowflake Discord will accept is `9223372036854775807` but this may change in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

The earlier reference to "uint64" should be removed. Referencing "63 bits" is just confusing and not necessary, and clashes with earlier wording.

Copy link
Contributor Author

@lukellmann lukellmann Aug 30, 2021

Choose a reason for hiding this comment

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

I think it should also include 0 as the smallest.

Suggested change
Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding. Note that Discords only accepts and returns snowflakes in the range from `0` to `9223372036854775807` (both inclusive), these are all values a 63 bit unsigned integer could hold.
Discord utilizes Twitter's [snowflake](https://github.com/twitter/snowflake/tree/snowflake-2010) format for uniquely identifiable descriptors (IDs). These IDs are guaranteed to be unique across all of Discord, except in some unique scenarios in which child objects share their parent's ID. Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API to prevent integer overflows in some languages. See [Gateway ETF/JSON](#DOCS_TOPICS_GATEWAY/etfjson) for more information regarding Gateway encoding. Currently the smallest snowflake Discord will accept is `0` and the largest is `9223372036854775807` but this may change in the future.

@SinisterRectus
Copy link
Contributor

How about removing references to the int size and just document the acceptable range as seen by users?

@lukellmann
Copy link
Contributor Author

Thanks for your suggestions!

Copy link
Contributor

@Mehgugs Mehgugs left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

Copy link
Contributor

@Lulalaby Lulalaby left a comment

Choose a reason for hiding this comment

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

LGTM

@lukellmann
Copy link
Contributor Author

Any updates on this?

@msciotti
Copy link
Contributor

msciotti commented Sep 8, 2021

This is technically correct, but doesn't seem necessary to document? It will be about 140 years before we create any snowflakes that reach anything near the upper limit, so it's not like you are ever going to receive a snowflake that large and need to know how to handle it.

This seems like an edge that's only really hit if you're trying to do so, not in the "normal course of operations". This can be reopened if there's a real need to document it, but I'm not sure there is.

@msciotti msciotti closed this Sep 8, 2021
@lukellmann
Copy link
Contributor Author

lukellmann commented Sep 8, 2021

If you want to provide some max Snowflake constant in your Library that is actually valid, this would be useful. (Used for "get me everything" in pagination.)

@msciotti
Copy link
Contributor

msciotti commented Sep 8, 2021

Yes, but that max snowflake constant is not a necessary thing to have. Snowflakes are generated by Discord; you aren't going to receive ones that are currently out of bounds.

More so, if we decide to change database infra and can then support larger snowflakes, this would be incorrect (though still not really useful).

I'm not doubting the validity of the information, but I think it's unnecessary complexity.

@SinisterRectus
Copy link
Contributor

Snowflakes are generated by Discord; you aren't going to receive ones that are currently out of bounds.

Snowflakes can be generated by users. For example, the after/before/around value in a message pagination does not have to be the exact snowflake of a message; it can be synthesized to represent a date and time. The lower bound may be useful for getting the first message in a channel (or you can use the channel ID) and the upper bound may be useful for getting the last message in a channel (or you can use a synthetic snowflake for the current date and time). And even if you don't generate your own snowflake, shouldn't the fact that there is a bound be sufficient to document it? Why should it matter that it's not practically reachable?

about 140 years

Trivial, but 9223372036854775807 corresponds to 2084 while 18446744073709551615 is 2154. This conflation is exactly what should be clarified.

@devsnek
Copy link
Contributor

devsnek commented Sep 8, 2021

you can use last_message_id for the last message in a channel, and the channel id for the first message in a channel.

@lukellmann
Copy link
Contributor Author

lukellmann commented Sep 8, 2021

More so, if we decide to change database infra and can then support larger snowflakes, this would be incorrect (though still not really useful).

Then it would only take one little change to make it correct again.

@SinisterRectus
Copy link
Contributor

you can use last_message_id for the last message in a channel

You have to track messages to know the last id, so you would have the last message anyway, if you cached it, and if you even tracked messages. Some users may not do that.

the channel id for the first message in a channel

And yes I listed this.

That's not the point, though. I'm just giving an example of where users input snowflakes instead of receive them.

@lukellmann
Copy link
Contributor Author

you can use last_message_id for the last message in a channel

This will change over time, right? So you would need to keep it up to date.

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.

7 participants