Skip to content

Commit

Permalink
set fee_limit up to 1000 trx
Browse files Browse the repository at this point in the history
  • Loading branch information
huzhenyuan committed Sep 5, 2018
1 parent 550b88b commit 2a572a2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 53 deletions.
18 changes: 10 additions & 8 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.EnergyCost;
import org.tron.common.runtime.vm.PrecompiledContracts;
Expand Down Expand Up @@ -70,7 +70,7 @@
public class Runtime {


private SystemProperties config = SystemProperties.getInstance();
private VMConfig config = VMConfig.getInstance();

private Transaction trx;
private BlockCapsule blockCap = null;
Expand Down Expand Up @@ -362,9 +362,10 @@ private void create()
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;

long feeLimit = trx.getRawData().getFeeLimit();
if (feeLimit < 0) {
logger.info("feeLimit < 0");
throw new ContractValidateException("feeLimit must be >= 0");
if (feeLimit < 0 || feeLimit > VMConfig.MAX_FEE_LIMIT) {
logger.warn("invalid feeLimit {}", feeLimit);
throw new ContractValidateException(
"feeLimit must be >= 0 and <= " + VMConfig.MAX_FEE_LIMIT);
}

long energyLimit = getEnergyLimit(creator, feeLimit, callValue);
Expand Down Expand Up @@ -439,9 +440,10 @@ private void call()
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;

long feeLimit = trx.getRawData().getFeeLimit();
if (feeLimit < 0) {
logger.info("feeLimit < 0");
throw new ContractValidateException("feeLimit must be >= 0");
if (feeLimit < 0 || feeLimit > VMConfig.MAX_FEE_LIMIT) {
logger.warn("invalid feeLimit {}", feeLimit);
throw new ContractValidateException(
"feeLimit must be >= 0 and <= " + VMConfig.MAX_FEE_LIMIT);
}
long energyLimit;
if (isCallConstant(contractAddress)) {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/tron/common/runtime/config/DefaultConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,31 @@
*/
package org.tron.common.runtime.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* For developer only
* For developer only
*/
public class SystemProperties {
public class VMConfig {

public static final int MAX_CODE_LENGTH = 1024 * 1024;

private static Logger logger = LoggerFactory.getLogger("general");
public static final int MAX_FEE_LIMIT = 1_000_000_000; //1000 trx

private boolean vmTraceCompressed = false;
private boolean vmOn = true;
private boolean vmTrace = false;

private SystemProperties() {

private VMConfig() {
}

private static class SystemPropertiesInstance {

private static final SystemProperties INSTANCE = new SystemProperties();
private static final VMConfig INSTANCE = new VMConfig();
}

public static SystemProperties getInstance() {
public static VMConfig getInstance() {
return SystemPropertiesInstance.INSTANCE;
}

public boolean vmOn() {
return vmOn;
}

public boolean vmTrace() {
return vmTrace;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/tron/common/runtime/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.program.Program;
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
import org.tron.common.runtime.vm.program.Program.OutOfEnergyException;
Expand All @@ -41,14 +41,14 @@ public class VM {
private boolean vmTrace;
// private long dumpBlock;

private final SystemProperties config;
private final VMConfig config;

public VM() {
config = SystemProperties.getInstance();
config = VMConfig.getInstance();
}

@Autowired
public VM(SystemProperties config) {
public VM(VMConfig config) {
this.config = config;
// vmTrace = config.vmTrace();
// dumpBlock = config.dumpBlock();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/tron/common/runtime/vm/VMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import java.io.*;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
Expand Down Expand Up @@ -47,7 +47,7 @@ public static void closeQuietly(Closeable closeable) {
}
}

private static File createProgramTraceFile(SystemProperties config, String txHash) {
private static File createProgramTraceFile(VMConfig config, String txHash) {
File result = null;

if (config.vmTrace()) {
Expand Down Expand Up @@ -86,7 +86,7 @@ private static void writeStringToFile(File file, String data) {
}
}

public static void saveProgramTraceFile(SystemProperties config, String txHash, String content) {
public static void saveProgramTraceFile(VMConfig config, String txHash, String content) {
File file = createProgramTraceFile(config, txHash);
if (file != null) {
writeStringToFile(file, content);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/tron/common/runtime/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.EnergyCost;
import org.tron.common.runtime.vm.MessageCall;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void setRootCallConstant(Boolean rootCallConstant) {

private ProgramPrecompile programPrecompile;

private final SystemProperties config;
private final VMConfig config;

//private byte[] transactionHash;

Expand All @@ -157,16 +157,16 @@ public Program(byte[] ops, ProgramInvoke programInvoke) {
}

public Program(byte[] ops, ProgramInvoke programInvoke, InternalTransaction transaction) {
this(ops, programInvoke, transaction, SystemProperties.getInstance(), null);
this(ops, programInvoke, transaction, VMConfig.getInstance(), null);
}

public Program(byte[] ops, ProgramInvoke programInvoke, InternalTransaction transaction,
SystemProperties config, BlockCapsule blockCap) {
VMConfig config, BlockCapsule blockCap) {
this(null, ops, programInvoke, transaction, config, blockCap);
}

public Program(byte[] codeHash, byte[] ops, ProgramInvoke programInvoke,
InternalTransaction transaction, SystemProperties config, BlockCapsule blockCap) {
InternalTransaction transaction, VMConfig config, BlockCapsule blockCap) {
this.config = config;
this.invoke = programInvoke;
this.transaction = transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.ArrayList;
import java.util.List;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.OpCode;
import org.tron.common.runtime.vm.program.invoke.ProgramInvoke;
Expand All @@ -41,7 +41,7 @@ public ProgramTrace() {
this(null, null);
}

public ProgramTrace(SystemProperties config, ProgramInvoke programInvoke) {
public ProgramTrace(VMConfig config, ProgramInvoke programInvoke) {
if (programInvoke != null && config.vmTrace()) {
contractAddress = Hex.toHexString(convertToTronAddress(programInvoke.getOwnerAddress().getLast20Bytes()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tron.core.net.message;

import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.exception.BadItemException;
Expand Down

0 comments on commit 2a572a2

Please sign in to comment.