Skip to content

Commit 9179742

Browse files
committed
multi: be consistent with UTC conversion of timestamp
1 parent 54fe5ef commit 9179742

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

accounts/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (a *OffChainBalanceAccount) HasExpired() bool {
130130
return false
131131
}
132132

133-
return a.ExpirationDate.Before(time.Now())
133+
return a.ExpirationDate.Before(time.Now().UTC())
134134
}
135135

136136
// CurrentBalanceSats returns the current account balance in satoshis.

cmd/litcli/autopilot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func listFeatures(cli *cli.Context) error {
251251

252252
func initAutopilotSession(cli *cli.Context) error {
253253
sessionLength := time.Second * time.Duration(cli.Uint64("expiry"))
254-
sessionExpiry := time.Now().Add(sessionLength).Unix()
254+
sessionExpiry := time.Now().UTC().Add(sessionLength).Unix()
255255

256256
ctx := getContext()
257257
clientConn, cleanup, err := connectClient(cli, false)

firewall/request_logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo,
195195

196196
action := &firewalldb.Action{
197197
RPCMethod: ri.URI,
198-
AttemptedAt: time.Now(),
198+
AttemptedAt: time.Now().UTC(),
199199
State: firewalldb.ActionStateInit,
200200
}
201201

rules/rate_limit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (r *RateLimitEnforcer) HandleRequest(ctx context.Context, uri string,
134134
// Determine the start time of the actions window.
135135
startTime := time.Now().Add(
136136
-time.Duration(rateLim.NumHours) * time.Hour,
137-
)
137+
).UTC()
138138

139139
// Now count all relevant actions which have taken place after the
140140
// start time.

session_rpcserver.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (s *sessionRpcServer) start(ctx context.Context) error {
132132
continue
133133
}
134134

135-
if sess.Expiry.Before(time.Now()) {
135+
if sess.Expiry.Before(time.Now().UTC()) {
136136
continue
137137
}
138138

@@ -190,7 +190,7 @@ func (s *sessionRpcServer) AddSession(ctx context.Context,
190190
req *litrpc.AddSessionRequest) (*litrpc.AddSessionResponse, error) {
191191

192192
expiry := time.Unix(int64(req.ExpiryTimestampSeconds), 0)
193-
if time.Now().After(expiry) {
193+
if time.Now().UTC().After(expiry) {
194194
return nil, fmt.Errorf("expiry must be in the future")
195195
}
196196

@@ -364,7 +364,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
364364
}
365365

366366
// Don't resume an expired session.
367-
if sess.Expiry.Before(time.Now()) {
367+
if sess.Expiry.Before(time.Now().UTC()) {
368368
log.Debugf("Not resuming session %x with expiry %s",
369369
pubKeyBytes, sess.Expiry)
370370

@@ -440,15 +440,15 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
440440
// we do not yet have a static remote pub key for.
441441
if sess.RemotePublicKey == nil {
442442
deadline := sess.CreatedAt.Add(s.cfg.firstConnectionDeadline)
443-
if deadline.Before(time.Now()) {
443+
if deadline.Before(time.Now().UTC()) {
444444
log.Debugf("Deadline for session %x has already "+
445445
"passed. Revoking session", pubKeyBytes)
446446

447447
return s.cfg.db.RevokeSession(pubKey)
448448
}
449449

450450
// Start the deadline timer.
451-
deadlineDuration := time.Until(deadline)
451+
deadlineDuration := deadline.Sub(time.Now().UTC())
452452
deadlineTimer := time.AfterFunc(deadlineDuration, func() {
453453
close(firstConnTimout)
454454
})
@@ -489,7 +489,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
489489
go func() {
490490
defer s.wg.Done()
491491

492-
ticker := time.NewTimer(time.Until(sess.Expiry))
492+
ticker := time.NewTimer(sess.Expiry.Sub(time.Now().UTC()))
493493
defer ticker.Stop()
494494

495495
select {
@@ -839,7 +839,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
839839
}
840840

841841
expiry := time.Unix(int64(req.ExpiryTimestampSeconds), 0)
842-
if time.Now().After(expiry) {
842+
if time.Now().UTC().After(expiry) {
843843
return nil, fmt.Errorf("expiry must be in the future")
844844
}
845845

0 commit comments

Comments
 (0)