Skip to content

Commit 8ce8645

Browse files
Merge pull request tronprotocol#2317 from tronprotocol/hotfix/trace_result_set
Hotfix/trace result set
2 parents 8b5a2cb + 3062f6d commit 8ce8645

File tree

6 files changed

+128
-7
lines changed

6 files changed

+128
-7
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ language: java
33
jdk: oraclejdk8
44
addons:
55
ssh_known_hosts:
6-
- 47.93.18.60:22008
7-
- 47.93.18.60:22008
8-
- 47.93.18.60:22008
96
- 47.93.42.145:22008
107
- 47.93.42.145:22008
118
- 47.93.42.145:22008
9+
- 47.93.18.60:22008
10+
- 47.93.18.60:22008
11+
- 47.93.18.60:22008
1212
sonarcloud:
1313
organization: tron-zhaohong
1414
token:

src/main/java/org/tron/core/actuator/ProposalCreateActuator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
309309
break;
310310
}
311311
case (26): {
312+
if (!dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_6)) {
313+
throw new ContractValidateException("Bad chain parameter id");
314+
}
312315
if (entry.getValue() != 1) {
313316
throw new ContractValidateException(
314317
"This value[ALLOW_TVM_CONSTANTINOPLE] is only allowed to be 1");

src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,29 @@
3232
import java.util.ArrayList;
3333
import java.util.HashMap;
3434
import java.util.List;
35+
import java.util.Objects;
3536
import java.util.concurrent.ExecutorService;
3637
import java.util.concurrent.Executors;
3738
import java.util.concurrent.Future;
3839
import java.util.concurrent.atomic.AtomicInteger;
3940
import lombok.Getter;
4041
import lombok.Setter;
4142
import lombok.extern.slf4j.Slf4j;
43+
import org.apache.commons.lang3.StringUtils;
4244
import org.tron.common.crypto.ECKey;
4345
import org.tron.common.crypto.ECKey.ECDSASignature;
4446
import org.tron.common.overlay.message.Message;
47+
import org.tron.common.runtime.vm.program.Program;
48+
import org.tron.common.runtime.vm.program.Program.BadJumpDestinationException;
49+
import org.tron.common.runtime.vm.program.Program.IllegalOperationException;
50+
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
51+
import org.tron.common.runtime.vm.program.Program.OutOfEnergyException;
52+
import org.tron.common.runtime.Runtime;
53+
import org.tron.common.runtime.vm.program.Program.OutOfMemoryException;
54+
import org.tron.common.runtime.vm.program.Program.OutOfTimeException;
55+
import org.tron.common.runtime.vm.program.Program.PrecompiledContractException;
56+
import org.tron.common.runtime.vm.program.Program.StackTooLargeException;
57+
import org.tron.common.runtime.vm.program.Program.StackTooSmallException;
4558
import org.tron.common.utils.ByteArray;
4659
import org.tron.common.utils.Sha256Hash;
4760
import org.tron.core.Wallet;
@@ -860,6 +873,61 @@ public String toString() {
860873
return toStringBuff.toString();
861874
}
862875

876+
public void setResult(Runtime runtime) {
877+
RuntimeException exception = runtime.getResult().getException();
878+
if (Objects.isNull(exception) && StringUtils
879+
.isEmpty(runtime.getRuntimeError()) && !runtime.getResult().isRevert()) {
880+
this.setResultCode(contractResult.SUCCESS);
881+
return;
882+
}
883+
if (runtime.getResult().isRevert()) {
884+
this.setResultCode(contractResult.REVERT);
885+
return;
886+
}
887+
if (exception instanceof IllegalOperationException) {
888+
this.setResultCode(contractResult.ILLEGAL_OPERATION);
889+
return;
890+
}
891+
if (exception instanceof OutOfEnergyException) {
892+
this.setResultCode(contractResult.OUT_OF_ENERGY);
893+
return;
894+
}
895+
if (exception instanceof BadJumpDestinationException) {
896+
this.setResultCode(contractResult.BAD_JUMP_DESTINATION);
897+
return;
898+
}
899+
if (exception instanceof OutOfTimeException) {
900+
this.setResultCode(contractResult.OUT_OF_TIME);
901+
return;
902+
}
903+
if (exception instanceof OutOfMemoryException) {
904+
this.setResultCode(contractResult.OUT_OF_MEMORY);
905+
return;
906+
}
907+
if (exception instanceof PrecompiledContractException) {
908+
this.setResultCode(contractResult.PRECOMPILED_CONTRACT);
909+
return;
910+
}
911+
if (exception instanceof StackTooSmallException) {
912+
this.setResultCode(contractResult.STACK_TOO_SMALL);
913+
return;
914+
}
915+
if (exception instanceof StackTooLargeException) {
916+
this.setResultCode(contractResult.STACK_TOO_LARGE);
917+
return;
918+
}
919+
if (exception instanceof JVMStackOverFlowException) {
920+
this.setResultCode(contractResult.JVM_STACK_OVER_FLOW);
921+
return;
922+
}
923+
if (exception instanceof Program.TransferException) {
924+
this.setResultCode(contractResult.TRANSFER_FAILED);
925+
return;
926+
}
927+
this.setResultCode(contractResult.UNKNOWN);
928+
return;
929+
}
930+
863931
public void setResultCode(contractResult code) {
864932
Result ret = Result.newBuilder().setContractRet(code).build();
865933
if (this.transaction.getRetCount() > 0) {

src/main/java/org/tron/core/db/Manager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block
12581258

12591259
trace.finalization();
12601260
if (Objects.nonNull(blockCap) && getDynamicPropertiesStore().supportVM()) {
1261-
trxCap.setResultCode(trace.getReceipt().getResult());
1261+
trxCap.setResult(trace.getRuntime());
12621262
}
12631263
transactionStore.put(trxCap.getTransactionId().getBytes(), trxCap);
12641264

src/main/java/org/tron/program/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
public class Version {
44
private static final String version = "3.6.0";
5-
public static final String versionName = "Odyssey-v3.5.0.1-318-gc6864f595";
6-
public static final String versionCode = "9911";
5+
public static final String versionName = "Odyssey-v3.5.1-890-gd39973cbb";
6+
public static final String versionCode = "10803";
77

88
public static String getVersion() {
99
return version;

src/test/java/stest/tron/wallet/account/WalletTestAccount013.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,62 @@ public void test5CanNotDelegateResourceToContract() {
411411
maxFeeLimit, 0L, consumeUserResourcePercent, null, accountForDeployKey,
412412
accountForDeployAddress, blockingStubFull);
413413
PublicMethed.waitProduceNextBlock(blockingStubFull);
414-
414+
//Account4 DelegatedResource of Energy to Contract
415415
//After 3.6 can not delegate resource to contract
416416
Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(
417417
account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1,
418418
ByteString.copyFrom(contractAddress), account4DelegatedResourceKey, blockingStubFull));
419419

420+
//Account4 DelegatedResource Energy to deploy
421+
// Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(
422+
// account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1,
423+
// ByteString.copyFrom(accountForDeployAddress),
424+
// account4DelegatedResourceKey, blockingStubFull));
425+
//
426+
// //get Energy of Account013,Account4,Contract before trigger contract
427+
// final long account013CurrentEnergyUsed = PublicMethed.getAccountResource(
428+
// account013Address, blockingStubFull).getEnergyUsed();
429+
// final long account013CurrentBandwidthUsed = PublicMethed.getAccountResource(
430+
// account013Address, blockingStubFull).getFreeNetUsed();
431+
// final long account4CurrentEnergyUsed = PublicMethed.getAccountResource(
432+
// account4DelegatedResourceAddress, blockingStubFull).getEnergyUsed();
433+
// final long contractCurrentEnergyUsed = PublicMethed.getAccountResource(
434+
// contractAddress, blockingStubFull).getEnergyUsed();
435+
// final long deployCurrentEnergyUsed = PublicMethed.getAccountResource(
436+
// accountForDeployAddress, blockingStubFull).getEnergyUsed();
437+
//
438+
// //Account013 trigger contract
439+
// String txid = PublicMethed.triggerContract(contractAddress,
440+
// "add2(uint256)", "1", false,
441+
// 0, 1000000000L, "0", 0, account013Address, testKeyForAccount013, blockingStubFull);
442+
// logger.info(txid);
443+
// infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
444+
// logger.info(String.valueOf(infoById.get().getResultValue()));
445+
// Assert.assertTrue(infoById.get().getResultValue() == 0);
446+
// //get transaction info of Energy used and Bandwidth used
447+
// final long contractTriggerEnergyUsed = infoById.get().getReceipt().getOriginEnergyUsage();
448+
// final long contractTriggerBandwidthUsed = infoById.get().getReceipt().getNetUsage();
449+
//
450+
// //get Energy of Account013,Account4,Contract after trigger contract
451+
// final long account013CurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource(
452+
// account013Address, blockingStubFull).getEnergyUsed();
453+
// final long account013CurrentBandwidthUsedAfterTrig = PublicMethed.getAccountResource(
454+
// account013Address, blockingStubFull).getFreeNetUsed();
455+
// final long account4CurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource(
456+
// account4DelegatedResourceAddress, blockingStubFull).getEnergyUsed();
457+
// final long contractCurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource(
458+
// contractAddress, blockingStubFull).getEnergyUsed();
459+
// final long deployCurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource(
460+
// accountForDeployAddress, blockingStubFull).getEnergyUsed();
461+
// //compare energy changed
462+
// Assert.assertTrue(account013CurrentEnergyUsed == account013CurrentEnergyUsedAfterTrig);
463+
// Assert.assertTrue(account4CurrentEnergyUsed == account4CurrentEnergyUsedAfterTrig);
464+
// Assert.assertTrue(contractCurrentEnergyUsed == contractCurrentEnergyUsedAfterTrig);
465+
// Assert.assertTrue(deployCurrentEnergyUsed
466+
// == deployCurrentEnergyUsedAfterTrig - contractTriggerEnergyUsed);
467+
// //compare bandwidth of Account013 before and after trigger contract
468+
// Assert.assertTrue(account013CurrentBandwidthUsed
469+
// == account013CurrentBandwidthUsedAfterTrig - contractTriggerBandwidthUsed);
420470

421471
}
422472

0 commit comments

Comments
 (0)