Skip to content

Commit

Permalink
Upgrade jsonrpc4j & Jackson; simplify BitcoindClient
Browse files Browse the repository at this point in the history
Change jsonrpc4j version from 1.5.3 to 1.6.0.bisq.1, forked to the Bisq
repo from the recent 1.6.0 release. The forked version changes the class
'com.googlecode.jsonrpc4j.HttpException' to be public, instead of (prob.
mistakenly) package private, so we can avoid using reflection to catch
it and re-throw as a 'bisq.network.http.HttpException'. Remove the now
unused constructors from the latter.

As part of this, upgrade Jackson to the latest stable (2.12.1) release,
since jsonrpc4j now depends on a newer version than the previous 2.8.10.
  • Loading branch information
stejbac committed Feb 4, 2021
1 parent e0aa76e commit b4ad6bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 53 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ configure(subprojects) {
httpclientVersion = '4.5.12'
httpcoreVersion = '4.4.13'
ioVersion = '2.6'
jacksonVersion = '2.8.10'
jacksonVersion = '2.12.1'
javafxVersion = '11.0.2'
javaxAnnotationVersion = '1.2'
jcsvVersion = '1.4.0'
jetbrainsAnnotationsVersion = '13.0'
jfoenixVersion = '9.0.6'
joptVersion = '5.0.4'
jsonsimpleVersion = '1.1.1'
jsonrpc4jVersion = '1.5.3'
jsonrpc4jVersion = '1.6.0.bisq.1'
junitVersion = '4.12'
jupiterVersion = '5.7.0'
kotlinVersion = '1.3.41'
Expand Down Expand Up @@ -314,8 +314,9 @@ configure(project(':core')) {
exclude(module: 'commons-codec')
}
compile "com.google.guava:guava:$guavaVersion"
compile("com.github.briandilley.jsonrpc4j:jsonrpc4j:$jsonrpc4jVersion") {
compile("com.github.bisq-network:jsonrpc4j:$jsonrpc4jVersion") {
exclude(module: 'base64')
exclude(module: 'httpcore-nio')
}
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import bisq.core.dao.state.model.blockchain.TxInput;
import bisq.core.user.Preferences;

import bisq.network.http.HttpException;

import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.handlers.ResultHandler;
Expand Down Expand Up @@ -188,7 +186,7 @@ private String decodeNodeVersion(Integer encodedVersion) {
.replaceAll("\\.0$", "");
}

private void checkNodeVersionAndHealth() throws IOException, HttpException {
private void checkNodeVersionAndHealth() throws IOException {
var networkInfo = client.getNetworkInfo();
var nodeVersion = decodeNodeVersion(networkInfo.getVersion());

Expand Down
35 changes: 6 additions & 29 deletions core/src/main/java/bisq/core/dao/node/full/rpc/BitcoindClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import bisq.core.dao.node.full.rpc.dto.DtoNetworkInfo;
import bisq.core.dao.node.full.rpc.dto.RawDtoBlock;

import bisq.network.http.HttpException;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -33,14 +31,10 @@

import java.io.IOException;


import java.util.Base64;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;

import java.lang.reflect.Type;

import static com.google.common.base.Preconditions.checkNotNull;


Expand All @@ -52,19 +46,19 @@

public interface BitcoindClient {
@JsonRpcMethod("getblock")
RawDtoBlock getBlock(String headerHash, int verbosity) throws IOException, HttpException;
RawDtoBlock getBlock(String headerHash, int verbosity) throws IOException;

@JsonRpcMethod("getblockcount")
Integer getBlockCount() throws IOException, HttpException;
Integer getBlockCount() throws IOException;

@JsonRpcMethod("getblockhash")
String getBlockHash(Integer blockHeight) throws IOException, HttpException;
String getBlockHash(Integer blockHeight) throws IOException;

@JsonRpcMethod("getbestblockhash")
String getBestBlockHash() throws IOException, HttpException;
String getBestBlockHash() throws IOException;

@JsonRpcMethod("getnetworkinfo")
DtoNetworkInfo getNetworkInfo() throws IOException, HttpException;
DtoNetworkInfo getNetworkInfo() throws IOException;

static Builder builder() {
return new Builder();
Expand Down Expand Up @@ -120,24 +114,7 @@ public BitcoindClient build() throws MalformedURLException {
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true),
new URL("http", rpcHost, rpcPort, "", urlStreamHandler),
headers) {
@Override
public Object invoke(String methodName,
Object argument,
Type returnType,
Map<String, String> extraHeaders) throws Throwable {
try {
return super.invoke(methodName, argument, returnType, extraHeaders);
} catch (RuntimeException e) {
// Convert the following package-private exception into one that we can catch directly,
// so that HTTP errors (such as authentication failure) can be handled more gracefully.
if (e.getClass().getName().equals("com.googlecode.jsonrpc4j.HttpException")) {
throw new HttpException(e.getMessage(), e.getCause());
}
throw e;
}
}
};
headers);
Optional.ofNullable(requestIDGenerator).ifPresent(httpClient::setRequestIDGenerator);
return ProxyUtil.createClientProxy(getClass().getClassLoader(), BitcoindClient.class, httpClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import bisq.core.dao.node.full.rpc.dto.RawDtoBlock;
import bisq.core.dao.node.full.rpc.dto.RawDtoTransaction;

import bisq.network.http.HttpException;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.ConnectException;
Expand Down Expand Up @@ -50,6 +48,7 @@



import com.googlecode.jsonrpc4j.HttpException;
import com.googlecode.jsonrpc4j.JsonRpcClientException;
import com.googlecode.jsonrpc4j.RequestIDGenerator;
import kotlin.text.Charsets;
Expand Down Expand Up @@ -102,7 +101,7 @@ public void setUp() throws Exception {

@Test
public void testGetBlockCount() throws Exception {
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getblockcount'}");
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getblockcount','params':[]}");
mockResponse = toJsonIS("{'result':'150','error':null,'id':'123456789'}");

assertEquals((Integer) 150, client.getBlockCount());
Expand Down Expand Up @@ -135,7 +134,7 @@ public void testGetBlockHash() throws Exception {

@Test
public void testGetBestBlockHash() throws Exception {
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getbestblockhash'}");
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getbestblockhash','params':[]}");
mockResponse = toJsonIS("{'result':'" + TEST_BLOCK_HASH + "','error':null,'id':'123456789'}");

assertEquals(TEST_BLOCK_HASH, client.getBestBlockHash());
Expand Down Expand Up @@ -200,7 +199,7 @@ public void testGetBlock_malformedHash() throws Exception {

@Test
public void testGetNetworkInfo() throws Exception {
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getnetworkinfo'}");
var expectedRequest = toJson("{'id':'987654321','jsonrpc':'2.0','method':'getnetworkinfo','params':[]}");
mockResponse = toJsonIS("{'result':" + TEST_NETWORK_INFO + ",'error':null,'id':'123456789'}");

var networkInfo = client.getNetworkInfo();
Expand Down
8 changes: 4 additions & 4 deletions gradle/witness/gradle-witness.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ dependencyVerification {
'aopalliance:aopalliance:0addec670fedcd3f113c5c8091d783280d23f75e3acb841b61a9cdb079376a08',
'ch.qos.logback:logback-classic:86a0268c3c96888d4e49d8a754b5b2173286aee100559e803efcbb0df676c66e',
'ch.qos.logback:logback-core:58738067842476feeae5768e832cd36a0e40ce41576ba5739c3632d376bd8c86',
'com.fasterxml.jackson.core:jackson-annotations:2566b3a6662afa3c6af4f5b25006cb46be2efc68f1b5116291d6998a8cdf7ed3',
'com.fasterxml.jackson.core:jackson-core:39a74610521d7fb9eb3f437bb8739bbf47f6435be12d17bf954c731a0c6352bb',
'com.fasterxml.jackson.core:jackson-databind:fcf3c2b0c332f5f54604f7e27fa7ee502378a2cc5df6a944bbfae391872c32ff',
'com.fasterxml.jackson.core:jackson-annotations:203cefdfa6c81e6aa84e11f292f29ca97344a3c3bc0293abea065cd837592873',
'com.fasterxml.jackson.core:jackson-core:cc899cb6eae0c80b87d590eea86528797369cc4feb7b79463207d6bb18f0c257',
'com.fasterxml.jackson.core:jackson-databind:f2ca3c28ebded59c98447d51afe945323df961540af66a063c015597af936aa0',
'com.github.JesusMcCloud:jtorctl:389d61b1b5a85eb2f23c582c3913ede49f80c9f2b553e4762382c836270e57e5',
'com.github.bisq-network.netlayer:tor.external:a3606a592d6b6caa6a2fb7db224eaf43c6874c6730da4815bd37ad686b283dcb',
'com.github.bisq-network.netlayer:tor.native:b15aba7fe987185037791c7ec7c529cb001b90d723d047d54aab87aceb3b3d45',
'com.github.bisq-network.netlayer:tor:a974190aa3a031067ccd1dda28a3ae58cad14060792299d86ea38a05fb21afc5',
'com.github.bisq-network:bitcoinj:65ed08fa5777ea4a08599bdd575e7dc1f4ba2d4d5835472551439d6f6252e68a',
'com.github.briandilley.jsonrpc4j:jsonrpc4j:c9078f037b3b5f45a30a4296f10e4a8de29aa6ace54607fe68e3693b5feeb314',
'com.github.bisq-network:jsonrpc4j:842b4a660440ef53cd436da2e21c3e1fed939b620a3fc7542307deb3e77fdeb6',
'com.github.cd2357.tor-binary:tor-binary-geoip:ae27b6aca1a3a50a046eb11e38202b6d21c2fcd2b8643bbeb5ea85e065fbc1be',
'com.github.cd2357.tor-binary:tor-binary-linux32:7b5d6770aa442ef6d235e8a9bfbaa7c62560690f9fe69ff03c7a752eae84f7dc',
'com.github.cd2357.tor-binary:tor-binary-linux64:24111fa35027599a750b0176392dc1e9417d919414396d1b221ac2e707eaba76',
Expand Down
10 changes: 1 addition & 9 deletions p2p/src/main/java/bisq/network/http/HttpException.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@

public class HttpException extends Exception {
@Getter
private int responseCode;

public HttpException(String message) {
super(message);
}

public HttpException(String message, Throwable cause) {
super(message, cause);
}
private final int responseCode;

public HttpException(String message, int responseCode) {
super(message);
Expand Down

0 comments on commit b4ad6bf

Please sign in to comment.