Skip to content

Commit 9b3f546

Browse files
authored
Merge pull request #1218 from ainblockchain/bugfix/platfowner/bugfix
Fix newly found issues due to latest changes
2 parents c00dc8d + 9c3b5b2 commit 9b3f546

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

common/common-util.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,7 @@ class CommonUtil {
751751
* @param {Object} gasAmount gas amount
752752
* @returns
753753
*/
754-
static getTotalGasCost(gasPrice, gasAmount, gasPriceUnit, blockNumber = 2) {
755-
const { isEnabledTimerFlag } = require('../common/constants');
754+
static getTotalGasCost(gasPrice, gasAmount, gasPriceUnit, enableGasCostFlooring = true) {
756755
if (!CommonUtil.isNumber(gasPrice)) {
757756
gasPrice = 0; // Default gas price = 0 microain
758757
}
@@ -761,18 +760,18 @@ class CommonUtil {
761760
}
762761
let cost = gasPrice * gasPriceUnit * gasAmount;
763762
// NOTE(platfowner): Apply gas cost flooring up-to 6 decimals.
764-
if (isEnabledTimerFlag('allow_up_to_6_decimal_transfer_value_only', blockNumber)) {
763+
if (enableGasCostFlooring) {
765764
cost = Math.floor(cost * 1000000) / 1000000; // gas cost flooring
766765
}
767766
return cost;
768767
}
769768

770-
static getServiceGasCostTotalFromTxList(txList, resList, gasPriceUnit, blockNumber = 2) {
769+
static getServiceGasCostTotalFromTxList(txList, resList, gasPriceUnit, enableGasCostFlooring = true) {
771770
return resList.reduce((acc, cur, index) => {
772771
const tx = txList[index];
773772
return CommonUtil.mergeNumericJsObjects(acc, {
774773
gasAmountTotal: cur.gas_amount_charged,
775-
gasCostTotal: CommonUtil.getTotalGasCost(tx.tx_body.gas_price, cur.gas_amount_charged, gasPriceUnit, blockNumber)
774+
gasCostTotal: CommonUtil.getTotalGasCost(tx.tx_body.gas_price, cur.gas_amount_charged, gasPriceUnit, enableGasCostFlooring)
776775
});
777776
}, { gasAmountTotal: 0, gasCostTotal: 0 });
778777
}

consensus/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
StateVersions,
1919
ValueChangedEventSources,
2020
TransactionStates,
21+
isEnabledTimerFlag,
2122
} = require('../common/constants');
2223
const { ConsensusErrorCode } = require('../common/result-code');
2324
const {
@@ -713,8 +714,9 @@ class Consensus {
713714
});
714715
}
715716
const gasPriceUnit = node.getBlockchainParam('resource/gas_price_unit', number, db.stateVersion);
717+
const enableGasCostFlooring = isEnabledTimerFlag('allow_up_to_6_decimal_transfer_value_only', number);
716718
const { gasAmountTotal, gasCostTotal } =
717-
CommonUtil.getServiceGasCostTotalFromTxList(transactions, txsRes, gasPriceUnit, number);
719+
CommonUtil.getServiceGasCostTotalFromTxList(transactions, txsRes, gasPriceUnit, enableGasCostFlooring);
718720
if (gasAmountTotal !== expectedGasAmountTotal) {
719721
throw new ConsensusError({
720722
code: ConsensusErrorCode.INVALID_GAS_AMOUNT_TOTAL,

db/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ class DB {
17021702
auth, tx, timestamp, blockNumber, blockTime, executionResult, eventSource, isDryrun) {
17031703
const gasPriceUnit =
17041704
DB.getBlockchainParam('resource/gas_price_unit', blockNumber, this.stateRoot);
1705+
const enableGasCostFlooring = isEnabledTimerFlag('allow_up_to_6_decimal_transfer_value_only', blockNumber);
17051706
const gasPrice = tx.tx_body.gas_price;
17061707
// Use only the service gas amount total
17071708
const serviceBandwidthGasAmount = _.get(tx, 'extra.gas.bandwidth.service', 0);
@@ -1711,7 +1712,7 @@ class DB {
17111712
if (gasAmountChargedByTransfer <= 0 || gasPrice === 0) { // No fees to collect
17121713
executionResult.gas_amount_charged = gasAmountChargedByTransfer;
17131714
executionResult.gas_cost_total =
1714-
CommonUtil.getTotalGasCost(gasPrice, gasAmountChargedByTransfer, gasPriceUnit, blockNumber);
1715+
CommonUtil.getTotalGasCost(gasPrice, gasAmountChargedByTransfer, gasPriceUnit, enableGasCostFlooring);
17151716
return;
17161717
}
17171718
const billing = tx.tx_body.billing;
@@ -1724,7 +1725,7 @@ class DB {
17241725
}
17251726
}
17261727
let balance = this.getBalance(billedTo);
1727-
const gasCost = CommonUtil.getTotalGasCost(gasPrice, gasAmountChargedByTransfer, gasPriceUnit, blockNumber);
1728+
const gasCost = CommonUtil.getTotalGasCost(gasPrice, gasAmountChargedByTransfer, gasPriceUnit, enableGasCostFlooring);
17281729
if (!isDryrun && balance < gasCost) {
17291730
Object.assign(executionResult, {
17301731
code: TxResultCode.FEE_BALANCE_TOO_LOW,
@@ -1736,7 +1737,7 @@ class DB {
17361737
}
17371738
executionResult.gas_amount_charged = gasAmountChargedByTransfer;
17381739
executionResult.gas_cost_total =
1739-
CommonUtil.getTotalGasCost(gasPrice, executionResult.gas_amount_charged, gasPriceUnit, blockNumber);
1740+
CommonUtil.getTotalGasCost(gasPrice, executionResult.gas_amount_charged, gasPriceUnit, enableGasCostFlooring);
17401741
if (isDryrun || executionResult.gas_cost_total <= 0) {
17411742
return;
17421743
}

node/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const {
2323
TrafficEventTypes,
2424
trafficStatsManager,
2525
ValueChangedEventSources,
26+
isEnabledTimerFlag,
2627
} = require('../common/constants');
2728
const { TxResultCode } = require('../common/result-code');
2829
const { ValidatorOffenseTypes } = require('../consensus/constants');
@@ -949,8 +950,9 @@ class BlockchainNode {
949950
}
950951
const gasPriceUnit =
951952
this.getBlockchainParam('resource/gas_price_unit', blockNumber, baseDb.stateVersion);
953+
const enableGasCostFlooring = isEnabledTimerFlag('allow_up_to_6_decimal_transfer_value_only', blockNumber);
952954
const { gasAmountTotal, gasCostTotal } =
953-
CommonUtil.getServiceGasCostTotalFromTxList(transactions, resList, gasPriceUnit, blockNumber);
955+
CommonUtil.getServiceGasCostTotalFromTxList(transactions, resList, gasPriceUnit, enableGasCostFlooring);
954956
const receipts = CommonUtil.txResultsToReceipts(resList);
955957
return { transactions, receipts, gasAmountTotal, gasCostTotal };
956958
}

start_node_genesis_gcp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
# NOTE(minsulee2): Since exit really exits terminals, those are replaced to return 1.
4-
if [[ $# -lt 4 ]] || [[ $# -gt 12 ]]; then
5-
printf "Usage: bash start_node_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <GCP Username> <Shard Index> <Node Index> [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func]\n"
4+
if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then
5+
printf "Usage: bash start_node_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <GCP Username> <Shard Index> <Node Index> [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler]\n"
66
printf "Example: bash start_node_genesis_gcp.sh spring gcp_user 0 0 --keystore --no-keep-code --full-sync --no-chown-data\n"
77
printf "\n"
88
return 1

start_node_incremental_gcp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
if [[ $# -lt 4 ]] || [[ $# -gt 12 ]]; then
4-
printf "Usage: bash start_node_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <GCP Username> <Shard Index> <Node Index> [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func]\n"
3+
if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then
4+
printf "Usage: bash start_node_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <GCP Username> <Shard Index> <Node Index> [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler]\n"
55
printf "Example: bash start_node_incremental_gcp.sh spring gcp_user 0 0 --keystore --no-keep-code --full-sync --no-chown-data\n"
66
printf "\n"
77
exit

tools/genesis-file/createGenesisBlock.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
getBlockchainConfig,
1515
buildOwnerPermissions,
1616
BlockchainParams,
17+
isEnabledTimerFlag,
1718
} = require('../../common/constants');
1819
const CommonUtil = require('../../common/common-util');
1920
const FileUtil = require('../../common/file-util');
@@ -400,8 +401,9 @@ function executeGenesisTxsAndGetData(genesisTxs) {
400401
}
401402
resList.push(res);
402403
}
404+
const enableGasCostFlooring = isEnabledTimerFlag('allow_up_to_6_decimal_transfer_value_only', 0);
403405
const { gasAmountTotal, gasCostTotal } = CommonUtil.getServiceGasCostTotalFromTxList(
404-
genesisTxs, resList, BlockchainParams.resource.gas_price_unit, 0);
406+
genesisTxs, resList, BlockchainParams.resource.gas_price_unit, enableGasCostFlooring);
405407
return {
406408
stateProofHash: tempGenesisDb.getProofHash('/'),
407409
gasAmountTotal,

0 commit comments

Comments
 (0)