Skip to content

Commit a201942

Browse files
authored
Merge pull request #1449 from tronprotocol/fix_timeout_bug
Fix timeout bug
2 parents b6cf587 + 1940257 commit a201942

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.tron.common.runtime.vm.program.InternalTransaction.ExecutorType;
3535
import org.tron.common.runtime.vm.program.Program;
3636
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
37+
import org.tron.common.runtime.vm.program.Program.OutOfResourceException;
3738
import org.tron.common.runtime.vm.program.ProgramPrecompile;
3839
import org.tron.common.runtime.vm.program.ProgramResult;
3940
import org.tron.common.runtime.vm.program.invoke.ProgramInvoke;
@@ -500,10 +501,12 @@ public void go() {
500501
long saveCodeEnergy = getLength(code) * EnergyCost.getInstance().getCREATE_DATA();
501502
long afterSpend = program.getEnergyLimitLeft().longValue() - saveCodeEnergy;
502503
if (afterSpend < 0) {
503-
result.setException(
504-
Program.Exception
505-
.notEnoughSpendEnergy("No energy to save just created contract code",
506-
saveCodeEnergy, program.getEnergyLimitLeft().longValue()));
504+
if (null == result.getException()) {
505+
result.setException(
506+
Program.Exception
507+
.notEnoughSpendEnergy("save just created contract code",
508+
saveCodeEnergy, program.getEnergyLimitLeft().longValue()));
509+
}
507510
} else {
508511
result.spendEnergy(saveCodeEnergy);
509512
// have saveCode in create()
@@ -529,6 +532,12 @@ public void go() {
529532
deposit.commit();
530533
}
531534
} catch (JVMStackOverFlowException e) {
535+
program.spendAllEnergy();
536+
result.setException(e);
537+
runtimeError = result.getException().getMessage();
538+
logger.error("runtime error is :{}", result.getException().getMessage());
539+
} catch (OutOfResourceException e) {
540+
program.spendAllEnergy();
532541
result.setException(e);
533542
runtimeError = result.getException().getMessage();
534543
logger.error("runtime error is :{}", result.getException().getMessage());

src/main/java/org/tron/common/runtime/vm/VM.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.tron.common.runtime.vm.program.Program;
1919
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
2020
import org.tron.common.runtime.vm.program.Program.OutOfEnergyException;
21+
import org.tron.common.runtime.vm.program.Program.OutOfResourceException;
2122
import org.tron.common.runtime.vm.program.Stack;
2223

2324
@Slf4j(topic = "VM")
@@ -1332,7 +1333,9 @@ public void play(Program program) {
13321333
}
13331334

13341335
} catch (JVMStackOverFlowException e) {
1335-
throw new JVMStackOverFlowException();
1336+
throw e;
1337+
} catch (OutOfResourceException e) {
1338+
throw e;
13361339
} catch (RuntimeException e) {
13371340
if (StringUtils.isEmpty(e.getMessage())) {
13381341
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));

src/main/java/org/tron/common/runtime/vm/program/Program.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@ public void checkCPUTimeLimit(String opName) {
790790
}
791791
long vmNowInUs = System.nanoTime() / 1000;
792792
if (vmNowInUs > getVmShouldEndInUs()) {
793+
logger.error("minTimeRatio: {}", Args.getInstance().getMinTimeRatio());
794+
logger.error("maxTimeRatio: {}", Args.getInstance().getMaxTimeRatio());
795+
logger.error("vm should end time in us: {}", getVmShouldEndInUs());
796+
logger.error("vm start time in us: {}", getVmStartInUs());
793797
throw Exception.notEnoughTime(opName);
794798
}
795799

0 commit comments

Comments
 (0)