Align staking derive redeemableSum with Rust source (currentEra vs activeEra usage) (#5242)

This commit is contained in:
Jaco
2022-09-27 14:18:56 +03:00
committed by GitHub
parent 62df7e4ead
commit c1a6f3f302
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -7,6 +7,10 @@ Contributed:
- Allow for new `ink_primitives` types (Thanks to https://github.com/statictype)
- Fix contracts runtime `instantiate` call params (Thanks to https://github.com/statictype)
Changes:
- Align staking derive redeemableSum with Rust source (`currentEra` vs `activeEra` usage)
## 9.4.2 Sep 24, 2022
+5 -1
View File
@@ -47,7 +47,11 @@ function calculateUnlocking (api: DeriveApi, stakingLedger: PalletStakingStaking
function redeemableSum (api: DeriveApi, stakingLedger: PalletStakingStakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance {
return api.registry.createType('Balance', (stakingLedger?.unlocking || [] as PalletStakingUnlockChunk[]).reduce((total, { era, value }): BN => {
return sessionInfo.activeEra.gte(era.unwrap())
// aligns with https://github.com/paritytech/substrate/blob/fdfdc73f9e64dc47934b72eb9af3e1989e4ba699/frame/staking/src/pallet/mod.rs#L973-L975
// (ensure era > currentEra passed, as per https://github.com/paritytech/substrate/blob/fdfdc73f9e64dc47934b72eb9af3e1989e4ba699/frame/staking/src/lib.rs#L477-L494)
// NOTE: Previously we used era >= active_era, while the outcome doesn't change using era > current_era (active_era
// being one less), this aligns correctly with the Rust source
return sessionInfo.currentEra.gt(era.unwrap())
? total.iadd(value.unwrap())
: total;
}, new BN(0)));