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

Set brave wallet string state synchronously. #12748

Merged
merged 1 commit into from
Mar 28, 2022
Merged

Set brave wallet string state synchronously. #12748

merged 1 commit into from
Mar 28, 2022

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented Mar 25, 2022

When wallet is first created, it is written to profile prefs by asynchronous SetStringState mojo call (in Wallet::SetWallet function). After that wallet is requested shortly by running synchronous GetStringState mojo call (in PostWalletBrave::Request function). This leads to race condition so requested wallet could be null (it happens due to mojo async tasks queue execution is interrupted on mojo sync tasks execution).

This PR changes wallet set state mojo calls to synchronous calls (like SetStringState)

Resolves brave/brave-browser#21809

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Need to confirm that we able to create a wallet on clean install.
  • Trigger an ad, confirm we got credited for viewing it
  • Confirm tips are processed

@aseren aseren requested review from a team as code owners March 25, 2022 12:41
@@ -193,6 +193,8 @@ interface BatLedgerClient {
SetDoubleState(string name, double value);
[Sync]
GetStringState(string name) => (string value);
[Sync]
SetStringStateSync(string name, string value) => ();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me that all of the Set*State methods are going to be prone to the same race condition.

As far as I know, all the "Set" methods are used exactly as if they were sync. Instead of introducing a "Sync" version of SetStringState, can we just add the [Sync] attribute to all of these "SetState" methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thanks for the idea!

@aseren aseren requested review from zenparsing and removed request for a team March 28, 2022 06:49
Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

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

LGTM

@aseren aseren added this to the 1.39.x - Nightly milestone Mar 28, 2022
@aseren aseren merged commit 8f65aa9 into master Mar 28, 2022
@aseren aseren deleted the issues/21809 branch March 28, 2022 16:41
brave-builds pushed a commit that referenced this pull request Mar 29, 2022
brave-builds pushed a commit that referenced this pull request Mar 29, 2022
@kjozwiak
Copy link
Member

kjozwiak commented Apr 5, 2022

Verification PASSED on Win 11 x64 using the following build(s):

Brave | 1.39.28 Chromium: 100.0.4896.60 (Official Build) nightly (64-bit)
-- | --
Revision | 6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896@{#875}
OS | Windows 11 Version 21H2 (Build 22000.593)
  • ensured that creating a Brave Wallet via brave://wallet worked without any issues on new profiles
  • ensured that users can trigger ad notifications and are being credited
[17832:8708:0405/024937.703:VERBOSE1:ad_notification_serving.cc(142)] Found 1 eligible ads
[17832:8708:0405/024937.703:VERBOSE1:ad_notification_serving.cc(266)] Serving ad notification:
  uuid: b15ae4fa-79ad-406f-b67d-618223dad35e
  creativeInstanceId: f9a0eac9-a311-4189-ba46-e96dbbfc3f05
  creativeSetId: c2ec9fda-9fff-437c-97d5-b211315ef0c4
  campaignId: c67c92ca-6eba-4d49-85cb-3cabfe608dab
  advertiserId: 247767b8-0eef-4349-83fd-a51d0f4d9a55
  segment: business
  title: Sophos Incident Response Guide
  body: Discover the 10 steps you need to take to stop a cyberattack
  targetUrl: https://secure2.sophos.com/en-us/security-news-trends/whitepapers/gated-wp/incident-response-guide.aspx?cmp=120536&utm_source=brave&utm_medium=cpc&utm_campaign=GPD-2021-NA-Display-Brave-Push-Notification-Incident-Response-Guide-DG-120536&utm_content=push-note
[17832:8708:0405/024939.614:VERBOSE1:confirmations.cc(60)] Confirming click for ad_notification with transaction id 26e4acff-ea34-4695-b9ad-dec5e989207d and creative instance id f9a0eac9-a311-4189-ba46-e96dbbfc3f05
  • ensured that tips are being processed
[47444:44176:0405/025436.895:VERBOSE1:contribution.cc(388)] Creating contribution for wallet type uphold (amount: 1, type: ONE_TIME_TIP)
[47444:44176:0405/025436.901:VERBOSE1:contribution.cc(117)] Queue timer set for 4 s
[47444:44176:0405/025436.902:VERBOSE1:database_server_publisher_banner.cc(142)] Server publisher banner not found
[47444:44176:0405/025436.902:VERBOSE5:ledger_impl.cc(119)]
[ REQUEST ]
> URL: https://api.uphold.com/v0/me/cards/a571b03e-b504-4ee8-adc5-bf93e5dca8ab/transactions
> Method: POST
> Content: {"denomination":{"amount":"0.950000","currency":"BAT"},"destination":"7b23cde4-226b-4cd1-87af-fc4ab5c4f1f2","message":""}
> Content Type: application/json; charset=utf-8
[47444:44176:0405/025437.043:VERBOSE6:logging_util.cc(137)]
[ RESPONSE - OnRequest ]
> Url: https://api.uphold.com/v0/me/cards/a571b03e-b504-4ee8-adc5-bf93e5dca8ab/transactions
> Result: Success
> HTTP Code: 202

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.

Fix flaky RequestAdsEnabledApiTestEnabled.RewardsEnablePopupAccepted browser tests
4 participants