Align staking derive redeemableSum with Rust source (currentEra vs activeEra usage) (#5242)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user