Skip to content

Commit d969a4c

Browse files
committed
add tolerance
1 parent 225b0bb commit d969a4c

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎src/main/java/org/tron/common/runtime/Runtime.java‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,17 @@ private void create()
392392
// }
393393

394394
long thisTxCPULimitInUs;
395-
long tolerance = max(0, min(100, Args.getInstance().getTolerance()));
396395
if (ET_NORMAL_TYPE == executorType) {
397396
if (contract.getReceipt().getResult() == ResourceReceipt.code.OUT_OF_TIME) {
398-
thisTxCPULimitInUs =
399-
Constant.MAX_CPU_TIME_OF_ONE_TX * (100 - tolerance) / 100;
397+
thisTxCPULimitInUs = max(0, Args.getInstance().getLowTolerance());
400398
} else {
401-
thisTxCPULimitInUs = Constant.MAX_CPU_TIME_OF_ONE_TX_WHEN_VERIFY_BLOCK;
399+
thisTxCPULimitInUs = max(0, Args.getInstance().getHighTolerance());
402400
}
403401
} else {
404402
thisTxCPULimitInUs =
405-
Constant.MAX_CPU_TIME_OF_ONE_TX * (100 + tolerance) / 100;
403+
Constant.MAX_CPU_TIME_OF_ONE_TX;
406404
}
405+
407406
long vmStartInUs = System.nanoTime() / 1000;
408407
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;
409408

@@ -471,17 +470,15 @@ private void call()
471470
.getOriginAddress().toByteArray());
472471

473472
long thisTxCPULimitInUs;
474-
long tolerance = max(0, min(100, Args.getInstance().getTolerance()));
475473
if (ET_NORMAL_TYPE == executorType) {
476474
if (contract.getReceipt().getResult() == ResourceReceipt.code.OUT_OF_TIME) {
477-
thisTxCPULimitInUs =
478-
Constant.MAX_CPU_TIME_OF_ONE_TX * (100 - tolerance) / 100;
475+
thisTxCPULimitInUs = max(0, Args.getInstance().getLowTolerance());
479476
} else {
480-
thisTxCPULimitInUs = Constant.MAX_CPU_TIME_OF_ONE_TX_WHEN_VERIFY_BLOCK;
477+
thisTxCPULimitInUs = max(0, Args.getInstance().getHighTolerance());
481478
}
482479
} else {
483480
thisTxCPULimitInUs =
484-
Constant.MAX_CPU_TIME_OF_ONE_TX * (100 + tolerance) / 100;
481+
Constant.MAX_CPU_TIME_OF_ONE_TX;
485482
}
486483

487484
long vmStartInUs = System.nanoTime() / 1000;

‎src/main/java/org/tron/core/Constant.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class Constant {
4848

4949
// config for smart contract
5050
public static final long MEM_LIMIT_IN_ONE_TX_OF_SMART_CONTRACT = 32 * 1024 * 1024L; // 32MB
51-
public static final long MAX_CPU_TIME_OF_ONE_TX_WHEN_VERIFY_BLOCK = 250000; // 250 ms = 250000 us
5251
public static final long MAX_CPU_TIME_OF_ONE_TX = 50000; // 50 ms = 50000 us
5352
public static final long STORAGE_LIMIT_IN_ONE_TX_OF_SMART_CONTRACT = 32 * 1024 * 1024L; // 32MB
5453
public static final long SUN_PER_ENERGY = 100; // 1 us = 100 DROP = 100 * 10^-6 TRX

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.tron.core.config.args;
22

3+
import static java.lang.Math.max;
4+
import static java.lang.Math.min;
5+
36
import com.beust.jcommander.JCommander;
47
import com.beust.jcommander.Parameter;
58
import com.typesafe.config.Config;
@@ -72,8 +75,13 @@ public class Args {
7275

7376
@Getter
7477
@Setter
75-
@Parameter(names = {"--tolerance"})
76-
private long tolerance = 30;
78+
@Parameter(names = {"--low-tolerance"})
79+
private long lowTolerance = 50000; // 50ms = 50000us
80+
81+
@Getter
82+
@Setter
83+
@Parameter(names = {"--high-tolerance"})
84+
private long highTolerance = calcHighTolerance();
7785

7886
@Getter
7987
@Parameter(description = "--seed-nodes")
@@ -777,6 +785,11 @@ public ECKey getMyKey() {
777785
return ECKey.fromPrivate(Hex.decode(INSTANCE.p2pNodeId));
778786
}
779787

788+
private static long calcHighTolerance() {
789+
double ratio = min(1.0, 4.0 / max(Runtime.getRuntime().availableProcessors(), 1));
790+
return 100000 + (long) (150000 * ratio);
791+
}
792+
780793
private static void initBackupProperty(Config config) {
781794
INSTANCE.backupPriority = config.hasPath("node.backup.priority")
782795
? config.getInt("node.backup.priority") : 0;

0 commit comments

Comments
 (0)