Skip to content

Commit dcb2c3c

Browse files
committed
fix: outdated active validators
paritytech/polkadot-sdk#1189
1 parent cb5e7b7 commit dcb2c3c

9 files changed

Lines changed: 187 additions & 146 deletions

File tree

apps/portal/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"@emotion/styled": "^11.11.0",
2424
"@polkadot-onboard/core": "^1.1.0",
2525
"@polkadot-onboard/injected-wallets": "^1.1.0",
26-
"@polkadot/api": "^10.12.6",
27-
"@polkadot/api-contract": "^10.12.6",
28-
"@polkadot/extension-dapp": "^0.46.6",
26+
"@polkadot/api": "^10.13.1",
27+
"@polkadot/api-contract": "^10.13.1",
28+
"@polkadot/extension-dapp": "^0.47.1",
2929
"@polkawallet/bridge": "^0.1.5-38",
3030
"@recoiljs/refine": "^0.1.1",
3131
"@sentry/react": "^7.85.0",

apps/portal/src/components/widgets/staking/substrate/StakeForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export const ControlledStakeForm = (props: { assetSelector: ReactNode; account?:
327327
activeEraLoadable.state !== 'hasValue'
328328
? constSelector(undefined)
329329
: eraStakersState({ endpoint: apiEndpoint, era: activeEraLoadable.contents.unwrapOrDefault().index })
330-
).map(value => new Set(value?.map(x => x[0].args[1].toHuman())))
330+
).map(value => new Set(value?.map(x => x.toString())))
331331

332332
const existingPool =
333333
poolMembersLoadable.state === 'hasValue' ? poolMembersLoadable.contents.unwrapOr(undefined) : undefined

apps/portal/src/domains/fastUnstake/worker.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ export type WorkerFunction = typeof getExposure
88

99
export type ExposureRecord = Record<number, Record<string, boolean>>
1010

11+
// DEPRECATION: Paged Rewards
12+
//
13+
// Temporary until paged rewards migration has completed on all networks. Wait 84 eras from Polkadot
14+
// start: 1420 + 84 = 1504, when full history depth will be moved over to new paged rewards storage.
15+
const pagedRewardsActiveEras: Record<`0x${string}`, number> = {
16+
// Polkadot
17+
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 1420,
18+
// Kusama
19+
'0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe': 6514,
20+
// Westend
21+
'0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e': 7167,
22+
}
23+
24+
const getEraExposeds = async (api: ApiPromise, era: number) => {
25+
const pagedRewardsActiveEra = pagedRewardsActiveEras[api.genesisHash.toHex()]
26+
if (pagedRewardsActiveEra === undefined || pagedRewardsActiveEra < era) {
27+
const stakers = await api.query.staking.erasStakers.entries(era)
28+
29+
const exposeds = stakers
30+
.map(staker => staker[1])
31+
.flatMap(staker => staker.others.map(other => other.who.toString()))
32+
33+
return new Set(exposeds)
34+
}
35+
36+
const stakerKeys = await api.query.staking.erasStakersOverview.keys(era)
37+
const stakers = await Promise.all(
38+
stakerKeys
39+
.map(key => key.args[1])
40+
.map(async address => await api.query.staking.erasStakersPaged.entries(era, address))
41+
)
42+
43+
const exposeds = stakers
44+
.flat()
45+
.map(staker => staker[1])
46+
.filter(staker => staker.isSome)
47+
.flatMap(staker => staker.unwrap().others.map(other => other.who.toString()))
48+
49+
return new Set(exposeds)
50+
}
51+
1152
const generateExposure = async function* (
1253
endpoint: string,
1354
activeEra: number,
@@ -26,9 +67,7 @@ const generateExposure = async function* (
2667
const addressesToCheck = encodedAddresses.filter(address => !(address in eraExposure))
2768

2869
if (addressesToCheck.length > 0) {
29-
const exposeds = await api.query.staking.erasStakers
30-
.entries(era)
31-
.then(x => new Set(x.flatMap(([_, exposure]) => exposure.others.flatMap(({ who }) => who.toString()))))
70+
const exposeds = await getEraExposeds(api, era)
3271

3372
for (const address of addressesToCheck) {
3473
eraExposure[address] = exposeds.has(address)

apps/portal/src/domains/staking/substrate/nominationPools/hooks/usePoolStake.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const usePoolStakes = <T extends Account | Account[]>(account: T) => {
6666
)
6767

6868
const _eraStakers = useRecoilValue(useEraStakersState(activeEra.unwrapOrDefault().index))
69-
const eraStakers = useMemo(() => new Set(_eraStakers.map(x => x[0].args[1].toHuman())), [_eraStakers])
69+
const eraStakers = useMemo(() => new Set(_eraStakers.map(x => x.toString())), [_eraStakers])
7070

7171
const pools = useMemo(
7272
() =>

apps/portal/src/domains/staking/substrate/nominationPools/recoils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export const eraStakersState = selectorFamily({
4242
async ({ get }) => {
4343
const api = get(substrateApiState(endpoint))
4444

45-
return await api.query.staking.erasStakers.entries(era)
45+
const stakers = await (api.query.staking.erasStakersOverview ?? api.query.staking.erasStakers).keys(era)
46+
47+
return stakers.map(staker => staker.args[1])
4648
},
4749
cachePolicy_UNSTABLE: { eviction: 'most-recent' },
4850
// NOTE: polkadot.js returned codec object includes reference to the registry

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
"turbo": "^1.11.2"
2929
},
3030
"resolutions": {
31-
"@polkadot/api-augment": "^10.12.6",
32-
"@polkadot/api-derive": "^10.12.6",
31+
"@polkadot/api-augment": "^10.13.1",
32+
"@polkadot/api-derive": "^10.13.1",
3333
"@polkadot/keyring": "^12.6.2",
34-
"@polkadot/rpc-augment": "^10.12.6",
35-
"@polkadot/types": "^10.12.6",
36-
"@polkadot/types-augment": "^10.12.6",
37-
"@polkadot/types-codec": "^10.12.6",
38-
"@polkadot/types-create": "^10.12.6",
39-
"@polkadot/types-known": "^10.12.6",
34+
"@polkadot/rpc-augment": "^10.13.1",
35+
"@polkadot/types": "^10.13.1",
36+
"@polkadot/types-augment": "^10.13.1",
37+
"@polkadot/types-codec": "^10.13.1",
38+
"@polkadot/types-create": "^10.13.1",
39+
"@polkadot/types-known": "^10.13.1",
4040
"@polkadot/util": "^12.6.2",
4141
"@polkadot/util-crypto": "^12.6.2",
4242
"@polkadot/wasm-crypto": "^7.3.2",

packages/nft/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"devDependencies": {
2323
"@acala-network/types": "^5.1.2",
2424
"@graphql-codegen/cli": "^5.0.0",
25-
"@polkadot/api": "^10.12.6",
25+
"@polkadot/api": "^10.13.1",
2626
"prettier": "^2.8.8",
2727
"typescript": "^5.0.2",
2828
"viem": "^1.20.3"

packages/react-polkadot-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"check-types": "tsc --noEmit"
1212
},
1313
"devDependencies": {
14-
"@polkadot/api": "^10.12.6",
14+
"@polkadot/api": "^10.13.1",
1515
"@talismn/eslint-config": "workspace:^",
1616
"@talismn/tsconfig": "workspace:^",
1717
"@types/react": "^18.2.57",

0 commit comments

Comments
 (0)