Skip to content

Commit

Permalink
debug condition move into checkcputime function
Browse files Browse the repository at this point in the history
  • Loading branch information
tjchern committed Aug 4, 2018
1 parent 8c58a89 commit 7052a86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ src/main/resources/META-INF/
/output_witness/
output*
nodeId.properties
Wallet
Wallet

# conf
config-local-tjchern.conf
5 changes: 1 addition & 4 deletions src/main/java/org/tron/common/runtime/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.tron.common.runtime.vm.program.Program;
import org.tron.common.runtime.vm.program.Program.OutOfResourceException;
import org.tron.common.runtime.vm.program.Stack;
import org.tron.core.config.args.Args;
import org.tron.core.exception.ContractExeException;

public class VM {
Expand Down Expand Up @@ -298,9 +297,7 @@ public void step(Program program)
// DEBUG System.out.println(" OP IS " + op.name() + " GASCOST IS " + gasCost + " NUM IS " + op.asInt());
// program.spendDrop(dropCost, op.name());

if (!Args.getInstance().isDebug()) {
program.checkCPULimit(op.name());
}
program.checkCPULimit(op.name());
// logger.info("after opName: {}, {}", op.name(), System.nanoTime() / 1000 - lastTime);

// Execute operation
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/org/tron/common/runtime/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize)
newBalance = deposit.addBalance(newAddress, endowment);
}

if (!Args.getInstance().isDebug()) {
checkCPULimit("BEFORE CREATE");
}
checkCPULimit("BEFORE CREATE");


// [5] COOK THE INVOKE AND EXECUTE
Expand All @@ -499,9 +497,7 @@ this, new DataWord(newAddress), getOwnerAddress(), value,
getResult().merge(result);
}

if (!Args.getInstance().isDebug()) {
checkCPULimit("AFTER CREATE");
}
checkCPULimit("AFTER CREATE");

// 4. CREATE THE CONTRACT OUT OF RETURN
byte[] code = result.getHReturn();
Expand Down Expand Up @@ -621,9 +617,7 @@ public void callToAddress(MessageCall msg)
InternalTransaction internalTx = addInternalTx(getDroplimit(), senderAddress, contextAddress,
endowment, data, "call");

if (!Args.getInstance().isDebug()) {
checkCPULimit("BEFORE CALL");
}
checkCPULimit("BEFORE CALL");

ProgramResult result = null;
if (isNotEmpty(programCode)) {
Expand Down Expand Up @@ -675,9 +669,7 @@ this, new DataWord(contextAddress),
stackPushOne();
}

if (!Args.getInstance().isDebug()) {
checkCPULimit("BEFORE CALL");
}
checkCPULimit("BEFORE CALL");

// 3. APPLY RESULTS: result.getHReturn() into out_memory allocated
if (result != null) {
Expand Down Expand Up @@ -716,9 +708,11 @@ public void spendDrop(long dropValue, String cause) {

public void checkCPULimit(String opName) throws OutOfResourceException {

long vmNowInUs = System.nanoTime() / 1000;
if (vmNowInUs > getVmShouldEndInUs()) {
throw Exception.notEnoughCPU(opName);
if (!Args.getInstance().isDebug()) {
long vmNowInUs = System.nanoTime() / 1000;
if (vmNowInUs > getVmShouldEndInUs()) {
throw Exception.notEnoughCPU(opName);
}
}
}

Expand Down

0 comments on commit 7052a86

Please sign in to comment.