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

Word64 values in Haskell schema are treated as Int64 in Persistent large values be displayed as negative #163

Closed
cardanians opened this issue Jul 1, 2020 · 3 comments · May be fixed by yesodweb/persistent#1096
Labels

Comments

@cardanians
Copy link
Contributor

SELECT * FROM pool WHERE hash='\xdc240e2e02c1ff7914a840749df10452b900531e43e99d7554e4a59d'

15 "binary data" 12345678000000 22733 14 0.1234 12345000000 424
37 "binary data" 1000000000000 22733 14 0.1234 12345000000 1044
327 "binary data" -2537764290116403776 22733 14 0.9999 -2537764290116403776 50091

@erikd
Copy link
Contributor

erikd commented Jul 1, 2020

The problem here is that the ledger allows arbitrary (and nonsensical) values for the pledge amount (and fixedCost). Specifically that allow any Word64 even if that value is greater than the current total supply.

Even Word64 is problematic due to yesodweb/persistent#1095

@erikd
Copy link
Contributor

erikd commented Jul 2, 2020

I have a potential fix for this but it I am waiting on some dependency and Nix/CI issues to be fixed before I can test my solution.

@erikd
Copy link
Contributor

erikd commented Jul 5, 2020

I have a fix for this on my erikd/persistent-Word64 branch, but I would prefer not to merge that until I make further progress getting yesodweb/persistent#1096 merged.

@erikd erikd added the shelley label Jul 6, 2020
@erikd erikd changed the title negative fixed cost Word64 values in Haskell schema are treated as Int64 in Persistent large values be displayed as negative Jul 22, 2020
erikd added a commit that referenced this issue Jul 24, 2020
This commit uses a version of persistent that has been modified to add
proper Word64 support.

Previously when the schema used `Word64` as the column type, Persistent
would use `SqlInt64` as the SQL representation which means that `Word64`
values above `maxBound :: Int64` would be stored as negative values in
the database. That is fine for a database only accessed from Haskell but
is a pain in the neck when the database is used as an interop layer for
other languages.

The solution is to define a 'DbWord64' newtype wrapper around 'Word64'
and then map 'DbWord64' to the 'numeric(20,0)' SQL type with a bounds
check.

Closes: #163
erikd added a commit that referenced this issue Jul 24, 2020
This commit uses a version of persistent that has been modified to add
proper Word64 support.

Previously when the schema used `Word64` as the column type, Persistent
would use `SqlInt64` as the SQL representation which means that `Word64`
values above `maxBound :: Int64` would be stored as negative values in
the database. That is fine for a database only accessed from Haskell but
is a pain in the neck when the database is used as an interop layer for
other languages.

The solution is to define a 'DbWord64' newtype wrapper around 'Word64'
and then map 'DbWord64' to the 'numeric(20,0)' SQL type with a bounds
check.

Closes: #163
erikd added a commit that referenced this issue Jul 24, 2020
This commit uses a version of persistent that has been modified to ad
Previously when the schema used `Word64` as the column type, Persistent
would use `SqlInt64` as the SQL representation which means that `Word64`
values above `maxBound :: Int64` would be stored as negative values in
the database. That is fine for a database only accessed from Haskell but
is a pain in the neck when the database is used as an interop layer for
other languages.

The solution is to define a 'DbWord64' newtype wrapper around 'Word64'
and then map 'DbWord64' to the 'numeric(20,0)' SQL type with a bounds
check.

Closes: #163
erikd added a commit that referenced this issue Jul 24, 2020
Previously when the schema used `Word64` as the column type, Persistent
would use `SqlInt64` as the SQL representation which means that `Word64`
values above `maxBound :: Int64` would be stored as negative values in
the database. That is fine for a database only accessed from Haskell but
is a pain in the neck when the database is used as an interop layer for
other languages.

The solution is to define a 'DbWord64' newtype wrapper around 'Word64'
and then map 'DbWord64' to the 'numeric(20,0)' SQL type with a bounds
check.

Closes: #163
@erikd erikd closed this as completed in b629f2f Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants