Skip to content

Commit 42fc7e2

Browse files
committed
Fix MND cliff epochs bug in license rewards calculation
1 parent c4ceb2f commit 42fc7e2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/actions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export const getNodeAvailability = async (
2323
const currentEpoch: number = getCurrentEpoch(config);
2424
const firstCheckEpoch: number = getLicenseFirstCheckEpoch(config, assignTimestamp);
2525

26+
if (currentEpoch - firstCheckEpoch <= 1) {
27+
console.log('getNodeLastEpoch');
28+
} else {
29+
console.log('getNodeEpochsRange', firstCheckEpoch, currentEpoch - 1);
30+
}
31+
2632
// If the license was linked in the current or previous epoch
2733
return currentEpoch - firstCheckEpoch <= 1
2834
? await getNodeLastEpoch(nodeEthAddr)

lib/api/blockchain.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,19 @@ const calculateLicenseRewards = async (
287287
return 0n;
288288
}
289289

290+
// Disregard epochs before the cliff epoch for MNDs
291+
if (cliffEpochs > 0 && epochs[0] < cliffEpochs) {
292+
const start = cliffEpochs - epochs[0];
293+
epochs = epochs.slice(start);
294+
epochs_vals = epochs_vals.slice(start);
295+
}
296+
290297
if (epochsToClaim !== epochs.length || epochsToClaim !== epochs_vals.length) {
291-
throw new Error('Invalid epochs array length.');
298+
console.error(
299+
`Invalid epochs array length. Received ${epochs.length} epochs, but there are ${epochsToClaim} epochs to claim.`,
300+
);
301+
302+
return 0n;
292303
}
293304

294305
const maxRewardsPerEpoch = license.totalAssignedAmount / BigInt(vestingEpochs);

0 commit comments

Comments
 (0)