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

next_stake_amount in CurrentEraInfo storage is not updated on contract unregistration #1333

Closed
ipapandinas opened this issue Aug 21, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ipapandinas
Copy link
Contributor

Description

A storage invariant issue was detected through try-state checks on the CurrentEraInfo item.

The next_stake_amount in CurrentEraInfo is not updated when a contract is unregistered. This is a problem because the next stake amount does not accurately reflect the total amount staked when iterating over all contracts in ContractStake.

Steps to Reproduce

This issue can be reproduced by executing the tests unstake_on_invalid_dapp_fails & unregister_with_active_stake_is_ok.

Suggested Solution

Before removing the contract, use the total_staked_amount helper function along with the current period number to retrieve the contract's staked amount. Then, adjust the next_stake_amount in CurrentEraInfo by subtracting the unregistered contract staked amount.

@ipapandinas ipapandinas added bug Something isn't working good first issue Good for newcomers labels Aug 21, 2024
@ipapandinas
Copy link
Contributor Author

After some investigation, this behavior is the expected one as mentioned here:

https://github.com/AstarNetwork/Astar/blob/40c4b6ceb5ad67e66ad23d6fd3438cb09601355c/pallets/dapp-staking-v3/src/lib.rs#L1368C1-L1370C1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant