Skip to content

Commit

Permalink
[SKIP CI] Merge pull request #495 from subquery/fix/channel-rewards
Browse files Browse the repository at this point in the history
fix: channel rewards
  • Loading branch information
cool-firer authored Aug 22, 2024
2 parents 3d9db8d + b7cce52 commit cc8e94b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/indexer-coordinator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/indexer-coordinator",
"version": "2.4.0",
"version": "2.4.1",
"description": "",
"author": "SubQuery",
"license": "Apache-2.0",
Expand Down
22 changes: 21 additions & 1 deletion apps/indexer-coordinator/src/reward/reward.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class RewardService implements OnModuleInit {
private readonly oneDay = 24 * 60 * 60 * 1000;
private readonly allocationBypassTimeLimit = 3 * this.oneDay;
private readonly allocationStartTimes: Map<string, number> = new Map();
private readonly channelRewardsStartTimes: Map<string, number> = new Map();

private readonly logger = getLogger('RewardService');

Expand Down Expand Up @@ -248,12 +249,31 @@ export class RewardService implements OnModuleInit {
const thresholdConfig = await this.configService.get(ConfigType.STATE_CHANNEL_REWARD_THRESHOLD);
const threshold = BigNumber.from(thresholdConfig);

const timeLimit = this.allocationBypassTimeLimit;
const openChannels = await this.paygService.getOpenChannels();
for (const channel of openChannels) {
const unclaimed = BigNumber.from(channel.remote).sub(channel.onchain);
if (unclaimed.lte(threshold)) continue;
if (unclaimed.lte(0)) continue;

let startTime = this.channelRewardsStartTimes.get(channel.id);
if (!startTime) {
startTime = Date.now();
this.channelRewardsStartTimes.set(channel.id, startTime);
}

if (unclaimed.lte(threshold) && Date.now() - startTime < timeLimit) {
this.logger.debug(
`Bypassed channel rewards [${unclaimed.toString()}] for channel ${channel.id} ${(
(Date.now() - startTime) /
this.oneDay
).toFixed(2)}/${timeLimit / this.oneDay} days`
);
continue;
}

try {
await this.paygService.checkpoint(channel.id, txType);
this.channelRewardsStartTimes.delete(channel.id);
} catch (e) {
this.logger.error(`Failed to checkpoint for channel ${channel.id}: ${e}`);
this.txOngoingMap[this.collectStateChannelRewards.name] = true;
Expand Down

0 comments on commit cc8e94b

Please sign in to comment.