Skip to content

Commit c99bdbd

Browse files
authored
LogTopic - empty list is wildcard log topic (#8420)
* empty list is wildcard log topic Signed-off-by: Sally MacFarlane <[email protected]> --------- Signed-off-by: Sally MacFarlane <[email protected]>
1 parent c924e76 commit c99bdbd

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ have support in besu-native can run mainnet ethereum configurations. Windows su
5959
- Add a fallback pivot strategy when the safe block does not change for a long time, to make possible to complete the initial sync in case the chain is not finalizing [#8395](https://github.com/hyperledger/besu/pull/8395)
6060
- Fix issue with new QBFT/IBFT blocks being produced under certain circumstances. [#8308](https://github.com/hyperledger/besu/issues/8308)
6161
- Fix QBFT and IBFT transitions that change the mining beneficiary [#8387](https://github.com/hyperledger/besu/issues/8387)
62+
- `eth_getLogs` - empty topic is a wildcard match [#8420](https://github.com/hyperledger/besu/pull/8420)
6263

6364
## 25.2.2 hotfix
6465
- Pectra - Sepolia: Fix for deposit contract log decoding [#8383](https://github.com/hyperledger/besu/pull/8383)

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ private Optional<Wei> getBlobGasPrice(
795795
* @param toBlockNumber The block number defining the last block in the search range (inclusive).
796796
* @param query Constraints on required topics by topic index. For a given index if the set of
797797
* topics is non-empty, the topic at this index must match one of the values in the set.
798-
* @param isQueryAlive Whether or not the backend query should stay alive.
798+
* @param isQueryAlive Whether the backend query should stay alive.
799799
* @return The set of logs matching the given constraints.
800800
*/
801801
public List<LogWithMetadata> matchingLogs(
@@ -988,8 +988,8 @@ public List<LogWithMetadata> matchingLogs(
988988

989989
/**
990990
* Wraps an operation on MutableWorldState with try-with-resources the corresponding block hash.
991-
* This method provides access to the worldstate via a mapper function in order to ensure all of
992-
* the uses of the MutableWorldState are subsequently closed, via the try-with-resources block.
991+
* This method provides access to the worldstate via a mapper function in order to ensure all uses
992+
* of the MutableWorldState are subsequently closed, via the try-with-resources block.
993993
*
994994
* @param <U> return type of the operation on the MutableWorldState
995995
* @param blockHash the block hash

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/LogsQuery.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private boolean matchesTopics(final List<LogTopic> topics) {
9999
}
100100

101101
private boolean matchesTopic(final LogTopic topic, final List<LogTopic> matchCriteria) {
102-
return matchCriteria.contains(null) || matchCriteria.contains(topic);
102+
return matchCriteria.isEmpty() || matchCriteria.contains(null) || matchCriteria.contains(topic);
103103
}
104104

105105
@Override

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/LogsQueryTest.java

-21
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter;
1616

17-
import static java.util.Collections.emptyList;
18-
import static java.util.Collections.singletonList;
1917
import static org.assertj.core.api.Assertions.assertThat;
2018

2119
import org.hyperledger.besu.datatypes.Address;
@@ -428,23 +426,4 @@ public void multivariateTopicMatchMultivariateQueryReturnTrue() {
428426
assertThat(query.couldMatch(LogsBloomFilter.builder().insertLog(log).build())).isTrue();
429427
assertThat(query.matches(log)).isTrue();
430428
}
431-
432-
@Test
433-
public void emptySubTopicProducesNoMatches() {
434-
final Address address = Address.fromHexString("0x1111111111111111111111111111111111111111");
435-
436-
final LogTopic topic1 =
437-
LogTopic.fromHexString(
438-
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
439-
final LogTopic topic2 =
440-
LogTopic.fromHexString(
441-
"0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
442-
final List<List<LogTopic>> queryParameter =
443-
Lists.newArrayList(singletonList(topic1), emptyList());
444-
445-
final LogsQuery query = new LogsQuery.Builder().address(address).topics(queryParameter).build();
446-
final Log log = new Log(address, data, Lists.newArrayList(topic1, topic2));
447-
448-
assertThat(query.matches(log)).isFalse();
449-
}
450429
}

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/LogsQueryTest.java

+35
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,39 @@ public void testMatches() {
7171
List.of(ERC20_TRANSFER_EVENT, SECOND_ADDRESS_TOPIC, FIRST_ADDRESS_TOPIC))))
7272
.isTrue();
7373
}
74+
75+
@Test
76+
public void testWildcardMatches() {
77+
final LogsQuery query =
78+
new LogsQuery(
79+
List.of(),
80+
List.of(
81+
List.of(), // wildcard match in first spot
82+
List.of(SECOND_ADDRESS_TOPIC)));
83+
84+
assertThat(query.matches(new Log(FIRST_ADDRESS, Bytes.EMPTY, List.of()))).isFalse();
85+
assertThat(query.matches(new Log(FIRST_ADDRESS, Bytes.EMPTY, List.of(ERC20_TRANSFER_EVENT))))
86+
.isFalse();
87+
assertThat(
88+
query.matches(
89+
new Log(
90+
FIRST_ADDRESS,
91+
Bytes.EMPTY,
92+
List.of(ERC20_TRANSFER_EVENT, FIRST_ADDRESS_TOPIC))))
93+
.isFalse();
94+
assertThat(
95+
query.matches(
96+
new Log(
97+
FIRST_ADDRESS,
98+
Bytes.EMPTY,
99+
List.of(ERC20_TRANSFER_EVENT, SECOND_ADDRESS_TOPIC))))
100+
.isTrue();
101+
assertThat(
102+
query.matches(
103+
new Log(
104+
FIRST_ADDRESS,
105+
Bytes.EMPTY,
106+
List.of(ERC20_TRANSFER_EVENT, SECOND_ADDRESS_TOPIC, FIRST_ADDRESS_TOPIC))))
107+
.isTrue();
108+
}
74109
}

0 commit comments

Comments
 (0)