Skip to content

Commit c8dca57

Browse files
committed
merge develop
2 parents b534b64 + 3899187 commit c8dca57

40 files changed

Lines changed: 2257 additions & 138 deletions

‎src/main/java/org/tron/common/logsfilter/ContractEventParser.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static String parseDataBytes(byte[] data, String typeStr, int index) {
171171
private static Type basicType(String type) {
172172
if (!Pattern.matches("^.*\\[\\d*\\]$", type)) {
173173
// ignore not valide type such as "int92", "bytes33", these types will be compiled failed.
174-
if ((type.startsWith("int") || type.startsWith("uint"))) {
174+
if (type.startsWith("int") || type.startsWith("uint") || type.startsWith("trcToken")) {
175175
return Type.INT_NUMBER;
176176
} else if (type.equals("bool")) {
177177
return Type.BOOL;

‎src/main/java/org/tron/common/runtime/RuntimeImpl.java‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
import com.google.protobuf.ByteString;
1212
import java.math.BigInteger;
13-
import java.util.Arrays;
14-
import java.util.List;
15-
import java.util.Objects;
13+
import java.util.*;
14+
1615
import lombok.Getter;
1716
import lombok.Setter;
1817
import lombok.extern.slf4j.Slf4j;
@@ -21,12 +20,7 @@
2120
import org.tron.common.logsfilter.EventPluginLoader;
2221
import org.tron.common.logsfilter.trigger.ContractTrigger;
2322
import org.tron.common.runtime.config.VMConfig;
24-
import org.tron.common.runtime.vm.DataWord;
25-
import org.tron.common.runtime.vm.EnergyCost;
26-
import org.tron.common.runtime.vm.LogInfoTriggerParser;
27-
import org.tron.common.runtime.vm.VM;
28-
import org.tron.common.runtime.vm.VMConstant;
29-
import org.tron.common.runtime.vm.VMUtils;
23+
import org.tron.common.runtime.vm.*;
3024
import org.tron.common.runtime.vm.program.InternalTransaction;
3125
import org.tron.common.runtime.vm.program.InternalTransaction.ExecutorType;
3226
import org.tron.common.runtime.vm.program.InternalTransaction.TrxType;
@@ -94,7 +88,6 @@ public class RuntimeImpl implements Runtime {
9488
@Setter
9589
private boolean enableEventLinstener;
9690

97-
9891
private LogInfoTriggerParser logInfoTriggerParser;
9992

10093
/**
@@ -450,10 +443,7 @@ private void create()
450443
(EventPluginLoader.getInstance().isContractEventTriggerEnable()
451444
|| EventPluginLoader.getInstance().isContractLogTriggerEnable())
452445
&& isCheckTransaction()){
453-
454-
logInfoTriggerParser = new LogInfoTriggerParser(newSmartContract.getAbi(),
455-
blockCap.getNum(), blockCap.getTimeStamp(), txId,
456-
callerAddress, callerAddress, callerAddress, contractAddress);
446+
logInfoTriggerParser = new LogInfoTriggerParser(blockCap.getNum(), blockCap.getTimeStamp(), txId, callerAddress);
457447

458448
}
459449
} catch (Exception e) {
@@ -542,15 +532,11 @@ private void call()
542532
}
543533
AccountCapsule caller = this.deposit.getAccount(callerAddress);
544534
long energyLimit;
545-
byte[] creatorAddress = null;
546-
byte[] originAddress = null;
547535
if (isCallConstant(contractAddress)) {
548536
isStaticCall = true;
549537
energyLimit = Constant.ENERGY_LIMIT_IN_CONSTANT_TX;
550538
} else {
551-
originAddress = deployedContract.getInstance().getOriginAddress().toByteArray();
552-
AccountCapsule creator = this.deposit.getAccount(originAddress);
553-
creatorAddress = creator.getAddress().toByteArray();
539+
AccountCapsule creator = this.deposit.getAccount(deployedContract.getInstance().getOriginAddress().toByteArray());
554540
energyLimit = getTotalEnergyLimit(creator, caller, contract, feeLimit, callValue);
555541
}
556542
long maxCpuTimeOfOneTx = deposit.getDbManager().getDynamicPropertiesStore()
@@ -579,9 +565,7 @@ private void call()
579565
|| EventPluginLoader.getInstance().isContractLogTriggerEnable())
580566
&& isCheckTransaction()){
581567

582-
logInfoTriggerParser = new LogInfoTriggerParser(deployedContract.getInstance().getAbi(),
583-
blockCap.getNum(), blockCap.getTimeStamp(), txId,
584-
callerAddress, creatorAddress, originAddress, contractAddress);
568+
logInfoTriggerParser = new LogInfoTriggerParser(blockCap.getNum(), blockCap.getTimeStamp(), txId, callerAddress);
585569
}
586570
}
587571

@@ -660,7 +644,7 @@ public void go() {
660644
deposit.commit();
661645

662646
if (logInfoTriggerParser != null){
663-
List<ContractTrigger> triggers = logInfoTriggerParser.parseLogInfos(program.getResult().getLogInfoList());
647+
List<ContractTrigger> triggers = logInfoTriggerParser.parseLogInfos(program.getResult().getLogInfoList(), this.deposit);
664648
program.getResult().setTriggerList(triggers);
665649
}
666650

‎src/main/java/org/tron/common/runtime/vm/DataWord.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public byte[] getClonedData() {
9999
if (data != null){
100100
ret = new byte[DATAWORD_UNIT_SIZE];
101101
int dataSize = Math.min(data.length, DATAWORD_UNIT_SIZE);
102-
System.arraycopy(data, 0, ret, DATAWORD_UNIT_SIZE - dataSize, dataSize);
102+
System.arraycopy(data, 0, ret, 0, dataSize);
103103
}
104104
return ret;
105105
}

‎src/main/java/org/tron/common/runtime/vm/LogInfoTriggerParser.java‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,37 @@
44
import java.util.LinkedList;
55
import java.util.List;
66
import java.util.Map;
7+
8+
import jdk.nashorn.internal.objects.annotations.Setter;
79
import org.apache.commons.lang3.ArrayUtils;
810
import org.spongycastle.util.encoders.Hex;
911
import org.tron.common.crypto.Hash;
1012
import org.tron.common.logsfilter.trigger.ContractLogTrigger;
1113
import org.tron.common.logsfilter.trigger.ContractTrigger;
14+
import org.tron.common.storage.Deposit;
1215
import org.tron.core.Wallet;
1316
import org.tron.protos.Protocol.SmartContract.ABI;
1417

1518
public class LogInfoTriggerParser {
1619

17-
private ABI abi;
1820
private Long blockNum;
1921
private Long blockTimestamp;
2022
private String txId;
21-
private String callerAddress;
22-
private String creatorAddress;
2323
private String originAddress;
24-
private String contractAddress;
25-
2624

27-
public LogInfoTriggerParser(ABI abi,
28-
Long blockNum,
25+
public LogInfoTriggerParser(Long blockNum,
2926
Long blockTimestamp,
30-
byte[] txId,
31-
byte[] callerAddress,
32-
byte[] creatorAddress,
33-
byte[] originAddress,
34-
byte[] contractAddress) {
27+
byte[] txId, byte[] originAddress) {
3528

36-
this.abi = abi;
3729
this.blockNum = blockNum;
3830
this.blockTimestamp = blockTimestamp;
3931
this.txId = ArrayUtils.isEmpty(txId) ? "" : Hex.toHexString(txId);
40-
this.callerAddress =
41-
ArrayUtils.isEmpty(callerAddress) ? "" : Wallet.encode58Check(callerAddress);
42-
this.contractAddress =
43-
ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
4432
this.originAddress =
4533
ArrayUtils.isEmpty(originAddress) ? "" : Wallet.encode58Check(originAddress);
46-
this.creatorAddress =
47-
ArrayUtils.isEmpty(creatorAddress) ? "" : Wallet.encode58Check(creatorAddress);
4834

4935
}
5036

51-
public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
37+
public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos, Deposit deposit) {
5238

5339
List<ContractTrigger> list = new LinkedList<>();
5440
if (logInfos == null || logInfos.size() <= 0) {
@@ -58,28 +44,43 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
5844
Map<String, ABI.Entry> fullMap = new HashMap<>();
5945
Map<String, String> signMap = new HashMap<>();
6046

61-
// calculate the sha3 of the event signature first.
62-
if (abi != null && abi.getEntrysCount() > 0) {
63-
for (ABI.Entry entry : abi.getEntrysList()) {
64-
if (entry.getType() != ABI.Entry.EntryType.Event || entry.getAnonymous()) {
65-
continue;
47+
for (LogInfo logInfo : logInfos) {
48+
49+
byte[] contractAddress = logInfo.getAddress();
50+
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
51+
if (signMap.get(strContractAddr) == null) {
52+
ABI abi = deposit.getContract(contractAddress).getInstance().getAbi();
53+
signMap.put(strContractAddr, "1"); // mark as found.
54+
55+
// calculate the sha3 of the event signature first.
56+
if (abi != null && abi.getEntrysCount() > 0) {
57+
for (ABI.Entry entry : abi.getEntrysList()) {
58+
if (entry.getType() != ABI.Entry.EntryType.Event || entry.getAnonymous()) {
59+
continue;
60+
}
61+
String signature = getEntrySignature(entry);
62+
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
63+
fullMap.put(strContractAddr + "_" + sha3, entry);
64+
signMap.put(strContractAddr + "_" + sha3, signature);
65+
}
6666
}
67-
String signature = getEntrySignature(entry);
68-
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
69-
fullMap.put(sha3, entry);
70-
signMap.put(sha3, signature);
7167
}
7268
}
69+
7370
int index = 1;
7471
for (LogInfo logInfo : logInfos) {
72+
73+
byte[] contractAddress = logInfo.getAddress();
74+
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
75+
7576
List<DataWord> topics = logInfo.getTopics();
7677
ABI.Entry entry = null;
7778
String signature = "";
7879
if (topics != null && topics.size() > 0 && !ArrayUtils.isEmpty(topics.get(0).getData())
7980
&& fullMap.size() > 0) {
8081
String firstTopic = topics.get(0).toString();
81-
entry = fullMap.get(firstTopic);
82-
signature = signMap.get(firstTopic);
82+
entry = fullMap.get(strContractAddr + "_" + firstTopic);
83+
signature = signMap.get(strContractAddr + "_" + firstTopic);
8384
}
8485

8586
boolean isEvent = (entry != null);
@@ -97,10 +98,10 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
9798
}
9899
event.setUniqueId(txId + "_" + index);
99100
event.setTransactionId(txId);
100-
event.setContractAddress(contractAddress);
101-
event.setCallerAddress(callerAddress);
101+
event.setContractAddress(strContractAddr);
102102
event.setOriginAddress(originAddress);
103-
event.setCreatorAddress(creatorAddress);
103+
event.setCallerAddress("");
104+
event.setCreatorAddress("");
104105
event.setBlockNumber(blockNum);
105106
event.setTimeStamp(blockTimestamp);
106107

‎src/main/java/org/tron/common/runtime/vm/program/InternalTransaction.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public byte[] getSender() {
193193
}
194194

195195
public byte[] getReceiveAddress() {
196-
if (sendAddress == null) {
196+
if (receiveAddress == null) {
197197
return EMPTY_BYTE_ARRAY;
198198
}
199199
return receiveAddress.clone();

‎src/main/java/org/tron/core/actuator/TransferActuator.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.tron.core.exception.BalanceInsufficientException;
1515
import org.tron.core.exception.ContractExeException;
1616
import org.tron.core.exception.ContractValidateException;
17+
import org.tron.core.exception.WhitelistException;
18+
import org.tron.core.services.WhitelistService;
1719
import org.tron.protos.Contract.TransferContract;
1820
import org.tron.protos.Protocol.AccountType;
1921
import org.tron.protos.Protocol.Transaction.Result.code;
@@ -115,7 +117,6 @@ public boolean validate() throws ContractValidateException {
115117
}
116118

117119
try {
118-
119120
AccountCapsule toAccount = dbManager.getAccountStore().get(toAddress);
120121
if (toAccount == null) {
121122
fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract();

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.beust.jcommander.JCommander;
44
import com.beust.jcommander.Parameter;
5+
import com.google.common.collect.Maps;
56
import com.typesafe.config.Config;
67
import com.typesafe.config.ConfigObject;
78
import io.grpc.internal.GrpcUtil;
@@ -19,7 +20,9 @@
1920
import java.net.URL;
2021
import java.util.ArrayList;
2122
import java.util.Collections;
23+
import java.util.HashMap;
2224
import java.util.List;
25+
import java.util.Map;
2326
import java.util.Objects;
2427
import java.util.Optional;
2528
import java.util.Properties;
@@ -915,6 +918,21 @@ public String getOutputDirectory() {
915918
return this.outputDirectory;
916919
}
917920

921+
public Map<String, String> getBlacklist() {
922+
Config config = Configuration.getByFileName(INSTANCE.shellConfFileName, Constant.TESTNET_CONF);
923+
if (!config.hasPath("blacklist")) {
924+
return Collections.emptyMap();
925+
}
926+
927+
return config.getObjectList("blacklist").stream()
928+
.map((ConfigObject e) -> Maps.immutableEntry(
929+
e.get("from") == null ? "" : e.get("from").unwrapped().toString(),
930+
e.get("to") == null ? "" : e.get("to").unwrapped().toString()))
931+
.filter(e -> e.getKey() != null)
932+
.filter(e -> e.getValue() != null)
933+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (k1, k2) -> k2));
934+
}
935+
918936
private static List<Node> getNodes(final com.typesafe.config.Config config, String path) {
919937
if (!config.hasPath(path)) {
920938
return Collections.emptyList();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
import org.tron.core.exception.VMIllegalException;
102102
import org.tron.core.exception.ValidateScheduleException;
103103
import org.tron.core.exception.ValidateSignatureException;
104+
import org.tron.core.exception.WhitelistException;
105+
import org.tron.core.services.WhitelistService;
104106
import org.tron.core.services.WitnessService;
105107
import org.tron.core.witness.ProposalController;
106108
import org.tron.core.witness.WitnessController;
@@ -1206,6 +1208,13 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule
12061208
throw new ValidateSignatureException("trans sig validate failed");
12071209
}
12081210

1211+
try {
1212+
WhitelistService.check(trxCap);
1213+
} catch (WhitelistException e) {
1214+
logger.debug(e.getMessage());
1215+
throw new ContractValidateException(e.getMessage(), e);
1216+
}
1217+
12091218
TransactionTrace trace = new TransactionTrace(trxCap, this);
12101219
trxCap.setTrxTrace(trace);
12111220

‎src/main/java/org/tron/core/exception/ContractValidateException.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ public ContractValidateException() {
99
public ContractValidateException(String message) {
1010
super(message);
1111
}
12+
13+
public ContractValidateException(String message, Throwable throwable) {
14+
super(message, throwable);
15+
}
1216
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.tron.core.exception;
2+
3+
public class WhitelistException extends TronException {
4+
5+
public WhitelistException() {
6+
super();
7+
}
8+
9+
public WhitelistException(String message) {
10+
super(message);
11+
}
12+
13+
public WhitelistException(String message, Throwable cause) {
14+
super(message, cause);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)