Skip to content

Commit

Permalink
Upgrade vertx to 4.5.7 (Consensys#986)
Browse files Browse the repository at this point in the history
* Upgrade vertx to 4.5.7
* Fixing deprecated code
* fix: CORS throws VertxException
  • Loading branch information
usmansaleem committed Apr 5, 2024
1 parent 4d2b631 commit 9be746e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Next Version

### Bugs fixed
- Update Vert.x to 4.4.9 to fix CVE-2024-1023
- Update Vert.x to 4.5.7 (which include fixes for CVE-2024-1023)
- Update Postgresql JDBC driver to fix CVE-2024-1597
- Fix cached gvr to be thread-safe during first boot. [#978](https://github.com/Consensys/web3signer/issues/978)

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ subprojects {
tasks.withType(JavaCompile) {
options.fork = true
options.incremental = true
options.compilerArgs = ['-Xlint:deprecation']
}

sourceSets {
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/tech/pegasys/web3signer/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public void run() {
final MetricsSystem metricsSystem = MetricsSystemFactory.create(metricsConfiguration);
Optional<MetricsService> metricsService = Optional.empty();

final Vertx vertx = Vertx.vertx(createVertxOptions(metricsSystem));
final Vertx vertx =
Vertx.builder()
.with(createVertxOptions())
.withMetrics(new VertxMetricsAdapterFactory(metricsSystem))
.build();
final Router router = Router.router(vertx);

final LogErrorHandler errorHandler = new LogErrorHandler();
Expand Down Expand Up @@ -227,13 +231,10 @@ private void createVersionMetric(final MetricsSystem metricsSystem) {
.labels(() -> 1, ApplicationInfo.version());
}

private VertxOptions createVertxOptions(final MetricsSystem metricsSystem) {
private VertxOptions createVertxOptions() {
return new VertxOptions()
.setWorkerPoolSize(baseConfig.getVertxWorkerPoolSize())
.setMetricsOptions(
new MetricsOptions()
.setEnabled(true)
.setFactory(new VertxMetricsAdapterFactory(metricsSystem)));
.setMetricsOptions(new MetricsOptions().setEnabled(true));
}

protected abstract ArtifactSignerProvider createArtifactSignerProvider(
Expand Down Expand Up @@ -339,7 +340,7 @@ private static HttpServerOptions applyTlsKeyStore(
tlsConfig.getKeyStoreFile().toPath().toAbsolutePath().toString();
final String password =
FileUtil.readFirstLineFromFile(tlsConfig.getKeyStorePasswordFile().toPath());
result.setPfxKeyCertOptions(new PfxOptions().setPath(keyStorePathname).setPassword(password));
result.setKeyCertOptions(new PfxOptions().setPath(keyStorePathname).setPassword(password));
return result;
} catch (final NoSuchFileException e) {
throw new InitializationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public WebClientOptions createWebClientOptions(final Eth1Config eth1Config) {
new WebClientOptions()
.setDefaultPort(eth1Config.getDownstreamHttpPort())
.setDefaultHost(eth1Config.getDownstreamHttpHost())
.setTryUseCompression(true)
.setDecompressionSupported(true)
.setProxyOptions(getProxyOptions(eth1Config).orElse(null));

applyTlsOptions(clientOptions, eth1Config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void sendRequest(
.onSuccess(
request -> {
request.response().onSuccess(this::handleResponse).onFailure(this::handleException);
request.setTimeout(httpRequestTimeout.toMillis());
request.idleTimeout(httpRequestTimeout.toMillis());
request.exceptionHandler(this::handleException);
headers.forEach(entry -> request.headers().add(entry.getKey(), entry.getValue()));
request.setChunked(false);
Expand All @@ -85,7 +85,10 @@ private void handleException(final Throwable thrown) {
LOG.error("Transmission failed", thrown);
if (!responseHandled.getAndSet(true)) {
vertx.executeBlocking(
future -> bodyHandler.handleFailure(thrown),
() -> {
bodyHandler.handleFailure(thrown);
return null;
},
false,
res -> {
if (res.failed()) {
Expand All @@ -101,11 +104,13 @@ private void handleResponse(final HttpClientResponse response) {
response.bodyHandler(
body ->
vertx.executeBlocking(
future ->
bodyHandler.handleResponse(
response.headers(),
response.statusCode(),
body.toString(StandardCharsets.UTF_8)),
() -> {
bodyHandler.handleResponse(
response.headers(),
response.statusCode(),
body.toString(StandardCharsets.UTF_8));
return null;
},
false,
res -> {
if (res.failed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
package tech.pegasys.web3signer.core.service.jsonrpc;

import java.io.IOException;
import java.io.InputStream;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBufInputStream;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.DecodeException;

Expand All @@ -30,7 +28,7 @@ public JsonDecoder(final ObjectMapper mapper) {

public <T> T decodeValue(final Buffer buf, final Class<T> clazz) throws DecodeException {
try {
return mapper.readValue((InputStream) new ByteBufInputStream(buf.getByteBuf()), clazz);
return mapper.readValue(buf.getBytes(), clazz);
} catch (IOException e) {
throw new DecodeException("Failed to decode:" + e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.Handler;
import io.vertx.core.VertxException;
import io.vertx.ext.web.RoutingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void handle(final RoutingContext context) {
requestId,
statusCode,
JsonRpcError.CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT);
} else if (failure instanceof IllegalStateException
} else if ((failure instanceof IllegalStateException || failure instanceof VertxException)
&& statusCode == HttpResponseStatus.FORBIDDEN.code()) {
// send status code and empty body
context.response().setStatusCode(statusCode);
Expand Down
2 changes: 1 addition & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencyManagement {

dependency 'info.picocli:picocli:4.6.2'

dependencySet(group: 'io.vertx', version: '4.4.9') {
dependencySet(group: 'io.vertx', version: '4.5.7') {
entry 'vertx-codegen'
entry ('vertx-core') {
exclude group: 'io.netty', name: 'netty-handler'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private HttpClient createHttpClient(final URI interlockURI) {
new HttpClientOptions()
.setDefaultHost(interlockURI.getHost())
.setDefaultPort(port)
.setTryUseCompression(true)
.setDecompressionSupported(true)
.setConnectTimeout((int) httpClientTimeout.toMillis())
.setSsl(useSsl);
if (useSsl) {
Expand Down

0 comments on commit 9be746e

Please sign in to comment.