Skip to content

Commit b352e49

Browse files
committed
refactor: init epoch to 1 and add a note to make it clear why this is that way
1 parent 064d362 commit b352e49

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

contracts/epochs/EpochManager.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ contract EpochManager is EpochManagerV1Storage, GraphUpgradeable, IEpochManager
2929

3030
Managed._initialize(_controller);
3131

32-
lastLengthUpdateEpoch = 0;
32+
// NOTE: We make the first epoch to be one instead of zero to avoid any issue
33+
// with composing contracts that may use zero as an empty value
34+
lastLengthUpdateEpoch = 1;
3335
lastLengthUpdateBlock = blockNum();
3436
epochLength = _epochLength;
3537

@@ -104,7 +106,7 @@ contract EpochManager is EpochManagerV1Storage, GraphUpgradeable, IEpochManager
104106
* @return The current epoch based on epoch length
105107
*/
106108
function currentEpoch() public view override returns (uint256) {
107-
return lastLengthUpdateEpoch.add(epochsSinceUpdate()).add(1);
109+
return lastLengthUpdateEpoch.add(epochsSinceUpdate());
108110
}
109111

110112
/**

test/epochs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ describe('EpochManager', () => {
6868
})
6969

7070
describe('calculations', () => {
71+
it('first epoch should be 1', async function () {
72+
const currentEpoch = await epochManager.currentEpoch()
73+
expect(currentEpoch).eq(1)
74+
})
75+
7176
it('should return correct block number', async function () {
7277
const currentBlock = await latestBlock()
7378
expect(await epochManager.blockNum()).eq(currentBlock)

0 commit comments

Comments
 (0)