From a13600f2f3dbd41f6eada21bad9a05fff1565392 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sun, 1 Sep 2019 18:40:33 +0200 Subject: [PATCH 1/2] Add rpcBlockNotificationHost option --- .../java/bisq/core/app/BisqEnvironment.java | 6 +++- .../java/bisq/core/app/BisqExecutable.java | 4 +++ .../main/java/bisq/core/dao/DaoModule.java | 2 ++ .../java/bisq/core/dao/DaoOptionKeys.java | 1 + .../bisq/core/dao/node/full/RpcService.java | 32 ++++++++++++------- .../main/java/bisq/core/user/Preferences.java | 3 +- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqEnvironment.java b/core/src/main/java/bisq/core/app/BisqEnvironment.java index c43cd4407e4..fdc211ad583 100644 --- a/core/src/main/java/bisq/core/app/BisqEnvironment.java +++ b/core/src/main/java/bisq/core/app/BisqEnvironment.java @@ -192,7 +192,7 @@ public static boolean isDaoActivated(Environment environment) { protected List bannedSeedNodes, bannedBtcNodes, bannedPriceRelayNodes; protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, rpcPassword, - rpcHost, rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode, + rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress, torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile, socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, @@ -314,6 +314,9 @@ public BisqEnvironment(PropertySource commandLineProperties) { rpcBlockNotificationPort = commandLineProperties.containsProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) ? (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) : ""; + rpcBlockNotificationHost = commandLineProperties.containsProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) ? + (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) : + ""; dumpBlockchainData = commandLineProperties.containsProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA) ? (String) commandLineProperties.getProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA) : ""; @@ -509,6 +512,7 @@ private PropertySource defaultProperties() { setProperty(DaoOptionKeys.RPC_HOST, rpcHost); setProperty(DaoOptionKeys.RPC_PORT, rpcPort); setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, rpcBlockNotificationPort); + setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, rpcBlockNotificationHost); setProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA, dumpBlockchainData); setProperty(DaoOptionKeys.FULL_DAO_NODE, fullDaoNode); setProperty(DaoOptionKeys.GENESIS_TX_ID, genesisTxId); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index b88423c7bfb..4430f151242 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -544,6 +544,10 @@ protected void customizeOptionParsing(OptionParser parser) { "Bitcoind rpc port for block notifications") .withRequiredArg(); + parser.accepts(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, + "Bitcoind rpc accepted incoming host for block notifications") + .withRequiredArg(); + parser.accepts(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA, format("If set to true the blockchain data from RPC requests to Bitcoin Core are " + "stored as json file in the data dir. (default: %s)", "false")) diff --git a/core/src/main/java/bisq/core/dao/DaoModule.java b/core/src/main/java/bisq/core/dao/DaoModule.java index 98b360fec0f..4ed2d8b4518 100644 --- a/core/src/main/java/bisq/core/dao/DaoModule.java +++ b/core/src/main/java/bisq/core/dao/DaoModule.java @@ -229,6 +229,8 @@ protected void configure() { bindConstant().annotatedWith(named(DaoOptionKeys.RPC_PORT)).to(environment.getRequiredProperty(DaoOptionKeys.RPC_PORT)); bindConstant().annotatedWith(named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT)) .to(environment.getRequiredProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT)); + bindConstant().annotatedWith(named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST)) + .to(environment.getRequiredProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST)); bindConstant().annotatedWith(named(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA)) .to(environment.getRequiredProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA)); bindConstant().annotatedWith(named(DaoOptionKeys.FULL_DAO_NODE)) diff --git a/core/src/main/java/bisq/core/dao/DaoOptionKeys.java b/core/src/main/java/bisq/core/dao/DaoOptionKeys.java index b3140a6a7c9..7829dcaf36d 100644 --- a/core/src/main/java/bisq/core/dao/DaoOptionKeys.java +++ b/core/src/main/java/bisq/core/dao/DaoOptionKeys.java @@ -25,6 +25,7 @@ public class DaoOptionKeys { public static final String RPC_PASSWORD = "rpcPassword"; public static final String RPC_PORT = "rpcPort"; public static final String RPC_BLOCK_NOTIFICATION_PORT = "rpcBlockNotificationPort"; + public static final String RPC_BLOCK_NOTIFICATION_HOST = "rpcBlockNotificationHost"; public static final String RPC_HOST = "rpcHost"; public static final String DUMP_BLOCKCHAIN_DATA = "dumpBlockchainData"; diff --git a/core/src/main/java/bisq/core/dao/node/full/RpcService.java b/core/src/main/java/bisq/core/dao/node/full/RpcService.java index b60b34d7276..af3c5f86655 100644 --- a/core/src/main/java/bisq/core/dao/node/full/RpcService.java +++ b/core/src/main/java/bisq/core/dao/node/full/RpcService.java @@ -75,6 +75,7 @@ public class RpcService { private final String rpcHost; private final String rpcPort; private final String rpcBlockPort; + private final String rpcBlockHost; private BtcdClient client; private BtcdDaemon daemon; @@ -93,7 +94,8 @@ public class RpcService { public RpcService(Preferences preferences, @Named(DaoOptionKeys.RPC_HOST) String rpcHost, @Named(DaoOptionKeys.RPC_PORT) String rpcPort, - @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockPort) { + @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockPort, + @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) String rpcBlockHost) { this.rpcUser = preferences.getRpcUser(); this.rpcPassword = preferences.getRpcPw(); @@ -107,9 +109,11 @@ public RpcService(Preferences preferences, this.rpcPort = isPortSet ? rpcPort : isMainnet || isDaoBetaNet ? "8332" : isTestnet ? "18332" : - "18443"; // regtest - this.rpcBlockPort = rpcBlockPort != null && !rpcBlockPort.isEmpty() ? rpcBlockPort : "5125"; - + "18443"; // regtest + boolean isBlockPortSet = rpcBlockPort != null && !rpcBlockPort.isEmpty(); + boolean isBlockHostSet = rpcBlockHost != null && !rpcBlockHost.isEmpty(); + this.rpcBlockPort = isBlockPortSet ? rpcBlockPort : "5125"; + this.rpcBlockHost = isBlockHostSet ? rpcBlockHost : "127.0.0.1"; } @@ -120,8 +124,10 @@ public RpcService(Preferences preferences, void setup(ResultHandler resultHandler, Consumer errorHandler) { ListenableFuture future = executor.submit(() -> { try { - log.info("Starting RPCService with btcd-cli4j version {} on {}:{} with user {}, listening for blocknotify on port {}", - BtcdCli4jVersion.VERSION, this.rpcHost, this.rpcPort, this.rpcUser, this.rpcBlockPort); + log.info("Starting RPCService with btcd-cli4j version {} on {}:{} with user {}, " + + "listening for blocknotify on port {} from {}", + BtcdCli4jVersion.VERSION, this.rpcHost, this.rpcPort, this.rpcUser, this.rpcBlockPort, + this.rpcBlockHost); long startTs = System.currentTimeMillis(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); @@ -134,6 +140,7 @@ void setup(ResultHandler resultHandler, Consumer errorHandler) { nodeConfig.setProperty("node.bitcoind.rpc.password", rpcPassword); nodeConfig.setProperty("node.bitcoind.rpc.port", rpcPort); nodeConfig.setProperty("node.bitcoind.notification.block.port", rpcBlockPort); + nodeConfig.setProperty("node.bitcoind.notification.block.host", rpcBlockHost); nodeConfig.setProperty("node.bitcoind.notification.alert.port", String.valueOf(bisq.network.p2p.Utils.findFreeSystemPort())); nodeConfig.setProperty("node.bitcoind.notification.wallet.port", String.valueOf(bisq.network.p2p.Utils.findFreeSystemPort())); @@ -252,7 +259,8 @@ public void onFailure(@NotNull Throwable throwable) { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private RawTx getTxFromRawTransaction(RawTransaction rawBtcTx, com.neemre.btcdcli4j.core.domain.RawBlock rawBtcBlock) { + private RawTx getTxFromRawTransaction(RawTransaction rawBtcTx, + com.neemre.btcdcli4j.core.domain.RawBlock rawBtcBlock) { String txId = rawBtcTx.getTxId(); long blockTime = rawBtcBlock.getTime() * 1000; // We convert block time from sec to ms int blockHeight = rawBtcBlock.getHeight(); @@ -284,7 +292,7 @@ private RawTx getTxFromRawTransaction(RawTransaction rawBtcTx, com.neemre.btcdcl .filter(e -> e != null && e.getN() != null && e.getValue() != null && e.getScriptPubKey() != null) .map(rawBtcTxOutput -> { byte[] opReturnData = null; - com.neemre.btcdcli4j.core.domain.PubKeyScript scriptPubKey = rawBtcTxOutput.getScriptPubKey(); + com.neemre.btcdcli4j.core.domain.PubKeyScript scriptPubKey = rawBtcTxOutput.getScriptPubKey(); if (ScriptTypes.NULL_DATA.equals(scriptPubKey.getType()) && scriptPubKey.getAsm() != null) { String[] chunks = scriptPubKey.getAsm().split(" "); // We get on testnet a lot of "OP_RETURN 0" data, so we filter those away @@ -304,10 +312,10 @@ private RawTx getTxFromRawTransaction(RawTransaction rawBtcTx, com.neemre.btcdcl // We don't support raw MS which are the only case where scriptPubKey.getAddresses()>1 String address = scriptPubKey.getAddresses() != null && scriptPubKey.getAddresses().size() == 1 ? scriptPubKey.getAddresses().get(0) : null; - PubKeyScript pubKeyScript = new PubKeyScript(scriptPubKey); - return new RawTxOutput(rawBtcTxOutput.getN(), - rawBtcTxOutput.getValue().movePointRight(8).longValue(), - rawBtcTx.getTxId(), + PubKeyScript pubKeyScript = new PubKeyScript(scriptPubKey); + return new RawTxOutput(rawBtcTxOutput.getN(), + rawBtcTxOutput.getValue().movePointRight(8).longValue(), + rawBtcTx.getTxId(), pubKeyScript, address, opReturnData, diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 8a81286c673..4d575029d24 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -158,7 +158,8 @@ public Preferences(Storage storage, @Named(DaoOptionKeys.FULL_DAO_NODE) String fullDaoNode, @Named(DaoOptionKeys.RPC_USER) String rpcUser, @Named(DaoOptionKeys.RPC_PASSWORD) String rpcPassword, - @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockNotificationPort) { + @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockNotificationPort, + @Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) String rpcBlockNotificationHost) { this.storage = storage; From f30b68b39ff86803df0de3bf1a6cf34ed376abb3 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sun, 1 Sep 2019 19:10:26 +0200 Subject: [PATCH 2/2] Fix tests --- core/src/test/java/bisq/core/user/PreferencesTest.java | 2 +- desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/bisq/core/user/PreferencesTest.java b/core/src/test/java/bisq/core/user/PreferencesTest.java index 5c37b6b0c47..6da24a2288e 100644 --- a/core/src/test/java/bisq/core/user/PreferencesTest.java +++ b/core/src/test/java/bisq/core/user/PreferencesTest.java @@ -61,7 +61,7 @@ public void setUp() { storage = mock(Storage.class); bisqEnvironment = mock(BisqEnvironment.class); - preferences = new Preferences(storage, bisqEnvironment, null, null, null, null, null, null, null); + preferences = new Preferences(storage, bisqEnvironment, null, null, null, null, null, null, null, null); } @Test diff --git a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java index 1cd33a1ad51..230b1ad6d90 100644 --- a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java +++ b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java @@ -43,7 +43,7 @@ public class PreferenceMakers { lookup.valueOf(btcNodesFromOptions, new SameValueDonor(null)), lookup.valueOf(useTorFlagFromOptions, new SameValueDonor(null)), lookup.valueOf(referralID, new SameValueDonor(null)), - null, null, null, null); + null, null, null, null, null); public static final Preferences empty = make(a(Preferences));