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

1604 hastokenbalance should ignore randomizer and use index only #1605

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/pretty-poets-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@penumbra-zone/services': minor
'@penumbra-zone/storage': minor
'@penumbra-zone/types': minor
---

fix source randomizer
5 changes: 5 additions & 0 deletions apps/minifront/src/state/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export const planBuildBroadcast = async (
const rpcMethod = options?.skipAuth ? viewClient.witnessAndBuild : viewClient.authorizeAndBuild;

try {
// TODO: Temp fix to not compare randomizer. Can delete after v11.10 is released.
if (req.source) {
req.source.randomizer = new Uint8Array();
}

const transactionPlan = await plan(req);

const transaction = await build({ transactionPlan }, rpcMethod, status =>
Expand Down
4 changes: 2 additions & 2 deletions packages/services/src/view-service/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const getAssetFromGasPriceTable = async (
// If a specific asset ID is provided, extracted from the transaction request, check its balance is
// positive and GasPrices for that asset exist.
if (assetId) {
const balance = await indexedDb.hasTokenBalance(request.source, assetId);
const balance = await indexedDb.hasTokenBalance(request.source.account, assetId);
// This check ensures that the alternative fee token is a valid fee token, for example, TestUSD is not.
const isInGasTable = altGasPrices.find(gp => gp.assetId?.equals(assetId));
if (balance && isInGasTable) {
Expand All @@ -129,7 +129,7 @@ export const getAssetFromGasPriceTable = async (
// GasPrices table as a fallback case.
for (const gasPrice of altGasPrices) {
if (gasPrice.assetId) {
const balance = await indexedDb.hasTokenBalance(request.source, gasPrice.assetId);
const balance = await indexedDb.hasTokenBalance(request.source.account, gasPrice.assetId);
if (balance) {
return gasPrice.assetId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const transactionPlanner: Impl['transactionPlanner'] = async (req, ctx) =
const { indexedDb } = await services.getWalletServices();

// Query IndexedDB directly to check for the existence of staking token
const nativeToken = await indexedDb.hasTokenBalance(req.source!, indexedDb.stakingTokenAssetId);
const nativeToken = await indexedDb.hasTokenBalance(
req.source!.account,
indexedDb.stakingTokenAssetId,
);

// Check if we should use the native token or extract an alternate gas fee token.
// Special cased for swap claims as gas fee needs to match the claimFee on the corresponding swap.
Expand Down
6 changes: 4 additions & 2 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ export class IndexedDb implements IndexedDbInterface {
};
}

async hasTokenBalance(addressIndex: AddressIndex, assetId: AssetId): Promise<boolean> {
async hasTokenBalance(accountIndex: number, assetId: AssetId): Promise<boolean> {
const spendableNotes = await this.db.getAllFromIndex(
'SPENDABLE_NOTES',
'assetId',
Expand All @@ -878,10 +878,12 @@ export class IndexedDb implements IndexedDbInterface {

return spendableNotes.some(note => {
const spendableNote = SpendableNoteRecord.fromJson(note);

// randomizer should be ignored
return (
spendableNote.heightSpent === 0n &&
!isZero(getAmountFromRecord(spendableNote)) &&
spendableNote.addressIndex?.equals(addressIndex)
spendableNote.addressIndex?.account === accountIndex
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/indexed-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export interface IndexedDbInterface {
auctionId: AuctionId,
): Promise<{ input: Value; output: Value } | undefined>;

hasTokenBalance(addressIndex: AddressIndex, assetId: AssetId): Promise<boolean>;
hasTokenBalance(addressIndex: number, assetId: AssetId): Promise<boolean>;
}

export interface PenumbraDb extends DBSchema {
Expand Down
Loading