Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 15 additions & 9 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,8 @@ private long getGasLimit(AccountCapsule account, long feeLimit) {
cpuGasFromFeeLimit = feeLimit / Constant.SUN_PER_GAS;
} else {
long totalCpuGasFromFreeze = cpuProcessor.calculateGlobalCpuLimit(balanceForCpuFreeze);
long leftBalanceForCpuFreeze = BigInteger.valueOf(cpuGasFromFreeze)
.multiply(BigInteger.valueOf(balanceForCpuFreeze))
.divide(BigInteger.valueOf(totalCpuGasFromFreeze)).longValue();
long leftBalanceForCpuFreeze = getCpuFee(balanceForCpuFreeze, cpuGasFromFreeze,
totalCpuGasFromFreeze);

if (leftBalanceForCpuFreeze >= feeLimit) {
cpuGasFromFeeLimit = BigInteger.valueOf(totalCpuGasFromFreeze)
Expand Down Expand Up @@ -627,15 +626,14 @@ private boolean spendUsage(long usedStorageSize) {
long callerCpuFrozen = caller.getCpuFrozenBalance();
long callerCpuLeft = cpuProcessor.getAccountLeftCpuInUsFromFreeze(caller);
long callerCpuTotal = cpuProcessor.calculateGlobalCpuLimit(callerCpuFrozen);

if (callerCpuUsage <= callerCpuLeft) {
long cpuFee = BigInteger.valueOf(callerCpuFrozen).multiply(BigInteger.valueOf(callerCpuUsage))
.divide(BigInteger.valueOf(callerCpuTotal)).longValue();
long cpuFee = getCpuFee(callerCpuUsage, callerCpuFrozen, callerCpuTotal);
storageFee -= cpuFee;
} else {
long cpuFee = BigInteger.valueOf(callerCpuFrozen).multiply(BigInteger.valueOf(callerCpuLeft))
.divide(BigInteger.valueOf(callerCpuTotal)).longValue();
storageFee -= cpuFee + Math
.multiplyExact(callerCpuUsage - callerCpuLeft, Constant.SUN_PER_GAS);
long cpuFee = getCpuFee(callerCpuLeft, callerCpuFrozen, callerCpuTotal);
storageFee -= (cpuFee + Math
.multiplyExact(callerCpuUsage - callerCpuLeft, Constant.SUN_PER_GAS));
}
long tryBuyStorage = storageMarket.tryBuyStorage(storageFee);
if (tryBuyStorage + caller.getStorageLeft() < callerStorageUsage) {
Expand All @@ -646,6 +644,14 @@ private boolean spendUsage(long usedStorageSize) {
return true;
}

private long getCpuFee(long callerCpuUsage, long callerCpuFrozen, long callerCpuTotal) {
if (callerCpuTotal <= 0) {
return 0;
}
return BigInteger.valueOf(callerCpuFrozen).multiply(BigInteger.valueOf(callerCpuUsage))
.divide(BigInteger.valueOf(callerCpuTotal)).longValue();
}

private boolean isCallConstant() {
if (TRX_CONTRACT_CALL_TYPE.equals(trxType)) {
ABI abi = deposit.getContract(result.getContractAddress()).getInstance().getAbi();
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/tron/core/services/WitnessService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.google.common.collect.Maps;
import com.google.protobuf.ByteString;
import java.util.Date;
import java.util.Map;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -248,9 +247,6 @@ private BlockProductionCondition tryProduceBlock() throws InterruptedException {

try {

logger.error("setGeneratingBlock true " + String
.format("%tF %tT", new Date(), new Date()));

controller.setGeneratingBlock(true);
BlockCapsule block = generateBlock(scheduledTime, scheduledWitness);

Expand Down Expand Up @@ -280,11 +276,7 @@ private BlockProductionCondition tryProduceBlock() throws InterruptedException {
return BlockProductionCondition.EXCEPTION_PRODUCING_BLOCK;
} finally {
controller.setGeneratingBlock(false);
logger.error("setGeneratingBlock true " + String
.format("%tF %tT", new Date(), new Date()));
}


}

private void broadcastBlock(BlockCapsule block) {
Expand Down