Skip to content

Commit 7267c01

Browse files
committed
add config item node.jsonrpc.maxFilterNum
1 parent bf26ec0 commit 7267c01

File tree

10 files changed

+21
-3
lines changed

10 files changed

+21
-3
lines changed

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ public class CommonParameter {
527527
@Getter
528528
@Setter
529529
public int jsonRpcMaxSubTopics = 1000;
530+
@Getter
531+
@Setter
532+
public int jsonRpcMaxFilterNum = 50000;
530533

531534
@Getter
532535
@Setter

common/src/main/java/org/tron/core/Constant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public class Constant {
154154
public static final String NODE_JSONRPC_HTTP_PBFT_PORT = "node.jsonrpc.httpPBFTPort";
155155
public static final String NODE_JSONRPC_MAX_BLOCK_RANGE = "node.jsonrpc.maxBlockRange";
156156
public static final String NODE_JSONRPC_MAX_SUB_TOPICS = "node.jsonrpc.maxSubTopics";
157+
public static final String NODE_JSONRPC_MAX_FILTER_NUM = "node.jsonrpc.maxFilterNum";
157158

158159
public static final String NODE_DISABLED_API_LIST = "node.disabledApi";
159160

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public static void clearParam() {
207207
PARAMETER.jsonRpcHttpPBFTNodeEnable = false;
208208
PARAMETER.jsonRpcMaxBlockRange = 5000;
209209
PARAMETER.jsonRpcMaxSubTopics = 1000;
210+
PARAMETER.jsonRpcMaxFilterNum = 50000;
210211
PARAMETER.nodeMetricsEnable = false;
211212
PARAMETER.metricsStorageEnable = false;
212213
PARAMETER.metricsPrometheusEnable = false;
@@ -491,6 +492,11 @@ public static void setParam(final Config config) {
491492
config.getInt(Constant.NODE_JSONRPC_MAX_SUB_TOPICS);
492493
}
493494

495+
if (config.hasPath(Constant.NODE_JSONRPC_MAX_FILTER_NUM)) {
496+
PARAMETER.jsonRpcMaxFilterNum =
497+
config.getInt(Constant.NODE_JSONRPC_MAX_FILTER_NUM);
498+
}
499+
494500
if (config.hasPath(Constant.VM_MIN_TIME_RATIO)) {
495501
PARAMETER.minTimeRatio = config.getDouble(Constant.VM_MIN_TIME_RATIO);
496502
}

framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.tron.core.Wallet;
5454
import org.tron.core.capsule.BlockCapsule;
5555
import org.tron.core.capsule.TransactionCapsule;
56+
import org.tron.core.config.args.Args;
5657
import org.tron.core.db.Manager;
5758
import org.tron.core.db2.core.Chainbase;
5859
import org.tron.core.exception.BadItemException;
@@ -113,7 +114,7 @@ public enum RequestSource {
113114

114115
private static final String FILTER_NOT_FOUND = "filter not found";
115116
public static final int EXPIRE_SECONDS = 5 * 60;
116-
private static final int MAX_FILTER_NUM = 50000;
117+
private static final int maxFilterNum = Args.getInstance().getJsonRpcMaxFilterNum();
117118
private static final Cache<LogFilterElement, LogFilterElement> logElementCache =
118119
CacheBuilder.newBuilder()
119120
.maximumSize(300_000L) // 300s * tps(1000) * 1 log/tx ≈ 300_000
@@ -1436,8 +1437,8 @@ public String newBlockFilter() throws JsonRpcMethodNotFoundException,
14361437
} else {
14371438
blockFilter2Result = blockFilter2ResultSolidity;
14381439
}
1439-
if (blockFilter2Result.size() >= MAX_FILTER_NUM) {
1440-
throw new JsonRpcTooManyFilterException("Block filter's num exceeds " + MAX_FILTER_NUM);
1440+
if (blockFilter2Result.size() >= maxFilterNum) {
1441+
throw new JsonRpcTooManyFilterException("exceed max block filters: " + maxFilterNum);
14411442
}
14421443

14431444
BlockFilterAndResult filterAndResult = new BlockFilterAndResult();

framework/src/main/resources/config-localtest.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ node {
163163
# httpPBFTPort = 8565
164164
# maxBlockRange = 5000
165165
# maxSubTopics = 1000
166+
# maxFilterNum = 50000
166167
}
167168

168169
}

framework/src/main/resources/config.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ node {
375375
# The maximum number of allowed topics within a topic criteria, default value is 1000,
376376
# should be > 0, otherwise means no limit.
377377
maxSubTopics = 1000
378+
# Allowed maximum number for blockFilter
379+
maxFilterNum = 50000
378380
}
379381

380382
# Disabled api list, it will work for http, rpc and pbft, both FullNode and SolidityNode,

framework/src/test/resources/config-localtest.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ node {
167167
# httpPBFTPort = 8565
168168
# maxBlockRange = 5000
169169
# maxSubTopics = 1000
170+
# maxFilterNum = 50000
170171
}
171172

172173
}

framework/src/test/resources/config-test-index.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ node {
8888
httpPBFTEnable = false
8989
# maxBlockRange = 5000
9090
# maxSubTopics = 1000
91+
# maxFilterNum = 50000
9192
}
9293

9394
rpc {

framework/src/test/resources/config-test-mainnet.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ node {
9494
httpPBFTEnable = false
9595
# maxBlockRange = 5000
9696
# maxSubTopics = 1000
97+
# maxFilterNum = 50000
9798
}
9899

99100
rpc {

framework/src/test/resources/config-test.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ node {
118118
httpPBFTEnable = false
119119
# maxBlockRange = 5000
120120
# maxSubTopics = 1000
121+
# maxFilterNum = 50000
121122
}
122123

123124
# use your ipv6 address for node discovery and tcp connection, default false

0 commit comments

Comments
 (0)