diff --git a/accounts/interface.go b/accounts/interface.go index 11d3efe93..fe191ece3 100644 --- a/accounts/interface.go +++ b/accounts/interface.go @@ -130,7 +130,7 @@ func (a *OffChainBalanceAccount) HasExpired() bool { return false } - return a.ExpirationDate.Before(time.Now()) + return a.ExpirationDate.Before(time.Now().UTC()) } // CurrentBalanceSats returns the current account balance in satoshis. diff --git a/cmd/litcli/autopilot.go b/cmd/litcli/autopilot.go index 1c5b552bf..fb2982be3 100644 --- a/cmd/litcli/autopilot.go +++ b/cmd/litcli/autopilot.go @@ -251,7 +251,7 @@ func listFeatures(cli *cli.Context) error { func initAutopilotSession(cli *cli.Context) error { sessionLength := time.Second * time.Duration(cli.Uint64("expiry")) - sessionExpiry := time.Now().Add(sessionLength).Unix() + sessionExpiry := time.Now().UTC().Add(sessionLength).Unix() ctx := getContext() clientConn, cleanup, err := connectClient(cli, false) diff --git a/docs/release-notes/release-notes-0.14.1.md b/docs/release-notes/release-notes-0.14.1.md index 667714cac..6191b9487 100644 --- a/docs/release-notes/release-notes-0.14.1.md +++ b/docs/release-notes/release-notes-0.14.1.md @@ -20,6 +20,17 @@ quotes](https://github.com/lightninglabs/lightning-terminal/pull/920). Fixes fee estimation bug when using Loop In for a specific channel. +* [Fix inconsistent timestamp local such that we strictly use UTC + time](https://github.com/lightninglabs/lightning-terminal/pull/976). + This will mean that previously serialised timestamps that were not first + converted to UTC will not be interpreted as UTC and so may be off by a few + hours depending on the timezone of where the server is running. This should + not be an issue for majority of cases. The possible side effects are that an + LNC session's expiry may differ by a few hours. There is an unlikely edge case + that can happen if an LNC session is created, not connected to, and then LiT + is upgraded all within a 10 min timespan. If this happens then the session may + immediately be revoked. The solution to this is just to recreate the session. + ### Functional Changes/Additions ### Technical and Architectural Updates diff --git a/firewall/request_logger.go b/firewall/request_logger.go index dad96339b..1047d5428 100644 --- a/firewall/request_logger.go +++ b/firewall/request_logger.go @@ -195,7 +195,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo, action := &firewalldb.Action{ RPCMethod: ri.URI, - AttemptedAt: time.Now(), + AttemptedAt: time.Now().UTC(), State: firewalldb.ActionStateInit, } diff --git a/rules/rate_limit.go b/rules/rate_limit.go index 4bff4bbe0..bb2274f94 100644 --- a/rules/rate_limit.go +++ b/rules/rate_limit.go @@ -134,7 +134,7 @@ func (r *RateLimitEnforcer) HandleRequest(ctx context.Context, uri string, // Determine the start time of the actions window. startTime := time.Now().Add( -time.Duration(rateLim.NumHours) * time.Hour, - ) + ).UTC() // Now count all relevant actions which have taken place after the // start time. diff --git a/session_rpcserver.go b/session_rpcserver.go index 666744cd0..2e1119950 100644 --- a/session_rpcserver.go +++ b/session_rpcserver.go @@ -132,7 +132,7 @@ func (s *sessionRpcServer) start(ctx context.Context) error { continue } - if sess.Expiry.Before(time.Now()) { + if sess.Expiry.Before(time.Now().UTC()) { continue } @@ -190,7 +190,7 @@ func (s *sessionRpcServer) AddSession(ctx context.Context, req *litrpc.AddSessionRequest) (*litrpc.AddSessionResponse, error) { expiry := time.Unix(int64(req.ExpiryTimestampSeconds), 0) - if time.Now().After(expiry) { + if time.Now().UTC().After(expiry) { return nil, fmt.Errorf("expiry must be in the future") } @@ -364,7 +364,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, } // Don't resume an expired session. - if sess.Expiry.Before(time.Now()) { + if sess.Expiry.Before(time.Now().UTC()) { log.Debugf("Not resuming session %x with expiry %s", pubKeyBytes, sess.Expiry) @@ -440,7 +440,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, // we do not yet have a static remote pub key for. if sess.RemotePublicKey == nil { deadline := sess.CreatedAt.Add(s.cfg.firstConnectionDeadline) - if deadline.Before(time.Now()) { + if deadline.Before(time.Now().UTC()) { log.Debugf("Deadline for session %x has already "+ "passed. Revoking session", pubKeyBytes) @@ -448,7 +448,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, } // Start the deadline timer. - deadlineDuration := time.Until(deadline) + deadlineDuration := deadline.Sub(time.Now().UTC()) deadlineTimer := time.AfterFunc(deadlineDuration, func() { close(firstConnTimout) }) @@ -489,7 +489,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, go func() { defer s.wg.Done() - ticker := time.NewTimer(time.Until(sess.Expiry)) + ticker := time.NewTimer(sess.Expiry.Sub(time.Now().UTC())) defer ticker.Stop() select { @@ -839,7 +839,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context, } expiry := time.Unix(int64(req.ExpiryTimestampSeconds), 0) - if time.Now().After(expiry) { + if time.Now().UTC().After(expiry) { return nil, fmt.Errorf("expiry must be in the future") }