Skip to content

Conversation

JonathanOppenheimer
Copy link
Member

Why this should be merged

Previously upgradeAccount would naively assume that any upgrade.BalanceChange was positive, even though the underlying BalanceChange was a Big.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 #1717

How 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

@JonathanOppenheimer JonathanOppenheimer self-assigned this Sep 23, 2025
@JonathanOppenheimer JonathanOppenheimer requested a review from a team as a code owner September 23, 2025 19:33
@JonathanOppenheimer JonathanOppenheimer added enhancement New feature or request bug Something isn't working subnet-upgrades and removed enhancement New feature or request subnet-upgrades labels Sep 23, 2025
JonathanOppenheimer and others added 2 commits September 23, 2025 15:57
Co-authored-by: Austin Larson <[email protected]>
Signed-off-by: Jonathan Oppenheimer <[email protected]>
JonathanOppenheimer and others added 2 commits September 23, 2025 16:48
Co-authored-by: Austin Larson <[email protected]>
Signed-off-by: Jonathan Oppenheimer <[email protected]>
Copy link
Contributor

@alarso16 alarso16 left a 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

errBalanceOverflow, account.Hex(), currentBalance.ToBig().String(), balanceChange.ToBig().String())
}
state.AddBalance(account, balanceChange)
case -1: // Negative
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for adding tests!

Copy link
Collaborator

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)

Copy link
Member Author

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?

Copy link
Collaborator

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)

Copy link
Member Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Additional State Upgrade Config Validation

3 participants