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

storage/client: don't crash on 0 delegated shares #719

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Jul 1, 2024

Due to bugs, we can end up with invalid delegations in DB with 0 shares.

I believe most of these cases are fixed in: #713 #711 #712
but still, don't panic since this is part of the public API; instead, log an error and report 0 shares.

@ptrus ptrus force-pushed the ptrus/fix/dont-crash-on-0-shares branch from 43ae792 to 769f149 Compare July 1, 2024 14:39
@ptrus ptrus force-pushed the ptrus/fix/dont-crash-on-0-shares branch from 769f149 to 1b4f32c Compare July 1, 2024 14:55
Copy link
Collaborator

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

as described

@@ -844,10 +844,19 @@ func (c *StorageClient) Account(ctx context.Context, address staking.Address) (*
}

// Computes shares worth given total shares and total balance.
func amountFromShares(shares common.BigInt, totalShares common.BigInt, totalBalance common.BigInt) common.BigInt {
func amountFromShares(shares common.BigInt, totalShares common.BigInt, totalBalance common.BigInt) (common.BigInt, error) {
if shares.IsZero() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ℹ️ db has some leftover cases where shares=0 and totalShares=0. this prevents us from complaining in that case

(is that right? in my understanding from the PR description and related PRs)

Copy link
Member Author

Choose a reason for hiding this comment

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

is that right? in my understanding from the PR description and related PRs

Yes, although I'm not 100% sure if shares=0 and totalShares=0 will still exist after all PRs are deployed and we do a reindex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will recheck in future

@ptrus ptrus merged commit c60b5e6 into main Jul 2, 2024
16 checks passed
@ptrus ptrus deleted the ptrus/fix/dont-crash-on-0-shares branch July 2, 2024 08:40
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.

2 participants