Skip to content

Commit ff4ab00

Browse files
committed
hotFixed internal Event Parser
1 parent c138e55 commit ff4ab00

File tree

5 files changed

+47
-60
lines changed

5 files changed

+47
-60
lines changed

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: 37 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,45 @@ 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+
Map<byte[], ABI> abiMap = new HashMap<>();
48+
49+
for (LogInfo logInfo : logInfos) {
50+
51+
byte[] contractAddress = logInfo.getAddress();
52+
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
53+
ABI abi = abiMap.get(contractAddress);
54+
if (abi == null) {
55+
abi = deposit.getContract(contractAddress).getInstance().getAbi();
56+
abiMap.put(contractAddress, abi);
57+
}
58+
// calculate the sha3 of the event signature first.
59+
if (abi != null && abi.getEntrysCount() > 0) {
60+
for (ABI.Entry entry : abi.getEntrysList()) {
61+
if (entry.getType() != ABI.Entry.EntryType.Event || entry.getAnonymous()) {
62+
continue;
63+
}
64+
String signature = getEntrySignature(entry);
65+
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
66+
fullMap.put(strContractAddr + "_" + sha3, entry);
67+
signMap.put(strContractAddr + "_" + sha3, signature);
6668
}
67-
String signature = getEntrySignature(entry);
68-
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
69-
fullMap.put(sha3, entry);
70-
signMap.put(sha3, signature);
7169
}
7270
}
71+
7372
int index = 1;
7473
for (LogInfo logInfo : logInfos) {
74+
75+
byte[] contractAddress = logInfo.getAddress();
76+
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
77+
7578
List<DataWord> topics = logInfo.getTopics();
7679
ABI.Entry entry = null;
7780
String signature = "";
7881
if (topics != null && topics.size() > 0 && !ArrayUtils.isEmpty(topics.get(0).getData())
7982
&& fullMap.size() > 0) {
8083
String firstTopic = topics.get(0).toString();
81-
entry = fullMap.get(firstTopic);
82-
signature = signMap.get(firstTopic);
84+
entry = fullMap.get(strContractAddr + "_" + firstTopic);
85+
signature = signMap.get(strContractAddr + "_" + firstTopic);
8386
}
8487

8588
boolean isEvent = (entry != null);
@@ -97,10 +100,10 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
97100
}
98101
event.setUniqueId(txId + "_" + index);
99102
event.setTransactionId(txId);
100-
event.setContractAddress(contractAddress);
101-
event.setCallerAddress(callerAddress);
103+
event.setContractAddress(strContractAddr);
102104
event.setOriginAddress(originAddress);
103-
event.setCreatorAddress(creatorAddress);
105+
event.setCallerAddress("");
106+
event.setCreatorAddress("");
104107
event.setBlockNumber(blockNum);
105108
event.setTimeStamp(blockTimestamp);
106109

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();

0 commit comments

Comments
 (0)