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

rpc: unify all ledger sequence types to uint32 and stop stringyfying integers < 53-bits wide #1097

Merged
merged 5 commits into from
Nov 28, 2023

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Nov 23, 2023

What

Closes #1081

Why

Consistent is good plus it's cleaner to not stringify fields we don't need to (since they can be treated by javascript).

Known limitations

Downstream tickets are needed.

@2opremio 2opremio requested a review from Shaptic November 23, 2023 15:40
@leighmcculloch
Copy link
Member

javascript doesn't handle uints that large

JS handles numbers safely up to Number.MAX_SAFE_INTEGER, that is 9,007,199,254,740,991.

Uint32 max is 4,294,967,295.

So I think JS will handle uint32's fine. Anything over 53-bit is a problem though.

@2opremio
Copy link
Contributor Author

2opremio commented Nov 23, 2023

uint32 should ne enough for all practical purposes (in fact I think the XDR uses uint32 at some places?).

However, also if I recall properly, Horizon uses int64 everywhere (which is why I think we started using int64 in soroban-rpc). @Shaptic @tamirms , do you know why that is?

@leighmcculloch
Copy link
Member

leighmcculloch commented Nov 23, 2023

in fact I think the XDR uses uint32 at some places?

This is correct. The XDR uses uint32 for ledger seq.

https://github.com/stellar/stellar-xdr/blob/6a620d160aab22609c982d54578ff6a63bfcdc01/Stellar-ledger.x#L82

https://github.com/search?q=repo:stellar/stellar-xdr%20ledgerSeq&type=code

I imagine it would be such a heavy lift to change from uint32 to uint64 in the XDR that for a future change like that updating Horizon and Soroban RPC's APIs in support of that would probably be a small job in comparison to everything else.

But I also think it's reasonable to have the RPC API use strings for all integers irrespective of their bit size. I just wanted to surface that 32bit and ledger seq would fit if it was preferred to be a number.

@leighmcculloch
Copy link
Member

leighmcculloch commented Nov 23, 2023

@Shaptic
Copy link
Contributor

Shaptic commented Nov 24, 2023

We may have conflated account sequence with ledger sequence: the former needs to be int64 (see Horizon) because it can be set to any value, while the latter is guaranteed to grow sequentially and is uint32 in the XDR as you guys have mentioned.

I don't think there's anything wrong with leaving it stringified, but it is not necessary because all languages can handle them being encoded as integers (while JS has issues with values over 53 bits, like Leigh said).

Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

I will leave it up to you whether or not we want to keep them JSON-encoded as strings! I'm just glad we are consistent, now.

@2opremio
Copy link
Contributor Author

It think it's cleaner to not stringify them but ... at this point it may cause too much turmoil.

@Shaptic you are dealing with downstream tickets nowadays, wdyt?

@Shaptic
Copy link
Contributor

Shaptic commented Nov 26, 2023

@2opremio imo it's all the same: we have to issue a downstream ticket no matter what for at least a single field, so we might as well fix them all while we're there, and the maintainers are all very responsive.

@2opremio
Copy link
Contributor Author

Alright. Uint32 it is then!

@2opremio 2opremio force-pushed the ledger-types-uint32 branch from eb4a116 to cc68e53 Compare November 27, 2023 19:07
@2opremio 2opremio changed the title rpc: unify all ledger sequence types to json-stringified uint32 rpc: unify all ledger sequence types to uint32 and stop stringyfying integers < 53-bits wide Nov 27, 2023
@2opremio
Copy link
Contributor Author

OK, I changed all ledger sequences types to uint32 and removed the stringification of any field with a width less that 53 bits.

I still need to fix the tests though.

@2opremio 2opremio force-pushed the ledger-types-uint32 branch from 8f8e696 to af1ac65 Compare November 27, 2023 21:56
@2opremio 2opremio enabled auto-merge (squash) November 28, 2023 02:14
@2opremio 2opremio merged commit be3fcd5 into main Nov 28, 2023
22 checks passed
@2opremio 2opremio deleted the ledger-types-uint32 branch November 28, 2023 02:30
@2opremio
Copy link
Contributor Author

@Shaptic can you please create downstream tickets? I will update the documentation.

@Shaptic
Copy link
Contributor

Shaptic commented Nov 28, 2023

@2opremio draft is here, please double-check it! I will also cross-reference it with the doc updates once you make them.

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.

Sequence JSON return types are inconsistent across methods
3 participants