Skip to content

Commit fd89088

Browse files
committed
feat(jsonrpc): refactor to set min and max section
1 parent 9965edc commit fd89088

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

framework/src/main/java/org/tron/core/services/jsonrpc/filters/LogBlockQuery.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,21 @@ public LogBlockQuery(LogFilterWrapper logFilterWrapper, SectionBloomStore sectio
3939
this.currentMaxBlockNum = currentMaxBlockNum;
4040

4141
if (logFilterWrapper.getFromBlock() == Long.MAX_VALUE) {
42-
minSection = (int) (currentMaxBlockNum / Bloom.BLOOM_BIT_SIZE);
4342
minBlock = currentMaxBlockNum;
4443
} else {
45-
minSection = (int) (logFilterWrapper.getFromBlock() / Bloom.BLOOM_BIT_SIZE);
4644
minBlock = logFilterWrapper.getFromBlock();
4745
}
46+
minSection = (int) (minBlock / Bloom.BLOOM_BIT_SIZE);
4847

4948
if (logFilterWrapper.getToBlock() == Long.MAX_VALUE) {
50-
maxSection = (int) (currentMaxBlockNum / Bloom.BLOOM_BIT_SIZE);
5149
maxBlock = currentMaxBlockNum;
5250
} else {
53-
maxSection = (int) (logFilterWrapper.getToBlock() / Bloom.BLOOM_BIT_SIZE);
5451
maxBlock = logFilterWrapper.getToBlock();
5552
if (maxBlock > currentMaxBlockNum) {
5653
maxBlock = currentMaxBlockNum;
5754
}
5855
}
56+
maxSection = (int) (maxBlock / Bloom.BLOOM_BIT_SIZE);
5957
}
6058

6159
public List<Long> getPossibleBlock() throws ExecutionException, InterruptedException,
@@ -71,7 +69,7 @@ public List<Long> getPossibleBlock() throws ExecutionException, InterruptedExcep
7169
BitSet blockNumBitSet = new BitSet(capacity);
7270
blockNumBitSet.set(0, capacity);
7371

74-
//works serial
72+
// works serial
7573
for (int[][] conditionsIndex : allConditionsIndex) {
7674
BitSet bitSet = subMatch(conditionsIndex);
7775
blockNumBitSet.and(bitSet);

framework/src/main/java/org/tron/core/services/jsonrpc/filters/LogFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
7070
if (fr.getTopics() != null) {
7171
//restrict depth of topics, because event has a signature and most 3 indexed parameters
7272
if (fr.getTopics().length > maxTopics) {
73-
throw new JsonRpcInvalidParamsException("topics size should be <= 4");
73+
throw new JsonRpcInvalidParamsException("topics size should be <= " + maxTopics);
7474
}
7575
for (Object topic : fr.getTopics()) {
7676
if (topic == null) {

framework/src/main/resources/config.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ node {
293293
# httpPBFTPort = 8565
294294

295295
# The maximum blocks range to retrieve logs for eth_getLogs, default value is 5000,
296-
# should be >= 0, 0 means no limit.
296+
# should be > 0, otherwise means no limit.
297297
# maxBlockRange = 5000
298298

299299
# The maximum number of allowed topics within a topic criteria, default value is 1000,
300-
# should be >= 0, 0 means no limit.
300+
# should be > 0, otherwise means no limit.
301301
# maxSubTopics = 1000
302302
}
303303

framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,20 @@ public void testLogFilterWrapper() {
694694
Assert.fail();
695695
}
696696

697+
Args.getInstance().setJsonRpcMaxBlockRange(-2);
698+
try {
699+
new LogFilterWrapper(new FilterRequest("0x0", "0x1f40", null,
700+
null, null), 10_000, null, true);
701+
} catch (JsonRpcInvalidParamsException e) {
702+
Assert.fail();
703+
}
704+
try {
705+
new LogFilterWrapper(new FilterRequest("0x0", "0x1f40", null,
706+
null, null), 10_000, null, false);
707+
} catch (JsonRpcInvalidParamsException e) {
708+
Assert.fail();
709+
}
710+
697711
// reset
698712
Args.getInstance().setJsonRpcMaxBlockRange(oldMaxBlockRange);
699713
}

0 commit comments

Comments
 (0)