Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
724b35d
test
tjchern Aug 27, 2018
8976ae2
add test
tjchern Aug 27, 2018
cd1412a
Donot print stack trace
ithinker1991 Aug 29, 2018
b8db35a
add test about energy
tjchern Aug 30, 2018
311ecf4
test
tjchern Aug 30, 2018
c18c7a4
mergr from origin/develop
tjchern Aug 30, 2018
b54702b
proposalController while minor change
nanfengpo Aug 30, 2018
2453c85
fix bugs and add test about exception
tjchern Aug 30, 2018
b074da8
Add stack out by contract and Triple Trigger test case
Aug 31, 2018
be2d102
Merge pull request #1414 from tronprotocol/fix_null_bug_and_add_test
huzhenyuan Aug 31, 2018
c2ec8bb
Merge pull request #1416 from tronprotocol/stest_VM_detail_fee
pangpangfeng Aug 31, 2018
7a79a26
judge insufficient balance.
CodeNinjaEvan Aug 31, 2018
a32b7be
do not print tracestack
tjchern Aug 31, 2018
07a7576
throws ContractExeException.
CodeNinjaEvan Aug 31, 2018
9a79f56
Add value equal balance, the deploy will be failed
Aug 31, 2018
ac20145
Merge pull request #1417 from tronprotocol/do_not_print_tracestack
huzhenyuan Aug 31, 2018
f9e0b27
Merge pull request #1413 from tronprotocol/fix/print_useless_log
huzhenyuan Aug 31, 2018
a0826d2
Merge pull request #1418 from tronprotocol/judge_insufficient_balance
huzhenyuan Aug 31, 2018
7dd2977
Merge pull request #1419 from tronprotocol/stest_VM_detail_fee
pangpangfeng Aug 31, 2018
0fcae58
fix db can't be revert when calling precompile function
taihaofu Aug 31, 2018
552dc1d
Merge branch 'develop' into fix_precompile_db_not_revert_issue
taihaofu Aug 31, 2018
54047b3
refine pre-check before executing actuator
taihaofu Sep 1, 2018
acb9b6b
resolve sonar error
taihaofu Sep 1, 2018
06749e9
update config-test-net.conf
ithinker1991 Sep 1, 2018
dbcbed0
update config
ithinker1991 Sep 1, 2018
4faca08
Merge pull request #1421 from tronprotocol/update_config
huzhenyuan Sep 3, 2018
cd69a8d
use child for deposit
taihaofu Sep 3, 2018
7e642a7
add time benchmark
tjchern Sep 3, 2018
d30f148
refine db logic
taihaofu Sep 3, 2018
403d604
1. add max_time_on_tx range limit; 2. do not checktime in solidity no…
tjchern Sep 3, 2018
568974c
fix bug
tjchern Sep 3, 2018
1e3d0cb
Merge pull request #1422 from tronprotocol/dont_check_time_on_solidity
huzhenyuan Sep 3, 2018
6e22660
convert nonce, rootTransactionid, rootIsConstant to non-static fields
taihaofu Sep 3, 2018
346d40e
fix duplicate remove gr power
nanfengpo Sep 3, 2018
370a434
opt solidty
olenheim Sep 3, 2018
4491d0d
refine typo
taihaofu Sep 3, 2018
bbe913b
set result contract.
CodeNinjaEvan Sep 3, 2018
04354bd
Merge remote-tracking branch 'remotes/origin/develop' into test_about…
tjchern Sep 3, 2018
679bf31
add test about energy
tjchern Sep 3, 2018
0018237
Merge pull request #1423 from tronprotocol/set_contract_result
huzhenyuan Sep 4, 2018
757b81e
Merge pull request #1420 from tronprotocol/fix_precompile_db_not_reve…
huzhenyuan Sep 4, 2018
28e4731
Merge pull request #1426 from tronprotocol/hotfix/odyssey3.0_minor_ch…
pangpangfeng Sep 4, 2018
191aaed
Merge pull request #1424 from tronprotocol/test_about_energy
huzhenyuan Sep 4, 2018
8565c8e
invalid bytecode return DataWord(0);
ithinker1991 Sep 4, 2018
b0f9396
fix bug for calc bandwidth
Sep 4, 2018
919dc90
add saveCode energy
tjchern Sep 4, 2018
9435e41
Merge pull request #1428 from tronprotocol/fix_bandwidth
nanfengpo Sep 4, 2018
ab1b81a
modify test
tjchern Sep 4, 2018
aca840f
Merge remote-tracking branch 'remotes/origin/develop' into test_about…
tjchern Sep 4, 2018
f471ef6
ignore
tjchern Sep 4, 2018
acdd692
Merge pull request #1429 from tronprotocol/add_saveCodeEnergy
huzhenyuan Sep 4, 2018
c977d7d
Merge pull request #1427 from tronprotocol/fix/invalid_bytecode
huzhenyuan Sep 4, 2018
d942e26
feeLimit <= 0, fali
tjchern Sep 4, 2018
d6b8129
fix feeLimit <= 0.
CodeNinjaEvan Sep 4, 2018
1691f37
fix feeLimit <= 0.
CodeNinjaEvan Sep 4, 2018
ee54667
Update ReceiptCapsule.java
huzhenyuan Sep 4, 2018
9dfc5bc
do not print tracestack in SolidityNode.java
tjchern Sep 4, 2018
097ad63
Merge pull request #1431 from tronprotocol/fix_feeLimit_bug
huzhenyuan Sep 4, 2018
f47c6b4
Merge pull request #1432 from tronprotocol/dont_print_tracestack_in_s…
CodeNinjaEvan Sep 4, 2018
b82a62f
fix bug
tjchern Sep 4, 2018
d1bc09a
fix deepcopy method
ithinker1991 Sep 4, 2018
c6cf3c9
Merge pull request #1434 from tronprotocol/test_about_energy
huzhenyuan Sep 4, 2018
647e599
Merge pull request #1433 from tronprotocol/fix/value_deepcopy
huzhenyuan Sep 4, 2018
1bea488
move finalization to test
tjchern Sep 4, 2018
de34170
Merge remote-tracking branch 'origin/develop' into test_about_energy
tjchern Sep 4, 2018
44bd352
Merge pull request #1435 from tronprotocol/optSolidty
huzhenyuan Sep 4, 2018
3fb6c69
Merge pull request #1436 from tronprotocol/move_finalization_to_test
huzhenyuan Sep 4, 2018
dff6303
refine contract state
taihaofu Sep 4, 2018
444d362
Merge pull request #1438 from tronprotocol/refine_contractState
huzhenyuan Sep 4, 2018
2757548
stest_adapt_deploy_contract_cost_increase
Sep 4, 2018
1ff2e78
Merge pull request #1439 from tronprotocol/stest_adapt_deploy_contrac…
pangpangfeng Sep 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 64 additions & 13 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.commons.lang3.ArrayUtils.getLength;
import static org.apache.commons.lang3.ArrayUtils.isEmpty;
import static org.tron.common.runtime.utils.MUtil.convertToTronAddress;
import static org.tron.common.runtime.utils.MUtil.transfer;
Expand All @@ -26,6 +27,7 @@
import org.spongycastle.util.encoders.Hex;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.EnergyCost;
import org.tron.common.runtime.vm.PrecompiledContracts;
import org.tron.common.runtime.vm.VM;
import org.tron.common.runtime.vm.program.InternalTransaction;
Expand Down Expand Up @@ -95,7 +97,7 @@ public class Runtime {
/**
* For blockCap's trx run
*/
public Runtime(TransactionTrace trace, BlockCapsule block, Deposit deosit,
public Runtime(TransactionTrace trace, BlockCapsule block, Deposit deposit,
ProgramInvokeFactory programInvokeFactory) {
this.trace = trace;
this.trx = trace.getTrx().getInstance();
Expand All @@ -107,7 +109,7 @@ public Runtime(TransactionTrace trace, BlockCapsule block, Deposit deosit,
this.blockCap = new BlockCapsule(Block.newBuilder().build());
this.executorType = ET_PRE_TYPE;
}
this.deposit = deosit;
this.deposit = deposit;
this.programInvokeFactory = programInvokeFactory;
this.energyProcessor = new EnergyProcessor(deposit.getDbManager());
this.storageMarket = new StorageMarket(deposit.getDbManager());
Expand Down Expand Up @@ -293,8 +295,9 @@ private double getThisTxCPULimitInUsRatio() {
/*
**/
private void create()
throws ContractValidateException {
throws ContractValidateException {
if (!deposit.getDbManager().getDynamicPropertiesStore().supportVM()) {
logger.error("vm work is off, need to be opened by the committee");
throw new ContractValidateException("vm work is off, need to be opened by the committee");
}

Expand All @@ -307,11 +310,14 @@ private void create()

long percent = contract.getNewContract().getConsumeUserResourcePercent();
if (percent < 0 || percent > 100) {
logger.error("percent must be >= 0 and <= 100");
throw new ContractValidateException("percent must be >= 0 and <= 100");
}

// insure the new contract address haven't exist
if (deposit.getAccount(contractAddress) != null) {
logger.error("Trying to create a contract with existing contract address: " + Wallet
.encode58Check(contractAddress));
throw new ContractValidateException(
"Trying to create a contract with existing contract address: " + Wallet
.encode58Check(contractAddress));
Expand Down Expand Up @@ -342,6 +348,11 @@ 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");
}

long energyLimit = getEnergyLimit(creator, feeLimit, callValue);
byte[] ops = newSmartContract.getBytecode().toByteArray();
InternalTransaction internalTransaction = new InternalTransaction(trx);
Expand All @@ -351,9 +362,9 @@ private void create()
blockCap.getInstance(), deposit, vmStartInUs, vmShouldEndInUs, energyLimit);
this.vm = new VM(config);
this.program = new Program(ops, programInvoke, internalTransaction, config, this.blockCap);
Program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
Program.resetNonce();
Program.setRootCallConstant(isCallConstant());
this.program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
this.program.resetNonce();
this.program.setRootCallConstant(isCallConstant());
} catch (Exception e) {
logger.error(e.getMessage());
throw new ContractValidateException(e.getMessage());
Expand Down Expand Up @@ -381,9 +392,10 @@ private void create()
*/

private void call()
throws ContractValidateException {
throws ContractValidateException {

if (!deposit.getDbManager().getDynamicPropertiesStore().supportVM()) {
logger.error("vm work is off, need to be opened by the committee");
throw new ContractValidateException("VM work is off, need to be opened by the committee");
}

Expand Down Expand Up @@ -413,6 +425,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");
}
long energyLimit;
if (isCallConstant(contractAddress)) {
energyLimit = Constant.MAX_ENERGY_IN_TX;
Expand All @@ -427,9 +443,9 @@ private void call()
InternalTransaction internalTransaction = new InternalTransaction(trx);
this.program = new Program(null, code, programInvoke, internalTransaction, config,
this.blockCap);
Program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
Program.resetNonce();
Program.setRootCallConstant(isCallConstant());
this.program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
this.program.resetNonce();
this.program.setRootCallConstant(isCallConstant());
}

program.getResult().setContractAddress(contractAddress);
Expand All @@ -443,6 +459,17 @@ private void call()

public void go() {
try {

TransactionCapsule trxCap = new TransactionCapsule(trx);
if (null != trxCap.getContractRet() && contractResult.OUT_OF_TIME
.equals(trxCap.getContractRet())) {
result = program.getResult();
program.spendAllEnergy();
runtimeError = "Haven Time Out";
result.setException(Program.Exception.notEnoughTime("Haven Time Out"));
throw Program.Exception.notEnoughTime("Haven Time Out");
}

if (vm != null) {
vm.play(program);

Expand All @@ -457,6 +484,21 @@ public void go() {
return;
}

if (TRX_CONTRACT_CREATION_TYPE == trxType && !result.isRevert()) {
byte[] code = program.getResult().getHReturn();
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()));
} else {
result.spendEnergy(saveCodeEnergy);
// have saveCode in create()
}
}

if (result.getException() != null || result.isRevert()) {
result.getDeleteAccounts().clear();
result.getLogInfoList().clear();
Expand All @@ -480,6 +522,7 @@ public void go() {
runtimeError = result.getException().getMessage();
logger.error("runtime error is :{}", result.getException().getMessage());
} catch (Throwable e) {
program.spendAllEnergy();
if (Objects.isNull(result.getException())) {
logger.error(e.getMessage(), e);
result.setException(new RuntimeException("Unknown Throwable"));
Expand All @@ -506,9 +549,17 @@ public boolean isCallConstant() throws ContractValidateException {
TriggerSmartContract triggerContractFromTransaction = ContractCapsule
.getTriggerContractFromTransaction(trx);
if (TRX_CONTRACT_CALL_TYPE.equals(trxType)) {
ABI abi = deposit
.getContract(triggerContractFromTransaction.getContractAddress().toByteArray())
.getInstance().getAbi();

ContractCapsule contract = deposit
.getContract(triggerContractFromTransaction.getContractAddress().toByteArray());
if (contract == null) {
logger.error("contract: {} is not in contract store", Wallet
.encode58Check(triggerContractFromTransaction.getContractAddress().toByteArray()));
throw new ContractValidateException("contract: " + Wallet
.encode58Check(triggerContractFromTransaction.getContractAddress().toByteArray())
+ " is not in contract store");
}
ABI abi = contract.getInstance().getAbi();
if (Wallet.isConstant(abi, triggerContractFromTransaction)) {
return true;
}
Expand Down
Loading