penumbra-zone / web

Apache License 2.0
10 stars 7 forks source link

Modify `GasPrices` storage to support multi-asset fees #1310

Open Valentine1898 opened 1 week ago

Valentine1898 commented 1 week ago

You are right, GasPrices does contain an asset_id, I missed that because asset_id is never defined. But the problem is that our GasPrices storage is deprecated and not suitable for multi-asset fees

Now we store GasPrices assuming that we can only have one record

GAS_PRICES: {
    key: 'gas_prices';
    value: Jsonified<GasPrices>;
  };

Instead, we should use the assetId as the key

GAS_PRICES: {
    key: Jsonified<Required<GasPrices>['assetId']['inner']>;
    value: Jsonified<GasPrices>;
  };

But in that case, I expect we'll run into an error, because pd purposely omits the assetId for native GasPrices, but that's bad for us, because undefined can't be a key in indexed-db

We will have to manually add the assetId for native GasPrices or come up with another trick

Also, note that the getGasPrices function will also have to be modified

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

Also need to change the gasPrices rpc for the view service so that it retrieves alt_gas_prices

And the block processor logic that should save alt_gas_prices to indexed-db when needed

_Originally posted by @Valentine1898 in https://github.com/penumbra-zone/web/pull/1268#discussion_r1642984352_