Skip to content

Commit f23957b

Browse files
committed
Fix at compilation
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
1 parent 8042838 commit f23957b

File tree

53 files changed

+243
-906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+243
-906
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Unreleased
44

55
### Breaking Changes
6+
- RPC changes to enhance compatibility with other ELs
7+
- RPCs using filter parameter including `eth_getLogs` and `trace_filter` return an error if `fromBlock` is greater than `toBlock`, or if `toBlock` extends beyond chain head (previously returned an empty list) [#9604](https://github.com/hyperledger/besu/pull/9604)
68

79
### Upcoming Breaking Changes
810
- ETC Classic and Mordor network support in Besu is deprecated [#9437](https://github.com/hyperledger/besu/pull/9437)
@@ -17,7 +19,7 @@
1719
- Performance: Optimise EIP-196 AltBn128: EcAdd 33-128% faster, EcMul 8% faster [#9570](https://github.com/hyperledger/besu/pull/9570)
1820
- Update to Netty 4.2.9.Final [#9587](https://github.com/hyperledger/besu/pull/9587)
1921
- Update to log4j 2.25.3 [#9600](https://github.com/hyperledger/besu/pull/9600)
20-
- Add `engine_getBlobsV3` method [#9582](https://github.com/hyperledger/besu/pull/9582)
22+
- Add `engine_getBlobsV3` method [#9582](https://github.com/hyperledger/besu/pull/9582)
2123

2224
## 25.12.0
2325

acceptance-tests/tests/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ processTestResources.dependsOn(
103103
':acceptance-tests:catalogless-test-plugins:jar'
104104
)
105105

106+
compileTestJava.dependsOn ':buildDetachedTestPlugins'
107+
106108
// FKA acceptanceTestNotPrivacy
107109
task acceptanceTest(type: Test) {
108110
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
108108
new InvalidJsonRpcParameters(
109109
"toBlock not found: " + filter.getToBlock(),
110110
RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS));
111+
112+
FilterParameter.validateBlockRange(
113+
fromBlockNumber, toBlockNumber, blockchain.headBlockNumber());
111114
if (maxLogRange > 0 && (toBlockNumber - fromBlockNumber) > maxLogRange) {
112115
throw new InvalidJsonRpcParameters(
113116
"Requested range exceeds maximum range limit",

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
106106
final long toBlock = resolveBlockNumber(filterParameter.getToBlock());
107107
LOG.trace("Received RPC rpcName={} fromBlock={} toBlock={}", getName(), fromBlock, toBlock);
108108

109+
FilterParameter.validateBlockRange(
110+
fromBlock, toBlock, getBlockchainQueries().headBlockNumber());
111+
109112
if (maxRange > 0 && toBlock - fromBlock > maxRange) {
110113
LOG.atDebug()
111114
.setMessage("trace_filter request {} failed:")

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/FilterParameter.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.hyperledger.besu.datatypes.Address;
2020
import org.hyperledger.besu.datatypes.Hash;
21+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
22+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
2123
import org.hyperledger.besu.ethereum.api.query.LogsQuery;
2224
import org.hyperledger.besu.evm.log.LogTopic;
2325

@@ -178,4 +180,31 @@ public String toString() {
178180
public boolean isValid() {
179181
return isValid;
180182
}
183+
184+
/**
185+
* Validates that fromBlock <= toBlock and toBlock <= latestBlock for already resolved block
186+
* numbers.
187+
*
188+
* @param fromBlockNumber the resolved from block number
189+
* @param toBlockNumber the resolved to block number
190+
* @param latestBlockNumber the latest block number in the chain
191+
* @throws InvalidJsonRpcParameters if fromBlock > toBlock or toBlock > latestBlock
192+
*/
193+
public static void validateBlockRange(
194+
final long fromBlockNumber, final long toBlockNumber, final long latestBlockNumber) {
195+
if (fromBlockNumber > toBlockNumber) {
196+
throw new InvalidJsonRpcParameters(
197+
"fromBlock (" + fromBlockNumber + ") is greater than toBlock (" + toBlockNumber + ")",
198+
RpcErrorType.INVALID_PARAMS);
199+
}
200+
if (toBlockNumber > latestBlockNumber) {
201+
throw new InvalidJsonRpcParameters(
202+
"toBlock ("
203+
+ toBlockNumber
204+
+ ") is greater than latest block ("
205+
+ latestBlockNumber
206+
+ ")",
207+
RpcErrorType.INVALID_PARAMS);
208+
}
209+
}
181210
}

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogsTest.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ public void shouldQueryFinalizedBlock() {
8787

8888
when(blockchainQueries.finalizedBlockHeader()).thenReturn(Optional.of(blockHeader));
8989
when(blockHeader.getNumber()).thenReturn(blockNumber);
90+
when(blockchainQueries.headBlockNumber()).thenReturn(100L);
9091
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
9192
.thenReturn(new ArrayList<>());
9293

9394
final JsonRpcResponse response = method.response(request);
9495
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
9596

9697
verify(blockchainQueries).matchingLogs(eq(blockNumber), eq(blockNumber), any(), any());
97-
verify(blockchainQueries, never()).headBlockNumber();
98+
verify(blockchainQueries, times(1)).headBlockNumber();
9899
verify(blockchainQueries, never()).safeBlockHeader();
99100
}
100101

@@ -125,6 +126,7 @@ public void shouldQuerySafeBlock() {
125126

126127
when(blockchainQueries.safeBlockHeader()).thenReturn(Optional.of(blockHeader));
127128
when(blockHeader.getNumber()).thenReturn(blockNumber);
129+
when(blockchainQueries.headBlockNumber()).thenReturn(100L);
128130
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
129131
.thenReturn(new ArrayList<>());
130132

@@ -133,7 +135,7 @@ public void shouldQuerySafeBlock() {
133135

134136
verify(blockchainQueries).matchingLogs(eq(blockNumber), eq(blockNumber), any(), any());
135137
verify(blockchainQueries, never()).finalizedBlockHeader();
136-
verify(blockchainQueries, never()).headBlockNumber();
138+
verify(blockchainQueries, times(1)).headBlockNumber();
137139
}
138140

139141
@Test
@@ -142,6 +144,7 @@ public void shouldQueryNumericBlock() {
142144
final long toBlock = 10L;
143145
final JsonRpcRequestContext request = buildRequest(fromBlock, toBlock);
144146

147+
when(blockchainQueries.headBlockNumber()).thenReturn(100L);
145148
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
146149
.thenReturn(new ArrayList<>());
147150

@@ -151,7 +154,7 @@ public void shouldQueryNumericBlock() {
151154
verify(blockchainQueries).matchingLogs(eq(fromBlock), eq(toBlock), any(), any());
152155

153156
verify(blockchainQueries, never()).finalizedBlockHeader();
154-
verify(blockchainQueries, never()).headBlockNumber();
157+
verify(blockchainQueries, times(1)).headBlockNumber();
155158
verify(blockchainQueries, never()).safeBlockHeader();
156159
}
157160

@@ -161,6 +164,7 @@ public void shouldQueryEarliestToNumeric() {
161164
final long latestBlock = 50L;
162165
final JsonRpcRequestContext request = buildRequest("earliest", latestBlock);
163166

167+
when(blockchainQueries.headBlockNumber()).thenReturn(100L);
164168
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
165169
.thenReturn(new ArrayList<>());
166170

@@ -179,6 +183,7 @@ public void shouldQueryWrappedNumeric() {
179183
final JsonRpcRequestContext request =
180184
buildRequest(String.valueOf(fromBlock), String.valueOf(toBlock));
181185

186+
when(blockchainQueries.headBlockNumber()).thenReturn(150L);
182187
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
183188
.thenReturn(new ArrayList<>());
184189

@@ -187,7 +192,7 @@ public void shouldQueryWrappedNumeric() {
187192

188193
verify(blockchainQueries).matchingLogs(eq(fromBlock), eq(toBlock), any(), any());
189194
verify(blockchainQueries, never()).finalizedBlockHeader();
190-
verify(blockchainQueries, never()).headBlockNumber();
195+
verify(blockchainQueries, times(1)).headBlockNumber();
191196
verify(blockchainQueries, never()).safeBlockHeader();
192197
}
193198

@@ -197,6 +202,7 @@ public void shouldQueryWrappedNumericToNumeric() {
197202
final long toBlock = 100L;
198203
final JsonRpcRequestContext request = buildRequest(String.valueOf(fromBlock), toBlock);
199204

205+
when(blockchainQueries.headBlockNumber()).thenReturn(150L);
200206
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
201207
.thenReturn(new ArrayList<>());
202208

@@ -205,7 +211,7 @@ public void shouldQueryWrappedNumericToNumeric() {
205211

206212
verify(blockchainQueries).matchingLogs(eq(fromBlock), eq(toBlock), any(), any());
207213
verify(blockchainQueries, never()).finalizedBlockHeader();
208-
verify(blockchainQueries, never()).headBlockNumber();
214+
verify(blockchainQueries, times(1)).headBlockNumber();
209215
verify(blockchainQueries, never()).safeBlockHeader();
210216
}
211217

@@ -240,6 +246,8 @@ public void shouldQuerySafeToFinalized() {
240246
when(blockchainQueries.safeBlockHeader()).thenReturn(Optional.of(safeBlockHeader));
241247
when(finalizedBlockHeader.getNumber()).thenReturn(finalizedBlockNumber);
242248
when(safeBlockHeader.getNumber()).thenReturn(safeBlockNumber);
249+
when(blockchainQueries.headBlockNumber())
250+
.thenReturn(100L); // Latest block higher than finalized
243251
when(blockchainQueries.matchingLogs(anyLong(), anyLong(), any(), any()))
244252
.thenReturn(new ArrayList<>());
245253

@@ -250,7 +258,7 @@ public void shouldQuerySafeToFinalized() {
250258
.matchingLogs(eq(safeBlockNumber), eq(finalizedBlockNumber), any(), any());
251259
verify(blockchainQueries, times(1)).finalizedBlockHeader();
252260
verify(blockchainQueries, times(1)).safeBlockHeader();
253-
verify(blockchainQueries, never()).headBlockNumber();
261+
verify(blockchainQueries, times(1)).headBlockNumber();
254262
}
255263

256264
@Test
@@ -278,12 +286,35 @@ public void shouldFailIfParamsExceedMaxRange() {
278286
final JsonRpcRequestContext request = buildRequest(0, 50);
279287
maxLogRange = 20L;
280288
method = new EthGetLogs(blockchainQueries, maxLogRange);
289+
when(blockchainQueries.headBlockNumber()).thenReturn(100L);
281290
final JsonRpcResponse response = method.response(request);
282291
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
283292
final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response;
284293
assertThat(errorResponse.getErrorType()).isEqualTo(RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE);
285294
}
286295

296+
@Test
297+
public void shouldFailIfFromBlockGreaterThanToBlock() {
298+
final JsonRpcRequestContext request = buildRequest(10, 9);
299+
final JsonRpcResponse response = method.response(request);
300+
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
301+
final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response;
302+
assertThat(errorResponse.getErrorType()).isEqualTo(RpcErrorType.INVALID_PARAMS);
303+
}
304+
305+
@Test
306+
public void shouldFailIfToBlockGreaterThanLatestBlock() {
307+
final long latestBlockNumber = 100L;
308+
final long toBlock = 150L; // Greater than latest
309+
when(blockchainQueries.headBlockNumber()).thenReturn(latestBlockNumber);
310+
311+
final JsonRpcRequestContext request = buildRequest(50, toBlock);
312+
final JsonRpcResponse response = method.response(request);
313+
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
314+
final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response;
315+
assertThat(errorResponse.getErrorType()).isEqualTo(RpcErrorType.INVALID_PARAMS);
316+
}
317+
287318
private JsonRpcRequestContext buildRequest(final long fromBlock, final long toBlock) {
288319
final FilterParameter filterParameter =
289320
buildFilterParameter(new BlockParameter(fromBlock), new BlockParameter(toBlock));

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.mockito.Mockito.when;
1819

1920
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
2021
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
@@ -48,10 +49,7 @@ public class TraceFilterTest {
4849
@Mock BlockchainQueries blockchainQueries;
4950

5051
@ParameterizedTest
51-
@CsvSource({
52-
"0, 1001, 1000", "0, 5000, 1000", "1, 1002, 1000", "1, 6002, 1000", "1000, 3000, 1000",
53-
"0, 501, 500", "0, 5000, 500", "1, 502, 500", "1, 6002, 500", "1000, 3000, 500"
54-
})
52+
@CsvSource({"0, 1001, 1000", "1, 6002, 1000", "1000, 3000, 500"})
5553
public void shouldFailIfParamsExceedMaxRange(
5654
final long fromBlock, final long toBlock, final long maxFilterRange) {
5755
final FilterParameter filterParameter =
@@ -70,6 +68,9 @@ public void shouldFailIfParamsExceedMaxRange(
7068
new JsonRpcRequestContext(
7169
new JsonRpcRequest("2.0", "trace_filter", new Object[] {filterParameter}));
7270

71+
// Mock headBlockNumber for validation with a value higher than toBlock
72+
when(blockchainQueries.headBlockNumber()).thenReturn(Math.max(toBlock + 1000, 10000L));
73+
7374
method =
7475
new TraceFilter(
7576
protocolSchedule,

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getLogs_fromBlockExceedToBlock.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"response": {
1414
"jsonrpc": "2.0",
1515
"id": 406,
16-
"result" : []
16+
"error" : {
17+
"code": -32602,
18+
"message": "Invalid params"
19+
}
1720
},
1821
"statusCode": 200
1922
}

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-filter/trace_filter_0x21_0x1_after_0_count_19_0xfe3_0x000.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-filter/trace_filter_0x21_0x1_after_0_count_19_0xfe3_all.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)