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

Commit

Permalink
Merge pull request #1844 from LiskHQ/1843-fix-transaction-estimate-fees
Browse files Browse the repository at this point in the history
Transaction estimate fees throws an error on the sidechain
  • Loading branch information
priojeetpriyom authored Sep 14, 2023
2 parents fca4a98 + 1a10bc0 commit 868862c
Show file tree
Hide file tree
Showing 34 changed files with 332 additions and 119 deletions.
Binary file added framework/dist/lisk-service-framework-1.5.1.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion framework/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-service-framework",
"version": "1.5.0",
"version": "1.5.1",
"description": "Lisk Service Framework",
"keywords": [
"lisk",
Expand Down
2 changes: 2 additions & 0 deletions framework/src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const request = async (url, params = {}) => {
response = { data, headers, status, statusText };

if (key) cache.set(key, response, params.cacheTTL);
} else {
response = httpResponse;
}
}

Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-app-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"bluebird": "^3.7.2",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz",
"lodash": "^4.17.21",
"octokit": "^2.0.4",
"tar": "^6.1.11"
Expand Down
6 changes: 3 additions & 3 deletions services/blockchain-app-registry/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3069,9 +3069,9 @@ lines-and-columns@^1.1.6:
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz":
version "1.5.0"
resolved "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz#603c04f96b32f19a5abff8c08d1ff81054b8f128"
"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz":
version "1.5.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz#2283db2156d98ed1b39ff30d01838774a755a78e"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"big-json": "^3.1.0",
"bluebird": "^3.7.2",
"knex": "^2.4.0",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz",
"moment": "^2.29.4",
"signals": "^1.0.0",
"tar": "^6.1.11"
Expand Down
6 changes: 3 additions & 3 deletions services/blockchain-connector/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3672,9 +3672,9 @@ lines-and-columns@^1.1.6:
resolved "https://npm.lisk.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz":
version "1.5.0"
resolved "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz#603c04f96b32f19a5abff8c08d1ff81054b8f128"
"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz":
version "1.5.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz#2283db2156d98ed1b39ff30d01838774a755a78e"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-coordinator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"bluebird": "^3.7.2",
"bull": "^4.8.1",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz"
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz"
},
"devDependencies": {
"@babel/preset-env": "^7.14.0",
Expand Down
6 changes: 3 additions & 3 deletions services/blockchain-coordinator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3467,9 +3467,9 @@ lines-and-columns@^1.1.6:
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz":
version "1.5.0"
resolved "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz#603c04f96b32f19a5abff8c08d1ff81054b8f128"
"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz":
version "1.5.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz#2283db2156d98ed1b39ff30d01838774a755a78e"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"bull": "^4.8.1",
"camelcase": "^6.3.0",
"ioredis": "^4.28.5",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/8eb70b4eb11972cbd65eb9911991e8a4f8e0725d/framework/dist/lisk-service-framework-1.5.0.tgz",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/bf8048b920f61a2b27d7c28535dfefed5bd679cb/framework/dist/lisk-service-framework-1.5.1.tgz",
"lodash": "^4.17.21",
"require-all": "^3.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let feeEstimates = {
low: 0,
med: 0,
high: 0,
minFeePerByte: 1000,
};

const setFeeEstimates = async (payload) => {
Expand Down
12 changes: 8 additions & 4 deletions services/blockchain-indexer/shared/dataService/business/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const {
getChainAccount,
getMainchainID,
reloadBlockchainAppsStats,
isMainchain,
resolveMainchainServiceURL,
resolveChannelInfo,
getCurrentChainID,
} = require('./interoperability');

const {
Expand Down Expand Up @@ -99,7 +103,6 @@ const {
getNetworkPeersStatistics,
} = require('./network');
const { estimateTransactionFees } = require('./transactionsEstimateFees');
const { isMainchain, resolveMainchainServiceURL } = require('./mainchain');
const { invokeEndpoint } = require('./invoke');

const { setFeeEstimates, getFeeEstimates } = require('./feeEstimates');
Expand Down Expand Up @@ -144,6 +147,10 @@ module.exports = {
getMainchainID,
getBlockchainAppsStatistics,
reloadBlockchainAppsStats,
isMainchain,
resolveMainchainServiceURL,
resolveChannelInfo,
getCurrentChainID,

// Token
tokenHasUserAccount,
Expand Down Expand Up @@ -194,8 +201,5 @@ module.exports = {
getNetworkDisconnectedPeers,
getNetworkPeersStatistics,

isMainchain,
resolveMainchainServiceURL,

invokeEndpoint,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { getNetworkStatus } = require('../network');
const regex = require('../../../regex');

let chainID;

const getCurrentChainID = async () => {
if (!chainID) {
const networkStatus = await getNetworkStatus();
if (networkStatus.data && networkStatus.data.chainID) {
chainID = networkStatus.data.chainID;
}
}
return chainID;
};

const isMainchain = async () => regex.MAINCHAIN_ID.test(await getCurrentChainID());

module.exports = {
isMainchain,

// For unit testing
getCurrentChainID,
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,16 @@ const {
Exceptions: { ValidationException },
} = require('lisk-service-framework');

const { getNetworkStatus } = require('./network');
const regex = require('../../regex');
const config = require('../../../config');
const { LENGTH_CHAIN_ID, LENGTH_NETWORK_ID } = require('../../constants');
const { requestConnector } = require('../../utils/request');

let chainID;

const isMainchain = async () => {
if (!chainID) {
const networkStatus = (await getNetworkStatus()).data;
chainID = networkStatus.chainID;
}
return regex.MAINCHAIN_ID.test(chainID);
};
const { getCurrentChainID, isMainchain } = require('./chain');
const regex = require('../../../regex');
const config = require('../../../../config');
const { LENGTH_CHAIN_ID, LENGTH_NETWORK_ID } = require('../../../constants');
const { requestConnector } = require('../../../utils/request');

const resolveMainchainServiceURL = async () => {
if (config.endpoints.mainchainServiceUrl) return config.endpoints.mainchainServiceUrl;

if (!chainID) {
const networkStatus = (await getNetworkStatus()).data;
chainID = networkStatus.chainID;
}

const chainID = await getCurrentChainID();
const networkID = chainID.substring(0, LENGTH_NETWORK_ID);
const mainchainID = networkID.padEnd(LENGTH_CHAIN_ID, '0');
const [{ serviceURL } = {}] = config.networks.LISK
Expand All @@ -50,31 +36,40 @@ const resolveMainchainServiceURL = async () => {
};

const resolveChannelInfo = async (inputChainID) => {
if (inputChainID === await getCurrentChainID()) {
throw new ValidationException('Channel info cannot be determined when receivingChainID and currentChainID are same.');
}

try {
if (await isMainchain() && !regex.MAINCHAIN_ID.test(inputChainID)) {
if ((await isMainchain() && !regex.MAINCHAIN_ID.test(inputChainID))
|| (!await isMainchain() && regex.MAINCHAIN_ID.test(inputChainID))) {
const channelInfo = await requestConnector('getChannel', { chainID: inputChainID });
return channelInfo;
}

// Redirect call to the mainchain service
const serviceURL = await resolveMainchainServiceURL();
const invokeEndpoint = `${serviceURL}/api/v3/invoke`;
const { data: { data: channelInfo } } = await HTTP.post(
const { data: response } = await HTTP.post(
invokeEndpoint,
{
endpoint: 'interoperability_getChannel',
params: { chainID: inputChainID },
},
);

if (response.error) {
throw new ValidationException(`Channel info is not available for the chain: ${inputChainID}.`);
}

const { data: channelInfo } = response;
return channelInfo;
} catch (error) {
throw new ValidationException(`Error while retrieving channel info for the chain: ${inputChainID}.\nError: ${error}`);
}
};

module.exports = {
isMainchain,
resolveMainchainServiceURL,
resolveChannelInfo,
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ const { getBlockchainApps } = require('./blockchainApps');
const { getChainAccount } = require('./chainAccount');
const { getMainchainID } = require('./mainchain');
const { getBlockchainAppsStatistics, reloadBlockchainAppsStats } = require('./blockchainAppsStats');
const { isMainchain, getCurrentChainID } = require('./chain');
const { resolveMainchainServiceURL, resolveChannelInfo } = require('./channel');

module.exports = {
getBlockchainApps,
getChainAccount,
getMainchainID,
getBlockchainAppsStatistics,
reloadBlockchainAppsStats,
isMainchain,
resolveMainchainServiceURL,
resolveChannelInfo,
getCurrentChainID,
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {
Logger,
} = require('lisk-service-framework');

const { resolveMainchainServiceURL, resolveChannelInfo } = require('./mainchain');
const { resolveMainchainServiceURL, resolveChannelInfo, getCurrentChainID } = require('./interoperability');
const { dryRunTransactions } = require('./transactionsDryRun');
const { tokenHasUserAccount, getTokenConstants } = require('./token');
const { getSchemas } = require('./schemas');
Expand Down Expand Up @@ -207,13 +207,16 @@ const calcAdditionalFees = async (transaction) => {
const { data: tokenConstantsResponse } = await HTTP.get(`${receivingServiceURL}/api/v3/token/constants`);
const { data: { extraCommandFees } } = tokenConstantsResponse;

// Check if escrow account exists
const { exists: escrowAccountExists } = await requestConnector('tokenHasEscrowAccount', { tokenID, escrowChainID: transaction.params.receivingChainID });
if (!escrowAccountExists) {
additionalFees.fee = {
escrowAccountInitializationFee: extraCommandFees.escrowAccountInitializationFee,
};
additionalFees.total += BigInt(extraCommandFees.escrowAccountInitializationFee);
// Check if escrow account exists only when tokenID specified in the params is a native token
const currentChainID = await getCurrentChainID();
if (tokenID.startsWith(currentChainID)) {
const { exists: escrowAccountExists } = await requestConnector('tokenHasEscrowAccount', { tokenID, escrowChainID: transaction.params.receivingChainID });
if (!escrowAccountExists) {
additionalFees.fee = {
escrowAccountInitializationFee: extraCommandFees.escrowAccountInitializationFee,
};
additionalFees.total += BigInt(extraCommandFees.escrowAccountInitializationFee);
}
}

// Check if user account exists on the receiving chain
Expand Down
4 changes: 4 additions & 0 deletions services/blockchain-indexer/shared/dataService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const {
deleteEventsFromCache,
isMainchain,
resolveMainchainServiceURL,
getCurrentChainID,
resolveChannelInfo,
} = require('./business');

const {
Expand Down Expand Up @@ -145,6 +147,8 @@ module.exports = {
getChainAccount,
getMainchainID,
reloadBlockchainAppsStats,
getCurrentChainID,
resolveChannelInfo,

// Events
getEvents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const mockTransferCrossChainTxResult = {
transaction: {
fee: {
tokenID: '0400000000000000',
minimum: '130000',
minimum: '166000',
},
params: {
messageFee: {
Expand All @@ -196,7 +196,7 @@ const mockTransferCrossChainTxResult = {
breakdown: {
fee: {
minimum: {
byteFee: '160000',
byteFee: '167000',
additionalFees: {},
},
},
Expand Down Expand Up @@ -373,6 +373,27 @@ const mockAuthInfoForMultisigAccount = {
],
};

const mockChannelInfo = {
messageFeeTokenID: '0400000000000000',
outbox: {
appendPath: [
'20706b5f7117b283f7be38aa12dc9623fd1d07a91425fa6c087830008b145075',
'9f87b56843694d5b90eb528793fd16cf8613f606a106b7d70bea2ffa1ef20c2d',
],
root: '4855a43e751c5df45ea0e963fa204bf0236a01f773b5b0cc19ff8e6edaee0204',
size: 12,
},
inbox: {
appendPath: [
'3e168e2181b08e53e656ee112abe15fd456a0598717241a1beeaada2983a1350',
],
root: '3e168e2181b08e53e656ee112abe15fd456a0598717241a1beeaada2983a1350',
size: 2,
},
partnerChainOutboxRoot: '3e168e2181b08e53e656ee112abe15fd456a0598717241a1beeaada2983a1350',
minReturnFeePerByte: '1000',
};

module.exports = {
mockTxRequest,
mockTransferCrossChainTxRequest,
Expand All @@ -394,4 +415,6 @@ module.exports = {
mockInteroperabilitySubmitMainchainCrossChainUpdateTxResult,
mockInteroperabilityRegisterSidechainTxRequest,
mockInteroperabilityRegisterSidechainTxResult,

mockChannelInfo,
};
Loading

0 comments on commit 868862c

Please sign in to comment.