Skip to content

Commit 5c75bec

Browse files
committed
(BIDS-1823) Adjusts the format of numerous time durations
1 parent 2bf7611 commit 5c75bec

25 files changed

+74
-76
lines changed

cmd/misc/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func main() {
336336
)
337337
if err != nil {
338338
logrus.Errorf("error exporting genesis-deposits: %v", err)
339-
time.Sleep(time.Second * 60)
339+
time.Sleep(time.Minute)
340340
continue
341341
}
342342
}

db/bigtable.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ func (bigtable *Bigtable) getValidatorIncomeDetailsHistoryV2(validators []uint64
23022302
startEpoch = 0
23032303
}
23042304

2305-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*180)
2305+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
23062306
defer cancel()
23072307

23082308
res := make(map[uint64]map[uint64]*itypes.ValidatorEpochIncome, len(validators))
@@ -2378,7 +2378,7 @@ func (bigtable *Bigtable) getValidatorIncomeDetailsHistoryV1(validators []uint64
23782378
startEpoch = 0
23792379
}
23802380

2381-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*180)
2381+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
23822382
defer cancel()
23832383

23842384
ranges := bigtable.getEpochRangesV1(startEpoch, endEpoch)
@@ -2530,7 +2530,7 @@ func (bigtable *Bigtable) GetTotalValidatorIncomeDetailsHistory(startEpoch uint6
25302530
startEpoch = 0
25312531
}
25322532

2533-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*180)
2533+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
25342534
defer cancel()
25352535

25362536
res := make(map[uint64]*itypes.ValidatorEpochIncome, endEpoch-startEpoch+1)

db/bigtable_eth1.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func (bigtable *Bigtable) GetFullBlocksDescending(stream chan<- *types.Eth1Block
451451
})
452452
defer tmr.Stop()
453453

454-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second*180))
454+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Minute*3))
455455
defer cancel()
456456

457457
if high < low {
@@ -3026,7 +3026,7 @@ func (bigtable *Bigtable) GetMetadataUpdates(prefix string, startToken string, l
30263026
})
30273027
defer tmr.Stop()
30283028

3029-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Minute*120))
3029+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Hour*2))
30303030
defer cancel()
30313031

30323032
keys := make([]string, 0, limit)
@@ -3062,7 +3062,7 @@ func (bigtable *Bigtable) GetMetadata(startToken string, limit int) ([]string, [
30623062
})
30633063
defer tmr.Stop()
30643064

3065-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Minute*120))
3065+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Hour*2))
30663066
defer cancel()
30673067

30683068
keys := make([]string, 0, limit)
@@ -3411,7 +3411,7 @@ func (bigtable *Bigtable) GetAddressName(address []byte) (string, error) {
34113411
rowKey := fmt.Sprintf("%s:%x", bigtable.chainId, address)
34123412
cacheKey := bigtable.chainId + ":NAME:" + rowKey
34133413

3414-
if wanted, err := cache.TieredCache.GetStringWithLocalTimeout(cacheKey, time.Hour*24); err == nil {
3414+
if wanted, err := cache.TieredCache.GetStringWithLocalTimeout(cacheKey, utils.Day); err == nil {
34153415
// logrus.Infof("retrieved name for address %x from cache", address)
34163416
return wanted, nil
34173417
}
@@ -3495,7 +3495,7 @@ func (bigtable *Bigtable) GetContractMetadata(address []byte) (*types.ContractMe
34953495

34963496
rowKey := fmt.Sprintf("%s:%x", bigtable.chainId, address)
34973497
cacheKey := bigtable.chainId + ":CONTRACT:" + rowKey
3498-
if cached, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Hour*24, new(types.ContractMetadata)); err == nil {
3498+
if cached, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, utils.Day, new(types.ContractMetadata)); err == nil {
34993499
ret := cached.(*types.ContractMetadata)
35003500
val, err := abi.JSON(bytes.NewReader(ret.ABIJson))
35013501
ret.ABI = &val
@@ -3520,7 +3520,7 @@ func (bigtable *Bigtable) GetContractMetadata(address []byte) (*types.ContractMe
35203520
} else {
35213521
utils.LogError(err, "Fetching contract metadata", 0, logAdditionalInfo)
35223522
}
3523-
err := cache.TieredCache.Set(cacheKey, &types.ContractMetadata{}, time.Hour*24)
3523+
err := cache.TieredCache.Set(cacheKey, &types.ContractMetadata{}, utils.Day)
35243524
if err != nil {
35253525
utils.LogError(err, "Caching contract metadata", 0, logAdditionalInfo)
35263526
}
@@ -3530,14 +3530,14 @@ func (bigtable *Bigtable) GetContractMetadata(address []byte) (*types.ContractMe
35303530

35313531
// No contract found, caching empty
35323532
if ret == nil {
3533-
err = cache.TieredCache.Set(cacheKey, &types.ContractMetadata{}, time.Hour*24)
3533+
err = cache.TieredCache.Set(cacheKey, &types.ContractMetadata{}, utils.Day)
35343534
if err != nil {
35353535
utils.LogError(err, "Caching contract metadata", 0, map[string]interface{}{"address": fmt.Sprintf("%x", address)})
35363536
}
35373537
return nil, nil
35383538
}
35393539

3540-
err = cache.TieredCache.Set(cacheKey, ret, time.Hour*24)
3540+
err = cache.TieredCache.Set(cacheKey, ret, utils.Day)
35413541
if err != nil {
35423542
utils.LogError(err, "Caching contract metadata", 0, map[string]interface{}{"address": fmt.Sprintf("%x", address)})
35433543
}
@@ -3565,7 +3565,7 @@ func (bigtable *Bigtable) GetContractMetadata(address []byte) (*types.ContractMe
35653565
}
35663566
}
35673567

3568-
err = cache.TieredCache.Set(cacheKey, ret, time.Hour*24)
3568+
err = cache.TieredCache.Set(cacheKey, ret, utils.Day)
35693569
return ret, err
35703570
}
35713571

@@ -4096,7 +4096,7 @@ func (bigtable *Bigtable) markBalanceUpdate(address []byte, token []byte, mutati
40964096
mutations.Keys = append(mutations.Keys, balanceUpdateKey)
40974097
mutations.Muts = append(mutations.Muts, mut)
40984098

4099-
cache.Set(balanceUpdateCacheKey, []byte{0x1}, int((time.Hour * 48).Seconds()))
4099+
cache.Set(balanceUpdateCacheKey, []byte{0x1}, int((utils.Day * 2).Seconds()))
41004100
}
41014101
}
41024102

db/bigtable_init.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func InitBigtableSchema() error {
2929
DEFAULT_FAMILY_BLOCKS: gcp_bigtable.MaxVersionsGCPolicy(1),
3030
}
3131
tables["data"] = map[string]gcp_bigtable.GCPolicy{
32-
CONTRACT_METADATA_FAMILY: gcp_bigtable.MaxAgeGCPolicy(time.Hour * 24),
32+
CONTRACT_METADATA_FAMILY: gcp_bigtable.MaxAgeGCPolicy(utils.Day),
3333
DEFAULT_FAMILY: nil,
3434
}
3535
tables["machine_metrics"] = map[string]gcp_bigtable.GCPolicy{
36-
MACHINE_METRICS_COLUMN_FAMILY: gcp_bigtable.MaxAgeGCPolicy(time.Hour * 24 * 31),
36+
MACHINE_METRICS_COLUMN_FAMILY: gcp_bigtable.MaxAgeGCPolicy(utils.Day * 31),
3737
}
3838
tables["metadata"] = map[string]gcp_bigtable.GCPolicy{
3939
ACCOUNT_METADATA_FAMILY: nil,
@@ -44,7 +44,7 @@ func InitBigtableSchema() error {
4444
SERIES_FAMILY: gcp_bigtable.MaxVersionsGCPolicy(1),
4545
}
4646
tables["metadata_updates"] = map[string]gcp_bigtable.GCPolicy{
47-
METADATA_UPDATES_FAMILY_BLOCKS: gcp_bigtable.MaxAgeGCPolicy(time.Hour * 24),
47+
METADATA_UPDATES_FAMILY_BLOCKS: gcp_bigtable.MaxAgeGCPolicy(utils.Day),
4848
DEFAULT_FAMILY: nil,
4949
}
5050
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)

db/statistics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ func GetValidatorIncomeHistory(validatorIndices []uint64, lowerBoundDay uint64,
13151315
func WriteChartSeriesForDay(day int64) error {
13161316
startTs := time.Now()
13171317

1318-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
1318+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
13191319
defer cancel()
13201320
g, gCtx := errgroup.WithContext(ctx)
13211321

db/subscriptions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func UpdateSubscriptionLastSent(tx *sqlx.Tx, ts uint64, epoch uint64, subID uint
270270

271271
// CountSentMail increases the count of sent mails in the table `mails_sent` for this day.
272272
func CountSentMail(email string) error {
273-
day := time.Now().Truncate(time.Hour * 24).Unix()
273+
day := time.Now().Truncate(utils.Day).Unix()
274274
_, err := FrontendWriterDB.Exec(`
275275
INSERT INTO mails_sent (email, ts, cnt) VALUES ($1, TO_TIMESTAMP($2), 1)
276276
ON CONFLICT (email, ts) DO UPDATE SET cnt = mails_sent.cnt+1`, email, day)
@@ -279,7 +279,7 @@ func CountSentMail(email string) error {
279279

280280
// GetMailsSentCount returns the number of sent mails for the day of the passed time.
281281
func GetMailsSentCount(email string, t time.Time) (int, error) {
282-
day := t.Truncate(time.Hour * 24).Unix()
282+
day := t.Truncate(utils.Day).Unix()
283283
count := 0
284284
err := FrontendWriterDB.Get(&count, "SELECT cnt FROM mails_sent WHERE email = $1 AND ts = TO_TIMESTAMP($2)", email, day)
285285
if err == sql.ErrNoRows {

eth1data/eth1data.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func GetEth1Transaction(hash common.Hash) (*types.Eth1TxData, error) {
288288
}
289289
}
290290

291-
err = cache.TieredCache.Set(cacheKey, txPageData, time.Hour*24)
291+
err = cache.TieredCache.Set(cacheKey, txPageData, utils.Day)
292292
if err != nil {
293293
return nil, fmt.Errorf("error writing data for tx to cache: %w", err)
294294
}
@@ -308,7 +308,7 @@ func IsContract(ctx context.Context, address common.Address) (bool, error) {
308308
}
309309

310310
isContract := len(code) != 0
311-
err = cache.TieredCache.SetBool(cacheKey, isContract, time.Hour*24)
311+
err = cache.TieredCache.SetBool(cacheKey, isContract, utils.Day)
312312
if err != nil {
313313
return false, fmt.Errorf("error writing code data for address %v to cache: %w", address, err)
314314
}

exporter/appsubscription_oracle.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func checkSubscriptions() {
7070
}
7171

7272
logger.WithField("subscriptions", len(receipts)).WithField("duration", time.Since(start)).Info("subscription update completed")
73-
time.Sleep(time.Second * 60 * 60 * 4) // 4h
73+
time.Sleep(time.Hour * 4)
7474
}
7575
}
7676

exporter/eth1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func eth1DepositsExporter() {
155155
continue
156156
}
157157

158-
time.Sleep(time.Second * 60)
158+
time.Sleep(time.Minute)
159159
}
160160
}
161161

exporter/exporter.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func genesisDepositsExporter(client rpc.Client) {
125125
}
126126

127127
if latestEpoch == 0 {
128-
time.Sleep(time.Second * 60)
128+
time.Sleep(time.Minute)
129129
continue
130130
}
131131

@@ -134,7 +134,7 @@ func genesisDepositsExporter(client rpc.Client) {
134134
err = db.WriterDb.Get(&genesisDepositsCount, "SELECT COUNT(*) FROM blocks_deposits WHERE block_slot=0")
135135
if err != nil {
136136
logger.Errorf("error retrieving genesis-deposits-count when exporting genesis-deposits: %v", err)
137-
time.Sleep(time.Second * 60)
137+
time.Sleep(time.Minute)
138138
continue
139139
}
140140

@@ -146,14 +146,14 @@ func genesisDepositsExporter(client rpc.Client) {
146146
genesisValidators, err := client.GetValidatorState(0)
147147
if err != nil {
148148
logger.Errorf("error retrieving genesis validator data for genesis-epoch when exporting genesis-deposits: %v", err)
149-
time.Sleep(time.Second * 60)
149+
time.Sleep(time.Minute)
150150
continue
151151
}
152152

153153
tx, err := db.WriterDb.Beginx()
154154
if err != nil {
155155
logger.Errorf("error beginning db-tx when exporting genesis-deposits: %v", err)
156-
time.Sleep(time.Second * 60)
156+
time.Sleep(time.Minute)
157157
continue
158158
}
159159

@@ -169,7 +169,7 @@ func genesisDepositsExporter(client rpc.Client) {
169169
if err != nil {
170170
tx.Rollback()
171171
logger.Errorf("error exporting genesis-deposits: %v", err)
172-
time.Sleep(time.Second * 60)
172+
time.Sleep(time.Minute)
173173
continue
174174
}
175175
}
@@ -186,7 +186,7 @@ func genesisDepositsExporter(client rpc.Client) {
186186
if err != nil {
187187
tx.Rollback()
188188
logger.Errorf("error hydrating eth1 data into genesis-deposits: %v", err)
189-
time.Sleep(time.Second * 60)
189+
time.Sleep(time.Minute)
190190
continue
191191
}
192192

@@ -195,15 +195,15 @@ func genesisDepositsExporter(client rpc.Client) {
195195
if err != nil {
196196
tx.Rollback()
197197
logger.Errorf("error updating deposit count for the genesis slot: %v", err)
198-
time.Sleep(time.Second * 60)
198+
time.Sleep(time.Minute)
199199
continue
200200
}
201201

202202
err = tx.Commit()
203203
if err != nil {
204204
tx.Rollback()
205205
logger.Errorf("error committing db-tx when exporting genesis-deposits: %v", err)
206-
time.Sleep(time.Second * 60)
206+
time.Sleep(time.Minute)
207207
continue
208208
}
209209

exporter/rocketpool.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func NewRocketpoolExporter(eth1Client *ethclient.Client, storageContractAddressH
138138
rpe.Eth1Client = eth1Client
139139
rpe.API = rp
140140
rpe.DB = db
141-
rpe.UpdateInterval = time.Second * 60
141+
rpe.UpdateInterval = time.Minute
142142
rpe.MinipoolsByAddress = map[string]*RocketpoolMinipool{}
143143
rpe.NodesByAddress = map[string]*RocketpoolNode{}
144144
rpe.DAOProposalsByID = map[uint64]*RocketpoolDAOProposal{}
@@ -219,7 +219,7 @@ func (rp *RocketpoolExporter) InitDAOMembers() error {
219219
}
220220

221221
func (rp *RocketpoolExporter) Run() error {
222-
errorInterval := time.Second * 60
222+
errorInterval := time.Minute
223223
t := time.NewTicker(rp.UpdateInterval)
224224
defer t.Stop()
225225
var count int64 = 0

exporter/ssv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func exportSSV() error {
7575
}
7676
}()
7777

78-
qryValidatorsTicker := time.NewTicker(time.Second * 600)
78+
qryValidatorsTicker := time.NewTicker(time.Minute * 10)
7979
defer qryValidatorsTicker.Stop()
8080

8181
for {

handlers/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
)
2222

2323
var authSessionName = "auth"
24-
var authResetEmailRateLimit = time.Second * 60 * 2
25-
var authConfirmEmailRateLimit = time.Second * 60 * 2
24+
var authResetEmailRateLimit = time.Minute * 2
25+
var authConfirmEmailRateLimit = time.Minute * 2
2626
var authInternalServerErrorFlashMsg = "Error: Something went wrong :( Please retry later"
2727

2828
// Register handler renders a template that allows for the creation of a new user.

handlers/gasnow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func GasNow(w http.ResponseWriter, r *http.Request) {
2323
data := InitPageData(w, r, "gasnow", "/gasnow", fmt.Sprintf("%v Gwei", 34), templateFiles)
2424

2525
now := time.Now().Truncate(time.Minute)
26-
lastWeek := time.Now().Truncate(time.Minute).Add(-time.Hour * 24 * 7)
26+
lastWeek := time.Now().Truncate(time.Minute).Add(-utils.Week)
2727

2828
history, err := db.BigtableClient.GetGasNowHistory(now, lastWeek)
2929
if err != nil {

mail/mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func SendMailRateLimited(to, subject string, msg types.Email, attachment []types
9090
return err
9191
}
9292
if count >= utils.Config.Frontend.MaxMailsPerEmailPerDay {
93-
timeLeft := now.Add(time.Hour * 24).Truncate(time.Hour * 24).Sub(now)
93+
timeLeft := now.Add(utils.Day).Truncate(utils.Day).Sub(now)
9494
return &types.RateLimitError{TimeLeft: timeLeft}
9595
}
9696
}

rpc/lighthouse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ var errNotFound = errors.New("not found 404")
12701270
func (lc *LighthouseClient) get(url string) ([]byte, error) {
12711271
// t0 := time.Now()
12721272
// defer func() { fmt.Println(url, time.Since(t0)) }()
1273-
client := &http.Client{Timeout: time.Second * 120}
1273+
client := &http.Client{Timeout: time.Minute * 2}
12741274
resp, err := client.Get(url)
12751275
if err != nil {
12761276
return nil, err

services/charts_updater.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func chartsPageDataUpdater(wg *sync.WaitGroup) {
9090

9191
// if start.Add(time.Minute * -20).After(utils.EpochToTime(latestEpoch)) {
9292
// logger.Info("skipping chartsPageDataUpdater because the explorer is syncing")
93-
// time.Sleep(time.Second * 60)
93+
// time.Sleep(time.Minute)
9494
// continue
9595
// }
9696

@@ -104,7 +104,7 @@ func chartsPageDataUpdater(wg *sync.WaitGroup) {
104104
logger.WithField("epoch", latestEpoch).WithField("duration", time.Since(start)).Info("chartPageData update completed")
105105

106106
cacheKey := fmt.Sprintf("%d:frontend:chartsPageData", utils.Config.Chain.ClConfig.DepositChainID)
107-
cache.TieredCache.Set(cacheKey, data, time.Hour*24)
107+
cache.TieredCache.Set(cacheKey, data, utils.Day)
108108

109109
prevEpoch = latestEpoch
110110

@@ -114,7 +114,7 @@ func chartsPageDataUpdater(wg *sync.WaitGroup) {
114114
}
115115
if latestEpoch == 0 {
116116
ReportStatus("chartsPageDataUpdater", "Running", nil)
117-
time.Sleep(time.Second * 60 * 10)
117+
time.Sleep(time.Minute * 10)
118118
}
119119
}
120120
}
@@ -277,7 +277,7 @@ func activeValidatorsChartData() (*types.GenericChartData, error) {
277277
dailyActiveValidators := [][]float64{}
278278

279279
for _, row := range rows {
280-
day := float64(utils.EpochToTime(row.Epoch).Truncate(time.Hour*24).Unix() * 1000)
280+
day := float64(utils.EpochToTime(row.Epoch).Truncate(utils.Day).Unix() * 1000)
281281

282282
if len(dailyActiveValidators) == 0 || dailyActiveValidators[len(dailyActiveValidators)-1][0] != day {
283283
dailyActiveValidators = append(dailyActiveValidators, []float64{day, float64(row.ValidatorsCount)})

0 commit comments

Comments
 (0)