Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instances of time.Now() which should be set to UTC #551

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Oct 5, 2023

Closes #541

I have confirmed that the failing unit test now passes.

I think we should enforce UTC location in clock.NewTestClock (LND). Thoughts on this @guggero ?

@ffranr ffranr requested a review from guggero October 5, 2023 23:30
@ffranr ffranr self-assigned this Oct 5, 2023
@ffranr ffranr requested a review from jharveyb October 5, 2023 23:30
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@guggero
Copy link
Member

guggero commented Oct 6, 2023

I think we should enforce UTC location in clock.NewTestClock (LND). Thoughts on this @guggero ?

Yes, that sounds good. Perhaps we can simply create a UTCClock implementation of the clock interface in Tapd and then replace Now() with Now().UTC().

@jharveyb
Copy link
Collaborator

jharveyb commented Oct 6, 2023

We have some other writes that should probably be UTC?

TransferTime: time.Now(),

Coin lease duration seems like local time rn instead of UTC also:

expiry := time.Now().Add(defaultCoinLeaseDuration)

time.Now().Add(defaultBroadcastCoinLeaseDuration),

IIUC we should query the DB in UTC as well:

startTime = time.Now().AddDate(0, 0, -30)

startTime := time.Now().Add(startOffset)

LastSyncTime: time.Now(),

return c.cfg.AddrBook.SetAddrManaged(ctxt, addr, time.Now())

We also still have a bunch of non-UTC usage in tests and the test mock utilities.

In general I imagine we should store all times in UTC and only convert to local timezone for display, @guggero ?

@guggero
Copy link
Member

guggero commented Oct 6, 2023

@jharveyb I don't think we need to do anything outside of the tapdb package. Because for example in the RPC interface we use .Unix() which implicitly does UTC. This is specifically a database issue (the way sqlc and the DB driver format the time), not a general issue in my opinion.

So we should only make sure we use .UTC() before storing a timestamp in the DB.

@jharveyb
Copy link
Collaborator

jharveyb commented Oct 6, 2023

Ah I see, the timezone we use elsewhere won't matter since the DB normalizes to UTC before write I guess?

I looked through the DB logic for other tables where we have timestamps and they look ok.

Copy link
Collaborator

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍🏽

@ffranr ffranr added this pull request to the merge queue Oct 6, 2023
Merged via the queue into main with commit aa8d776 Oct 6, 2023
14 checks passed
@guggero guggero deleted the use-utc-consistently branch October 6, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure all instances of clock.Now() are u.clock.Now().UTC()
3 participants