Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public List<String> getCheckpointList() {

private void deleteCheckpoint() {
if(checkTmpStore == null) {
// only occurs in mock test. TODO fix test
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ public boolean isBusy() {
}
int queueSize = 0;
if (eventListeners == null || eventListeners.isEmpty()) {
// only occurs in mock test. TODO fix test
return false;
}
for (IPluginEventListener listener : eventListeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void statusCheck() {
long now = System.currentTimeMillis();

if (tronNetDelegate == null) {
//only occurs in mock test. TODO fix test
// only occurs in mock test. TODO fix test
return;
}
tronNetDelegate.getActivePeer().forEach(peer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.googlecode.jsonrpc4j.JsonRpcMethod;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -472,5 +473,35 @@ public LogFilterElement(String blockHash, Long blockNum, String txId, Integer tx
}
this.removed = removed;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
LogFilterElement item = (LogFilterElement) o;
if (!Objects.equals(blockHash, item.blockHash)) {
return false;
}
if (!Objects.equals(transactionHash, item.transactionHash)) {
return false;
}
if (!Objects.equals(transactionIndex, item.transactionIndex)) {
return false;
}
if (!Objects.equals(logIndex, item.logIndex)) {
return false;
}
return removed == item.removed;
}

@Override
public int hashCode() {
return Objects.hash(blockHash, transactionHash, transactionIndex, logIndex, removed);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import static org.tron.core.services.jsonrpc.JsonRpcApiUtil.triggerCallContract;

import com.alibaba.fastjson.JSON;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.protobuf.ByteString;
import com.google.protobuf.GeneratedMessageV3;
import java.io.Closeable;
Expand All @@ -25,10 +27,10 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -110,6 +112,11 @@ public enum RequestSource {

private static final String FILTER_NOT_FOUND = "filter not found";
public static final int EXPIRE_SECONDS = 5 * 60;
private static final Cache<LogFilterElement, LogFilterElement> logElementCache =
CacheBuilder.newBuilder()
.maximumSize(300_000L) // 300s * tps(1000) * 1 log/tx ≈ 300_000
.expireAfterWrite(EXPIRE_SECONDS, TimeUnit.SECONDS)
.recordStats().build(); //LRU cache
/**
* for log filter in Full Json-RPC
*/
Expand Down Expand Up @@ -191,6 +198,9 @@ public static void handleBLockFilter(BlockFilterCapsule blockFilterCapsule) {
}
}

/**
* append LogsFilterCapsule's LogFilterElement list to each filter if matched
*/
public static void handleLogsFilter(LogsFilterCapsule logsFilterCapsule) {
Iterator<Entry<String, LogFilterAndResult>> it;

Expand Down Expand Up @@ -226,8 +236,17 @@ public static void handleLogsFilter(LogsFilterCapsule logsFilterCapsule) {
LogMatch.matchBlock(logFilter, logsFilterCapsule.getBlockNumber(),
logsFilterCapsule.getBlockHash(), logsFilterCapsule.getTxInfoList(),
logsFilterCapsule.isRemoved());
if (CollectionUtils.isNotEmpty(elements)) {
logFilterAndResult.getResult().addAll(elements);

for (LogFilterElement element : elements) {
LogFilterElement newElement;
try {
// compare with hashcode() first, then with equals(). If not exist, put it.
newElement = logElementCache.get(element, () -> element);
} catch (ExecutionException e) {
logger.error("Getting/loading LogFilterElement from cache fails", e);// never happen
continue;
}
logFilterAndResult.getResult().add(newElement);
}
}
}
Expand Down Expand Up @@ -797,7 +816,7 @@ public TransactionReceipt getTransactionReceipt(String txId)
long blockNum = blockCapsule.getNum();
TransactionInfoList transactionInfoList = wallet.getTransactionInfoByBlockNum(blockNum);
long energyFee = wallet.getEnergyFee(blockCapsule.getTimeStamp());

// Find transaction context
TransactionReceipt.TransactionContext context
= findTransactionContext(transactionInfoList,
Expand All @@ -806,7 +825,7 @@ public TransactionReceipt getTransactionReceipt(String txId)
if (context == null) {
return null; // Transaction not found in block
}

return new TransactionReceipt(blockCapsule, transactionInfo, context, energyFee);
}

Expand Down Expand Up @@ -1529,6 +1548,7 @@ public static Object[] getFilterResult(String filterId, Map<String, BlockFilterA

@Override
public void close() throws IOException {
logElementCache.invalidateAll();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to call invalidateAll()?

The close() method is invoked when the application is about to stop completely. When the entire application (the JVM process) exits, all the memory it occupies, including all objects stored in the logElementCache, will be automatically reclaimed by the operating system.

At the very last moment before the application shuts down, would manually clearing a memory cache that is about to vanish along with it (i.e., invalidateAll()) consume the final CPU cycles to perform a meaningless task?

ExecutorServiceManager.shutdownAndAwaitTermination(sectionExecutor, esName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.junit.Assert;
import org.junit.Test;
import org.tron.common.runtime.vm.DataWord;
Expand Down Expand Up @@ -220,6 +221,18 @@ public void testMatchBlock() {
List<LogFilterElement> elementList =
matchBlock(logFilter, 100, null, transactionInfoList, false);
Assert.assertEquals(1, elementList.size());

//test LogFilterElement
List<LogFilterElement> elementList2 =
matchBlock(logFilter, 100, null, transactionInfoList, false);
Assert.assertEquals(1, elementList2.size());

LogFilterElement logFilterElement1 = elementList.get(0);
LogFilterElement logFilterElement2 = elementList2.get(0);

Assert.assertEquals(logFilterElement1.hashCode(), logFilterElement2.hashCode());
Assert.assertEquals(logFilterElement1, logFilterElement2);

} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ private void updateTotalShieldedPoolValue(long valueBalance) {
chainBaseManager.getDynamicPropertiesStore().saveTotalShieldedPoolValue(totalShieldedPoolValue);
}

@Test
public void testIsMining() {
Assert.assertTrue(wallet.isMining());
}

/*
* test of change ShieldedTransactionFee proposal
*/
Expand Down