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

Feat(suite-native): retry FW revision check if it's stale #17437

Merged
merged 2 commits into from
Mar 10, 2025

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Mar 6, 2025

Description

  • add a new Connect method to prompt retrying of FW authenticity checks, if eligible for retry
    • currently, retries happen only during a device call, which'd necessitate a purposeless call just to rerun them
  • in mobile, periodically query rerun FW authenticity checks, if eligible for retry

Related Issue

Resolve #17133

Screenshots:

Video demonstrating it on the testing branch.

  • Using with physical T2B1 via trezord mocked with unrecognized version 9,8,7
  • It starts with forced NetworkError
  • Lots of retries at the beginning (lots of calls to device during handshake & account discovery)
  • Then I let it retry a few times with the given interval
  • Then I allowed network requests again, so that FW rev check finally settles
testing.webm

Copy link

github-actions bot commented Mar 6, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 26
  • More info

Learn more about 𝝠 Expo Github Action

this.authenticityChecks = {
...this.authenticityChecks,
firmwareRevision: result,
};
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 shouldn't be necessary 😅
But it is 🙈 see slack convo

TL;DR: there is not yet deepclone isolation between Connect and redux in mobile 📱 , like it is on Web. That causes problems because the objects are passed byRef from Connect, redux does its magic with them, and it causes weird bugs back in Connect. Namely: assignment of authenticityChecks.firmwareRevision does not work, have to assign authenticityChecks 🙉

@Lemonexe Lemonexe marked this pull request as ready for review March 6, 2025 10:11
Copy link

coderabbitai bot commented Mar 6, 2025

Walkthrough

The changes update the firmware authenticity verification process and its integration into the application. The device module now creates new objects for firmware hash and revision updates instead of modifying the existing object directly. A new custom React hook, useRetryFwAuthenticityChecks, is introduced to periodically recheck firmware authenticity when a retriable error is detected. This hook leverages React’s useEffect and Redux’s useSelector to monitor error states and conditionally trigger repeated verification at fixed intervals. The global hooks initialization routine is updated to include this new hook, ensuring it is executed during app startup. Additionally, a new dependency for type utilities is added, and the TypeScript configuration is updated to reference the corresponding package, making the type utilities available within the device module.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d58576 and c69d23f.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • suite-native/app/src/hooks/useGlobalHooks.tsx (2 hunks)
  • suite-native/device/package.json (1 hunks)
  • suite-native/device/src/hooks/useRetryFwAuthenticityChecks.ts (1 hunks)
  • suite-native/device/src/index.ts (1 hunks)
  • suite-native/device/tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • suite-native/device/tsconfig.json
  • suite-native/device/src/index.ts
  • suite-native/app/src/hooks/useGlobalHooks.tsx
  • suite-native/device/src/hooks/useRetryFwAuthenticityChecks.ts
  • suite-native/device/package.json
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: build-deploy
  • GitHub Check: build-deploy
  • GitHub Check: build
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-web
  • GitHub Check: transport-e2e-test
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: test
  • GitHub Check: prepare_android_test_app
  • GitHub Check: EAS Update
  • GitHub Check: Socket Security: Pull Request Alerts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
suite-native/device/src/hooks/useRetryFwAuthenticityChecks.ts (1)

19-24: Consider adding error handling

While the comment explains that you're not concerned with the promise result, it's a good practice to add error handling to prevent unhandled promise rejections.

-                TrezorConnect.runAuthenticityChecks().then();
+                TrezorConnect.runAuthenticityChecks().catch(error => {
+                    console.error('Error retrying firmware authenticity checks:', error);
+                });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cec28ce and 0419d57.

📒 Files selected for processing (9)
  • packages/connect/src/api/index.ts (1 hunks)
  • packages/connect/src/api/runAuthenticityChecks.ts (1 hunks)
  • packages/connect/src/device/Device.ts (4 hunks)
  • packages/connect/src/factory.ts (1 hunks)
  • packages/connect/src/types/api/index.ts (2 hunks)
  • packages/connect/src/types/api/runAuthenticityChecks.ts (1 hunks)
  • suite-native/app/src/hooks/useGlobalHooks.tsx (2 hunks)
  • suite-native/device/src/hooks/useRetryFwAuthenticityChecks.ts (1 hunks)
  • suite-native/device/src/index.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
🔇 Additional comments (14)
packages/connect/src/api/index.ts (1)

50-50: New API method added correctly

The runAuthenticityChecks method is properly exported, maintaining the same pattern as other API methods in this file.

packages/connect/src/types/api/runAuthenticityChecks.ts (1)

1-4: Type declaration looks good

The type declaration for runAuthenticityChecks is correctly defined, taking optional common parameters and returning the appropriate response type.

suite-native/device/src/index.ts (1)

7-7: Hook properly exported

The useRetryFwAuthenticityChecks hook is correctly exported, making it available for use in the application to implement the retry mechanism for firmware authenticity checks.

packages/connect/src/factory.ts (1)

174-175: Method implementation follows established pattern

The runAuthenticityChecks method is properly implemented in the factory, following the same pattern as other methods and maintaining consistent spacing.

suite-native/app/src/hooks/useGlobalHooks.tsx (1)

5-5: Implementation looks clean!

Good integration of the new useRetryFwAuthenticityChecks hook into the global hooks. The placement after the existing authenticity-related hooks is logical and maintains the code's organization.

Also applies to: 25-26

packages/connect/src/types/api/index.ts (1)

69-69: LGTM: Interface properly extended

The runAuthenticityChecks method is correctly imported and added to the TrezorConnect interface with appropriate typings.

Don't forget to add documentation links in the future as noted in the TODO comment.

Also applies to: 299-301

packages/connect/src/api/runAuthenticityChecks.ts (2)

5-7: Verify permission settings with Connect team

Based on the previous comments, there seems to be uncertainty about the correct configuration. The useEmptyPassphrase setting is necessary, but you might want to double-check if the current permissions settings are complete.


10-15: Method implementation looks good

The run method correctly calls the required firmware check methods and returns a success message. The sequence of operations is logical - first checking the firmware hash and then checking the firmware revision.

suite-native/device/src/hooks/useRetryFwAuthenticityChecks.ts (2)

14-16: Good error check implementation

The code correctly identifies retriable errors by checking both for non-null error state and membership in the predefined list of retriable errors.


25-28: Clean interval management

The interval setup and cleanup are correctly implemented. Good use of the dependency array to re-establish the interval only when the isRetriableError state changes.

packages/connect/src/device/Device.ts (4)

786-786: Method visibility changed from private to public

This change makes checkFirmwareHashWithRetries accessible from outside the Device class, which aligns with the PR objective of implementing a retry mechanism for firmware authenticity checks.


799-803: Immutable state update pattern applied

The change ensures that the authenticityChecks object is updated immutably by creating a new object reference instead of modifying properties directly. This addresses the Redux integration issue mentioned in the past review comments.


883-883: Method visibility changed from private to public

Similar to the previous change, exposing checkFirmwareRevisionWithRetries enables external components to trigger firmware revision checks with retries.


922-925: Immutable state update pattern applied

As with the earlier change, this ensures the authenticityChecks object is updated immutably by creating a new object reference, which prevents issues with Redux in mobile environments as noted in the past review comments.

@Lemonexe Lemonexe force-pushed the fix-FW-rev-check-persistent-offline branch 2 times, most recently from 091cb5e to 08d830c Compare March 6, 2025 16:38
Copy link
Member

@matejkriz matejkriz left a comment

Choose a reason for hiding this comment

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

I'm not sure about the refresh interval value, but otherwise the suite-native part looks good. I'm not approving the connect part :-)

@Lemonexe Lemonexe force-pushed the fix-FW-rev-check-persistent-offline branch from 08d830c to 739897e Compare March 7, 2025 16:31
@Lemonexe Lemonexe force-pushed the fix-FW-rev-check-persistent-offline branch from 739897e to 2d58576 Compare March 10, 2025 07:51
@Lemonexe Lemonexe force-pushed the fix-FW-rev-check-persistent-offline branch from 2d58576 to c69d23f Compare March 10, 2025 07:53
@Lemonexe Lemonexe merged commit f534c08 into develop Mar 10, 2025
73 checks passed
@Lemonexe Lemonexe deleted the fix-FW-rev-check-persistent-offline branch March 10, 2025 09: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.

Offline fw revision check banner doesn't disappear after going online
3 participants