Skip to content

Commit d5ff7f0

Browse files
committed
Merge branch 'develop' into feature/ALLOW_CREATION_OF_CONTRACTS
2 parents b68de6e + 8526b50 commit d5ff7f0

147 files changed

Lines changed: 5428 additions & 1329 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ repositories {
4949
maven { url 'http://mvnrepository.com' }
5050
mavenLocal()
5151
mavenCentral()
52+
maven { url 'http://repo.spring.io/plugins-release' }
5253
}
5354
def versions = [
5455
checkstyle: '8.7',
@@ -68,6 +69,24 @@ configurations.getByName('checkstyleConfig') {
6869
transitive = false
6970
}
7071

72+
static def isWindows() {
73+
return org.gradle.internal.os.OperatingSystem.current().isWindows()
74+
}
75+
76+
if (isWindows()) {
77+
ext {
78+
leveldbGroup = "org.ethereum"
79+
leveldbName = "leveldbjni-all"
80+
leveldbVersion = "1.18.3"
81+
}
82+
} else {
83+
ext {
84+
leveldbGroup = "org.fusesource.leveldbjni"
85+
leveldbName = "leveldbjni-all"
86+
leveldbVersion = "1.8"
87+
}
88+
}
89+
7190
dependencies {
7291
//local libraries
7392
compile fileTree(dir: 'libs', include: '*.jar')
@@ -95,8 +114,7 @@ dependencies {
95114

96115
compile "org.iq80.leveldb:leveldb:0.7"
97116

98-
compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all',
99-
version: '1.8'
117+
compile group: leveldbGroup, name: leveldbName, version: leveldbVersion
100118

101119
compile "org.apache.commons:commons-collections4:4.0"
102120

src/main/java/org/tron/common/application/ApplicationFactory.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,10 @@
1515

1616
package org.tron.common.application;
1717

18-
import com.google.inject.Guice;
19-
import com.google.inject.Injector;
2018
import org.springframework.context.ApplicationContext;
2119

2220
public class ApplicationFactory {
2321

24-
/**
25-
* Build a Guice instance.
26-
*
27-
* @return Guice
28-
*/
29-
public Injector buildGuice() {
30-
return Guice.createInjector(
31-
new Module());
32-
}
33-
3422
/**
3523
* Build a new application.
3624
*/

src/main/java/org/tron/common/application/ApplicationImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void shutdown() {
7575
closeAllStore();
7676
}
7777
closeConnection();
78-
dbManager.getRepushThread().interrupt();
78+
dbManager.stopRepushThread();
7979
System.err.println("******** end to shutdown ********");
8080
}
8181

src/main/java/org/tron/common/application/Module.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.tron.common.application;
2+
3+
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
import org.tron.core.db.Manager;
6+
7+
public class TronApplicationContext extends AnnotationConfigApplicationContext {
8+
9+
public TronApplicationContext() {
10+
}
11+
12+
public TronApplicationContext(DefaultListableBeanFactory beanFactory) {
13+
super(beanFactory);
14+
}
15+
16+
public TronApplicationContext(Class<?>... annotatedClasses) {
17+
super(annotatedClasses);
18+
}
19+
20+
public TronApplicationContext(String... basePackages) {
21+
super(basePackages);
22+
}
23+
24+
@Override
25+
public void destroy() {
26+
27+
Manager dbManager = getBean(Manager.class);
28+
dbManager.stopRepushThread();
29+
30+
super.destroy();
31+
}
32+
}

src/main/java/org/tron/common/overlay/message/P2pMessageFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class P2pMessageFactory extends MessageFactory {
2828
@Override
2929
public P2pMessage create(byte[] data) throws Exception{
3030
if (data.length <= 1){
31-
throw new P2pException(TypeEnum.MESSAGE_WITH_WRONG_LENGTH, "len=" + data.length);
31+
throw new P2pException(TypeEnum.MESSAGE_WITH_WRONG_LENGTH, "len=" + data.length
32+
+ ", MessageType=" + (data.length == 1 ? data[0] : "unknow"));
3233
}
3334
try {
3435
byte type = data[0];

src/main/java/org/tron/common/overlay/server/Channel.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ public void disconnect(ReasonCode reason) {
162162
logger.info("Send to {}, {}", ctx.channel().remoteAddress(), msg);
163163
getNodeStatistics().nodeDisconnectedLocal(reason);
164164
ctx.writeAndFlush(msg.getSendData()).addListener(future -> close());
165-
cleanAll();
166165
}
167166

168167
public void processException(Throwable throwable) {
@@ -301,9 +300,6 @@ public int hashCode() {
301300
public String toString() {
302301
return String.format("%s | %s", inetSocketAddress, getPeerId());
303302
}
304-
305-
public void cleanAll() {
306-
307-
}
303+
308304
}
309305

src/main/java/org/tron/common/overlay/server/PeerConnectionCheckService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public void run() {
114114
logger.warn("connection pool is full, disconnect the peer : {}",
115115
peerConnection.getInetAddress());
116116
peerConnection.disconnect(ReasonCode.RESET);
117-
peerConnection.cleanAll();
118117
}
119118
}
120119
}

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,6 @@ private void create()
363363
if (percent < 0 || percent > 100) {
364364
throw new ContractExeException("percent must be >= 0 and <= 100");
365365
}
366-
// insure one owner just have one contract
367-
// if (this.deposit.getContractByNormalAccount(ownerAddress) != null) {
368-
// logger.error("Trying to create second contract with one account: address: " + Wallet
369-
// .encode58Check(ownerAddress));
370-
// return;
371-
// }
372366

373367
// insure the new contract address haven't exist
374368
if (deposit.getAccount(contractAddress) != null) {
@@ -412,6 +406,8 @@ private void create()
412406
block, deposit, vmStartInUs, vmShouldEndInUs, energyLimit);
413407
this.vm = new VM(config);
414408
this.program = new Program(ops, programInvoke, internalTransaction, config);
409+
Program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
410+
Program.resetNonce();
415411
} catch (Exception e) {
416412
logger.error(e.getMessage());
417413
throw new ContractExeException(e.getMessage());
@@ -491,6 +487,8 @@ private void call()
491487
this.vm = new VM(config);
492488
InternalTransaction internalTransaction = new InternalTransaction(trx);
493489
this.program = new Program(null, code, programInvoke, internalTransaction, config);
490+
Program.setRootTransactionId(new TransactionCapsule(trx).getTransactionId().getBytes());
491+
Program.resetNonce();
494492
}
495493

496494
program.getResult().setContractAddress(contractAddress);
@@ -502,7 +500,7 @@ private void call()
502500

503501
}
504502

505-
public void go() throws OutOfSlotTimeException, ContractExeException {
503+
public void go() throws OutOfSlotTimeException {
506504
if (!readyToExecute) {
507505
return;
508506
}
@@ -520,9 +518,6 @@ public void go() throws OutOfSlotTimeException, ContractExeException {
520518
}
521519
return;
522520
}
523-
524-
// todo: consume bandwidth for successful creating contract
525-
526521
if (result.getException() != null || result.isRevert()) {
527522
result.getDeleteAccounts().clear();
528523
result.getLogInfoList().clear();
@@ -531,30 +526,29 @@ public void go() throws OutOfSlotTimeException, ContractExeException {
531526
if (result.getException() != null) {
532527
program.spendAllEnergy();
533528
runtimeError = result.getException().getMessage();
534-
trace.setBill(result.getEnergyUsed());
535529
throw result.getException();
536530
} else {
537531
runtimeError = "REVERT opcode executed";
538532
}
539533
} else {
540534
deposit.commit();
541535
}
542-
trace.setBill(result.getEnergyUsed());
543536
} else {
544537
deposit.commit();
545538
}
546539
} catch (OutOfResourceException e) {
547-
logger.error(e.getMessage());
540+
logger.error("runtime error is :{}", e.getMessage());
548541
throw new OutOfSlotTimeException(e.getMessage());
549-
} catch (ArithmeticException e) {
550-
logger.error(e.getMessage());
551-
throw new ContractExeException(e.getMessage());
552-
} catch (Exception e) {
553-
logger.error(e.getMessage());
554-
if (StringUtils.isNoneEmpty(runtimeError)) {
555-
runtimeError = e.getMessage();
542+
} catch (Throwable e) {
543+
if (Objects.isNull(result.getException())) {
544+
result.setException(new RuntimeException("Unknown Throwable"));
545+
}
546+
if (StringUtils.isEmpty(runtimeError)) {
547+
runtimeError = result.getException().getMessage();
556548
}
549+
logger.error("runtime error is :{}", result.getException().getMessage());
557550
}
551+
trace.setBill(result.getEnergyUsed());
558552
}
559553

560554
private long getEnergyFee(long callerEnergyUsage, long callerEnergyFrozen,

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
}

0 commit comments

Comments
 (0)