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

chore: track walletType usage #774

Closed
wants to merge 5 commits into from
Closed

Conversation

arcoraven
Copy link
Contributor

@arcoraven arcoraven commented Nov 18, 2024

closes infra-438


PR-Codex overview

This PR focuses on refactoring the getWalletDetails function to use walletAddress instead of address, enhancing clarity and consistency across the codebase. Additionally, it introduces type improvements and cache handling for wallet details.

Detailed summary

  • Changed parameter name from address to walletAddress in getWalletDetails.
  • Updated calls to getWalletDetails across multiple files to use the new parameter.
  • Added walletDetailsCache for caching wallet details.
  • Introduced walletType property in various transaction types.
  • Enhanced error handling for wallet details retrieval.
  • Added transformation functions for smart backend wallets in transaction processing.
  • Improved address normalization and handling in transaction insertion logic.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@arcoraven arcoraven requested a review from d4mr November 18, 2024 04:41
src/db/wallets/getWalletDetails.ts Show resolved Hide resolved
// Get wallet details. For EOA and SBW (v5 endpoints), `from` should return a valid backend wallet.
// For SBW (v4 endpoints), `accountAddress` should return a valid backend wallet.
// Else the provided details are incorrect (user error).
let walletDetails: ParsedWalletDetails | undefined;
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 is the big change @d4mr. To track walletType we need to query walletDetails for all transactions (not just SBW).

Copy link

This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days.

/**
* Try to resolve wallet details, determining if we're in V4 or V5 case
* For V5: wallet details should be found from 'from' address (Cases 1 & 3)
* For V4: wallet details are found from accountAddress (Cases 2 & 4)
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 is kinda weird for case 4: v4 SDK for an EOA sender. This flow sets the accountAddress even if it's not a userOp?

Comment on lines 146 to 149
"Account not found",
StatusCodes.BAD_REQUEST,
"ACCOUNT_NOT_FOUND",
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a clearer error here? Is this a use case the user can get into, or does it indicate a bug within Engine (5xx response)?

Copy link
Member

Choose a reason for hiding this comment

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

if a wallet address that doesn't exist in engine at all is sent, then that's user error, so 4xx

}

// Simulate the transaction.
// walletDetails is now narrowed to SmartBackendWalletDetails
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already know this is a smart backend wallet here.

Can we move validateSmartBackendWalletChainSupport out here? Then these transform methods are a lot simpler (and no longer async)

return { processedTransaction };
};

const normalizeAddresses = (
Copy link
Contributor Author

@arcoraven arcoraven Dec 4, 2024

Choose a reason for hiding this comment

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

This abstraction feels unnecessary, can we move it back inline?

I want this file to mostly read linearly without having to jump into helper functions unless its super obvious what the function does (e.g. isSmartBackendWallet(...))

Copy link

linear bot commented Dec 5, 2024

}
// Handle idempotency
const queueId: string = idempotencyKey ?? randomUUID();
if (idempotencyKey && (await TransactionDB.exists(queueId))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see you're reducing this code for readability. Actually maybe this line can just be:

if (await TransactionDB.exists(queueId)) {

The key difference being: if a RANDOMLY GENERATED queueId exists in DB (idempotency was not provided) this will fail. Previously, it would override the previous one. Arguably both are bad situations but extremely low probability, so might as well go with the simpler code.

// from is set to the SBW account address (this should be the SBW signer address)
// these values need to be corrected so the worker can process the transaction
// Case 1 & 2: Wallet found by 'from'
if (walletFoundByFrom && walletDetails) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't these be the same? If walletDetails is truthy, walletFoundByFrom must be true here.

walletDetails,
);
} else {
// Case 2: Regular wallet (V4 or V5) - just add wallet type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use "EOA" instead of "regular" for consistency and clarity

// From this point on, we're in Case 3 territory - check for V4 smart backend wallet
if (!queuedTransaction.accountAddress) {
throw createCustomError(
"Account not found",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible for a user to get into this state? If so, we should make the error more clear.

Invalid backend wallet configuration. See: https://portal.thirdweb.com/engine/troubleshooting

And maybe put more help there.

If a user can't get here and this will only fail if there's a bug within Engine, this should just throw (treated as a 500).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same with the next two thrown errors below.

Copy link

This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days.

}: GetWalletDetailsParams) => {
// Wallet details are stored in lowercase.
const walletAddress = _walletAddress.toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

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

ugh would love for all of us to align on lower vs checksum

Copy link

This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants