From 636405c0049db17265f39938b980fa7214875191 Mon Sep 17 00:00:00 2001 From: Roy van Kaathoven Date: Thu, 23 Aug 2018 13:55:14 +0200 Subject: [PATCH 01/18] include create account fees in the black hole account --- .../org/tron/core/actuator/CreateAccountActuator.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/core/actuator/CreateAccountActuator.java b/src/main/java/org/tron/core/actuator/CreateAccountActuator.java index 06958ac51b5..b1b74d4e14a 100755 --- a/src/main/java/org/tron/core/actuator/CreateAccountActuator.java +++ b/src/main/java/org/tron/core/actuator/CreateAccountActuator.java @@ -28,12 +28,14 @@ public boolean execute(TransactionResultCapsule ret) long fee = calcFee(); try { AccountCreateContract accountCreateContract = contract.unpack(AccountCreateContract.class); - AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract, - dbManager.getHeadBlockTimeStamp()); - dbManager.getAccountStore() - .put(accountCreateContract.getAccountAddress().toByteArray(), accountCapsule); + AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract, dbManager.getHeadBlockTimeStamp()); + + dbManager.getAccountStore().put(accountCreateContract.getAccountAddress().toByteArray(), accountCapsule); dbManager.adjustBalance(accountCreateContract.getOwnerAddress().toByteArray(), -fee); + // Add to blackhole address + dbManager.adjustBalance(dbManager.getAccountStore().getBlackhole().createDbKey(), fee); + ret.setStatus(fee, code.SUCESS); } catch (BalanceInsufficientException e) { logger.debug(e.getMessage(), e); From 9b631435eb6f7997e01fb55494b6b58a09057325 Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Tue, 4 Sep 2018 21:19:34 +0800 Subject: [PATCH 02/18] OwnerAddress not equals OriginAddress. --- src/main/java/org/tron/common/runtime/Runtime.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index ec60b3f560a..7c25b0a7034 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -303,7 +303,10 @@ private void create() CreateSmartContract contract = ContractCapsule.getSmartContractFromTransaction(trx); SmartContract newSmartContract = contract.getNewContract(); - + if (!contract.getOwnerAddress().equals(newSmartContract.getOriginAddress())) { + logger.error("OwnerAddress not equals OriginAddress"); + throw new ContractValidateException("OwnerAddress not equals OriginAddress"); + } byte[] code = newSmartContract.getBytecode().toByteArray(); byte[] contractAddress = Wallet.generateContractAddress(trx); byte[] ownerAddress = contract.getOwnerAddress().toByteArray(); From 13a0306b4f11aff5ae8f0a76d97808e7bb969cfa Mon Sep 17 00:00:00 2001 From: Matt Yue Date: Wed, 5 Sep 2018 11:57:00 +0800 Subject: [PATCH 03/18] upgrade blockchain version to 2 --- src/main/java/org/tron/core/config/Parameter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/config/Parameter.java b/src/main/java/org/tron/core/config/Parameter.java index 184c71edb6a..2a41b5b06ec 100644 --- a/src/main/java/org/tron/core/config/Parameter.java +++ b/src/main/java/org/tron/core/config/Parameter.java @@ -23,7 +23,7 @@ interface ChainConstant { int BLOCK_FILLED_SLOTS_NUMBER = 128; int MAX_VOTE_NUMBER = 30; int MAX_FROZEN_NUMBER = 1; - int version = 1; + int version = 2; } interface NodeConstant { From 9e122594b041c4dc52783b079c276e845baf91ab Mon Sep 17 00:00:00 2001 From: taihaofu Date: Wed, 5 Sep 2018 13:16:21 +0800 Subject: [PATCH 04/18] refine exceptions in vm --- .../java/org/tron/common/runtime/Runtime.java | 35 ++++++++++++------- .../runtime/vm/PrecompiledContracts.java | 4 --- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 7c25b0a7034..c74b66ad9f2 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -184,18 +184,29 @@ public BigInteger getBlockCPULeftInUs() { } public void execute() throws ContractValidateException, ContractExeException { - switch (trxType) { - case TRX_PRECOMPILED_TYPE: - precompiled(); - break; - case TRX_CONTRACT_CREATION_TYPE: - create(); - break; - case TRX_CONTRACT_CALL_TYPE: - call(); - break; - default: - throw new ContractValidateException("Unknown contract type"); + try { + switch (trxType) { + case TRX_PRECOMPILED_TYPE: + precompiled(); + break; + case TRX_CONTRACT_CREATION_TYPE: + create(); + break; + case TRX_CONTRACT_CALL_TYPE: + call(); + break; + default: + throw new ContractValidateException("Unknown contract type"); + } + } + catch (ContractExeException e){ + throw e; + } + catch (ContractValidateException e){ + throw e; + } + catch (Exception e){ + throw new ContractValidateException("Unknown contract error"); } } diff --git a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java index 0325ccaa44f..dbf4b5db28f 100644 --- a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java +++ b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java @@ -912,10 +912,6 @@ public Pair execute(byte[] data) { return Pair.of(true, new DataWord(0).getData()); } - if (data == null) { - data = EMPTY_BYTE_ARRAY; - } - Contract.WithdrawBalanceContract.Builder builder = Contract.WithdrawBalanceContract .newBuilder(); ByteString byteAddress = ByteString.copyFrom(getCallerAddress()); From 20158e3a37780d9983ef784c86670d58410cbcb8 Mon Sep 17 00:00:00 2001 From: tjchern Date: Wed, 5 Sep 2018 14:11:26 +0800 Subject: [PATCH 05/18] add log --- src/main/java/org/tron/common/runtime/Runtime.java | 10 ++++++---- .../org/tron/common/runtime/vm/program/Program.java | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index ec60b3f560a..a0f316a16b8 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -489,10 +489,12 @@ public void go() { long saveCodeEnergy = getLength(code) * EnergyCost.getInstance().getCREATE_DATA(); long afterSpend = program.getEnergyLimitLeft().longValue() - saveCodeEnergy; if (afterSpend < 0) { - result.setException( - Program.Exception - .notEnoughSpendEnergy("No energy to save just created contract code", - saveCodeEnergy, program.getEnergyLimitLeft().longValue())); + if (null == result.getException()) { + result.setException( + Program.Exception + .notEnoughSpendEnergy("save just created contract code", + saveCodeEnergy, program.getEnergyLimitLeft().longValue())); + } } else { result.spendEnergy(saveCodeEnergy); // have saveCode in create() diff --git a/src/main/java/org/tron/common/runtime/vm/program/Program.java b/src/main/java/org/tron/common/runtime/vm/program/Program.java index 751b26fc3e9..a5a26a7a98b 100644 --- a/src/main/java/org/tron/common/runtime/vm/program/Program.java +++ b/src/main/java/org/tron/common/runtime/vm/program/Program.java @@ -790,6 +790,10 @@ public void checkCPUTimeLimit(String opName) { } long vmNowInUs = System.nanoTime() / 1000; if (vmNowInUs > getVmShouldEndInUs()) { + logger.error("minTimeRatio: {}", Args.getInstance().getMinTimeRatio()); + logger.error("maxTimeRatio: {}", Args.getInstance().getMaxTimeRatio()); + logger.error("vm should end time in us: {}", getVmShouldEndInUs()); + logger.error("vm start time in us: {}", getVmStartInUs()); throw Exception.notEnoughTime(opName); } From 2a572a218988178932503e51c06a22053a665135 Mon Sep 17 00:00:00 2001 From: huzhenyuan Date: Wed, 5 Sep 2018 15:39:51 +0800 Subject: [PATCH 06/18] set fee_limit up to 1000 trx --- .../java/org/tron/common/runtime/Runtime.java | 18 ++++++++------- .../common/runtime/config/DefaultConfig.java | 16 ------------- .../{SystemProperties.java => VMConfig.java} | 23 ++++++++----------- .../java/org/tron/common/runtime/vm/VM.java | 8 +++---- .../org/tron/common/runtime/vm/VMUtils.java | 6 ++--- .../common/runtime/vm/program/Program.java | 10 ++++---- .../common/runtime/vm/trace/ProgramTrace.java | 4 ++-- .../core/net/message/TransactionMessage.java | 1 - 8 files changed, 33 insertions(+), 53 deletions(-) delete mode 100644 src/main/java/org/tron/common/runtime/config/DefaultConfig.java rename src/main/java/org/tron/common/runtime/config/{SystemProperties.java => VMConfig.java} (73%) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index c74b66ad9f2..3d1dc535286 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -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; @@ -70,7 +70,7 @@ public class Runtime { - private SystemProperties config = SystemProperties.getInstance(); + private VMConfig config = VMConfig.getInstance(); private Transaction trx; private BlockCapsule blockCap = null; @@ -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); @@ -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)) { diff --git a/src/main/java/org/tron/common/runtime/config/DefaultConfig.java b/src/main/java/org/tron/common/runtime/config/DefaultConfig.java deleted file mode 100644 index c06349d52ae..00000000000 --- a/src/main/java/org/tron/common/runtime/config/DefaultConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.tron.common.runtime.config; - -public class DefaultConfig { - - private static int CREATE_WITNESS = 100; - - private static int MAX_CODE_LENGTH = 1024 * 1024; - - public static int getCREATEWITNESS() { - return CREATE_WITNESS; - } - - public static int getMaxCodeLength() { - return MAX_CODE_LENGTH; - } -} diff --git a/src/main/java/org/tron/common/runtime/config/SystemProperties.java b/src/main/java/org/tron/common/runtime/config/VMConfig.java similarity index 73% rename from src/main/java/org/tron/common/runtime/config/SystemProperties.java rename to src/main/java/org/tron/common/runtime/config/VMConfig.java index 77ec2aaf28d..e9ffbbe0042 100644 --- a/src/main/java/org/tron/common/runtime/config/SystemProperties.java +++ b/src/main/java/org/tron/common/runtime/config/VMConfig.java @@ -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; } diff --git a/src/main/java/org/tron/common/runtime/vm/VM.java b/src/main/java/org/tron/common/runtime/vm/VM.java index e3548a993e9..f7d407ef73e 100644 --- a/src/main/java/org/tron/common/runtime/vm/VM.java +++ b/src/main/java/org/tron/common/runtime/vm/VM.java @@ -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; @@ -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(); diff --git a/src/main/java/org/tron/common/runtime/vm/VMUtils.java b/src/main/java/org/tron/common/runtime/vm/VMUtils.java index 518b796e792..581bc48b660 100644 --- a/src/main/java/org/tron/common/runtime/vm/VMUtils.java +++ b/src/main/java/org/tron/common/runtime/vm/VMUtils.java @@ -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; @@ -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()) { @@ -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); diff --git a/src/main/java/org/tron/common/runtime/vm/program/Program.java b/src/main/java/org/tron/common/runtime/vm/program/Program.java index 751b26fc3e9..4b8f3eb1aab 100644 --- a/src/main/java/org/tron/common/runtime/vm/program/Program.java +++ b/src/main/java/org/tron/common/runtime/vm/program/Program.java @@ -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; @@ -148,7 +148,7 @@ public void setRootCallConstant(Boolean rootCallConstant) { private ProgramPrecompile programPrecompile; - private final SystemProperties config; + private final VMConfig config; //private byte[] transactionHash; @@ -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; diff --git a/src/main/java/org/tron/common/runtime/vm/trace/ProgramTrace.java b/src/main/java/org/tron/common/runtime/vm/trace/ProgramTrace.java index 90938eb2fa7..3dd3ea0a0cc 100644 --- a/src/main/java/org/tron/common/runtime/vm/trace/ProgramTrace.java +++ b/src/main/java/org/tron/common/runtime/vm/trace/ProgramTrace.java @@ -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; @@ -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())); } diff --git a/src/main/java/org/tron/core/net/message/TransactionMessage.java b/src/main/java/org/tron/core/net/message/TransactionMessage.java index cc037398328..5757df59b0d 100644 --- a/src/main/java/org/tron/core/net/message/TransactionMessage.java +++ b/src/main/java/org/tron/core/net/message/TransactionMessage.java @@ -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; From 0bbd1e683dbb4ade49119c7d42de4e27545332e5 Mon Sep 17 00:00:00 2001 From: huzhenyuan Date: Wed, 5 Sep 2018 15:48:01 +0800 Subject: [PATCH 07/18] update code style --- src/main/java/org/tron/common/runtime/Runtime.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 3d1dc535286..b57ae3a8717 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -198,14 +198,9 @@ public void execute() throws ContractValidateException, ContractExeException { default: throw new ContractValidateException("Unknown contract type"); } - } - catch (ContractExeException e){ - throw e; - } - catch (ContractValidateException e){ + } catch (ContractExeException | ContractValidateException e) { throw e; - } - catch (Exception e){ + } catch (Exception e) { throw new ContractValidateException("Unknown contract error"); } } From 3770705a9fc13b362d44ef1e0d827bfc8c6e9f58 Mon Sep 17 00:00:00 2001 From: huzhenyuan Date: Wed, 5 Sep 2018 16:16:22 +0800 Subject: [PATCH 08/18] set fee_limit up to 1000trx for junit test --- .../tron/common/runtime/vm/ChargeTest.java | 16 ++++----- .../runtime/vm/EnergyWhenAssertStyleTest.java | 36 +++++++++---------- .../vm/EnergyWhenRequireStyleTest.java | 16 ++++----- .../vm/EnergyWhenSendAndTransferTest.java | 6 ++-- .../vm/EnergyWhenTimeoutStyleTest.java | 2 +- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/test/java/org/tron/common/runtime/vm/ChargeTest.java b/src/test/java/org/tron/common/runtime/vm/ChargeTest.java index ce896e1fa9d..fe0b59b2865 100644 --- a/src/test/java/org/tron/common/runtime/vm/ChargeTest.java +++ b/src/test/java/org/tron/common/runtime/vm/ChargeTest.java @@ -68,7 +68,7 @@ public void init() { public void testOverflow() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "testOverflow"; @@ -92,7 +92,7 @@ public void testOverflow() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 20000000000L, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof ArithmeticException); @@ -118,7 +118,7 @@ public void testOverflow() public void testNegative() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "testNegative"; @@ -142,7 +142,7 @@ public void testNegative() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, value, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof ArithmeticException); @@ -153,7 +153,7 @@ public void testNegative() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, -100, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof ArithmeticException); @@ -187,7 +187,7 @@ public void testFallback() public void testCallDepth() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "testCallDepth"; @@ -264,7 +264,7 @@ public void testCallDepth() public void testCallDepthAndWidth() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "testCallDepthAndWidth"; @@ -300,7 +300,7 @@ public void testCallDepthAndWidth() public void testCreateDepthAndWidth() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 90000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "testCallDepthAndWidth"; diff --git a/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java b/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java index 59ef83b3d2c..8bd3b49d0c3 100644 --- a/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java +++ b/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java @@ -85,7 +85,7 @@ public void outOfIndexTest() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -108,7 +108,7 @@ public void outOfIndexTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -130,7 +130,7 @@ public void bytesNTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -153,7 +153,7 @@ public void bytesNTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -174,7 +174,7 @@ public void divZeroTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -197,7 +197,7 @@ public void divZeroTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -219,7 +219,7 @@ public void shiftByNegativeTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -242,7 +242,7 @@ public void shiftByNegativeTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -265,7 +265,7 @@ public void enumTypeTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -288,7 +288,7 @@ public void enumTypeTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -309,7 +309,7 @@ public void functionPointerTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -332,7 +332,7 @@ public void functionPointerTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -353,7 +353,7 @@ public void assertTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -376,7 +376,7 @@ public void assertTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof IllegalOperationException); @@ -403,7 +403,7 @@ public void assertTest() public void systemPrecompileTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -430,7 +430,7 @@ public void systemPrecompileTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof PrecompiledContractException); @@ -451,7 +451,7 @@ public void systemPrecompileTest() public void outOfMemTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -474,7 +474,7 @@ public void outOfMemTest() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); Assert.assertTrue( result.getRuntime().getResult().getException() instanceof OutOfMemoryException); diff --git a/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java b/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java index 2e13731fc64..4fe04b50781 100644 --- a/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java +++ b/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java @@ -79,7 +79,7 @@ public void throwTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -124,7 +124,7 @@ public void requireTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -174,7 +174,7 @@ public void thisFunctionViaMessageCallTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -233,7 +233,7 @@ public void thatFunctionViaMessageCallTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -285,7 +285,7 @@ public void newContractTest1() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -309,7 +309,7 @@ public void newContractTest1() .triggerContractAndReturnTVMTestResult(Hex.decode(OWNER_ADDRESS), contractAddress, triggerData, 0, feeLimit, deposit, null); - Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 200000000000L); + Assert.assertEquals(result.getReceipt().getEnergyUsageTotal(), 10_000_000L); // todo: revert should be true!! see later Assert.assertEquals(result.getRuntime().getResult().isRevert(), false); @@ -344,7 +344,7 @@ public void receiveTrxWithoutPayableTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 10; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; @@ -411,7 +411,7 @@ public void revertTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; String contractName = "test"; diff --git a/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java b/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java index 60d405d1ca5..217122bede3 100644 --- a/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java +++ b/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java @@ -87,7 +87,7 @@ public void callValueTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 10000000L; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; TVMTestResult result = deployCallValueTestContract(value, feeLimit, consumeUserResourcePercent); @@ -150,7 +150,7 @@ public void sendTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 1000L; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; TVMTestResult result = deploySendAndTransferTestContract(value, feeLimit, consumeUserResourcePercent); @@ -176,7 +176,7 @@ public void transferTest() long value = 1000L; // long value = 10000000L; - long feeLimit = 20000000000000L; // sun + long feeLimit = 1000_000_000L; // sun long consumeUserResourcePercent = 100; TVMTestResult result = deploySendAndTransferTestContract(value, feeLimit, consumeUserResourcePercent); diff --git a/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java b/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java index 99fb78bb037..8f7439f74ef 100644 --- a/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java +++ b/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java @@ -78,7 +78,7 @@ public void endlessLoopTest() throws ContractExeException, TransactionTraceException, ContractValidateException, ReceiptCheckErrException { long value = 0; - long feeLimit = 20000000000000L; + long feeLimit = 1000_000_000L; long consumeUserResourcePercent = 0; TVMTestResult result = deployEndlessLoopContract(value, feeLimit, consumeUserResourcePercent); From 2c416b45ab51687faf8aef25d11b77f92cd7a4aa Mon Sep 17 00:00:00 2001 From: Matt Yue Date: Wed, 5 Sep 2018 16:35:28 +0800 Subject: [PATCH 09/18] :mute:fork log level to debug --- .../org/tron/common/utils/ForkController.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/tron/common/utils/ForkController.java b/src/main/java/org/tron/common/utils/ForkController.java index 9025da0a7d2..600f8fe297b 100644 --- a/src/main/java/org/tron/common/utils/ForkController.java +++ b/src/main/java/org/tron/common/utils/ForkController.java @@ -31,7 +31,9 @@ public void init(Manager manager) { public synchronized boolean shouldBeForked() { if (forked) { - logger.info("*****shouldBeForked:" + true); + if (logger.isDebugEnabled()) { + logger.debug("*****shouldBeForked:" + true); + } return true; } @@ -41,7 +43,9 @@ public synchronized boolean shouldBeForked() { for (int version : slots) { if (version != ChainConstant.version) { - logger.info("*****shouldBeForked:" + false); + if (logger.isDebugEnabled()) { + logger.debug("*****shouldBeForked:" + false); + } return false; } } @@ -49,7 +53,9 @@ public synchronized boolean shouldBeForked() { // todo add Maintenance or block number forked = true; manager.getDynamicPropertiesStore().forked(); - logger.info("*****shouldBeForked:" + true); + if (logger.isDebugEnabled()) { + logger.debug("*****shouldBeForked:" + true); + } return true; } @@ -57,7 +63,9 @@ public synchronized void hardFork(TransactionCapsule capsule) throws ContractExe boolean hardFork = shouldBeForked() || capsule.getInstance().getRawData().getContractList().get(0).getType().getNumber() <= DISCARD_SCOPE; - logger.info("*****hardFork:" + hardFork); + if (logger.isDebugEnabled()) { + logger.debug("*****hardFork:" + hardFork); + } if (!hardFork) { throw new ContractExeException("not yet hard forked"); } @@ -83,7 +91,7 @@ public synchronized void update(BlockCapsule blockCapsule) { slots[slot] = version; logger.info( - "*******update fork:" + Arrays.toString(slots) + "*******update hard fork:" + Arrays.toString(slots) + ",witness size:" + witnesses.size() + ",slot:" + slot + ",witness:" + ByteUtil.toHexString(witness.toByteArray()) From c795b751d52dd1cd14c14833f5e59d1db4425e7b Mon Sep 17 00:00:00 2001 From: taihaofu Date: Wed, 5 Sep 2018 17:42:26 +0800 Subject: [PATCH 10/18] comment out precompile functions --- .../runtime/vm/PrecompiledContracts.java | 80 +++++++++---------- .../runtime/vm/EnergyWhenAssertStyleTest.java | 2 +- .../runtime/vm/PrecompiledContractsTest.java | 14 ++-- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java index dbf4b5db28f..8e54f03cf03 100644 --- a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java +++ b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java @@ -121,28 +121,28 @@ public class PrecompiledContracts { "0000000000000000000000000000000000000000000000000000000000000007"); private static final DataWord altBN128PairingAddr = new DataWord( "0000000000000000000000000000000000000000000000000000000000000008"); - private static final DataWord voteContractAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010001"); +// private static final DataWord voteContractAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010001"); // private static final DataWord freezeBalanceAddr = new DataWord( // "0000000000000000000000000000000000000000000000000000000000010002"); // private static final DataWord unFreezeBalanceAddr = new DataWord( // "0000000000000000000000000000000000000000000000000000000000010003"); - private static final DataWord withdrawBalanceAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010004"); - private static final DataWord proposalApproveAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010005"); - private static final DataWord proposalCreateAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010006"); - private static final DataWord proposalDeleteAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010007"); - private static final DataWord convertFromTronBytesAddressAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010008"); - private static final DataWord convertFromTronBase58AddressAddr = new DataWord( - "0000000000000000000000000000000000000000000000000000000000010009"); +// private static final DataWord withdrawBalanceAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010004"); +// private static final DataWord proposalApproveAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010005"); +// private static final DataWord proposalCreateAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010006"); +// private static final DataWord proposalDeleteAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010007"); +// private static final DataWord convertFromTronBytesAddressAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010008"); +// private static final DataWord convertFromTronBase58AddressAddr = new DataWord( +// "0000000000000000000000000000000000000000000000000000000000010009"); // private static final DataWord transferAssetAddr = new DataWord( // "000000000000000000000000000000000000000000000000000000000001000a"); - private static final DataWord getTransferAssetAmountAddr = new DataWord( - "000000000000000000000000000000000000000000000000000000000001000b"); +// private static final DataWord getTransferAssetAmountAddr = new DataWord( +// "000000000000000000000000000000000000000000000000000000000001000b"); public static PrecompiledContract getContractForAddress(DataWord address) { @@ -161,39 +161,39 @@ public static PrecompiledContract getContractForAddress(DataWord address) { if (address.equals(identityAddr)) { return identity; } - if (address.equals(voteContractAddr)) { - return voteContract; - } +// if (address.equals(voteContractAddr)) { +// return voteContract; +// } // if (address.equals(freezeBalanceAddr)) { // return freezeBalance; // } // if (address.equals(unFreezeBalanceAddr)) { // return unFreezeBalance; // } - if (address.equals(withdrawBalanceAddr)) { - return withdrawBalance; - } - if (address.equals(proposalApproveAddr)) { - return proposalApprove; - } - if (address.equals(proposalCreateAddr)) { - return proposalCreate; - } - if (address.equals(proposalDeleteAddr)) { - return proposalDelete; - } - if (address.equals(convertFromTronBytesAddressAddr)) { - return convertFromTronBytesAddress; - } - if (address.equals(convertFromTronBase58AddressAddr)) { - return convertFromTronBase58Address; - } +// if (address.equals(withdrawBalanceAddr)) { +// return withdrawBalance; +// } +// if (address.equals(proposalApproveAddr)) { +// return proposalApprove; +// } +// if (address.equals(proposalCreateAddr)) { +// return proposalCreate; +// } +// if (address.equals(proposalDeleteAddr)) { +// return proposalDelete; +// } +// if (address.equals(convertFromTronBytesAddressAddr)) { +// return convertFromTronBytesAddress; +// } +// if (address.equals(convertFromTronBase58AddressAddr)) { +// return convertFromTronBase58Address; +// } // if (address.equals(transferAssetAddr)) { // return transferAsset; // } - if (address.equals(getTransferAssetAmountAddr)) { - return getTransferAssetAmount; - } +// if (address.equals(getTransferAssetAmountAddr)) { +// return getTransferAssetAmount; +// } // Byzantium precompiles if (address.equals(modExpAddr)) { diff --git a/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java b/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java index 8bd3b49d0c3..abd4bc5518b 100644 --- a/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java +++ b/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java @@ -399,7 +399,7 @@ public void assertTest() // // } - @Test + //@Test public void systemPrecompileTest() throws ContractExeException, ReceiptCheckErrException, TransactionTraceException, ContractValidateException { long value = 0; diff --git a/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java b/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java index 16a8b73541d..e6f71d9dbdb 100644 --- a/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java +++ b/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java @@ -154,7 +154,7 @@ private PrecompiledContract createPrecompiledContract(DataWord addr, String owne return contract; } - @Test + //@Test public void voteWitnessNativeTest() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ContractValidateException, ContractExeException { PrecompiledContract contract = createPrecompiledContract(voteContractAddr, OWNER_ADDRESS); @@ -196,7 +196,7 @@ public void voteWitnessNativeTest() Assert.assertEquals(true, result); } - @Test + //@Test public void withdrawBalanceNativeTest() { PrecompiledContract contract = createPrecompiledContract(withdrawBalanceAddr, WITNESS_ADDRESS); @@ -227,7 +227,7 @@ public void withdrawBalanceNativeTest() { } - @Test + //@Test public void proposalTest() { try { @@ -298,12 +298,12 @@ public void proposalTest() { @Test public void convertFromTronBytesAddressNativeTest() { - PrecompiledContract contract = createPrecompiledContract(convertFromTronBytesAddressAddr, WITNESS_ADDRESS); - byte[] solidityAddress = contract.execute(new DataWord(WITNESS_ADDRESS).getData()).getRight(); - Assert.assertArrayEquals(solidityAddress,new DataWord(Hex.decode(WITNESS_ADDRESS_BASE)).getData()); +// PrecompiledContract contract = createPrecompiledContract(convertFromTronBytesAddressAddr, WITNESS_ADDRESS); +// byte[] solidityAddress = contract.execute(new DataWord(WITNESS_ADDRESS).getData()).getRight(); +// Assert.assertArrayEquals(solidityAddress,new DataWord(Hex.decode(WITNESS_ADDRESS_BASE)).getData()); } - @Test + //@Test public void convertFromTronBase58AddressNative() { // 27WnTihwXsqCqpiNedWvtKCZHsLjDt4Hfmf TestNet address DataWord word1 = new DataWord("3237576e54696877587371437170694e65645776744b435a48734c6a44743448"); From c9176f0517ee01221122a22fb320ae3c2f92de23 Mon Sep 17 00:00:00 2001 From: taihaofu Date: Wed, 5 Sep 2018 17:47:41 +0800 Subject: [PATCH 11/18] comment out precompile instance --- .../runtime/vm/PrecompiledContracts.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java index 8e54f03cf03..4d86675a457 100644 --- a/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java +++ b/src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java @@ -88,17 +88,17 @@ public class PrecompiledContracts { private static final BN128Addition altBN128Add = new BN128Addition(); private static final BN128Multiplication altBN128Mul = new BN128Multiplication(); private static final BN128Pairing altBN128Pairing = new BN128Pairing(); - private static final VoteWitnessNative voteContract = new VoteWitnessNative(); - // private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative(); +// private static final VoteWitnessNative voteContract = new VoteWitnessNative(); +// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative(); // private static final UnfreezeBalanceNative unFreezeBalance = new UnfreezeBalanceNative(); - private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative(); - private static final ProposalApproveNative proposalApprove = new ProposalApproveNative(); - private static final ProposalCreateNative proposalCreate = new ProposalCreateNative(); - private static final ProposalDeleteNative proposalDelete = new ProposalDeleteNative(); - private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative(); - private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative(); +// private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative(); +// private static final ProposalApproveNative proposalApprove = new ProposalApproveNative(); +// private static final ProposalCreateNative proposalCreate = new ProposalCreateNative(); +// private static final ProposalDeleteNative proposalDelete = new ProposalDeleteNative(); +// private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative(); +// private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative(); // private static final TransferAssetNative transferAsset = new TransferAssetNative(); - private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative(); +// private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative(); private static final ECKey addressCheckECKey = new ECKey(); private static final String addressCheckECKeyAddress = Wallet From dc1e98c7ac4ab25715b733782c1ff98d9ac6ff51 Mon Sep 17 00:00:00 2001 From: nanfengpo Date: Wed, 5 Sep 2018 17:53:31 +0800 Subject: [PATCH 12/18] add fee in blackhole --- .../org/tron/core/actuator/ExchangeCreateActuator.java | 9 ++++++++- .../java/org/tron/core/actuator/TransferActuator.java | 1 + .../org/tron/core/actuator/TransferAssetActuator.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/actuator/ExchangeCreateActuator.java b/src/main/java/org/tron/core/actuator/ExchangeCreateActuator.java index 7f31961519c..1f42e3f2a36 100755 --- a/src/main/java/org/tron/core/actuator/ExchangeCreateActuator.java +++ b/src/main/java/org/tron/core/actuator/ExchangeCreateActuator.java @@ -11,6 +11,7 @@ import org.tron.core.capsule.TransactionResultCapsule; import org.tron.core.config.Parameter.ChainParameters; import org.tron.core.db.Manager; +import org.tron.core.exception.BalanceInsufficientException; import org.tron.core.exception.ContractExeException; import org.tron.core.exception.ContractValidateException; import org.tron.protos.Contract.ExchangeCreateContract; @@ -37,7 +38,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException long firstTokenBalance = exchangeCreateContract.getFirstTokenBalance(); long secondTokenBalance = exchangeCreateContract.getSecondTokenBalance(); - long newBalance = accountCapsule.getBalance() - calcFee(); + long newBalance = accountCapsule.getBalance() - fee; if (firstTokenID == "_".getBytes()) { accountCapsule.setBalance(newBalance - firstTokenBalance); @@ -68,7 +69,13 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException dbManager.getExchangeStore().put(exchangeCapsule.createDbKey(), exchangeCapsule); dbManager.getDynamicPropertiesStore().saveLatestExchangeNum(id); + dbManager.adjustBalance(dbManager.getAccountStore().getBlackhole().createDbKey(), fee); + ret.setStatus(fee, code.SUCESS); + } catch (BalanceInsufficientException e) { + logger.debug(e.getMessage(), e); + ret.setStatus(fee, code.FAILED); + throw new ContractExeException(e.getMessage()); } catch (InvalidProtocolBufferException e) { logger.debug(e.getMessage(), e); ret.setStatus(fee, code.FAILED); diff --git a/src/main/java/org/tron/core/actuator/TransferActuator.java b/src/main/java/org/tron/core/actuator/TransferActuator.java index eb5f87451c2..19924d75460 100755 --- a/src/main/java/org/tron/core/actuator/TransferActuator.java +++ b/src/main/java/org/tron/core/actuator/TransferActuator.java @@ -44,6 +44,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract(); } dbManager.adjustBalance(ownerAddress, -fee); + dbManager.adjustBalance(dbManager.getAccountStore().getBlackhole().createDbKey(), fee); ret.setStatus(fee, code.SUCESS); dbManager.adjustBalance(ownerAddress, -amount); dbManager.adjustBalance(toAddress, amount); diff --git a/src/main/java/org/tron/core/actuator/TransferAssetActuator.java b/src/main/java/org/tron/core/actuator/TransferAssetActuator.java index 09c2e724ea6..850dce0e549 100644 --- a/src/main/java/org/tron/core/actuator/TransferAssetActuator.java +++ b/src/main/java/org/tron/core/actuator/TransferAssetActuator.java @@ -62,6 +62,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException long amount = transferAssetContract.getAmount(); dbManager.adjustBalance(ownerAddress, -fee); + dbManager.adjustBalance(dbManager.getAccountStore().getBlackhole().createDbKey(), fee); AccountCapsule ownerAccountCapsule = accountStore.get(ownerAddress); if (!ownerAccountCapsule.reduceAssetAmount(assetName.toByteArray(), amount)) { From ea6dde70148094242c591001afe8f3002b4ea64f Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Wed, 5 Sep 2018 18:22:01 +0800 Subject: [PATCH 13/18] send Fee to Black hole. --- src/main/java/org/tron/core/capsule/ReceiptCapsule.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/tron/core/capsule/ReceiptCapsule.java b/src/main/java/org/tron/core/capsule/ReceiptCapsule.java index a1894336242..b93dcf66076 100644 --- a/src/main/java/org/tron/core/capsule/ReceiptCapsule.java +++ b/src/main/java/org/tron/core/capsule/ReceiptCapsule.java @@ -132,6 +132,9 @@ private void payEnergyBill( StringUtil.createReadableString(account.createDbKey()) + " insufficient balance"); } account.setBalance(balance - energyFee); + + manager.adjustBalance(manager.getAccountStore().getBlackhole().getAddress().toByteArray(), + energyFee);//send to blackhole } manager.getAccountStore().put(account.getAddress().toByteArray(), account); From 719b19ef2439001defbde40d7fc516320c986c32 Mon Sep 17 00:00:00 2001 From: tjchern Date: Wed, 5 Sep 2018 19:57:14 +0800 Subject: [PATCH 14/18] throw timeout --- src/main/java/org/tron/common/runtime/Runtime.java | 5 +++++ src/main/java/org/tron/common/runtime/vm/VM.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 4abb85212db..4be6a3f92c9 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -34,6 +34,7 @@ import org.tron.common.runtime.vm.program.InternalTransaction.ExecutorType; 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.OutOfResourceException; import org.tron.common.runtime.vm.program.ProgramPrecompile; import org.tron.common.runtime.vm.program.ProgramResult; import org.tron.common.runtime.vm.program.invoke.ProgramInvoke; @@ -526,6 +527,10 @@ public void go() { result.setException(e); runtimeError = result.getException().getMessage(); logger.error("runtime error is :{}", result.getException().getMessage()); + } catch (OutOfResourceException e) { + result.setException(e); + runtimeError = result.getException().getMessage(); + logger.error("runtime error is :{}", result.getException().getMessage()); } catch (Throwable e) { program.spendAllEnergy(); if (Objects.isNull(result.getException())) { diff --git a/src/main/java/org/tron/common/runtime/vm/VM.java b/src/main/java/org/tron/common/runtime/vm/VM.java index e3548a993e9..fb5a5cacdfe 100644 --- a/src/main/java/org/tron/common/runtime/vm/VM.java +++ b/src/main/java/org/tron/common/runtime/vm/VM.java @@ -18,6 +18,7 @@ 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; +import org.tron.common.runtime.vm.program.Program.OutOfResourceException; import org.tron.common.runtime.vm.program.Stack; @Slf4j(topic = "VM") @@ -1333,6 +1334,9 @@ public void play(Program program) { } catch (JVMStackOverFlowException e) { throw new JVMStackOverFlowException(); + } catch (OutOfResourceException e) { + program.setRuntimeFailure(e); + throw e; } catch (RuntimeException e) { if (StringUtils.isEmpty(e.getMessage())) { program.setRuntimeFailure(new RuntimeException("Unknown Exception")); From 63dd34df8d6d8e6456d286d8ece3db801476e972 Mon Sep 17 00:00:00 2001 From: tjchern Date: Wed, 5 Sep 2018 20:08:37 +0800 Subject: [PATCH 15/18] fix bug --- src/main/java/org/tron/common/runtime/Runtime.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 4be6a3f92c9..c11bf226a85 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -524,10 +524,12 @@ public void go() { deposit.commit(); } } catch (JVMStackOverFlowException e) { + program.spendAllEnergy(); result.setException(e); runtimeError = result.getException().getMessage(); logger.error("runtime error is :{}", result.getException().getMessage()); } catch (OutOfResourceException e) { + program.spendAllEnergy(); result.setException(e); runtimeError = result.getException().getMessage(); logger.error("runtime error is :{}", result.getException().getMessage()); From 0eaae135a4c5fe18727152be62d7f19d92d32524 Mon Sep 17 00:00:00 2001 From: ashu Date: Wed, 5 Sep 2018 21:03:07 +0800 Subject: [PATCH 16/18] create cmd should use child deposit --- src/main/java/org/tron/common/runtime/vm/program/Program.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/common/runtime/vm/program/Program.java b/src/main/java/org/tron/common/runtime/vm/program/Program.java index 4d5e27cbce0..9d158fb49fe 100644 --- a/src/main/java/org/tron/common/runtime/vm/program/Program.java +++ b/src/main/java/org/tron/common/runtime/vm/program/Program.java @@ -484,7 +484,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize) } */ - Deposit deposit = getContractState(); + Deposit deposit = getContractState().newDepositChild(); //In case of hashing collisions, check for any balance before createAccount() long oldBalance = deposit.getBalance(newAddress); From 1940257b6df0dd7a4be76e0c7aa2705a41021943 Mon Sep 17 00:00:00 2001 From: huzhenyuan <402124323@qq.com> Date: Wed, 5 Sep 2018 21:06:01 +0800 Subject: [PATCH 17/18] Update VM.java --- src/main/java/org/tron/common/runtime/vm/VM.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/tron/common/runtime/vm/VM.java b/src/main/java/org/tron/common/runtime/vm/VM.java index 9c2d18026d1..122981224ac 100644 --- a/src/main/java/org/tron/common/runtime/vm/VM.java +++ b/src/main/java/org/tron/common/runtime/vm/VM.java @@ -1333,9 +1333,8 @@ public void play(Program program) { } } catch (JVMStackOverFlowException e) { - throw new JVMStackOverFlowException(); + throw e; } catch (OutOfResourceException e) { - program.setRuntimeFailure(e); throw e; } catch (RuntimeException e) { if (StringUtils.isEmpty(e.getMessage())) { From 4c2977db92760fe5e15c95772bf1f3bf2b0c1e3e Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Wed, 5 Sep 2018 21:18:17 +0800 Subject: [PATCH 18/18] reset cacl bytesSize. --- src/main/java/org/tron/core/db/BandwidthProcessor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/core/db/BandwidthProcessor.java b/src/main/java/org/tron/core/db/BandwidthProcessor.java index d043332ffd4..9acf8173e4b 100644 --- a/src/main/java/org/tron/core/db/BandwidthProcessor.java +++ b/src/main/java/org/tron/core/db/BandwidthProcessor.java @@ -18,7 +18,10 @@ import org.tron.core.exception.TooBigTransactionResultException; import org.tron.protos.Contract.TransferAssetContract; import org.tron.protos.Contract.TransferContract; +import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; +import org.tron.protos.Protocol.Transaction.Result; +import org.tron.protos.Protocol.Transaction.Result.contractResult; @Slf4j public class BandwidthProcessor extends ResourceProcessor { @@ -60,10 +63,7 @@ public void consume(TransactionCapsule trx, TransactionResultCapsule ret, long bytesSize; if (dbManager.getDynamicPropertiesStore().supportVM()) { - TransactionCapsule txCapForEstimateBandWidth = new TransactionCapsule( - trx.getInstance().getRawData(), - trx.getInstance().getSignatureList()); - bytesSize = txCapForEstimateBandWidth.getSerializedSize(); + bytesSize = trx.getInstance().toBuilder().clearRet().build().getSerializedSize(); } else { bytesSize = trx.getSerializedSize(); }