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

Phishing controller test method should be async and it should not poll #897

Merged
merged 6 commits into from Sep 9, 2022

Conversation

BelfordZ
Copy link
Contributor

@BelfordZ BelfordZ commented Aug 24, 2022

PR Title

problems:

  1. Constructor starts polling, which is async. Starting async actions in a contructor makes testing hard.
  2. test depends on state.whitelist which is set async via poll > updatePhishingLists. It is a sync function, which creates race conditions.

solution:

  1. make test, have it update the phishing list if necessary
  2. remove polling

Description

  • BREAKING:

    • phishingController.test now returns a Promise<EthPhishingDetectResult>
    • instead of calling poll with a new interval to change the interval, use phishingController.setRefreshInterval or phishingController.configure({ refreshInterval: 123 }) (configure will be deprecated when we switch to using BaseController V2)
  • FIXED:

    • race conditions in Phishing controller tests

Checklist

  • [ x ] Tests are included if applicable
  • [ x ] Any added code is fully documented

Issue

Resolves #???

@BelfordZ BelfordZ requested a review from a team as a code owner August 24, 2022 09:10
@BelfordZ BelfordZ marked this pull request as draft August 24, 2022 09:10
@BelfordZ BelfordZ changed the title asd Phishing controller test method should be async and it should not poll Aug 24, 2022
@BelfordZ BelfordZ marked this pull request as ready for review August 24, 2022 20:40
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Left some comments below — mostly minor, but did want to see if we could make lastFetched private instead of public.

src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.test.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.test.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.test.ts Outdated Show resolved Hide resolved
src/third-party/PhishingController.test.ts Outdated Show resolved Hide resolved
@BelfordZ BelfordZ requested a review from mcmire September 7, 2022 18:50
@BelfordZ
Copy link
Contributor Author

BelfordZ commented Sep 7, 2022

@mcmire I've updated bypass to no longer be async & no longer call fetchIfNecessary

mcmire
mcmire previously approved these changes Sep 8, 2022
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This looks good to me!

src/third-party/PhishingController.ts Outdated Show resolved Hide resolved
@BelfordZ BelfordZ requested a review from mcmire September 8, 2022 17:53
@BelfordZ
Copy link
Contributor Author

BelfordZ commented Sep 8, 2022

@mcmire bump!

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt
Copy link
Member

Gudahtt commented Sep 9, 2022

Hmm. This might significantly slow down the phishing check when a page loads. The check is already made asynchronously, with the suspicious page sometimes loading partially before we have a chance to redirect to the warning page.

I'll test this out to see what it looks like in practice. Maybe there are ways to check sooner in the navigation process.

@Gudahtt
Copy link
Member

Gudahtt commented Sep 9, 2022

In testing, the slowdown is noticeable but barely. It doesn't seem appreciably different from before as far as I can tell. Before and after, there is a flash of the page rendering before redirect.

It'll be a bit difficult to manage this on the extension side because we normally check the phishing list just prior to setting up the RPC pipeline. If this is async, we'll need to continue to setup the pipeline without waiting (so we don't drop requests send during page load), but we won't want to process these requests until after the result returns. But that's fine, we can do that.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt Gudahtt merged commit a2f4bbe into main Sep 9, 2022
@Gudahtt Gudahtt deleted the phishing-controller-races branch September 9, 2022 12:44
@Gudahtt
Copy link
Member

Gudahtt commented Sep 9, 2022

I went ahead with merging this myself so that it could be included in the v31 release

MajorLift pushed a commit that referenced this pull request Oct 11, 2023
#897)

* Changed phishing controller interface to be async and not have polling

* fixed PR review issues

* Fixed linting issues in PhishingController test

* Removed fetching phishing list before bypass function body

* Added period to the end of param jsdoc

Co-authored-by: Shane Jonas <jonas.shane@gmail.com>
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
#897)

* Changed phishing controller interface to be async and not have polling

* fixed PR review issues

* Fixed linting issues in PhishingController test

* Removed fetching phishing list before bypass function body

* Added period to the end of param jsdoc

Co-authored-by: Shane Jonas <jonas.shane@gmail.com>
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