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

fix: avoid use queryInfo rpc call #1169

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Changes from 3 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
28 changes: 24 additions & 4 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { extractAuthor } from '@polkadot/api-derive/type/util';
import { Compact, GenericCall, Option, Struct, Vec } from '@polkadot/types';
import { GenericExtrinsic } from '@polkadot/types/extrinsic';
import {
AccountId32,
Block,
Expand All @@ -27,6 +28,7 @@ import {
EventRecord,
Header,
InclusionFee,
RuntimeDispatchInfo,
Weight,
} from '@polkadot/types/interfaces';
import { AnyJson, Codec, Registry } from '@polkadot/types/types';
Expand Down Expand Up @@ -260,10 +262,7 @@ export class BlocksService extends AbstractService {
class: dispatchClass,
partialFee,
weight,
} = await api.rpc.payment.queryInfo(
block.extrinsics[idx].toHex(),
previousBlockHash
);
} = await this.fetchQueryInfo(block.extrinsics[idx], previousBlockHash);

const transactionPaidFeeEvent = xtEvents.find(
({ method }) =>
Expand Down Expand Up @@ -368,6 +367,27 @@ export class BlocksService extends AbstractService {
return finalPartialFee;
}

/**
* Fetch `payment_queryInfo`.
*
* @param ext
* @param previousBlockHash
*/
private async fetchQueryInfo(
ext: GenericExtrinsic,
previousBlockHash: BlockHash
): Promise<RuntimeDispatchInfo> {
const { api } = this;
const apiAt = await api.at(previousBlockHash);
if (apiAt.call.transactionPaymentApi.queryInfo) {
const u8a = ext.toU8a();
return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length);
} else {
// fallback to rpc call
return api.rpc.payment.queryInfo(ext.toHex(), previousBlockHash);
}
}

/**
* Retrieve the blockHash for the previous block to the one getting queried.
* If the block is the geneisis hash it will return the same blockHash.
Expand Down