Skip to content

Commit

Permalink
fix runtime upgrade, bump polkadotjs api
Browse files Browse the repository at this point in the history
  • Loading branch information
ironoa committed Apr 24, 2024
1 parent 7bffcf8 commit 9e1b411
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 174 deletions.
4 changes: 2 additions & 2 deletions charts/polkadot-k8s-payouts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot K8s Payouts
name: polkadot-k8s-payouts
version: v1.2.8
appVersion: v1.2.8
version: v1.2.9
appVersion: v1.2.9
apiVersion: v2
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-payouts",
"version": "1.2.8",
"version": "1.2.9",
"description": "Automated transfers among accounts",
"repository": "[email protected]:w3f/accountant.git",
"author": "W3F Infrastructure Team <[email protected]>",
Expand All @@ -20,7 +20,7 @@
"start": "NODE_OPTIONS='--max-old-space-size=4096' node ./dist/index.js start"
},
"dependencies": {
"@polkadot/api": "^10.13.1",
"@polkadot/api": "^11.0.1",
"@w3f/config": "^0.1.1",
"@w3f/logger": "^0.4.3",
"async-wait-until": "^1.2.6",
Expand Down
38 changes: 23 additions & 15 deletions src/claimer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ClaimerInputConfig, Target, GracePeriod, ValidatorInfo, ValidatorsMap, ClaimPool } from './types';
import { getActiveEraIndex, initKey } from './utils';
import { getActiveEraIndex, initKey, setDifference } from './utils';
import { Logger, LoggerSingleton } from './logger';
import { ApiPromise, Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import waitUntil from 'async-wait-until';
import { BN } from 'bn.js';
import { batchSize, claimAttempts, gracePeriod, isDeepCheckEnabled } from './constants';
import { DeriveOwnExposure } from '@polkadot/api-derive/types';

export class Claimer {
private isDeepCheckEnabled = isDeepCheckEnabled
Expand Down Expand Up @@ -135,21 +136,28 @@ export class Claimer {


private async gatherUnclaimedInfo(validatorAddress: string, validatorInfo: ValidatorInfo): Promise<number[]> {

const ownRewardsIdx: Set<number> = new Set<number>
const exposure: DeriveOwnExposure[] = await this.api.derive.staking.ownExposures(validatorAddress)
exposure.forEach(e=>{
if(e.exposure.total.toBn().gt(new BN(0))) ownRewardsIdx.add(e.era.toNumber()) //legacy
if(e.exposureMeta?.value.total?.toBn().gt(new BN(0))) ownRewardsIdx.add(e.era.toNumber()) //new
})

const lastReward = validatorInfo.lastReward

const numOfPotentialUnclaimedPayouts = this.currentEraIndex - lastReward - 1;
const unclaimedPayouts: number[] = []
for ( let i = 1; i <= numOfPotentialUnclaimedPayouts; i++) {
const idx = lastReward + i;
const exposure = await this.api.query.staking.erasStakers(idx, validatorAddress);
if (exposure.total.toBn().gt(new BN(0))) {
unclaimedPayouts.push(idx)
}
}
validatorInfo.unclaimedPayouts=unclaimedPayouts

return unclaimedPayouts
const claimedIdx: Set<number> = new Set<number>
const stakingQuey = await this.api.derive.staking.query(validatorAddress,{withLedger:true, withClaimedRewardsEras: true})
stakingQuey.stakingLedger.legacyClaimedRewards.forEach(r=>claimedIdx.add(r.toNumber()))
stakingQuey.claimedRewardsEras.forEach(r=>claimedIdx.add(r.toNumber()))

const unclaimed: number[] = Array.from(setDifference(ownRewardsIdx,claimedIdx))
this.logger.debug(unclaimed.toString())

//bugFix: https://github.com/polkadot-js/api/issues/5859
//temporary solution
const unclaimedFixed = unclaimed.filter(x=>x>6513)

validatorInfo.unclaimedPayouts=unclaimedFixed
return unclaimedFixed
}

private async buildClaimPool(validatorsMap: ValidatorsMap): Promise<ClaimPool[]> {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export const initKey = (keystoreFilePath: string, passwordFilePath): any =>{ //s
logger.error(`problem unlocking the wallet, exiting ...`)
process.exit(1)
} else return keyPair
}

export const setDifference = <T>(setA: Set<T>, setB: Set<T>): Set<T> => {
return new Set([...setA].filter(x=>!setB.has(x)))
}
Loading

0 comments on commit 9e1b411

Please sign in to comment.