Issue 5719 - remove Pretty JSON and make it user configurable (#5766)

* add --pretty-json-enabled

* update changelog

Signed-off-by: George Tebrean <george@web3labs.com>

* Update CLI option name in CHANGELOG.md

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: George Tebrean <george@web3labs.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5779/head
George Tebrean 1 year ago committed by GitHub
parent 3b04f5cd27
commit 92a3c5b139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 7
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 1
      besu/src/test/resources/everything_config.toml
  4. 13
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcObjectExecutor.java
  5. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcConfiguration.java
  6. 16
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/EthJsonRpcHttpServiceTest.java

@ -8,6 +8,7 @@
### Additions and Improvements
- Added `benchmark` subcommand to `evmtool` [#5754](https://github.com/hyperledger/besu/issues/5754)
- JSON output is now compact by default. This can be overridden by the new `--json-pretty-print-enabled` CLI option. [#5766](https://github.com/hyperledger/besu/pull/5766)
### Bug Fixes
- Make smart contract permissioning features work with london fork [#5727](https://github.com/hyperledger/besu/pull/5727)

@ -27,6 +27,7 @@ import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
import static org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration.DEFAULT_GRAPHQL_HTTP_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_PRETTY_JSON_ENABLED;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.VALID_APIS;
import static org.hyperledger.besu.ethereum.api.jsonrpc.authentication.EngineAuthService.EPHEMERAL_JWT_FILE;
@ -779,6 +780,11 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
paramLabel = MANDATORY_LONG_FORMAT_HELP,
description = "Specifies the maximum request content length. (default: ${DEFAULT-VALUE})")
private final Long rpcHttpMaxRequestContentLength = DEFAULT_MAX_REQUEST_CONTENT_LENGTH;
@Option(
names = {"--json-pretty-print-enabled"},
description = "Enable JSON pretty print format (default: ${DEFAULT-VALUE})")
private final Boolean prettyJsonEnabled = DEFAULT_PRETTY_JSON_ENABLED;
}
// JSON-RPC Websocket Options
@ -2443,6 +2449,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
jsonRpcConfiguration.setMaxBatchSize(jsonRPCHttpOptionGroup.rpcHttpMaxBatchSize);
jsonRpcConfiguration.setMaxRequestContentLength(
jsonRPCHttpOptionGroup.rpcHttpMaxRequestContentLength);
jsonRpcConfiguration.setPrettyJsonEnabled(jsonRPCHttpOptionGroup.prettyJsonEnabled);
return jsonRpcConfiguration;
}

@ -87,6 +87,7 @@ rpc-http-tls-cipher-suites=["TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","TLS_ECDHE_R
rpc-http-max-batch-size=1
rpc-http-max-request-content-length = 5242880
rpc-max-logs-range=100
json-pretty-print-enabled=false
# PRIVACY TLS
privacy-tls-enabled=false

@ -36,7 +36,7 @@ import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
public class JsonRpcObjectExecutor extends AbstractJsonRpcExecutor {
private static final ObjectWriter jsonObjectWriter = createObjectWriter();
private final ObjectWriter jsonObjectWriter = createObjectWriter();
public JsonRpcObjectExecutor(
final JsonRpcExecutor jsonRpcExecutor,
@ -64,7 +64,7 @@ public class JsonRpcObjectExecutor extends AbstractJsonRpcExecutor {
return jsonObject.getString("method");
}
private static void handleJsonObjectResponse(
private void handleJsonObjectResponse(
final HttpServerResponse response,
final JsonRpcResponse jsonRpcResponse,
final RoutingContext ctx)
@ -90,9 +90,12 @@ public class JsonRpcObjectExecutor extends AbstractJsonRpcExecutor {
};
}
private static ObjectWriter createObjectWriter() {
return getJsonObjectMapper()
.writerWithDefaultPrettyPrinter()
private ObjectWriter createObjectWriter() {
ObjectWriter writer =
jsonRpcConfiguration.isPrettyJsonEnabled()
? getJsonObjectMapper().writerWithDefaultPrettyPrinter()
: getJsonObjectMapper().writer();
return writer
.without(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)
.with(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}

@ -38,6 +38,7 @@ public class JsonRpcConfiguration {
public static final int DEFAULT_MAX_ACTIVE_CONNECTIONS = 80;
public static final int DEFAULT_MAX_BATCH_SIZE = 1024;
public static final long DEFAULT_MAX_REQUEST_CONTENT_LENGTH = 5 * 1024 * 1024; // 5MB
public static final boolean DEFAULT_PRETTY_JSON_ENABLED = false;
private boolean enabled;
private int port;
@ -55,6 +56,7 @@ public class JsonRpcConfiguration {
private int maxActiveConnections;
private int maxBatchSize;
private long maxRequestContentLength;
private boolean prettyJsonEnabled;
public static JsonRpcConfiguration createDefault() {
final JsonRpcConfiguration config = new JsonRpcConfiguration();
@ -66,6 +68,7 @@ public class JsonRpcConfiguration {
config.setMaxActiveConnections(DEFAULT_MAX_ACTIVE_CONNECTIONS);
config.setMaxBatchSize(DEFAULT_MAX_BATCH_SIZE);
config.setMaxRequestContentLength(DEFAULT_MAX_REQUEST_CONTENT_LENGTH);
config.setPrettyJsonEnabled(DEFAULT_PRETTY_JSON_ENABLED);
return config;
}
@ -196,6 +199,14 @@ public class JsonRpcConfiguration {
this.httpTimeoutSec = httpTimeoutSec;
}
public boolean isPrettyJsonEnabled() {
return prettyJsonEnabled;
}
public void setPrettyJsonEnabled(final boolean prettyJsonEnabled) {
this.prettyJsonEnabled = prettyJsonEnabled;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)

@ -45,8 +45,7 @@ public class EthJsonRpcHttpServiceTest extends AbstractJsonRpcHttpServiceTest {
@Test
public void getFilterChanges_noBlocks() throws Exception {
startService();
final String expectedRespBody =
String.format("{%n \"jsonrpc\" : \"2.0\",%n \"id\" : 2,%n \"result\" : [ ]%n}");
final String expectedRespBody = String.format("{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[]}");
final ResponseBody body = ethNewBlockFilter(1).body();
final String result = getResult(body);
body.close();
@ -60,7 +59,7 @@ public class EthJsonRpcHttpServiceTest extends AbstractJsonRpcHttpServiceTest {
BlockchainSetupUtil blockchainSetupUtil = startServiceWithEmptyChain(DataStorageFormat.FOREST);
final String expectedRespBody =
String.format(
"{%n \"jsonrpc\" : \"2.0\",%n \"id\" : 2,%n \"result\" : [ \"0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9\" ]%n}");
"{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[\"0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9\"]}");
final ResponseBody body = ethNewBlockFilter(1).body();
final String result = getResult(body);
body.close();
@ -75,8 +74,7 @@ public class EthJsonRpcHttpServiceTest extends AbstractJsonRpcHttpServiceTest {
@Test
public void getFilterChanges_noTransactions() throws Exception {
startService();
final String expectedRespBody =
String.format("{%n \"jsonrpc\" : \"2.0\",%n \"id\" : 2,%n \"result\" : [ ]%n}");
final String expectedRespBody = String.format("{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[]}");
final ResponseBody body = ethNewPendingTransactionFilter(1).body();
final String result = getResult(body);
body.close();
@ -96,18 +94,14 @@ public class EthJsonRpcHttpServiceTest extends AbstractJsonRpcHttpServiceTest {
final Response resp = ethGetFilterChanges(2, result);
assertThat(resp.code()).isEqualTo(200);
final String expectedRespBody =
String.format(
"{%n \"jsonrpc\" : \"2.0\",%n \"id\" : 2,%n \"result\" : [ \""
+ transactionHash
+ "\" ]%n}");
String.format("{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[\"" + transactionHash + "\"]}");
assertThat(resp.body().string()).isEqualTo(expectedRespBody);
}
@Test
public void uninstallFilter() throws Exception {
startService();
final String expectedRespBody =
String.format("{%n \"jsonrpc\" : \"2.0\",%n \"id\" : 2,%n \"result\" : true%n}");
final String expectedRespBody = String.format("{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":true}");
final ResponseBody body = ethNewBlockFilter(1).body();
final String result = getResult(body);
body.close();

Loading…
Cancel
Save