Skip to content
Merged
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 @@ -4,11 +4,14 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.exit.ExitManager;

Expand All @@ -35,6 +38,22 @@ public static ScheduledExecutorService newSingleThreadScheduledExecutor(String n
new ThreadFactoryBuilder().setNameFormat(name).setDaemon(isDaemon).build());
}

public static ForkJoinPool newForkJoinPool(String name, int parallelism) {
return newForkJoinPool(name, parallelism, false);
}

public static ForkJoinPool newForkJoinPool(String name, int parallelism, boolean isDaemon) {
AtomicInteger counter = new AtomicInteger(0);
ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
ForkJoinWorkerThread thread =
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
thread.setName(name + "-" + counter.getAndIncrement());
thread.setDaemon(isDaemon);
return thread;
};
return new ForkJoinPool(parallelism, factory, null, false);
}

public static ExecutorService newFixedThreadPool(String name, int fixThreads) {
return newFixedThreadPool(name, fixThreads, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,18 @@ public class CommonParameter {
@Getter
@Setter
public int jsonRpcMaxBlockFilterNum = 50000;

@Getter
@Setter
public int jsonRpcMaxBatchSize = 100;
@Getter
@Setter
public int jsonRpcMaxResponseSize = 25 * 1024 * 1024;
@Getter
@Setter
public int jsonRpcMaxAddressSize = 1000;
@Getter
@Setter
public int jsonRpcMaxLogFilterNum = 20000;
@Getter
@Setter
public int maxTransactionPendingSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ public void setHttpPBFTPort(int v) {
private int maxBlockRange = 5000;
private int maxSubTopics = 1000;
private int maxBlockFilterNum = 50000;
private int maxBatchSize = 100;
private int maxResponseSize = 25 * 1024 * 1024;
private int maxAddressSize = 1000;
private int maxLogFilterNum = 20000;
private long maxMessageSize = 4194304;
}

Expand Down
17 changes: 11 additions & 6 deletions common/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,20 @@ node {
httpPBFTEnable = false
httpPBFTPort = 8565

# Maximum blocks range for eth_getLogs, >0 otherwise no limit
# The maximum blocks range to retrieve logs for eth_getLogs, default: 5000, <=0 means no limit
maxBlockRange = 5000

# Maximum topics within a topic criteria, >0 otherwise no limit
# Allowed max address count in filter request, default: 1000, <=0 means no limit
maxAddressSize = 1000
# The maximum number of allowed topics within a topic criteria, default: 1000, <=0 means no limit
maxSubTopics = 1000

# Maximum number for blockFilter
# Allowed maximum number for blockFilter, default: 50000, <=0 means no limit
maxBlockFilterNum = 50000

# Allowed batch size, default: 100, <=0 means no limit
maxBatchSize = 100
# Allowed max response byte size, default: 26214400 (25 MB), <=0 means no limit
maxResponseSize = 26214400
# Allowed maximum number for newFilter, <=0 means no limit
maxLogFilterNum = 20000
# Maximum JSON-RPC request body size, default 4MB. Independent from rpc.maxMessageSize.
maxMessageSize = 4M
}
Expand Down
1 change: 1 addition & 0 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
}

testImplementation group: 'org.springframework', name: 'spring-test', version: "${springVersion}"
testImplementation group: 'javax.portlet', name: 'portlet-api', version: '3.0.1'
implementation group: 'org.zeromq', name: 'jeromq', version: '0.5.3'
api project(":chainbase")
api project(":protocol")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.tron.core.db.Manager;
import org.tron.core.net.TronNetService;
import org.tron.core.services.event.EventService;
import org.tron.program.SolidityNode;

@Slf4j(topic = "app")
@Component
Expand All @@ -33,6 +34,9 @@ public class ApplicationImpl implements Application {
@Autowired
private ConsensusService consensusService;

@Autowired(required = false)
private SolidityNode solidityNode;

private final CountDownLatch shutdown = new CountDownLatch(1);

/**
Expand All @@ -50,11 +54,14 @@ public void startup() {
@Override
public void shutdown() {
this.shutdownServices();
if (!Args.getInstance().isSolidityNode() && (!Args.getInstance().p2pDisable)) {
if (!Args.getInstance().isSolidityNode() && !Args.getInstance().p2pDisable) {
tronNetService.close();
}
consensusService.stop();
eventService.close();
if (solidityNode != null) {
solidityNode.close();
}
dbManager.close();
shutdown.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Block getBlock(long blockNum) {
}

public void shutdown() {
channel.shutdown();
channel.shutdownNow();
}

public DynamicProperties getDynamicProperties() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tron.common.logsfilter.capsule;

import static org.tron.core.services.jsonrpc.TronJsonRpcImpl.handleBLockFilter;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand All @@ -20,19 +18,12 @@ public class BlockFilterCapsule extends FilterTriggerCapsule {
private boolean solidified;

public BlockFilterCapsule(BlockCapsule block, boolean solidified) {
blockHash = block.getBlockId().toString();
this.solidified = solidified;
this(block.getBlockId().toString(), solidified);
}

public BlockFilterCapsule(String blockHash, boolean solidified) {
this.blockHash = blockHash;
this.solidified = solidified;
}

@Override
public void processFilterTrigger() {
handleBLockFilter(this);
}

}

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.tron.common.logsfilter.capsule;

public class FilterTriggerCapsule extends TriggerCapsule {
public class FilterTriggerCapsule {

public void processFilterTrigger() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tron.common.logsfilter.capsule;

import static org.tron.core.services.jsonrpc.TronJsonRpcImpl.handleLogsFilter;

import java.util.List;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -43,8 +41,4 @@ public LogsFilterCapsule(long blockNumber, String blockHash, Bloom bloom,
this.removed = removed;
}

@Override
public void processFilterTrigger() {
handleLogsFilter(this);
}
}
}
4 changes: 4 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ private static void applyNodeConfig(NodeConfig nc) {
PARAMETER.jsonRpcMaxBlockRange = jsonrpc.getMaxBlockRange();
PARAMETER.jsonRpcMaxSubTopics = jsonrpc.getMaxSubTopics();
PARAMETER.jsonRpcMaxBlockFilterNum = jsonrpc.getMaxBlockFilterNum();
PARAMETER.jsonRpcMaxBatchSize = jsonrpc.getMaxBatchSize();
PARAMETER.jsonRpcMaxResponseSize = jsonrpc.getMaxResponseSize();
PARAMETER.jsonRpcMaxAddressSize = jsonrpc.getMaxAddressSize();
PARAMETER.jsonRpcMaxLogFilterNum = jsonrpc.getMaxLogFilterNum();
PARAMETER.jsonRpcMaxMessageSize = jsonrpc.getMaxMessageSize();

// ---- P2P sub-bean ----
Expand Down
32 changes: 12 additions & 20 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.tron.api.GrpcAPI;
import org.tron.api.GrpcAPI.TransactionInfoList;
Expand Down Expand Up @@ -142,6 +143,7 @@
import org.tron.core.service.MortgageService;
import org.tron.core.service.RewardViCalService;
import org.tron.core.services.event.exception.EventException;
import org.tron.core.services.jsonrpc.TronJsonRpcImpl;
import org.tron.core.store.AccountAssetStore;
import org.tron.core.store.AccountIdIndexStore;
import org.tron.core.store.AccountIndexStore;
Expand Down Expand Up @@ -277,6 +279,10 @@ public class Manager {
@Autowired
private RewardViCalService rewardViCalService;

@Lazy
@Autowired
private TronJsonRpcImpl tronJsonRpcImpl;

/**
* Cycle thread to rePush Transactions
*/
Expand Down Expand Up @@ -333,8 +339,10 @@ public class Manager {
while (isRunFilterProcessThread) {
try {
FilterTriggerCapsule filterCapsule = filterCapsuleQueue.poll(1, TimeUnit.SECONDS);
if (filterCapsule != null) {
filterCapsule.processFilterTrigger();
if (filterCapsule instanceof LogsFilterCapsule) {
tronJsonRpcImpl.handleLogsFilter((LogsFilterCapsule) filterCapsule);
} else if (filterCapsule instanceof BlockFilterCapsule) {
tronJsonRpcImpl.handleBLockFilter((BlockFilterCapsule) filterCapsule);
}
} catch (InterruptedException e) {
logger.error("FilterProcessLoop get InterruptedException, error is {}.",
Expand Down Expand Up @@ -1042,23 +1050,6 @@ public void eraseBlock() {
}
}

public void pushVerifiedBlock(BlockCapsule block) throws ContractValidateException,
ContractExeException, ValidateSignatureException, AccountResourceInsufficientException,
TransactionExpirationException, TooBigTransactionException, DupTransactionException,
TaposException, ValidateScheduleException, ReceiptCheckErrException,
VMIllegalException, TooBigTransactionResultException, UnLinkedBlockException,
NonCommonBlockException, BadNumberBlockException, BadBlockException, ZksnarkException,
EventBloomException {
block.generatedByMyself = true;
long start = System.currentTimeMillis();
pushBlock(block);
logger.info("Push block cost: {} ms, blockNum: {}, blockHash: {}, trx count: {}.",
System.currentTimeMillis() - start,
block.getNum(),
block.getBlockId(),
block.getTransactions().size());
}

private void applyBlock(BlockCapsule block) throws ContractValidateException,
ContractExeException, ValidateSignatureException, AccountResourceInsufficientException,
TransactionExpirationException, TooBigTransactionException, DupTransactionException,
Expand Down Expand Up @@ -2285,7 +2276,8 @@ private void reOrgLogsFilter() {
}

private void postBlockFilter(final BlockCapsule blockCapsule, boolean solidified) {
BlockFilterCapsule blockFilterCapsule = new BlockFilterCapsule(blockCapsule, solidified);
BlockFilterCapsule blockFilterCapsule =
new BlockFilterCapsule(blockCapsule, solidified);
if (!filterCapsuleQueue.offer(blockFilterCapsule)) {
logger.info("Too many filters, block filter lost: {}.", blockCapsule.getBlockId());
}
Expand Down
13 changes: 13 additions & 0 deletions framework/src/main/java/org/tron/core/net/TronNetDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ public Message getData(Sha256Hash hash, InventoryType type) throws P2pException
}
}

public void pushVerifiedBlock(BlockCapsule block) throws P2pException {
block.generatedByMyself = true;
long start = System.currentTimeMillis();
processBlock(block, true);
if (!hitDown) {
logger.info("Push block cost: {} ms, blockNum: {}, blockHash: {}, trx count: {}.",
System.currentTimeMillis() - start,
block.getNum(),
block.getBlockId(),
block.getTransactions().size());
}
}

public void processBlock(BlockCapsule block, boolean isSync) throws P2pException {
if (!hitDown && dbManager.getLatestSolidityNumShutDown() > 0
&& dbManager.getLatestSolidityNumShutDown() == dbManager.getDynamicPropertiesStore()
Expand Down
Loading
Loading