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

BitcoindRegtest: Mine initial regtest block on startup #534

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
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public BitcoindPsbtMultiSigIntegrationTests(BitcoindRegtestSetup regtestSetup) {

@Test
public void psbtMultiSigTest() throws MalformedURLException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();

var aliceWallet = regtestSetup.createAndInitializeNewWallet("alice_wallet");
var bobWallet = regtestSetup.createAndInitializeNewWallet("bob_wallet");
var charlieWallet = regtestSetup.createAndInitializeNewWallet("charlie_wallet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public BitcoindSendAndListTxsIntegrationTests(BitcoindRegtestSetup regtestSetup)

@Test
public void sendBtcAndListTxs() throws MalformedURLException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();
BitcoindWallet minerWallet = regtestSetup.getMinerWallet();

var receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public BitcoindSendAndListUnspentIntegrationTests(BitcoindRegtestSetup regtestSe

@Test
public void listUnspent() throws MalformedURLException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();
BitcoindWallet minerWallet = regtestSetup.getMinerWallet();

BitcoindWallet receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet_list_unspent");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public BitcoindSendIntegrationTests(BitcoindRegtestSetup regtestSetup) {

@Test
public void sendOneBtcToAddress() throws MalformedURLException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();
BitcoindWallet receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet_send_one_btc");

String receiverAddress = receiverBackend.getNewAddress(AddressType.BECH32, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public BitcoindSendUnconfirmedTxIntegrationTests(BitcoindRegtestSetup regtestSet
}

@BeforeAll
public void start() throws IOException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();
public void start() throws IOException {
receiverWallet = regtestSetup.createAndInitializeNewWallet("receiver_wallet_send_check_unconfirmed_balance");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public BitcoindZeroMqRawTxIntegrationTests(BitcoindRegtestSetup regtestSetup) {
}

@BeforeAll
public void start() throws IOException, InterruptedException {
regtestSetup.mineInitialRegtestBlocks();
public void start() throws IOException {
receiverWallet = regtestSetup.createAndInitializeNewWallet("receiver_wallet");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class MacLinuxElectrumRegtestSetup extends ElectrumRegtestSetup {

@Getter
private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(true);
private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup();

private final int electrumXServerPort = NetworkUtils.findFreeSystemPort();
private final ElectrumXServerRegtestProcess electrumXServerRegtestProcess =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

package bisq.wallets.electrum.regtest.electrum;

import bisq.common.util.FileUtils;
import bisq.wallets.core.RpcConfig;
import bisq.wallets.regtest.bitcoind.BitcoindRegtestSetup;
import bisq.wallets.regtest.bitcoind.RemoteBitcoind;
import bisq.wallets.regtest.process.MultiProcessCoordinator;
import lombok.Getter;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -46,8 +44,7 @@ public WindowsElectrumRegtestSetup() throws IOException {

public WindowsElectrumRegtestSetup(boolean doCreateWallet) throws IOException {
RpcConfig bitcoindRpcConfig = createBitcoindRpcConfigFromEnvironmentVars();
Path tmpDirPath = FileUtils.createTempDir();
this.remoteBitcoind = new RemoteBitcoind(bitcoindRpcConfig, true);
this.remoteBitcoind = new RemoteBitcoind(bitcoindRpcConfig);

RpcConfig electrumXRpcConfig = createElectrumXRpcConfigFromEnvironmentVars();
this.electrumRegtest = new ElectrumRegtest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class ElectrumXServerRegtestSetup extends AbstractRegtestSetup<MultiProcessCoordinator> {

@Getter
private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(true);
private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup();

private final int electrumXServerPort = NetworkUtils.findFreeSystemPort();
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ public AbstractRegtestSetup<MultiProcessCoordinator> createRegtestSetup() throws
@BeforeAll
public void start() throws IOException, InterruptedException {
super.start();

bitcoindRegtestSetup = elementsdRegtestSetup.getBitcoindRegtestSetup();
bitcoindRegtestSetup.mineInitialRegtestBlocks();

bitcoindDaemon = bitcoindRegtestSetup.getDaemon();

elementsdDaemon = elementsdRegtestSetup.getDaemon();
elementsdMinerWallet = elementsdRegtestSetup.getMinerWallet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import bisq.wallets.core.model.AddressType;
import bisq.wallets.process.BisqProcess;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -57,10 +56,6 @@ public void shutdown() {
zmqListeners.unregisterNewBlockMinedListener(newBlockMinedListener);
}

public void mineInitialRegtestBlocks() throws InterruptedException {
mineBlocks(101);
}

public List<String> mineBlocks(int numberOfBlocks) throws InterruptedException {
String minerAddress = minerWallet.getNewAddress(AddressType.BECH32, "");
List<String> blockHashes = daemon.generateToAddress(numberOfBlocks, minerAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ public class BitcoindRegtestSetup
private final RemoteBitcoind remoteBitcoind;

public BitcoindRegtestSetup() throws IOException {
this(false);
}

public BitcoindRegtestSetup(boolean doMineInitialRegtestBlocks) throws IOException {
super();
rpcConfig = createRpcConfig();
bitcoindProcess = createBitcoindProcess();
remoteBitcoind = new RemoteBitcoind(rpcConfig, doMineInitialRegtestBlocks);
remoteBitcoind = new RemoteBitcoind(rpcConfig);
}

@Override
Expand All @@ -66,10 +62,6 @@ public BitcoindWallet createAndInitializeNewWallet(String walletName) throws Mal
return remoteBitcoind.createAndInitializeNewWallet(walletName);
}

public void mineInitialRegtestBlocks() throws InterruptedException {
remoteBitcoind.mineInitialRegtestBlocks();
}

@Override
public List<String> mineOneBlock() throws InterruptedException {
return mineBlocks(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class RemoteBitcoind implements BisqProcess {
private final RpcConfig rpcConfig;
@Getter
private final BitcoindDaemon daemon;
private final boolean doMineInitialRegtestBlocks;
@Getter
private final ZmqListeners zmqListeners = new ZmqListeners();
@Getter
Expand All @@ -55,11 +54,9 @@ public class RemoteBitcoind implements BisqProcess {
private final List<BitcoindWallet> loadedWallets = new ArrayList<>();
private ZmqConnection bitcoindZeroMq;

public RemoteBitcoind(RpcConfig rpcConfig,
boolean doMineInitialRegtestBlocks) throws MalformedURLException {
public RemoteBitcoind(RpcConfig rpcConfig) throws MalformedURLException {
this.rpcConfig = rpcConfig;
this.daemon = createBitcoindDaemon();
this.doMineInitialRegtestBlocks = doMineInitialRegtestBlocks;
this.minerWallet = new BitcoindWallet(daemon, rpcConfig, MINER_WALLET_NAME);
this.blockMiner = new BitcoindRegtestBlockMiner(daemon, minerWallet, zmqListeners);
}
Expand All @@ -69,10 +66,7 @@ public void start() throws InterruptedException {
blockMiner.start();
initializeZmqListeners();
initializeWallet(minerWallet);

if (doMineInitialRegtestBlocks) {
mineInitialRegtestBlocks();
}
mineInitialRegtestBlocks();
}

@Override
Expand All @@ -88,10 +82,6 @@ public BitcoindWallet createAndInitializeNewWallet(String walletName) throws Mal
return bitcoindWallet;
}

public void mineInitialRegtestBlocks() throws InterruptedException {
blockMiner.mineInitialRegtestBlocks();
}

public List<String> mineBlocks(int numberOfBlocks) throws InterruptedException {
return blockMiner.mineBlocks(numberOfBlocks);
}
Expand Down Expand Up @@ -137,4 +127,8 @@ private void initializeWallet(BitcoindWallet wallet) {
wallet.initialize(Optional.of(WALLET_PASSPHRASE));
loadedWallets.add(wallet);
}

private void mineInitialRegtestBlocks() throws InterruptedException {
blockMiner.mineBlocks(101);
}
}