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

bitcoind: Remove the 'wait until blocks mined' functionality #2747

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand All @@ -34,7 +32,6 @@
public class BitcoindZeroMqBlockHashIntegrationIntegrationTests {

private final BitcoindRegtestSetup regtestSetup;
private final Set<String> minedBlockHashes = new CopyOnWriteArraySet<>();
private final CountDownLatch listenerReceivedBlockHashLatch = new CountDownLatch(1);

public BitcoindZeroMqBlockHashIntegrationIntegrationTests(BitcoindRegtestSetup regtestSetup) {
Expand All @@ -46,43 +43,36 @@ void blockHashNotification() throws InterruptedException {
ZmqListeners zmqListeners = regtestSetup.getZmqListeners();
zmqListeners.registerNewBlockMinedListener((blockHash) -> {
log.info("Notification: New block with hash {}", blockHash);

if (minedBlockHashes.contains(blockHash)) {
listenerReceivedBlockHashLatch.countDown();
} else {
minedBlockHashes.add(blockHash);
}
listenerReceivedBlockHashLatch.countDown();
});

createAndStartDaemonThread(() -> {
Thread thread = new Thread(() -> {
while (true) {
try {
List<String> blockHashes = regtestSetup.mineOneBlock();
log.info("Mined block: {}", blockHashes);

for (String blockHash : blockHashes) {
if (minedBlockHashes.contains(blockHash)) {
listenerReceivedBlockHashLatch.countDown();
return;
} else {
minedBlockHashes.add(blockHash);
}
if (Thread.interrupted()) {
break;
}

log.info("Sleeping for 200ms before mining next block.");
//noinspection BusyWait
Thread.sleep(200);

} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});

thread.start();

boolean await = listenerReceivedBlockHashLatch.await(1, TimeUnit.MINUTES);
thread.interrupt();

if (!await) {
throw new IllegalStateException("Didn't connect to bitcoind after 1 minute.");
}
}

private void createAndStartDaemonThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
thread.start();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import bisq.common.file.FileUtils;
import bisq.common.file.LogScanner;
import bisq.wallets.core.exceptions.WalletShutdownFailedException;
import bisq.wallets.core.exceptions.WalletStartupFailedException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -58,16 +58,10 @@ public void start() {

@Override
public void shutdown() {
try {
invokeStopRpcCall();
process.waitFor(2, TimeUnit.MINUTES);
} catch (InterruptedException e) {
String processName = process.info().command().orElse("<unknown process>");
throw new WalletShutdownFailedException("Cannot shutdown " + processName + ".", e);
}
invokeStopRpcCall();
}

private void waitUntilReady() {
protected void waitUntilReady() {
FutureTask<Boolean> waitingFuture = new FutureTask<>(this::waitUntilLogContainsLines);
Thread waitingThread = new Thread(waitingFuture);
waitingThread.start();
Expand All @@ -86,7 +80,9 @@ private void waitUntilReady() {
}
}

protected abstract Set<String> getIsSuccessfulStartUpLogLines();
protected Set<String> getIsSuccessfulStartUpLogLines() {
return Collections.emptySet();
}

public abstract void invokeStopRpcCall();

Expand All @@ -96,6 +92,7 @@ private Process createAndStartProcess() throws IOException {

var processBuilder = new ProcessBuilder(args);
processBuilder.redirectErrorStream(true);
processBuilder.redirectOutput(ProcessBuilder.Redirect.DISCARD);

Map<String, String> environment = processBuilder.environment();
environment.putAll(processConfig.getEnvironmentVars());
Expand All @@ -106,7 +103,9 @@ private Process createAndStartProcess() throws IOException {

public abstract ProcessConfig createProcessConfig();

protected abstract LogScanner getLogScanner();
protected LogScanner getLogScanner() {
return null;
}

protected boolean waitUntilLogContainsLines() {
try {
Expand Down
Loading
Loading