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

Update blocktracker and tracker to provide synchronous API #246

Merged
merged 12 commits into from
Jun 22, 2023

Conversation

sergerad
Copy link
Contributor

@sergerad sergerad commented May 18, 2023

Changes

  • Update blocktracker and tracker APIs to be synchronous
  • Remove logger from blocktracker
  • Handle ignored error
  • Update blocktracker to return subscription cancellation errors
  • Update unit tests

Why?

Pkg API funcs should return errors they encounter, rather than log them. This allows the caller to decide what to do on error and means we don't leak logging impl/semantics into ethgo (e.g. [ERROR] prefix).

See https://github.com/golang/go/wiki/CodeReviewComments#synchronous-functions

Usage goes from

// This runs a goroutine for us and does not return all errors from its stack
tracker.Sync()

to

go func() {
    // This goroutine receives all errors from Sync stack, we decide what to do with those errors
    err := tracker.Sync()
}

Alternative Impl?

Could keep the funcs asynchronous and update them to return a channel of errors. More complicated, more side effects

@vercel
Copy link

vercel bot commented May 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ethgo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 21, 2023 9:04pm

if err := block.UnmarshalJSON(buf); err != nil {
s.logger.Printf("[ERR]: Tracker failed to parse ethgo.Block: %v", err)
} else {
handle(&block)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error was being ignored completely

tracker/tracker_test.go Outdated Show resolved Hide resolved
@sergerad sergerad changed the title Update blocktracker to provide synchronous API Update blocktracker and tracker to provide synchronous API May 19, 2023
@sergerad
Copy link
Contributor Author

@ferranbt could you please take a look at this PR. My biggest concern is the unhandled error

@paulgoleary
Copy link
Contributor

bump @ferranbt @vcastellm

@ferranbt
Copy link
Contributor

Please check the CI.

@paulgoleary
Copy link
Contributor

The test that seems to be failing here, TestFilterIntegration does not fail for me locally.

pauloleary@Pauls-MacBook-Pro-3 ethgo % go test -v -run TestFilterIntegration ./tracker
=== RUN   TestFilterIntegration
--- PASS: TestFilterIntegration (3.97s)
PASS
ok  	github.com/umbracle/ethgo/tracker	4.159s

Not sure what the CI problem could be?

@sergerad
Copy link
Contributor Author

@paulgoleary thanks for taking a look. Sorry I have been out sick all week. Hoping to be back online tomorrow to look at this 🙏

@paulgoleary
Copy link
Contributor

re-bump @ferranbt @vcastellm

@sergerad sergerad requested a review from ferranbt June 21, 2023 20:48
Copy link
Collaborator

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

LGTM

@ferranbt ferranbt merged commit 8230f57 into umbracle:main Jun 22, 2023
3 checks passed
@sergerad sergerad deleted the synchronous-api-funcs branch June 22, 2023 21:30
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

4 participants