-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from ethpandaops/pk910/fix-max-amount-withdra…
…wals fix for storing uint64 values as int64 in db
- Loading branch information
Showing
9 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package db | ||
|
||
// ConvertUint64ToInt64 converts a uint64 to an int64, supporting the full range of uint64, | ||
// but the value is translated to the range of int64. | ||
func ConvertUint64ToInt64(u uint64) int64 { | ||
// Subtract half of uint64 max value to center the range around 0 | ||
// This maps: | ||
// uint64(0) -> int64.MinValue | ||
// uint64.MaxValue -> int64.MaxValue | ||
return int64(u - 1<<63) | ||
} | ||
|
||
// ConvertInt64ToUint64 converts an int64 to a uint64, supporting the full range of int64, | ||
// but the value is translated to the range of uint64. | ||
func ConvertInt64ToUint64(i int64) uint64 { | ||
// Add 2^63 to shift the range back to uint64 | ||
// This maps: | ||
// int64.MinValue -> uint64(0) | ||
// int64.MaxValue -> uint64.MaxValue | ||
return uint64(i) + 1<<63 | ||
} |
14 changes: 14 additions & 0 deletions
14
db/schema/pgsql/20250120215235_withdrawal-requests-fix.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
|
||
UPDATE public."withdrawal_requests" | ||
SET "amount" = "amount" - 9223372036854775808; | ||
|
||
UPDATE public."withdrawal_request_txs" | ||
SET "amount" = "amount" - 9223372036854775808; | ||
|
||
-- +goose StatementEnd | ||
-- +goose Down | ||
-- +goose StatementBegin | ||
SELECT 'NOT SUPPORTED'; | ||
-- +goose StatementEnd |
14 changes: 14 additions & 0 deletions
14
db/schema/sqlite/20250120215235_withdrawal-requests-fix.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
|
||
UPDATE "withdrawal_requests" | ||
SET "amount" = "amount" - 9223372036854775808; | ||
|
||
UPDATE "withdrawal_request_txs" | ||
SET "amount" = "amount" - 9223372036854775808; | ||
|
||
-- +goose StatementEnd | ||
-- +goose Down | ||
-- +goose StatementBegin | ||
SELECT 'NOT SUPPORTED'; | ||
-- +goose StatementEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters