Skip to content

Commit

Permalink
Ensure the last created epoch has the proper epoch length
Browse files Browse the repository at this point in the history
  • Loading branch information
abarmat authored and juanmardefago committed Apr 8, 2021
1 parent d8ea258 commit 7b3e9b8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mappings/epochManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function handleEpochLengthUpdate(event: EpochLengthUpdate): void {
// This returns a new epoch, or current epoch, with the old epoch length
let epoch = createOrLoadEpoch(event.block.number)

// Check that the endBlock for the current epoch match what it should based on the
// changed epoch length
let newEndBlock = epoch.startBlock + event.params.epochLength.toI32()
if (epoch.endBlock != newEndBlock) {
epoch.endBlock = newEndBlock
epoch.save()
}

// Now it is safe to update graphNetwork, since the past epoch is completed
// But we must reload it, since its currentEpoch may have been updated in createOrLoadEpoch
graphNetwork = GraphNetwork.load('1') as GraphNetwork
Expand Down

0 comments on commit 7b3e9b8

Please sign in to comment.