Skip to content

Commit c6c0874

Browse files
committed
Merge remote-tracking branch 'remotes/origin/develop' into set_getdifficulty
2 parents 7d8dae7 + 8526b50 commit c6c0874

26 files changed

Lines changed: 259 additions & 69 deletions

src/main/java/org/tron/common/runtime/Runtime.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,6 @@ public void go() throws OutOfSlotTimeException {
509509
}
510510
return;
511511
}
512-
513-
// todo: consume bandwidth for successful creating contract
514-
515512
if (result.getException() != null || result.isRevert()) {
516513
result.getDeleteAccounts().clear();
517514
result.getLogInfoList().clear();
@@ -527,7 +524,6 @@ public void go() throws OutOfSlotTimeException {
527524
} else {
528525
deposit.commit();
529526
}
530-
531527
} else {
532528
deposit.commit();
533529
}

src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import org.tron.common.crypto.zksnark.BN128G2;
4545
import org.tron.common.crypto.zksnark.Fp;
4646
import org.tron.common.crypto.zksnark.PairingCheck;
47+
import org.tron.common.runtime.vm.program.Program;
48+
import org.tron.common.runtime.vm.program.Program.PrecompiledContractException;
4749
import org.tron.common.runtime.vm.program.ProgramResult;
4850
import org.tron.common.storage.Deposit;
4951
import org.tron.common.utils.BIUtil;
@@ -714,13 +716,15 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
714716
} catch (ContractExeException e) {
715717
logger.debug("ContractExeException when calling voteWitness in vm");
716718
logger.debug("ContractExeException: {}", e.getMessage());
717-
return null;
719+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
720+
return Pair.of(false, new DataWord(0).getData());
718721
} catch (ContractValidateException e) {
719722
logger.debug("ContractValidateException when calling voteWitness in vm");
720723
logger.debug("ContractValidateException: {}", e.getMessage());
721-
return null;
724+
this.getResult().setException(new Program.Exception().contractValidateException(e));
725+
return Pair.of(false, new DataWord(0).getData());
722726
}
723-
return Pair.of(true, new DataWord(count).getData());
727+
return Pair.of(true, new DataWord(1).getData());
724728
}
725729
}
726730

@@ -886,11 +890,13 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
886890
} catch (ContractExeException e) {
887891
logger.debug("ContractExeException when calling withdrawBalanceNative in vm");
888892
logger.debug("ContractExeException: {}", e.getMessage());
889-
return null;
893+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
894+
return Pair.of(false, new DataWord(0).getData());
890895
} catch (ContractValidateException e) {
891896
logger.debug("ContractValidateException when calling withdrawBalanceNative in vm");
892897
logger.debug("ContractValidateException: {}", e.getMessage());
893-
return null;
898+
this.getResult().setException(new Program.Exception().contractValidateException(e));
899+
return Pair.of(false, new DataWord(0).getData());
894900
}
895901
return Pair.of(true, new DataWord(1).getData());
896902
}
@@ -944,7 +950,8 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
944950
} catch (ContractExeException e) {
945951
logger.debug("ContractExeException when calling proposalApproveNative in vm");
946952
logger.debug("ContractExeException: {}", e.getMessage());
947-
return null;
953+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
954+
return Pair.of(false, new DataWord(0).getData());
948955
} catch (ContractValidateException e) {
949956
logger.debug("ContractValidateException when calling proposalApproveNative in vm");
950957
logger.debug("ContractValidateException: {}", e.getMessage());
@@ -1009,11 +1016,13 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
10091016
} catch (ContractExeException e) {
10101017
logger.debug("ContractExeException when calling proposalCreateNative in vm");
10111018
logger.debug("ContractExeException: {}", e.getMessage());
1012-
return null;
1019+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
1020+
return Pair.of(false, new DataWord(0).getData());
10131021
} catch (ContractValidateException e) {
10141022
logger.debug("ContractValidateException when calling proposalCreateNative in vm");
10151023
logger.debug("ContractValidateException: {}", e.getMessage());
1016-
return null;
1024+
this.getResult().setException(new Program.Exception().contractValidateException(e));
1025+
return Pair.of(false, new DataWord(0).getData());
10171026
}
10181027
return Pair.of(true, new DataWord(id).getData());
10191028
}
@@ -1058,11 +1067,13 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
10581067
} catch (ContractExeException e) {
10591068
logger.debug("ContractExeException when calling proposalDeleteContract in vm");
10601069
logger.debug("ContractExeException: {}", e.getMessage());
1061-
return null;
1070+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
1071+
return Pair.of(false, new DataWord(0).getData());
10621072
} catch (ContractValidateException e) {
10631073
logger.debug("ContractValidateException when calling proposalDeleteContract in vm");
10641074
logger.debug("ContractValidateException: {}", e.getMessage());
1065-
return null;
1075+
this.getResult().setException(new Program.Exception().contractValidateException(e));
1076+
return Pair.of(false, new DataWord(0).getData());
10661077
}
10671078
return Pair.of(true, new DataWord(1).getData());
10681079
}
@@ -1181,11 +1192,13 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
11811192
} catch (ContractExeException e) {
11821193
logger.debug("ContractExeException when calling transferAssetContract in vm");
11831194
logger.debug("ContractExeException: {}", e.getMessage());
1184-
return null;
1195+
this.getResult().setException(new Program.Exception().contractExecuteException(e));
1196+
return Pair.of(false, new DataWord(0).getData());
11851197
} catch (ContractValidateException e) {
11861198
logger.debug("ContractValidateException when calling transferAssetContract in vm");
11871199
logger.debug("ContractValidateException: {}", e.getMessage());
1188-
return null;
1200+
this.getResult().setException(new Program.Exception().contractValidateException(e));
1201+
return Pair.of(false, new DataWord(0).getData());
11891202
}
11901203
return Pair.of(true, new DataWord(1).getData());
11911204
}

src/main/java/org/tron/common/runtime/vm/VM.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import lombok.extern.slf4j.Slf4j;
1414
import org.spongycastle.util.encoders.Hex;
1515
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.util.StringUtils;
1617
import org.tron.common.runtime.config.SystemProperties;
1718
import org.tron.common.runtime.vm.program.Program;
1819
import org.tron.common.runtime.vm.program.Program.OutOfEnergyException;
@@ -1360,7 +1361,11 @@ public void play(Program program) {
13601361
}
13611362

13621363
} catch (RuntimeException e) {
1363-
program.setRuntimeFailure(e);
1364+
if (StringUtils.isEmpty(e.getMessage())) {
1365+
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));
1366+
} else {
1367+
program.setRuntimeFailure(e);
1368+
}
13641369
} catch (ContractValidateException e) {
13651370
program.setRuntimeFailure(new RuntimeException(e.getMessage()));
13661371
} catch (StackOverflowError soe) {

src/main/java/org/tron/common/runtime/vm/program/Program.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Map;
3939
import java.util.NavigableSet;
40+
import java.util.Objects;
4041
import java.util.TreeSet;
4142
import lombok.extern.slf4j.Slf4j;
4243
import org.apache.commons.collections4.CollectionUtils;
@@ -69,6 +70,7 @@
6970
import org.tron.core.capsule.ContractCapsule;
7071
import org.tron.core.config.args.Args;
7172
import org.tron.core.exception.ContractValidateException;
73+
import org.tron.core.exception.TronException;
7274
import org.tron.protos.Protocol;
7375
import org.tron.protos.Protocol.SmartContract;
7476

@@ -1302,6 +1304,9 @@ public void callToPrecompiledAddress(MessageCall msg,
13021304
// spend all energy on failure, push zero and revert state changes
13031305
this.refundEnergy(0, "call pre-compiled");
13041306
this.stackPushZero();
1307+
if (Objects.nonNull(this.result.getException())) {
1308+
throw result.getException();
1309+
}
13051310
// deposit.rollback();
13061311
}
13071312

@@ -1363,6 +1368,14 @@ public OutOfStorageException(String message, Object... args) {
13631368
}
13641369
}
13651370

1371+
@SuppressWarnings("serial")
1372+
public static class PrecompiledContractException extends BytecodeExecutionException {
1373+
1374+
public PrecompiledContractException(String message, Object... args) {
1375+
super(format(message, args));
1376+
}
1377+
}
1378+
13661379
@SuppressWarnings("serial")
13671380
public static class IllegalOperationException extends BytecodeExecutionException {
13681381

@@ -1437,6 +1450,14 @@ public static OutOfStorageException notEnoughStorage() {
14371450
return new OutOfStorageException("Not enough ContractState resource");
14381451
}
14391452

1453+
public static PrecompiledContractException contractValidateException(TronException e) {
1454+
return new PrecompiledContractException(e.getMessage());
1455+
}
1456+
1457+
public static PrecompiledContractException contractExecuteException(TronException e) {
1458+
return new PrecompiledContractException(e.getMessage());
1459+
}
1460+
14401461
public static OutOfEnergyException energyOverflow(BigInteger actualEnergy,
14411462
BigInteger energyLimit) {
14421463
return new OutOfEnergyException("Energy value overflow: actualEnergy[%d], energyLimit[%d];",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl
147147
TransactionInfo.Builder builder = TransactionInfo.newBuilder();
148148

149149
builder.setResult(code.SUCESS);
150-
if (StringUtils.isNoneEmpty(runtime.getRuntimeError())) {
150+
if (StringUtils.isNoneEmpty(runtime.getRuntimeError()) || Objects
151+
.nonNull(runtime.getResult().getException())) {
151152
builder.setResult(code.FAILED);
152153
builder.setResMessage(ByteString.copyFromUtf8(runtime.getRuntimeError()));
153154
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ private void applyBlock(BlockCapsule block) throws ContractValidateException,
683683
processBlock(block);
684684
this.blockStore.put(block.getBlockId().getBytes(), block);
685685
this.blockIndexStore.put(block.getBlockId());
686+
updateFork();
686687
}
687688

688689
private void switchFork(BlockCapsule newHead)
@@ -1300,7 +1301,15 @@ public void updateLatestSolidifiedBlock() {
13001301
}
13011302
getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(latestSolidifiedBlockNum);
13021303
logger.info("update solid block, num = {}", latestSolidifiedBlockNum);
1304+
}
1305+
1306+
public void updateFork() {
1307+
if (forkController.shouldBeForked()) {
1308+
return;
1309+
}
1310+
13031311
try {
1312+
long latestSolidifiedBlockNum = dynamicPropertiesStore.getLatestSolidifiedBlockNum();
13041313
BlockCapsule solidifiedBlock = getBlockByNum(latestSolidifiedBlockNum);
13051314
forkController.update(solidifiedBlock);
13061315
} catch (ItemNotFoundException | BadItemException e) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura
175175

176176
Long afterBlockNum = 0L;
177177
Integer wait = 0;
178-
while (afterBlockNum < beforeBlockNum + 1 && wait < 10) {
178+
PublicMethed.waitProduceNextBlock(searchBlockingStubFull);
179+
/* while (afterBlockNum < beforeBlockNum + 1 && wait < 10) {
179180
Block currentBlock1 = searchBlockingStubFull.getNowBlock(EmptyMessage.newBuilder().build());
180181
afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber();
181182
wait++;
@@ -185,7 +186,7 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura
185186
} catch (InterruptedException e) {
186187
e.printStackTrace();
187188
}
188-
}
189+
}*/
189190

190191
Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull);
191192
Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance();

src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue007.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void beforeClass() {
121121
public void testParticipateAssetIssueUseParticipaterBandwidth() {
122122
logger.info(name);
123123
Assert.assertTrue(PublicMethed.waitProduceNextBlock(blockingStubFull));
124-
Assert.assertTrue(PublicMethed.waitProduceNextBlock(blockingStubFull));
124+
//Assert.assertTrue(PublicMethed.waitProduceNextBlock(blockingStubFull));
125125
//When no balance, participate an asset issue
126126
Assert.assertFalse(PublicMethed.participateAssetIssue(asset007Address, name.getBytes(),
127127
1L, participateAssetAddress, participateAssetCreateKey,blockingStubFull));

src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue017.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void atestGetPaginatedAssetIssueList() {
143143
}
144144
}
145145

146-
@Test(enabled = true)
146+
@Test(enabled = false)
147147
public void btestGetPaginatedAssetIssueListException() {
148148
//offset is 0, limit is 0.
149149
Integer offset = 0;
@@ -194,7 +194,7 @@ public void btestGetPaginatedAssetIssueListException() {
194194
Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() >= 1);
195195
}
196196

197-
@Test(enabled = true)
197+
@Test(enabled = false)
198198
public void ctestGetPaginatedAssetIssueListOnSolidityNode() {
199199

200200
Integer offset = 0;
@@ -216,7 +216,7 @@ public void ctestGetPaginatedAssetIssueListOnSolidityNode() {
216216
}
217217
}
218218

219-
@Test(enabled = true)
219+
@Test(enabled = false)
220220
public void dtestGetPaginatedAssetIssueListExceptionOnSolidityNode() {
221221
//offset is 0, limit is 0.
222222
Integer offset = 0;

src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue018.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ public void testSameAssetissueName() {
102102
testKey002,blockingStubFull));
103103

104104
//Create 3 the same name token.
105-
Long start = System.currentTimeMillis() + 3000;
105+
Long start = System.currentTimeMillis() + 2000;
106106
Long end = System.currentTimeMillis() + 1000000000;
107107
Assert.assertTrue(PublicMethed.createAssetIssue(assetAccount1Address,
108108
name, totalSupply, 1, 1, start, end, 1, description, url,
109109
2000L,2000L, 1L,1L,assetAccount1Key,blockingStubFull));
110-
start = System.currentTimeMillis() + 3000;
110+
start = System.currentTimeMillis() + 2000;
111111
end = System.currentTimeMillis() + 1000000000;
112112
Assert.assertTrue(PublicMethed.createAssetIssue(assetAccount2Address,
113113
name, totalSupply + 1, 2, 2, start, end, 2, description, url,
114114
3000L,3000L, 2L,2L,assetAccount2Key,blockingStubFull));
115-
start = System.currentTimeMillis() + 3000;
115+
start = System.currentTimeMillis() + 2000;
116116
end = System.currentTimeMillis() + 1000000000;
117117
Assert.assertTrue(PublicMethed.createAssetIssue(assetAccount3Address,
118118
name, totalSupply + 2, 3, 3, start, end, 3, description, url,
@@ -149,7 +149,7 @@ public void testSameAssetissueName() {
149149
asset3Name.getBytes(),3L,assetAccount3Address,assetAccount3Key,blockingStubFull));
150150

151151
try {
152-
Thread.sleep(10000);
152+
Thread.sleep(5000);
153153
} catch (InterruptedException e) {
154154
e.printStackTrace();
155155
}

0 commit comments

Comments
 (0)