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

Validate the calculated Bitcoin deposit address and track it in Sentry #257

Merged
merged 14 commits into from
Feb 27, 2024

Conversation

kkosiorowska
Copy link
Contributor

@kkosiorowska kkosiorowska commented Feb 21, 2024

Closes #238

This PR validates the calculated Bitcoin deposit address and tracks this action in Sentry. It is based on the solution implemented in this PR.

The verification outcome is attached to the telemetry data as two additional fields:

  • verificationStatus which can have three different values
    • valid: verification service responded with the same address as the generated one
    • invalid: verification service responded with a different address
    • error: request or verification service error
  • verificationResponse which holds the complete request outcome

@kkosiorowska kkosiorowska self-assigned this Feb 21, 2024
VITE_SENTRY_SUPPORT was a boolean but returned a string when parsed. We have to make sure to convert it to the desired type when using it in our code.
@kkosiorowska kkosiorowska marked this pull request as ready for review February 22, 2024 13:47
@ioay
Copy link
Contributor

ioay commented Feb 23, 2024

It looks like we would have duplicate tasks for this:
#202 -> PR: #259 (previously: #210)

CC: @nkuba

dapp/src/hooks/useDepositTelemetry.ts Outdated Show resolved Hide resolved
dapp/src/utils/externalApi.ts Outdated Show resolved Hide resolved
@@ -1,7 +1,6 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_SENTRY_SUPPORT: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we remove it? Looks like we use this env variable in useSentry hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. However, take a look here. Even though we set the type VITE_SENTRY_SUPPORT here, it will return a string. I treated it as a temporary solution for now. We need to check/improve working with env vars when these are of boolean type. I will create a separate task for this.

As shown above, VITE_SOME_KEY is a number but returns a string when parsed. The same would also happen for boolean env variables. Make sure to convert to the desired type when using it in your code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kkosiorowska kkosiorowska force-pushed the validate-deposit-address branch from 26de39d to c6bea23 Compare February 26, 2024 09:47
@kkosiorowska kkosiorowska force-pushed the validate-deposit-address branch from c6bea23 to c8478b8 Compare February 26, 2024 09:55
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's worth considering on creating one common catalog for Sentry and acre-react if we don't want to keep Sentry longer in the SDK directory., eg. src/vendor/.

CC: @r-czajkowski

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, the sentry directory was nested in the SDK directory. I took it a level up simply because it seems to me that the structure will be more clear. But I'm open to all suggestions

Copy link
Contributor

Choose a reason for hiding this comment

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

Sentry should not be a part of the acre-react. The dapp should care about the sentry or other integrations.

Copy link
Contributor

Choose a reason for hiding this comment

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

@r-czajkowski I didn't say that it should be part of acre-react, I just thought about putting it in one folder:
src:
-vendor:
-- acre-react
-- sentry


const response = await axios.get<{ address: string }>(
url,
{ timeout: 10000 }, // 10s
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{ timeout: 10000 }, // 10s
{ timeout: ONE_SEC_IN_MILLISECONDS * 10 },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

response: unknown
}> {
const endpoint =
"https://us-central1-keep-prd-210b.cloudfunctions.net/verify-deposit-address"
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move it out of this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depositAddress: string,
network: BitcoinNetwork,
): Promise<{
status: "valid" | "invalid" | "error"
Copy link
Contributor

Choose a reason for hiding this comment

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

create type for status

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm We don't really use this type anywhere else. Therefore, I wonder if it makes sense. 🤔 This status is strictly related only to verifyDepositAddress.

depositor.identifierHex
}/${blindingFactor.toString()}/${refundPublicKeyHash.toString()}/${refundLocktime.toString()}`

const url = extraData ? `${baseUrl}/${extraData.toString()}` : baseUrl
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a helper function to generate this url and baseUrl which will take the extraData parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kkosiorowska kkosiorowska requested a review from ioay February 27, 2024 12:13
@kkosiorowska kkosiorowska merged commit c1aef9f into main Feb 27, 2024
15 checks passed
@kkosiorowska kkosiorowska deleted the validate-deposit-address branch February 27, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate calculated Bitcoin deposit address with tBTC second track verification service
3 participants