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

balance uses uint64 #7

Open
WhoSoup opened this issue Oct 2, 2019 · 7 comments
Open

balance uses uint64 #7

WhoSoup opened this issue Oct 2, 2019 · 7 comments

Comments

@WhoSoup
Copy link
Contributor

WhoSoup commented Oct 2, 2019

The functions in pegnet/addresses.go all use uint64 for balances but sqlite doesn't support uint64. they need to be changed to int64 or a workaround found

@Emyrk
Copy link
Member

Emyrk commented Oct 2, 2019

Only if the top bit of the uint64 is set, then it becomes a problem

@WhoSoup
Copy link
Contributor Author

WhoSoup commented Oct 3, 2019

Only if the top bit of the uint64 is set, then it becomes a problem

it's something we need to address in the long run. i think the likelihood of it occurring during the intended operating window of pegnetd is, for most assets, very low, but not for all. what's your assessment?

without a top bit we can only go up to 92,233,720,368.54775807. using KRW at ~0.00083 usd per, that's 76k USD. our current fct marketcap is already over 100k

@Emyrk
Copy link
Member

Emyrk commented Oct 3, 2019

Oh jeeze, that is much lower than I had thought it would be. Is there another sql type we can use?

@WhoSoup
Copy link
Contributor Author

WhoSoup commented Oct 6, 2019

Oh jeeze, that is much lower than I had thought it would be. Is there another sql type we can use?

Unfortunately none that SQLite supports. SQLite's DECIMAL() only uses up to 8 bytes whereas something like MySQL's DECIMAL() would give us 65 digits to work with.

Since I assume requiring a dedicated sql database server is not an option, one of our options is to just store a marshaled big.Int or uint64 in the database. This is cumbersome to work with and will prevent us from running any queries involving values (which would be unfortunate) but it would solve this particular problem.

Another option is to have varying definitions of tokens instead of a simple 8-decimal systems. Something like KRW will never need 8 decimals so we're wasting a lot of room. This would complicate all other code and it would also make running queries that involve values from multiple tokens hard if not impossible.

Since this is a problem that also exists in FATd, we should really come up with something useful.

@Emyrk
Copy link
Member

Emyrk commented Oct 7, 2019

@WhoSoup I think you were off in the math. I am seeing the limit being 76 million USD into KRW. Which buys us more time to address this.

https://play.golang.org/p/sSLokttRlVO

@Emyrk
Copy link
Member

Emyrk commented Oct 7, 2019

But I agree we should come up with something.

@WhoSoup
Copy link
Contributor Author

WhoSoup commented Oct 8, 2019

I am seeing the limit being 76 million USD into KRW. Which buys us more time to address this.

yeah, thanks for double checking

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

No branches or pull requests

2 participants