@@ -398,13 +398,9 @@ private void create()
398398 byte [] ops = newSmartContract .getBytecode ().toByteArray ();
399399 rootInternalTx = new InternalTransaction (trx , trxType );
400400
401- long maxCpuTimeOfOneTx = rootRepository .getDynamicPropertiesStore ()
402- .getMaxCpuTimeOfOneTx () * VMConstant .ONE_THOUSAND ;
403- long thisTxCPULimitInUs = (long ) (maxCpuTimeOfOneTx * getCpuLimitInUsRatio ());
404- long constantCallTimeoutMs = CommonParameter .getInstance ().getConstantCallTimeoutMs ();
405- if (isConstantCall && constantCallTimeoutMs > 0L ) {
406- thisTxCPULimitInUs = constantCallTimeoutMs * VMConstant .ONE_THOUSAND ;
407- }
401+ long thisTxCPULimitInUs = calculateCpuLimitInUs (isConstantCall ,
402+ rootRepository .getDynamicPropertiesStore ().getMaxCpuTimeOfOneTx (),
403+ getCpuLimitInUsRatio (), CommonParameter .getInstance ().getConstantCallTimeoutMs ());
408404 long vmStartInUs = System .nanoTime () / VMConstant .ONE_THOUSAND ;
409405 long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs ;
410406 ProgramInvoke programInvoke = ProgramInvokeFactory
@@ -516,13 +512,9 @@ private void call()
516512 energyLimit = getTotalEnergyLimit (creator , caller , contract , feeLimit , callValue );
517513 }
518514
519- long maxCpuTimeOfOneTx = rootRepository .getDynamicPropertiesStore ()
520- .getMaxCpuTimeOfOneTx () * VMConstant .ONE_THOUSAND ;
521- long thisTxCPULimitInUs = (long ) (maxCpuTimeOfOneTx * getCpuLimitInUsRatio ());
522- long constantCallTimeoutMs = CommonParameter .getInstance ().getConstantCallTimeoutMs ();
523- if (isConstantCall && constantCallTimeoutMs > 0L ) {
524- thisTxCPULimitInUs = constantCallTimeoutMs * VMConstant .ONE_THOUSAND ;
525- }
515+ long thisTxCPULimitInUs = calculateCpuLimitInUs (isConstantCall ,
516+ rootRepository .getDynamicPropertiesStore ().getMaxCpuTimeOfOneTx (),
517+ getCpuLimitInUsRatio (), CommonParameter .getInstance ().getConstantCallTimeoutMs ());
526518 long vmStartInUs = System .nanoTime () / VMConstant .ONE_THOUSAND ;
527519 long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs ;
528520 ProgramInvoke programInvoke = ProgramInvokeFactory
@@ -699,6 +691,14 @@ private double getCpuLimitInUsRatio() {
699691 return cpuLimitRatio ;
700692 }
701693
694+ static long calculateCpuLimitInUs (boolean isConstantCall , long maxCpuTimeOfOneTxMs ,
695+ double cpuLimitInUsRatio , long constantCallTimeoutMs ) {
696+ if (isConstantCall && constantCallTimeoutMs > 0L ) {
697+ return constantCallTimeoutMs * VMConstant .ONE_THOUSAND ;
698+ }
699+ return (long ) (maxCpuTimeOfOneTxMs * VMConstant .ONE_THOUSAND * cpuLimitInUsRatio );
700+ }
701+
702702 public long getTotalEnergyLimitWithFixRatio (AccountCapsule creator , AccountCapsule caller ,
703703 TriggerSmartContract contract , long feeLimit , long callValue )
704704 throws ContractValidateException {
0 commit comments