-
Notifications
You must be signed in to change notification settings - Fork 275
fix: Implement correct balance updating logic #1745
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
base: master
Are you sure you want to change the base?
fix: Implement correct balance updating logic #1745
Conversation
Co-authored-by: Austin Larson <[email protected]> Signed-off-by: Jonathan Oppenheimer <[email protected]>
Co-authored-by: Austin Larson <[email protected]> Signed-off-by: Jonathan Oppenheimer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me, but you probably should get a maintainer review on this
stateupgrade/state_upgrade.go
Outdated
errBalanceOverflow, account.Hex(), currentBalance.ToBig().String(), balanceChange.ToBig().String()) | ||
} | ||
state.AddBalance(account, balanceChange) | ||
case -1: // Negative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not allow negative values. Can we check this in the verification and return an error if it's negative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't we allow negative values? I assume there are users who would like to subtract from some account's balance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we should probably add these tests to verification)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by we should add these tests to verification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ugly to have this in this package and then have the definition in config/extras
package. I'm working on a refactor to move them to here https://github.com/ava-labs/subnet-evm/pull/1811/files (this is not a blocker for this one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! If you'd like it to be a blocker, this PR can certainly wait until after that one (and perhaps that makes more sense).
Why this should be merged
Previously
upgradeAccount
would naively assume that anyupgrade.BalanceChange
was positive, even though the underlying BalanceChange was aBig.Int
, which can be negative. This meant that negative balance updates would be interpreted as positive updates, which is strange, and arguably incorrect behavior. This PR correctly implements the balance changing behavior, and adds checks to ensure account balances are not updated to non-sensical values. Closes #1717How this was tested
I added a new test file,
state_upgrade_test.go.
This behavior was seemingly not tested prior.Need to be documented?
I don't think so - we are not exposing any additional API methods, we're just fixing an existing one.
Need to update RELEASES.md?
No