Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't claim already claimed rewards #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/claimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,28 @@ export class Claimer {

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

const ledger = (await this.api.derive.staking.account(validatorAddress)).stakingLedger
if (!ledger) {
throw new Error(`Could not get ledger for ${validatorAddress}`);
}

const lastReward = validatorInfo.lastReward

const numOfPotentialUnclaimedPayouts = this.currentEraIndex - lastReward - 1;
const unclaimedPayouts: number[] = []
const claimedRewards: number[] = ledger.claimedRewards.map(x => x.toNumber());

for ( let i = 1; i <= numOfPotentialUnclaimedPayouts; i++) {
const idx = lastReward + i;
if (claimedRewards.includes(idx)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @mkaczanowski, thanks for the PR.
Could you elaborate a bit on why this would be necessary ? shouldn't the "validatorInfo.lastReward" be enough, why do you think it is not trustable ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, iirc (I made this PR a while ago) the validatorInfo.lastReward is not sufficient if you run with the deepCheck. It's fairly simple to repro this issue:

  1. set deepcheck to true
  2. start payouts and see that TXes will be created for the eras that have already been paid.

from what I see by quickly skimming through the code the deep check will make the payouts start prior to the validatorInfo.lastReward, thus create TXes that can only be rejected/fail.

This case never really worked even in the original repo:
github.com/w3f/polkadot-payouts

and I remember applying the same fix (among others I haven't published). But I would instead merge everything I have upstream :)

continue;
}
const exposure = await this.api.query.staking.erasStakers(idx, validatorAddress);
if (exposure.total.toBn().gt(new BN(0))) {
unclaimedPayouts.push(idx)
}
}
validatorInfo.unclaimedPayouts=unclaimedPayouts
validatorInfo.unclaimedPayouts = unclaimedPayouts

return unclaimedPayouts
}
Expand Down