From 92ee496c399f51e6dfb38af79149e709d8e5acf3 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 20 Dec 2022 16:13:34 +1300 Subject: [PATCH 1/4] avoid use queryInfo rpc call --- src/services/blocks/BlocksService.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index b612815de..5de343e10 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -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, @@ -27,6 +28,7 @@ import { EventRecord, Header, InclusionFee, + RuntimeDispatchInfo, Weight, } from '@polkadot/types/interfaces'; import { AnyJson, Codec, Registry } from '@polkadot/types/types'; @@ -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 }) => @@ -368,6 +367,22 @@ export class BlocksService extends AbstractService { return finalPartialFee; } + /** + * Fetch `payment_queryInfo`. + * + * @param ext + * @param previousBlockHash + */ + private async fetchQueryInfo( + ext: GenericExtrinsic, + previousBlockHash: BlockHash + ): Promise { + const { api } = this; + const apiAt = await api.at(previousBlockHash); + const u8a = ext.toU8a(); + return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length); + } + /** * 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. From cb1bd91be4850750fc8a2a3d56268fde00c87f4e Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 20 Dec 2022 16:23:17 +1300 Subject: [PATCH 2/4] fallback to rpc call --- src/services/blocks/BlocksService.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index 5de343e10..af57f6e3c 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -380,7 +380,12 @@ export class BlocksService extends AbstractService { const { api } = this; const apiAt = await api.at(previousBlockHash); const u8a = ext.toU8a(); - return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length); + if (apiAt.call.transactionPaymentApi.queryInfo) { + return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length); + } else { + // fallback to rpc call + return api.rpc.payment.queryInfo(ext.toHex(), previousBlockHash); + } } /** From 367219bfeaa47ecaa26e4ed22e72f6ed9533f34d Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 20 Dec 2022 16:27:29 +1300 Subject: [PATCH 3/4] minor improvement --- src/services/blocks/BlocksService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index af57f6e3c..53204916c 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -379,8 +379,8 @@ export class BlocksService extends AbstractService { ): Promise { const { api } = this; const apiAt = await api.at(previousBlockHash); - const u8a = ext.toU8a(); if (apiAt.call.transactionPaymentApi.queryInfo) { + const u8a = ext.toU8a(); return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length); } else { // fallback to rpc call From 2175bc2f5e24cd738eb1411c79a15f799819b81a Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 20 Dec 2022 22:43:45 +1300 Subject: [PATCH 4/4] update fetchQueryFeeDetails --- src/services/blocks/BlocksService.ts | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index 53204916c..608529b30 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -285,7 +285,7 @@ export class BlocksService extends AbstractService { ); if (doesQueryFeeDetailsExist === 'available') { finalPartialFee = await this.fetchQueryFeeDetails( - block.extrinsics[idx].toHex(), + block.extrinsics[idx], previousBlockHash, weightInfo.weight, weight @@ -295,7 +295,7 @@ export class BlocksService extends AbstractService { } else if (doesQueryFeeDetailsExist === 'unknown') { try { finalPartialFee = await this.fetchQueryFeeDetails( - block.extrinsics[idx].toHex(), + block.extrinsics[idx], previousBlockHash, weightInfo.weight, weight @@ -342,22 +342,36 @@ export class BlocksService extends AbstractService { /** * Fetch `payment_queryFeeDetails`. * - * @param extHex + * @param ext * @param previousBlockHash * @param extrinsicSuccessWeight * @param estWeight */ private async fetchQueryFeeDetails( - extHex: `0x${string}`, + ext: GenericExtrinsic, previousBlockHash: BlockHash, extrinsicSuccessWeight: Weight, estWeight: Weight ): Promise { const { api } = this; - const { inclusionFee } = await api.rpc.payment.queryFeeDetails( - extHex, - previousBlockHash - ); + const apiAt = await api.at(previousBlockHash); + + let inclusionFee; + if (apiAt.call.transactionPaymentApi.queryFeeDetails) { + const u8a = ext.toU8a(); + const result = await apiAt.call.transactionPaymentApi.queryFeeDetails( + u8a, + u8a.length + ); + inclusionFee = result.inclusionFee; + } else { + const result = await api.rpc.payment.queryFeeDetails( + ext.toHex(), + previousBlockHash + ); + inclusionFee = result.inclusionFee; + } + const finalPartialFee = this.calcPartialFee( extrinsicSuccessWeight, estWeight,