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

golangci-lint: add unconvert #11757

Merged
merged 2 commits into from
Jan 12, 2024
Merged

golangci-lint: add unconvert #11757

merged 2 commits into from
Jan 12, 2024

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Jan 12, 2024

No description provided.

Copy link
Contributor

I see that you haven't updated any README files. Would it make sense to do so?

@jmank88 jmank88 force-pushed the golangci-lint-unconvert branch 4 times, most recently from 58fe6f7 to 87f2b46 Compare January 12, 2024 01:10
@cl-sonarqube-production
Copy link

@@ -236,7 +236,7 @@ func (f *FwdMgr) runLoop() {
defer f.wg.Done()
tick := time.After(0)

for ; ; tick = time.After(utils.WithJitter(time.Duration(time.Minute))) {
for ; ; tick = time.After(utils.WithJitter(time.Minute)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to the scope of this PR - is there a more idiomatic way to write this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem odd. Moving the assignment to the body isn't straightforward though (extra bool might be most elegant?).

I might actually prefer moving the init here:

Suggested change
for ; ; tick = time.After(utils.WithJitter(time.Minute)) {
for tick := time.After(0); ; tick = time.After(utils.WithJitter(time.Minute)) {

Or, since this is a common pattern that we use instead of a plain time.Ticker, we could just make a custom type of Ticker which sends the first tick without delay. The jitter can become an implementation detail this way too:

Suggested change
for ; ; tick = time.After(utils.WithJitter(time.Minute)) {
ticker := services.NewTicker(time.Minute)
defer ticker.Stop()
for {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines 28 to 34
c.lock.RLock()
defer c.lock.RUnlock()

i := int64(block) % int64(c.cap)
i := int64(block) % c.cap
b := c.buffer[i]
if b.block != block {
return ocr2keepers.TransmitEvent{}, false
Copy link
Contributor

Choose a reason for hiding this comment

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

/nit This feels more readable to me

func (c *transmitEventCache) get(block int64, logID string) (ocr2keepers.TransmitEvent, bool) {
	c.lock.RLock()
	defer c.lock.RUnlock()

	i := block % c.cap // no longer has an int64 cast on block
	b := c.buffer[i]
	if int64(b.block) != block { //has an int64 cast on b.block
		return ocr2keepers.TransmitEvent{}, false
	}
	if len(b.records) == 0 {
		return ocr2keepers.TransmitEvent{}, false
	}
	e, ok := b.records[logID]

	return e, ok
}

I'm not sure on the tradeoff with this pattern:
type BlockNumber uint64

What's the readability/usability gain relative to all the casting when we need to perform an int64 operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know this code, but that makes sense to me.

@@ -74,7 +74,7 @@ var _ Task = (*BridgeTask)(nil)

var zeroURL = new(url.URL)

const stalenessCap = time.Duration(30 * time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a comment explaining where it comes from or be wired through config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem arbitrary. Introduced here: #7964

Copy link
Contributor

@patrickhuie19 patrickhuie19 left a comment

Choose a reason for hiding this comment

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

🚀

Had some questions outside the scope of this PR

@jmank88 jmank88 added this pull request to the merge queue Jan 12, 2024
Merged via the queue into develop with commit e595f5b Jan 12, 2024
80 checks passed
@jmank88 jmank88 deleted the golangci-lint-unconvert branch January 12, 2024 13:56
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.

None yet

3 participants