|
1 | 1 | # Changelog |
2 | 2 |
|
3 | | -## Spec 2 |
| 3 | +## Spec version 12 |
| 4 | + |
| 5 | +### Critical Migration & Bug Fix |
| 6 | + |
| 7 | +We were alerted that the agent |
| 8 | + |
| 9 | +<https://torex.rs/account/5GvBntw5j45K7kMwj9XahfwEW7ByJHRNPrSFmBzUyHcnaYNT> |
| 10 | + |
| 11 | +had been deregistered and that all stake delegated to it appeared to be "missing". |
| 12 | + |
| 13 | +#### Root cause |
| 14 | + |
| 15 | +The issue was introduced in the following code: |
| 16 | + |
| 17 | +```rs |
| 18 | +pub(crate) fn clear_key<T: crate::Config>(key: &AccountIdOf<T>) -> DispatchResult { |
| 19 | + for (staker, staked) in crate::StakingTo::<T>::iter() { |
| 20 | + if &staker == key || &staked == key { |
| 21 | + crate::StakingTo::<T>::remove(&staker, &staked); |
| 22 | + crate::StakedBy::<T>::remove(&staked, &staker); |
| 23 | + if let Err(err) = remove_stake::<T>( |
| 24 | + key: staker.clone(), |
| 25 | + agent_key: staked.clone(), |
| 26 | + amount, |
| 27 | + ) { |
| 28 | + error!( |
| 29 | + "could not remove stake from {:?} to {:?}: {err:?}", |
| 30 | + staker, staked |
| 31 | + ); |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + Ok(()) |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +`StakingTo` and `StakedBy` were deleted **before** the call to `remove_stake`. |
| 40 | +Because those storage items no longer existed, `remove_stake` exited early and the affected stake was effectively erased. |
| 41 | + |
| 42 | +#### Fix |
| 43 | + |
| 44 | +The code was changed entirely to a generic function that correctly removes stake, remove_stake0 |
| 45 | + |
| 46 | +#### Migration script |
| 47 | + |
| 48 | +You can find the migration here: |
| 49 | +[https://github.com/renlabs-dev/torus-substrate/blob/954a2485badc49c1ed35e8015b396fb8bad8e4c7/pallets/torus0/src/migrations.rs#L68](https://github.com/renlabs-dev/torus-substrate/blob/954a2485badc49c1ed35e8015b396fb8bad8e4c7/pallets/torus0/src/migrations.rs#L68) |
| 50 | + |
| 51 | +The migration calculates the difference between `TotalStake` (which remained **correctly** unchanged) and sums all actual stakes on the network. The difference is then sent to a recovery account, and redistributed to the original stakers via script |
| 52 | + |
| 53 | +**Original Stakers (OS)** |
| 54 | + |
| 55 | +```text |
| 56 | +5CuBSdUuBeLVxtzrTtrdiCjipEgjbvUoMJjxrss4T9f1MEoZ: 178467095451535513057748 |
| 57 | +5CwHfGwRTnUuZkFG4M5x5ZaXEgmn8RfaiG7Zy7RYUceKcwZT: 13425244249634765265782 |
| 58 | +5DJNtxnttEeuRiMErC6V6CR8z4BXEksKFpBjBukGeEWDxN9g: 299250156775756214045518 |
| 59 | +5EUPK5qrbFU5wFzfAMe1xVT4SLAV53YgeeRB97Z4aPYZUWQk: 76583203738628718841313 |
| 60 | +5FEGvoqFHUSYSFd1mYbpbasZNatsKfMeMPLGzwTwk276QBP9: 1024384116344227564972 |
| 61 | +5FNRQAB4xzpru9Gcu4gGe58FivaBZNCGiLJQ7xfCYUimMVLR: 42796457538016798301186 |
| 62 | +5Giu5U5XeJuYtTeSWTYq5yp9rooSy3NGTgEh9i2cghfhPLsW: 207369620960478104891376 |
| 63 | +5Gubvc4bG9LzzxWBtx6MWXgHb27YvMKPjJ99YSyfMh1hf4RN: 207368595393608853664012 |
| 64 | +5GvBntw5j45K7kMwj9XahfwEW7ByJHRNPrSFmBzUyHcnaYNT: 8826118395848226775843 |
| 65 | +``` |
| 66 | + |
| 67 | +### Refactor |
| 68 | + |
| 69 | +- Improved clarity and maintainability of stake removal logic. |
| 70 | +- Enhanced parameter naming for better readability. |
| 71 | +- Modified operation order in agent unregistration for consistency. |
| 72 | + |
| 73 | +### Tests |
| 74 | + |
| 75 | +- Revised and renamed tests to better reflect updated agent unregistration and staking behaviors. |
| 76 | + |
| 77 | +### Chores |
| 78 | + |
| 79 | +- Updated runtime and storage version numbers to reflect the latest changes. |
| 80 | +- Introduced workspace-wide linting configurations for consistent code quality. |
| 81 | +- Enforced stricter Clippy lint rules across the workspace. |
| 82 | + |
| 83 | +## Spec version 2 |
4 | 84 |
|
5 | 85 | - fix: expired expire applications only if they are Open |
6 | 86 | - fix: `torus0` on_initialize hook |
| 87 | +- Applied saturating arithmetic in various runtime and pallet modules to prevent overflow issues. |
| 88 | +- Improved arithmetic safety and robustness in emission and governance modules. |
| 89 | +- Refined author identification and gas limit calculations with safer arithmetic operations. |
| 90 | + |
0 commit comments