Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
fix(batch-worker): schema breaking changes
Browse files Browse the repository at this point in the history
Schema changes due to limiting the size of POV created
breaking change to how schemas are accessed.

Update how schemas are queried to ensure that a schema payload
is returned.

issue-84
  • Loading branch information
Enddy Dumbrique committed Mar 28, 2024
1 parent 10b690c commit f4a3bfe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions apps/worker/src/batch_announcer/batch.announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ParquetWriter } from '@dsnp/parquetjs';
import { fromFrequencySchema } from '@dsnp/frequency-schemas/parquet';
import { InjectRedis } from '@liaoliaots/nestjs-redis';
import Redis from 'ioredis';
import { PalletSchemasSchema } from '@polkadot/types/lookup';
import { hexToString } from '@polkadot/util';
import { RedisUtils } from '../../../../libs/common/src/utils/redis';
import { BlockchainService } from '../../../../libs/common/src/blockchain/blockchain.service';
Expand Down Expand Up @@ -33,13 +32,13 @@ export class BatchAnnouncer {
const schemaCacheKey = `schema:${schemaId}`;
let cachedSchema: string | null = await this.cacheManager.get(schemaCacheKey);
if (!cachedSchema) {
const schemaResponse = await this.blockchainService.getSchema(schemaId);
const schemaResponse = await this.blockchainService.getSchemaPayload(schemaId);
cachedSchema = JSON.stringify(schemaResponse);
await this.cacheManager.setex(schemaCacheKey, RedisUtils.STORAGE_EXPIRE_UPPER_LIMIT_SECONDS, cachedSchema);
}

const frequencySchema: PalletSchemasSchema = JSON.parse(cachedSchema);
const hexString: string = Buffer.from(frequencySchema.model).toString('utf8');
const frequencySchemaPayload = JSON.parse(cachedSchema);
const hexString: string = Buffer.from(frequencySchemaPayload).toString('utf8');
const schema = JSON.parse(hexToString(hexString));
if (!schema) {
throw new Error(`Unable to parse schema for schemaId ${schemaId}`);
Expand Down
8 changes: 4 additions & 4 deletions libs/common/src/blockchain/blockchain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { KeyringPair } from '@polkadot/keyring/types';
import { BlockHash, BlockNumber, DispatchError, DispatchInfo, Hash, SignedBlock } from '@polkadot/types/interfaces';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { AnyNumber, ISubmittableResult, RegistryError } from '@polkadot/types/types';
import { u32, Option, u128 } from '@polkadot/types';
import { PalletCapacityCapacityDetails, PalletCapacityEpochInfo, PalletSchemasSchema } from '@polkadot/types/lookup';
import { u32, Option, u128, Bytes } from '@polkadot/types';
import { PalletCapacityCapacityDetails, PalletCapacityEpochInfo } from '@polkadot/types/lookup';
import { ConfigService } from '../config/config.service';
import { Extrinsic } from './extrinsic';

Expand Down Expand Up @@ -152,8 +152,8 @@ export class BlockchainService implements OnApplicationBootstrap, OnApplicationS
return this.api.consts.frequencyTxPayment.maximumCapacityBatchLength.toNumber();
}

public async getSchema(schemaId: number): Promise<PalletSchemasSchema> {
const schema: PalletSchemasSchema = await this.query('schemas', 'schemas', schemaId);
public async getSchemaPayload(schemaId: number): Promise<Bytes> {
const schema: Bytes = await this.query('schemas', 'schemaPayloads', schemaId);
return schema;
}

Expand Down

0 comments on commit f4a3bfe

Please sign in to comment.