Skip to content

Commit

Permalink
add comments explaining calculation for epoch duration
Browse files Browse the repository at this point in the history
  • Loading branch information
akaladarshi committed Oct 2, 2024
1 parent efe4582 commit 4f59281
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chain/index/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ func (si *SqliteIndexer) gc(ctx context.Context) {
// -------------------------------------------------------------------------------------------------
// Also GC eth hashes

currHeadTime := time.Unix(int64(head.MinTimestamp()), 0)
// Calculate the retention duration based on the number of epochs to retain.
// retentionDuration represents the total duration (in nano seconds) for which data should be retained before considering it for garbage collection.
// graceDuration represents the additional duration (in nano seconds) to retain data after the retention duration.
// Since time.Duration expects a nanosecond value, we multiply the total seconds by time.Second to convert it to nanoseconds.
retentionDuration := time.Duration(si.gcRetentionEpochs*builtin.EpochDurationSeconds) * time.Second
totalRetentionDuration := retentionDuration + (time.Duration(graceEpochs) * time.Duration(builtin.EpochDurationSeconds) * time.Second)
graceDuration := time.Duration(graceEpochs*builtin.EpochDurationSeconds) * time.Second

// Calculate the total duration to retain data.
totalRetentionDuration := retentionDuration + graceDuration
currHeadTime := time.Unix(int64(head.MinTimestamp()), 0)
// gcTime is the time that is (gcRetentionEpochs + graceEpochs) before currHeadTime
gcTime := currHeadTime.Add(-totalRetentionDuration)

Expand Down

0 comments on commit 4f59281

Please sign in to comment.