Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #196 from ar-io/PE-5562-fix-distributions
Browse files Browse the repository at this point in the history
fix(PE-5562): bug in distributions where nextDistributionHeight…
  • Loading branch information
dtfiedler authored Feb 1, 2024
2 parents 69485dd + d94f926 commit a0ae592
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/actions/write/tick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ describe('tick', () => {
expect(gateways).toEqual(expectedGateways);
});

it('should distribute rewards to observers who submitted reports and gateways who passed, update distribution epoch values and increment performance stats', async () => {
it('should distribute rewards to observers who submitted reports and gateways who passed for the previous epoch, update distribution epoch values and increment performance stats', async () => {
const initialState: IOState = {
...getBaselineState(),
balances: {
Expand All @@ -977,6 +977,12 @@ describe('tick', () => {
},
},
},
distributions: {
...getBaselineState().distributions,
// setting these to next epoch values to validate distributions depend on only the nextDistributionHeight
epochEndHeight: SmartWeave.block.height + 2 * EPOCH_BLOCK_LENGTH - 1,
epochStartHeight: SmartWeave.block.height + EPOCH_BLOCK_LENGTH - 1,
},
};
const nextDistributionHeight =
initialState.distributions.nextDistributionHeight;
Expand Down Expand Up @@ -1054,7 +1060,7 @@ describe('tick', () => {
});

// top level tests
it('should tick distributions, update gateway performance stats and increment the nextDistributionHeight if a the interaction height is equal to the nextDistributionHeight', async () => {
it('should tick distributions for the previous epoch, update gateway performance stats and increment the nextDistributionHeight if a the interaction height is equal to the nextDistributionHeight', async () => {
const initialState: IOState = {
...getBaselineState(),
gateways: stubbedGateways,
Expand Down
12 changes: 9 additions & 3 deletions src/actions/write/tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DEFAULT_GATEWAY_PERFORMANCE_STATS,
DEFAULT_UNDERNAME_COUNT,
EPOCH_BLOCK_LENGTH,
EPOCH_DISTRIBUTION_DELAY,
EPOCH_REWARD_PERCENTAGE,
GATEWAY_PERCENTAGE_OF_EPOCH_REWARD,
GATEWAY_REGISTRY_SETTINGS,
Expand Down Expand Up @@ -461,9 +462,14 @@ export async function tickRewardDistribution({
};
}

// get our epoch heights
const epochStartHeight = new BlockHeight(distributions.epochStartHeight);
const epochEndHeight = new BlockHeight(distributions.epochEndHeight);
// get our epoch heights based off the distribution end height
const { epochStartHeight, epochEndHeight } = getEpochDataForHeight({
currentBlockHeight: new BlockHeight(
distributionHeightForLastEpoch.valueOf() - EPOCH_DISTRIBUTION_DELAY - 1,
),
epochZeroStartHeight: new BlockHeight(distributions.epochZeroStartHeight),
epochBlockLength: new BlockHeight(EPOCH_BLOCK_LENGTH),
});

// get all the reports submitted for the epoch based on its start height
const totalReportsSubmitted = Object.keys(
Expand Down

0 comments on commit a0ae592

Please sign in to comment.