AstarNetwork/Astar

`next_stake_amount` in `CurrentEraInfo` storage is not updated on contract unregistration

ipapandinas opened this issue · 1 comments

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.