From 77183f6d600cfdc17d2f309aac507a8d038a56b5 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Thu, 27 Jun 2024 13:09:00 +1000 Subject: [PATCH 1/3] javadoc: Adding javadoc for ethstats module (#7269) * javadoc: Adding javadoc for ethstats module --------- Signed-off-by: Usman Saleem --- .../logging/XmlExtensionConfiguration.java | 2 +- build.gradle | 1 - .../besu/ethstats/EthStatsService.java | 14 ++-- .../authentication/AuthenticationData.java | 19 +++++ .../ethstats/authentication/NodeInfo.java | 60 ++++++++++++++ .../besu/ethstats/report/BlockReport.java | 14 ++++ .../besu/ethstats/report/HistoryReport.java | 14 ++++ .../besu/ethstats/report/LatencyReport.java | 14 ++++ .../besu/ethstats/report/NodeStatsReport.java | 50 ++++++++++++ .../report/PendingTransactionsReport.java | 20 +++++ .../besu/ethstats/report/PingReport.java | 14 ++++ .../ethstats/request/EthStatsRequest.java | 65 +++++++++++++++ .../ethstats/util/EthStatsConnectOptions.java | 47 +++++++++++ .../ethstats/util/PrimusHeartBeatsHelper.java | 15 ++++ .../evmtool/src/main/resources/log4j2.xml | 2 +- util/build.gradle | 2 + .../log4j/plugin/BesuLogMessageConverter.java | 80 +++++++++++++++++++ .../plugin/BesuLogMessageConverterTest.java | 39 +++++++++ 18 files changed, 462 insertions(+), 10 deletions(-) create mode 100644 util/src/main/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverter.java create mode 100644 util/src/test/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverterTest.java diff --git a/besu/src/main/java/org/hyperledger/besu/cli/logging/XmlExtensionConfiguration.java b/besu/src/main/java/org/hyperledger/besu/cli/logging/XmlExtensionConfiguration.java index d2ae7071bdb..1e873276557 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/logging/XmlExtensionConfiguration.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/logging/XmlExtensionConfiguration.java @@ -102,7 +102,7 @@ private void createConsoleAppender() { dim("%t"), colorize("%-5level"), dim("%c{1}"), - colorize("%msg%n%throwable"))) + colorize("%msgc%n%throwable"))) .build(); final ConsoleAppender consoleAppender = ConsoleAppender.newBuilder().setName("Console").setLayout(patternLayout).build(); diff --git a/build.gradle b/build.gradle index 3db0da35ce2..d869daf5e69 100644 --- a/build.gradle +++ b/build.gradle @@ -368,7 +368,6 @@ allprojects { // TODO: these are temporary disabled (ethereum and sub modules), it should be removed in a future PR. '-org.hyperledger.besu.ethereum,' + '-org.hyperledger.besu.ethereum.*,' + - '-org.hyperledger.besu.ethstats.*,' + '-org.hyperledger.besu.evmtool', true) options.addStringOption('Xmaxerrs','65535') diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/EthStatsService.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/EthStatsService.java index 0fa93e1b68c..b96a48dc5e6 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/EthStatsService.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/EthStatsService.java @@ -80,8 +80,8 @@ import org.slf4j.LoggerFactory; /** - * This class describes the behaviour of the EthStats service. This class is used to report pending - * transactions, blocks, and several node-related information to a netstats server. + * This class describes the behaviour of the EthStatsService. This class is used to report pending + * transactions, blocks, and several node-related information to an ethstats server. */ public class EthStatsService { @@ -112,18 +112,18 @@ public class EthStatsService { private long pingTimestamp; /** - * Instantiates a new EthStats service. + * Instantiates a new EthStatsService. * - * @param ethStatsConnectOptions the netstats url + * @param ethStatsConnectOptions the ethstats options * @param blockchainQueries the blockchain queries * @param protocolManager the protocol manager * @param transactionPool the transaction pool * @param miningCoordinator the mining coordinator - * @param syncState the sync state - * @param vertx the vertx + * @param syncState the SyncState + * @param vertx the vertx instance * @param clientVersion the client version * @param genesisConfigOptions the genesis config options - * @param p2PNetwork the p 2 p network + * @param p2PNetwork the p2p network */ public EthStatsService( final EthStatsConnectOptions ethStatsConnectOptions, diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/AuthenticationData.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/AuthenticationData.java index 2e222f08b0c..cb68ebc7d13 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/AuthenticationData.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/AuthenticationData.java @@ -19,18 +19,37 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents the authentication data. It provides methods to get the id, info, and + * secret of the authentication data. + */ @Value.Immutable @JsonSerialize(as = ImmutableAuthenticationData.class) @JsonDeserialize(as = ImmutableAuthenticationData.class) @Value.Style(allParameters = true) public interface AuthenticationData { + /** + * Gets the id of the authentication data. + * + * @return the id of the authentication data. + */ @JsonProperty("id") String getId(); + /** + * Gets the info of the authentication data. + * + * @return the info of the authentication data. + */ @JsonProperty("info") NodeInfo getInfo(); + /** + * Gets the secret of the authentication data. + * + * @return the secret of the authentication data. + */ @JsonProperty("secret") String getSecret(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/NodeInfo.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/NodeInfo.java index 19c34db4b33..b54fd9fa395 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/NodeInfo.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/authentication/NodeInfo.java @@ -19,42 +19,102 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents the information of a node. It provides methods to get the name, node, + * port, network, protocol, api, os, os version, client, update history capability, and contact of + * the node. + */ @Value.Immutable @JsonSerialize(as = ImmutableNodeInfo.class) @JsonDeserialize(as = ImmutableNodeInfo.class) @Value.Style(allParameters = true) public interface NodeInfo { + /** + * Gets the name of the node. + * + * @return the name of the node. + */ @JsonProperty("name") String getName(); + /** + * Gets the node. + * + * @return the node. + */ @JsonProperty("node") String getNode(); + /** + * Gets the port of the node. + * + * @return the port of the node. + */ @JsonProperty("port") String getPort(); + /** + * Gets the network of the node. + * + * @return the network of the node. + */ @JsonProperty("net") String getNetwork(); + /** + * Gets the protocol of the node. + * + * @return the protocol of the node. + */ @JsonProperty("protocol") String getProtocol(); + /** + * Gets the api of the node. + * + * @return the api of the node. + */ @JsonProperty("api") String getApi(); + /** + * Gets the operating system of the node. + * + * @return the operating system of the node. + */ @JsonProperty("os") String getOs(); + /** + * Gets the operating system version of the node. + * + * @return the operating system version of the node. + */ @JsonProperty("os_v") String getOsVer(); + /** + * Gets the client of the node. + * + * @return the client of the node. + */ @JsonProperty("client") String getClient(); + /** + * Gets the update history capability of the node. + * + * @return the update history capability of the node. + */ @JsonProperty("canUpdateHistory") Boolean getCanUpdateHistory(); + /** + * Gets the contact of the node. + * + * @return the contact of the node. + */ @JsonProperty("contact") String getContact(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/BlockReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/BlockReport.java index ccedbb03950..c4816d6486a 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/BlockReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/BlockReport.java @@ -21,15 +21,29 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a block report. It provides methods to get the id and block result of + * the block report. + */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutableBlockReport.class) @JsonDeserialize(as = ImmutableBlockReport.class) public interface BlockReport { + /** + * Gets the id of the block report. + * + * @return the id of the block report. + */ @JsonProperty("id") String getId(); + /** + * Gets the block result of the block report. + * + * @return the block result of the block report. + */ @JsonProperty("block") BlockResult getBlock(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/HistoryReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/HistoryReport.java index 3aafa6200b8..5df2c848cab 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/HistoryReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/HistoryReport.java @@ -23,15 +23,29 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a history report. It provides methods to get the id and history of the + * history report. + */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutableHistoryReport.class) @JsonDeserialize(as = ImmutableHistoryReport.class) public interface HistoryReport { + /** + * Gets the id of the history report. + * + * @return the id of the history report. + */ @JsonProperty(value = "id") String getId(); + /** + * Gets the block results of the history report. + * + * @return the list of block results of the history report. + */ @JsonProperty("history") List getHistory(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/LatencyReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/LatencyReport.java index 58201332b9d..5c588427243 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/LatencyReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/LatencyReport.java @@ -19,15 +19,29 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a latency report. It provides methods to get the id and latency of the + * latency report. + */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutableLatencyReport.class) @JsonDeserialize(as = ImmutableLatencyReport.class) public interface LatencyReport { + /** + * Gets the id of the latency report. + * + * @return the id of the latency report. + */ @JsonProperty("id") String getId(); + /** + * Gets the latency of the latency report. + * + * @return the latency of the latency report. + */ @JsonProperty("latency") String getLatency(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/NodeStatsReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/NodeStatsReport.java index 67bc977a198..af95de720aa 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/NodeStatsReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/NodeStatsReport.java @@ -19,42 +19,92 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a node stats report. It provides methods to get the id and stats of the + * node stats report. + */ @Value.Immutable @Value.Style(deepImmutablesDetection = true, depluralize = true) @JsonSerialize(as = ImmutableNodeStatsReport.class) @JsonDeserialize(as = ImmutableNodeStatsReport.class) public interface NodeStatsReport { + /** + * Gets the id of the node stats report. + * + * @return the id of the node stats report. + */ @JsonProperty("id") String getId(); + /** + * Gets the stats of the node stats report. + * + * @return the stats of the node stats report. + */ @JsonProperty("stats") NStats getStats(); + /** This interface represents the stats of a node. */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutableNStats.class) @JsonDeserialize(as = ImmutableNStats.class) interface NStats { + /** + * Checks if the node is active. + * + * @return true if the node is active, false otherwise. + */ @JsonProperty("active") boolean isActive(); + /** + * Checks if the node is mining. + * + * @return true if the node is mining, false otherwise. + */ @JsonProperty("mining") boolean isMining(); + /** + * Gets the hashrate of the node. + * + * @return the hashrate of the node. + */ @JsonProperty("hashrate") long getHashrate(); + /** + * Gets the number of peers of the node. + * + * @return the number of peers of the node. + */ @JsonProperty("peers") int getPeers(); + /** + * Gets the gas price of the node. + * + * @return the gas price of the node. + */ @JsonProperty("gasPrice") long getGasPrice(); + /** + * Checks if the node is syncing. + * + * @return true if the node is syncing, false otherwise. + */ @JsonProperty("syncing") boolean isSyncing(); + /** + * Gets the uptime of the node. + * + * @return the uptime of the node. + */ @JsonProperty("uptime") int getUpTime(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PendingTransactionsReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PendingTransactionsReport.java index 5c168e29071..dbb19ac34b3 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PendingTransactionsReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PendingTransactionsReport.java @@ -19,24 +19,44 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a pending transactions report. It provides methods to get the id and + * stats of the pending transactions report. + */ @Value.Immutable @Value.Style(deepImmutablesDetection = true, depluralize = true) @JsonSerialize(as = ImmutablePendingTransactionsReport.class) @JsonDeserialize(as = ImmutablePendingTransactionsReport.class) public interface PendingTransactionsReport { + /** + * Gets the id of the pending transactions report. + * + * @return the id of the pending transactions report. + */ @JsonProperty("id") String getId(); + /** + * Gets the stats of the pending transactions report. + * + * @return the stats of the pending transactions report. + */ @JsonProperty("stats") PStats getStats(); + /** This interface represents the stats of a pending transactions report. */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutablePStats.class) @JsonDeserialize(as = ImmutablePStats.class) interface PStats { + /** + * Gets the number of pending transactions. + * + * @return the number of pending transactions. + */ @JsonProperty("pending") int getPending(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PingReport.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PingReport.java index 945f35530b2..d7470a65cf9 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PingReport.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/report/PingReport.java @@ -19,15 +19,29 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; +/** + * This interface represents a ping report. It provides methods to get the id and current time of + * the ping report. + */ @Value.Immutable @Value.Style(allParameters = true) @JsonSerialize(as = ImmutablePingReport.class) @JsonDeserialize(as = ImmutablePingReport.class) public interface PingReport { + /** + * Gets the id of the ping report. + * + * @return the id of the ping report. + */ @JsonProperty("id") String getId(); + /** + * Gets the current time of the ping report. + * + * @return the current time of the ping report. + */ @JsonProperty("clientTime") String getCurrentTime(); } diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/request/EthStatsRequest.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/request/EthStatsRequest.java index dbd8b9ccf66..8d2acf3a056 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/request/EthStatsRequest.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/request/EthStatsRequest.java @@ -23,10 +23,16 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +/** + * This class represents an Ethereum statistics request. It provides methods to get the type of the + * request and the parameters associated with it. + */ public class EthStatsRequest { + /** The constant MAPPER. */ public static final ObjectMapper MAPPER = new ObjectMapper(); + /** The constant EMIT_FIELD. */ public static final String EMIT_FIELD = "emit"; @JsonProperty(EMIT_FIELD) @@ -34,11 +40,22 @@ public class EthStatsRequest { private EthStatsRequest() {} + /** + * Constructs a new EthStatsRequest with the given type and parameters. + * + * @param type the type of the request + * @param parameters the parameters of the request + */ public EthStatsRequest(final Type type, final Object... parameters) { this.emit = Stream.concat(Stream.of(type.value), Stream.of(parameters)).collect(Collectors.toList()); } + /** + * Gets the type of the request. + * + * @return the type of the request + */ @JsonIgnore public Type getType() { return getEmit().stream() @@ -49,14 +66,31 @@ public Type getType() { .orElse(Type.UNKNOWN); } + /** + * Gets the parameters of the request. + * + * @return the parameters of the request + */ public List getEmit() { return emit; } + /** + * Generates a command string from the request. + * + * @return the command string + * @throws JsonProcessingException if there is an error processing the JSON + */ public String generateCommand() throws JsonProcessingException { return MAPPER.writeValueAsString(this); } + /** + * Creates an EthStatsRequest from a response string. + * + * @param value the response string + * @return the EthStatsRequest + */ public static EthStatsRequest fromResponse(final String value) { try { return MAPPER.readValue(value, EthStatsRequest.class); @@ -65,16 +99,36 @@ public static EthStatsRequest fromResponse(final String value) { } } + /** The enum Type represents the type of the request. */ public enum Type { + /** Represents the 'hello' type of the request. */ HELLO("hello"), + + /** Represents the 'ready' type of the request. */ READY("ready"), + + /** Represents the 'node-ping' type of the request. */ NODE_PING("node-ping"), + + /** Represents the 'node-pong' type of the request. */ NODE_PONG("node-pong"), + + /** Represents the 'latency' type of the request. */ LATENCY("latency"), + + /** Represents the 'block' type of the request. */ BLOCK("block"), + + /** Represents the 'history' type of the request. */ HISTORY("history"), + + /** Represents the 'pending' type of the request. */ PENDING("pending"), + + /** Represents the 'stats' type of the request. */ STATS("stats"), + + /** Represents an unknown type of the request. */ UNKNOWN(""); String value; @@ -83,10 +137,21 @@ public enum Type { this.value = value; } + /** + * Gets the value of the type. + * + * @return the value of the type + */ public String getValue() { return value; } + /** + * Gets the type from a value string. + * + * @param value the value string + * @return the type + */ public static Type fromValue(final String value) { for (Type type : values()) { if (type.value.equalsIgnoreCase(value)) { diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/EthStatsConnectOptions.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/EthStatsConnectOptions.java index 7f020adf452..1db74735239 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/EthStatsConnectOptions.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/EthStatsConnectOptions.java @@ -23,24 +23,71 @@ import org.immutables.value.Value; import org.slf4j.LoggerFactory; +/** + * This interface represents the connection options for Ethereum statistics. It provides methods to + * get the scheme, node name, secret, host, port, contact, and CA certificate. + */ @Value.Immutable public interface EthStatsConnectOptions { + /** + * Gets the scheme of the connection. + * + * @return the scheme of the connection. + */ @Nullable String getScheme(); + /** + * Gets the node name of the connection. + * + * @return the node name of the connection. + */ String getNodeName(); + /** + * Gets the secret of the connection. + * + * @return the secret of the connection. + */ String getSecret(); + /** + * Gets the host of the connection. + * + * @return the host of the connection. + */ String getHost(); + /** + * Gets the port of the connection. + * + * @return the port of the connection. + */ Integer getPort(); + /** + * Gets the contact of the connection. + * + * @return the contact of the connection. + */ String getContact(); + /** + * Gets the CA certificate of the connection. + * + * @return the CA certificate of the connection. + */ @Nullable Path getCaCert(); + /** + * Creates an EthStatsConnectOptions from the given parameters. + * + * @param url the url of the connection + * @param contact the contact of the connection + * @param caCert the CA certificate of the connection + * @return the EthStatsConnectOptions + */ static EthStatsConnectOptions fromParams( final String url, final String contact, final Path caCert) { try { diff --git a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/PrimusHeartBeatsHelper.java b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/PrimusHeartBeatsHelper.java index e96019ef818..03b6634af1d 100644 --- a/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/PrimusHeartBeatsHelper.java +++ b/ethereum/ethstats/src/main/java/org/hyperledger/besu/ethstats/util/PrimusHeartBeatsHelper.java @@ -18,14 +18,29 @@ import io.vertx.core.http.WebSocket; +/** This class provides helper methods for handling Primus heartbeats. */ public final class PrimusHeartBeatsHelper { + /** The constant PRIMUS_PING_REGEX. */ public static final Pattern PRIMUS_PING_REGEX = Pattern.compile("primus::ping::([\\d]+)"); + private PrimusHeartBeatsHelper() {} + + /** + * Checks if the given request is a heartbeat request. + * + * @param request the request to check + * @return true if the request is a heartbeat request, false otherwise + */ public static boolean isHeartBeatsRequest(final String request) { return PRIMUS_PING_REGEX.matcher(request).find(); } + /** + * Sends a heartbeat response through the given WebSocket. + * + * @param webSocket the WebSocket to send the response through + */ public static void sendHeartBeatsResponse(final WebSocket webSocket) { if (webSocket != null) { webSocket.writeTextMessage(String.format("\"primus::pong::%d\"", System.currentTimeMillis())); diff --git a/ethereum/evmtool/src/main/resources/log4j2.xml b/ethereum/evmtool/src/main/resources/log4j2.xml index 0d3a7de136c..8e70c35eea9 100644 --- a/ethereum/evmtool/src/main/resources/log4j2.xml +++ b/ethereum/evmtool/src/main/resources/log4j2.xml @@ -6,7 +6,7 @@ - + diff --git a/util/build.gradle b/util/build.gradle index b2a93b1c785..41e4badb333 100644 --- a/util/build.gradle +++ b/util/build.gradle @@ -31,6 +31,8 @@ jar { dependencies { api 'org.slf4j:slf4j-api' + annotationProcessor 'org.apache.logging.log4j:log4j-core' + implementation 'com.google.guava:guava' implementation 'net.java.dev.jna:jna' implementation 'org.apache.commons:commons-lang3' diff --git a/util/src/main/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverter.java b/util/src/main/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverter.java new file mode 100644 index 00000000000..5598f92f9d2 --- /dev/null +++ b/util/src/main/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverter.java @@ -0,0 +1,80 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.util.log4j.plugin; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.pattern.ConverterKeys; +import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; +import org.apache.logging.log4j.core.pattern.PatternConverter; + +/** + * Besu Log4j2 plugin for cleaner message logging. + * + *

Usage: In the pattern layout configuration, replace {@code %msg} with {@code %msgc}. + */ +@Plugin(name = "BesuLogMessageConverter", category = PatternConverter.CATEGORY) +@ConverterKeys({"msgc"}) +public class BesuLogMessageConverter extends LogEventPatternConverter { + + private BesuLogMessageConverter() { + super("BesuLogMessageConverter", null); + } + + /** + * Creates new instance of this class. Required by Log4j2. + * + * @param options Array of options + * @return instance of this class + */ + @SuppressWarnings("unused") // used by Log4j2 + public static BesuLogMessageConverter newInstance(final String[] options) { + return new BesuLogMessageConverter(); + } + + @Override + public void format(final LogEvent event, final StringBuilder toAppendTo) { + final String filteredString = formatBesuLogMessage(event.getMessage().getFormattedMessage()); + toAppendTo.append(filteredString); + } + + /** + * Format Besu log message. + * + * @param input The log message + * @return The formatted log message + */ + public static String formatBesuLogMessage(final String input) { + final StringBuilder builder = new StringBuilder(input.length()); + char prevChar = 0; + + for (int i = 0; i < input.length(); i++) { + final char c = input.charAt(i); + + if (c == 0x0A) { + if (prevChar == 0x0D) { + builder.append(prevChar); + } + builder.append(c); + } else if (c == 0x09 || !Character.isISOControl(c)) { + builder.append(c); + } + + prevChar = c; + } + + return builder.toString(); + } +} diff --git a/util/src/test/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverterTest.java b/util/src/test/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverterTest.java new file mode 100644 index 00000000000..777e5c31a38 --- /dev/null +++ b/util/src/test/java/org/hyperledger/besu/util/log4j/plugin/BesuLogMessageConverterTest.java @@ -0,0 +1,39 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.util.log4j.plugin; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +public class BesuLogMessageConverterTest { + + @Test + public void logCleanup() { + final StringBuilder testDataBuilder = new StringBuilder("log "); + for (int i = 0; i <= 0x001F; i++) { + testDataBuilder.append((char) i); + } + for (int i = 0x007F; i <= 0x009F; i++) { + testDataBuilder.append((char) i); + } + testDataBuilder.append((char) 0x0D).append((char) 0x0A).append("message"); + + String testData = testDataBuilder.toString(); + String cleanedData = BesuLogMessageConverter.formatBesuLogMessage(testData); + String expectedData = String.format("log %c%c%c%cmessage", 0x09, 0x0A, 0x0D, 0x0A); + assertThat(cleanedData).isEqualTo(expectedData); + } +} From bcacbab467d296825e99e98916fd96b5ee37b424 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Thu, 27 Jun 2024 14:03:25 +1000 Subject: [PATCH 2/3] Fix javadoc for ethereum:core top level package (#7270) * javadoc - Apply javadoc to ethereum core top level package --------- Signed-off-by: Usman Saleem --- build.gradle | 1 - .../besu/ethereum/BlockProcessingOutputs.java | 29 +++++++++ .../besu/ethereum/BlockProcessingResult.java | 52 ++++++++++++++++ .../besu/ethereum/BlockValidationResult.java | 40 +++++++++++++ .../besu/ethereum/BlockValidator.java | 49 +++++++++++++++ .../besu/ethereum/ConsensusContext.java | 12 ++++ .../ethereum/ConsensusContextFactory.java | 10 ++++ .../besu/ethereum/GasLimitCalculator.java | 23 +++++++- .../besu/ethereum/MainnetBlockValidator.java | 22 +++++++ .../besu/ethereum/ProtocolContext.java | 59 +++++++++++++++++++ 10 files changed, 295 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d869daf5e69..a8e02a88356 100644 --- a/build.gradle +++ b/build.gradle @@ -366,7 +366,6 @@ allprojects { '-org.hyperledger.besu.tests.acceptance.*,' + '-org.hyperledger.besu.tests.web3j.generated,' + // TODO: these are temporary disabled (ethereum and sub modules), it should be removed in a future PR. - '-org.hyperledger.besu.ethereum,' + '-org.hyperledger.besu.ethereum.*,' + '-org.hyperledger.besu.evmtool', true) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingOutputs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingOutputs.java index 4064b1ef119..92d97697684 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingOutputs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingOutputs.java @@ -21,17 +21,31 @@ import java.util.List; import java.util.Optional; +/** Contains the outputs of processing a block. */ public class BlockProcessingOutputs { private final MutableWorldState worldState; private final List receipts; private final Optional> maybeRequests; + /** + * Creates a new instance. + * + * @param worldState the world state after processing the block + * @param receipts the receipts produced by processing the block + */ public BlockProcessingOutputs( final MutableWorldState worldState, final List receipts) { this(worldState, receipts, Optional.empty()); } + /** + * Creates a new instance. + * + * @param worldState the world state after processing the block + * @param receipts the receipts produced by processing the block + * @param maybeRequests the requests produced by processing the block + */ public BlockProcessingOutputs( final MutableWorldState worldState, final List receipts, @@ -41,14 +55,29 @@ public BlockProcessingOutputs( this.maybeRequests = maybeRequests; } + /** + * Returns the world state after processing the block. + * + * @return the world state after processing the block + */ public MutableWorldState getWorldState() { return worldState; } + /** + * Returns the receipts produced by processing the block. + * + * @return the receipts produced by processing the block + */ public List getReceipts() { return receipts; } + /** + * Returns the requests produced by processing the block. + * + * @return the requests produced by processing the block + */ public Optional> getRequests() { return maybeRequests; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingResult.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingResult.java index be8b2dd3d44..926dd13abdf 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingResult.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockProcessingResult.java @@ -20,24 +20,43 @@ import java.util.List; import java.util.Optional; +/** Contains the outputs of processing a block. */ public class BlockProcessingResult extends BlockValidationResult { private final Optional yield; private final boolean isPartial; + /** A result indicating that processing failed. */ public static final BlockProcessingResult FAILED = new BlockProcessingResult("processing failed"); + /** + * A result indicating that processing was successful but incomplete. + * + * @param yield the outputs of processing a block + */ public BlockProcessingResult(final Optional yield) { this.yield = yield; this.isPartial = false; } + /** + * A result indicating that processing was successful but incomplete. + * + * @param yield the outputs of processing a block + * @param isPartial whether the processing was incomplete + */ public BlockProcessingResult( final Optional yield, final boolean isPartial) { this.yield = yield; this.isPartial = isPartial; } + /** + * A result indicating that processing was successful but incomplete. + * + * @param yield the outputs of processing a block + * @param errorMessage the error message if any + */ public BlockProcessingResult( final Optional yield, final String errorMessage) { super(errorMessage); @@ -45,6 +64,12 @@ public BlockProcessingResult( this.isPartial = false; } + /** + * A result indicating that processing was successful but incomplete. + * + * @param yield the outputs of processing a block + * @param cause the cause of the error if any + */ public BlockProcessingResult( final Optional yield, final Throwable cause) { super(cause.getLocalizedMessage(), cause); @@ -52,6 +77,13 @@ public BlockProcessingResult( this.isPartial = false; } + /** + * A result indicating that processing was successful but incomplete. + * + * @param yield the outputs of processing a block + * @param errorMessage the error message if any + * @param isPartial whether the processing was incomplete + */ public BlockProcessingResult( final Optional yield, final String errorMessage, @@ -61,20 +93,40 @@ public BlockProcessingResult( this.isPartial = isPartial; } + /** + * A result indicating that processing failed. + * + * @param errorMessage the error message + */ public BlockProcessingResult(final String errorMessage) { super(errorMessage); this.isPartial = false; this.yield = Optional.empty(); } + /** + * Gets the block processing outputs of the result. + * + * @return the block processing outputs of the result + */ public Optional getYield() { return yield; } + /** + * Checks if the processing was incomplete. + * + * @return true if the processing was incomplete, false otherwise + */ public boolean isPartial() { return isPartial; } + /** + * Gets the transaction receipts of the result. + * + * @return the transaction receipts of the result + */ public List getReceipts() { if (yield.isEmpty()) { return new ArrayList<>(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidationResult.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidationResult.java index 68a13c7d980..83734e29c06 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidationResult.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidationResult.java @@ -16,38 +16,78 @@ import java.util.Optional; +/** + * Represents the result of a block validation. This class holds the success status, error message, + * and cause of the validation. + */ public class BlockValidationResult { + /** The error message of the failed validation, if any. */ public final Optional errorMessage; + + /** The cause of the failed validation, if any. */ public final Optional cause; + + /** + * The success status of the validation. True if the validation was successful, false otherwise. + */ public final boolean success; + /** Constructs a new BlockValidationResult indicating a successful validation. */ public BlockValidationResult() { this.success = true; this.errorMessage = Optional.empty(); this.cause = Optional.empty(); } + /** + * Constructs a new BlockValidationResult indicating a failed validation with the given error + * message. + * + * @param errorMessage the error message of the failed validation + */ public BlockValidationResult(final String errorMessage) { this.success = false; this.errorMessage = Optional.of(errorMessage); this.cause = Optional.empty(); } + /** + * Constructs a new BlockValidationResult indicating a failed validation with the given error + * message and cause. + * + * @param errorMessage the error message of the failed validation + * @param cause the cause of the failed validation + */ public BlockValidationResult(final String errorMessage, final Throwable cause) { this.success = false; this.errorMessage = Optional.of(errorMessage); this.cause = Optional.of(cause); } + /** + * Checks if the validation was successful. + * + * @return true if the validation was successful, false otherwise + */ public boolean isSuccessful() { return this.success; } + /** + * Checks if the validation failed. + * + * @return true if the validation failed, false otherwise + */ public boolean isFailed() { return !isSuccessful(); } + /** + * Gets the cause of the failed validation. + * + * @return the cause of the failed validation + */ public Optional causedBy() { return cause; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidator.java index dc4c071ec11..e8136062bbd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/BlockValidator.java @@ -22,14 +22,39 @@ import java.util.List; import java.util.Optional; +/** + * The BlockValidator interface defines the methods for validating and processing blocks in the + * Ethereum protocol. + */ public interface BlockValidator { + /** + * Validates and processes a block with the given context, block, header validation mode, and + * ommer validation mode. + * + * @param context the protocol context + * @param block the block to validate and process + * @param headerValidationMode the header validation mode + * @param ommerValidationMode the ommer validation mode + * @return the result of the block processing + */ BlockProcessingResult validateAndProcessBlock( final ProtocolContext context, final Block block, final HeaderValidationMode headerValidationMode, final HeaderValidationMode ommerValidationMode); + /** + * Validates and processes a block with the given context, block, header validation mode, ommer + * validation mode, and persistence flag. + * + * @param context the protocol context + * @param block the block to validate and process + * @param headerValidationMode the header validation mode + * @param ommerValidationMode the ommer validation mode + * @param shouldPersist flag indicating whether the block should be persisted + * @return the result of the block processing + */ BlockProcessingResult validateAndProcessBlock( final ProtocolContext context, final Block block, @@ -37,6 +62,18 @@ BlockProcessingResult validateAndProcessBlock( final HeaderValidationMode ommerValidationMode, final boolean shouldPersist); + /** + * Validates and processes a block with the given context, block, header validation mode, ommer + * validation mode, persistence flag, and bad block recording flag. + * + * @param context the protocol context + * @param block the block to validate and process + * @param headerValidationMode the header validation mode + * @param ommerValidationMode the ommer validation mode + * @param shouldPersist flag indicating whether the block should be persisted + * @param shouldRecordBadBlock flag indicating whether bad blocks should be recorded + * @return the result of the block processing + */ BlockProcessingResult validateAndProcessBlock( final ProtocolContext context, final Block block, @@ -45,6 +82,18 @@ BlockProcessingResult validateAndProcessBlock( final boolean shouldPersist, final boolean shouldRecordBadBlock); + /** + * Performs fast block validation with the given context, block, transaction receipts, requests, + * header validation mode, and ommer validation mode. + * + * @param context the protocol context + * @param block the block to validate + * @param receipts the transaction receipts + * @param requests the requests + * @param headerValidationMode the header validation mode + * @param ommerValidationMode the ommer validation mode + * @return true if the block is valid, false otherwise + */ boolean fastBlockValidation( final ProtocolContext context, final Block block, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContext.java index dc1c117ae82..33ade39ab30 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContext.java @@ -14,7 +14,19 @@ */ package org.hyperledger.besu.ethereum; +/** + * The ConsensusContext interface defines a method for casting the consensus context to a specific + * class. + */ @FunctionalInterface public interface ConsensusContext { + + /** + * Casts the consensus context to the specified class. + * + * @param the type of the class to cast the consensus context to + * @param klass the class to cast the consensus context to + * @return the consensus context cast to the specified class + */ C as(final Class klass); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java index 848d861197b..a9381fa199f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java @@ -18,9 +18,19 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +/** The ConsensusContextFactory interface defines a method for creating a consensus context. */ @FunctionalInterface public interface ConsensusContextFactory { + /** + * Creates a consensus context with the given blockchain, world state archive, and protocol + * schedule. + * + * @param blockchain the blockchain + * @param worldStateArchive the world state archive + * @param protocolSchedule the protocol schedule + * @return the created consensus context + */ ConsensusContext create( Blockchain blockchain, WorldStateArchive worldStateArchive, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/GasLimitCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/GasLimitCalculator.java index 3d5375c4012..7c15d6229c0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/GasLimitCalculator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/GasLimitCalculator.java @@ -14,16 +14,37 @@ */ package org.hyperledger.besu.ethereum; +/** The GasLimitCalculator interface defines methods for calculating the gas limit. */ public interface GasLimitCalculator { - static final long BLOB_GAS_LIMIT = 786432; + /** The constant BLOB_GAS_LIMIT represents the gas limit for blob data. */ + long BLOB_GAS_LIMIT = 786432; + /** + * Calculates the next gas limit based on the current gas limit, target gas limit, and new block + * number. + * + * @param currentGasLimit the current gas limit + * @param targetGasLimit the target gas limit + * @param newBlockNumber the new block number + * @return the calculated next gas limit + */ long nextGasLimit(long currentGasLimit, long targetGasLimit, long newBlockNumber); + /** + * Returns a GasLimitCalculator that always returns the current gas limit. + * + * @return a GasLimitCalculator that always returns the current gas limit + */ static GasLimitCalculator constant() { return (currentGasLimit, targetGasLimit, newBlockNumber) -> currentGasLimit; } + /** + * Returns the current blob gas limit. + * + * @return the current blob gas limit + */ default long currentBlobGasLimit() { return BLOB_GAS_LIMIT; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java index 1b2847d08c4..5d80a951505 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java @@ -36,14 +36,36 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * The MainnetBlockValidator class implements the BlockValidator interface for the Mainnet Ethereum + * network. It validates and processes blocks according to the rules of the Mainnet Ethereum + * network. + */ public class MainnetBlockValidator implements BlockValidator { private static final Logger LOG = LoggerFactory.getLogger(MainnetBlockValidator.class); + + /** The BlockHeaderValidator used to validate block headers. */ protected final BlockHeaderValidator blockHeaderValidator; + + /** The BlockBodyValidator used to validate block bodies. */ protected final BlockBodyValidator blockBodyValidator; + + /** The BlockProcessor used to process blocks. */ protected final BlockProcessor blockProcessor; + + /** The BadBlockManager used to manage bad blocks. */ protected final BadBlockManager badBlockManager; + /** + * Constructs a new MainnetBlockValidator with the given BlockHeaderValidator, BlockBodyValidator, + * BlockProcessor, and BadBlockManager. + * + * @param blockHeaderValidator the BlockHeaderValidator used to validate block headers + * @param blockBodyValidator the BlockBodyValidator used to validate block bodies + * @param blockProcessor the BlockProcessor used to process blocks + * @param badBlockManager the BadBlockManager used to manage bad blocks + */ public MainnetBlockValidator( final BlockHeaderValidator blockHeaderValidator, final BlockBodyValidator blockBodyValidator, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index 1468c621026..e5ec5ae0921 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -35,6 +35,15 @@ public class ProtocolContext { private Optional synchronizer; + /** + * Constructs a new ProtocolContext with the given blockchain, world state archive, consensus + * context, and bad block manager. + * + * @param blockchain the blockchain of the protocol context + * @param worldStateArchive the world state archive of the protocol context + * @param consensusContext the consensus context of the protocol context + * @param badBlockManager the bad block manager of the protocol context + */ public ProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, @@ -47,6 +56,17 @@ public ProtocolContext( this.badBlockManager = badBlockManager; } + /** + * Initializes a new ProtocolContext with the given blockchain, world state archive, protocol + * schedule, consensus context factory, and bad block manager. + * + * @param blockchain the blockchain of the protocol context + * @param worldStateArchive the world state archive of the protocol context + * @param protocolSchedule the protocol schedule of the protocol context + * @param consensusContextFactory the consensus context factory of the protocol context + * @param badBlockManager the bad block manager of the protocol context + * @return the initialized ProtocolContext + */ public static ProtocolContext init( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, @@ -60,30 +80,69 @@ public static ProtocolContext init( badBlockManager); } + /** + * Gets the synchronizer of the protocol context. + * + * @return the synchronizer of the protocol context + */ public Optional getSynchronizer() { return synchronizer; } + /** + * Sets the synchronizer of the protocol context. + * + * @param synchronizer the synchronizer to set + */ public void setSynchronizer(final Optional synchronizer) { this.synchronizer = synchronizer; } + /** + * Gets the blockchain of the protocol context. + * + * @return the blockchain of the protocol context + */ public MutableBlockchain getBlockchain() { return blockchain; } + /** + * Gets the world state archive of the protocol context. + * + * @return the world state archive of the protocol context + */ public WorldStateArchive getWorldStateArchive() { return worldStateArchive; } + /** + * Gets the bad block manager of the protocol context. + * + * @return the bad block manager of the protocol context + */ public BadBlockManager getBadBlockManager() { return badBlockManager; } + /** + * Gets the consensus context of the protocol context. + * + * @param the type of the consensus context + * @param klass the klass + * @return the consensus context of the protocol context + */ public C getConsensusContext(final Class klass) { return consensusContext.as(klass); } + /** + * Gets the safe consensus context of the protocol context. + * + * @param the type of the consensus context + * @param klass the klass + * @return the consensus context of the protocol context + */ public Optional safeConsensusContext(final Class klass) { return Optional.ofNullable(consensusContext) .filter(c -> klass.isAssignableFrom(c.getClass())) From 571e03096dec1e5dbd8d6d9295e015b772b2bd08 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 27 Jun 2024 15:10:19 +1000 Subject: [PATCH 3/3] Disable Flaky tests - permissioning (#7256) * disable some flaky tests Signed-off-by: Sally MacFarlane * correct name for test Signed-off-by: Sally MacFarlane * formatting Signed-off-by: Sally MacFarlane * disable some flaky tests Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Co-authored-by: Usman Saleem --- .../NodeSmartContractPermissioningAcceptanceTest.java | 2 ++ .../NodeSmartContractPermissioningV2AcceptanceTest.java | 2 ++ ...NodeSmartContractPermissioningV2DNSAcceptanceTest.java | 8 ++------ .../api/jsonrpc/internal/methods/EthEstimateGasTest.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java index 8f17c78adde..903919c800c 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class NodeSmartContractPermissioningAcceptanceTest @@ -57,6 +58,7 @@ public void setUp() { } @Test + @Disabled("test is flaky") public void permissionedNodeShouldPeerOnlyWithAllowedNodes() { bootnode.verify(net.awaitPeerCount(3)); allowedNode.verify(net.awaitPeerCount(3)); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2AcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2AcceptanceTest.java index 843d14004fc..efb88178d6d 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2AcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2AcceptanceTest.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class NodeSmartContractPermissioningV2AcceptanceTest @@ -51,6 +52,7 @@ public void setUp() { } @Test + @Disabled("test is flaky") public void permissionedNodeShouldPeerOnlyWithAllowedNodes() { bootnode.verify(net.awaitPeerCount(3)); allowedNode.verify(net.awaitPeerCount(3)); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2DNSAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2DNSAcceptanceTest.java index 7a55283e4f4..435333a7760 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2DNSAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2DNSAcceptanceTest.java @@ -25,8 +25,10 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +@Disabled("test is flaky #7191") public class NodeSmartContractPermissioningV2DNSAcceptanceTest extends NodeSmartContractPermissioningV2AcceptanceTestBase { @@ -57,12 +59,6 @@ public void setUp() { permissionedNode.execute(allowNode(permissionedNode)); permissionedNode.verify(connectionIsAllowed(permissionedNode)); - - // Verify initial configuration - bootnode.verify(net.awaitPeerCount(3)); - allowedNode.verify(net.awaitPeerCount(3)); - forbiddenNode.verify(net.awaitPeerCount(2)); - permissionedNode.verify(net.awaitPeerCount(2)); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 98b9226404a..aa52a31c1f9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -361,7 +361,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabled() { } @Test - public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabled() { + public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeEnabled() { final JsonRpcRequestContext request = ethEstimateGasRequest(legacyTransactionCallParameter(Wei.ZERO, true)); mockTransientProcessorResultGasEstimate(1L, false, true);