Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rpcBlockNotificationHost option #3176

Merged
merged 2 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/main/java/bisq/core/app/BisqEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static boolean isDaoActivated(Environment environment) {
protected List<String> 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,
Expand Down Expand Up @@ -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) :
"";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/dao/DaoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/dao/DaoOptionKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
32 changes: 20 additions & 12 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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";
}


Expand All @@ -120,8 +124,10 @@ public RpcService(Preferences preferences,
void setup(ResultHandler resultHandler, Consumer<Throwable> errorHandler) {
ListenableFuture<Void> 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();
Expand All @@ -134,6 +140,7 @@ void setup(ResultHandler resultHandler, Consumer<Throwable> 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()));

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public Preferences(Storage<PreferencesPayload> 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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/bisq/core/user/PreferencesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PreferenceMakers {
lookup.valueOf(btcNodesFromOptions, new SameValueDonor<String>(null)),
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null)),
lookup.valueOf(referralID, new SameValueDonor<String>(null)),
null, null, null, null);
null, null, null, null, null);

public static final Preferences empty = make(a(Preferences));

Expand Down