Skip to content

Commit

Permalink
idb plainmessage gasprices (#1121)
Browse files Browse the repository at this point in the history
* idb plainmessage gasprices

* interface

* indexdb version bump

* add comments

* modified types to use jsonified

---------

Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
Co-authored-by: Tal Derei <talderei99@gmail.com>
Co-authored-by: Tal Derei <70081547+TalDerei@users.noreply.github.com>
  • Loading branch information
4 people authored May 16, 2024
1 parent 223544e commit 010bd1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/extension/.env.testnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CHAIN_ID=penumbra-testnet-deimos-8
IDB_VERSION=39
IDB_VERSION=40
MINIFRONT_URL=https://app.testnet.penumbra.zone
PRAX=lkpmkhpnhknhmibgnmmhdhgdilepfghe
30 changes: 19 additions & 11 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
DutchAuctionDescription,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { PartialMessage } from '@bufbuild/protobuf';

interface IndexedDbProps {
dbVersion: number; // Incremented during schema changes
Expand Down Expand Up @@ -286,15 +287,16 @@ export class IndexedDb implements IndexedDbInterface {
const savedGasPrices = await this.getGasPrices();
// These are arbitrarily set, but can take on any value.
// The gas prices set here will determine the fees to use Penumbra.
//
// Note: this is a temporary measure to enable gas prices in the web, but once
// https://github.com/penumbra-zone/penumbra/issues/4306 is merged, we can remove this.
if (!savedGasPrices) {
await this.saveGasPrices(
new GasPrices({
verificationPrice: 1n,
executionPrice: 1n,
blockSpacePrice: 1n,
compactBlockSpacePrice: 1n,
}),
);
await this.saveGasPrices({
verificationPrice: 1n,
executionPrice: 1n,
blockSpacePrice: 1n,
compactBlockSpacePrice: 1n,
});
}
}

Expand Down Expand Up @@ -389,11 +391,17 @@ export class IndexedDb implements IndexedDbInterface {
}

async getGasPrices(): Promise<GasPrices | undefined> {
return this.db.get('GAS_PRICES', 'gas_prices');
const jsonGasPrices = await this.db.get('GAS_PRICES', 'gas_prices');
if (!jsonGasPrices) return undefined;
return GasPrices.fromJson(jsonGasPrices);
}

async saveGasPrices(value: GasPrices): Promise<void> {
await this.u.update({ table: 'GAS_PRICES', value, key: 'gas_prices' });
async saveGasPrices(value: PartialMessage<GasPrices>): Promise<void> {
await this.u.update({
table: 'GAS_PRICES',
value: new GasPrices(value).toJson() as Jsonified<GasPrices>,
key: 'gas_prices',
});
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/indexed-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
AuctionId,
DutchAuctionDescription,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { PartialMessage } from '@bufbuild/protobuf';

export interface IdbUpdate<DBTypes extends PenumbraDb, StoreName extends StoreNames<DBTypes>> {
table: StoreName;
Expand Down Expand Up @@ -85,7 +86,7 @@ export interface IndexedDbInterface {
saveSwap(note: SwapRecord): Promise<void>;
getSwapByCommitment(commitment: StateCommitment): Promise<SwapRecord | undefined>;
getGasPrices(): Promise<GasPrices | undefined>;
saveGasPrices(value: GasPrices): Promise<void>;
saveGasPrices(value: PartialMessage<GasPrices>): Promise<void>;
getNotesForVoting(
addressIndex: AddressIndex | undefined,
votableAtHeight: bigint,
Expand Down Expand Up @@ -194,7 +195,7 @@ export interface PenumbraDb extends DBSchema {
};
GAS_PRICES: {
key: 'gas_prices';
value: GasPrices;
value: Jsonified<GasPrices>;
};
POSITIONS: {
key: string; // base64 PositionRecord['id']['inner'];
Expand Down

0 comments on commit 010bd1f

Please sign in to comment.