Skip to content

Commit

Permalink
Fix: reputationMiningCycle handler timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
rdig committed Dec 2, 2024
1 parent 3ccb27e commit f586af3
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ export default async (event: ContractEvent): Promise<void> => {
// The event signature looks like: event ReputationMiningCycleComplete(bytes32 hash, uint256 nLeaves);
// However, for current purposes (updating colony-wide contributor reputation), we don't care. We just need a timestamp.

// If we're running this in production, use the time of the actual
// mining cycle, which is the block time of when this event was emitted.
let lastCompletedAt = new Date(event.timestamp * 1000).toISOString();

// However, due to the time forwarding shennaningans we do when developing locally,
// This would break the UI badly, so we're forced to use the current time.
if (process.env.NODE_ENV === 'development') {
lastCompletedAt = new Date().toISOString();
}

// The current time cannot be used in production though, due to the fact that
// the ingestor might fall out of sync with the blockchain, and when it will attempt
// to catch up, and will come across this event, it will use an incorrect timestamp
// for it, basically the time it got to process it, meaning the UI will "lie" at that point

const { data } =
(await query<
GetReputationMiningCycleMetadataQuery,
Expand All @@ -34,7 +49,7 @@ export default async (event: ContractEvent): Promise<void> => {
>(UpdateReputationMiningCycleMetadataDocument, {
input: {
id: reputationMiningCycleMetadataId,
lastCompletedAt: new Date().toISOString(),
lastCompletedAt,
},
});
} else {
Expand All @@ -44,7 +59,7 @@ export default async (event: ContractEvent): Promise<void> => {
>(CreateReputationMiningCycleMetadataDocument, {
input: {
id: reputationMiningCycleMetadataId,
lastCompletedAt: new Date().toISOString(),
lastCompletedAt,
},
});
}
Expand Down

0 comments on commit f586af3

Please sign in to comment.