Skip to content

Commit

Permalink
Merge pull request #2447 from ManfredKarrer/dao-serverside-regtest
Browse files Browse the repository at this point in the history
Dao serverside regtest
  • Loading branch information
ManfredKarrer authored Feb 21, 2019
2 parents 8865ba6 + 0800301 commit d47fec2
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 180 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/app/BisqEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ private static String appDataDir(String userDataDir, String appName) {
public static boolean isDaoActivated(Environment environment) {
Boolean daoActivatedFromOptions = environment.getProperty(DaoOptionKeys.DAO_ACTIVATED, Boolean.class, false);
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isRegTestOrTestNet = (baseCurrencyNetwork.isTestnet() || baseCurrencyNetwork.isRegtest());
return daoActivatedFromOptions || isRegTestOrTestNet;
return daoActivatedFromOptions || !baseCurrencyNetwork.isMainnet();
}


Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

import static bisq.core.app.BisqEnvironment.DEFAULT_APP_NAME;
import static bisq.core.app.BisqEnvironment.DEFAULT_USER_DATA_DIR;
import static bisq.core.btc.BaseCurrencyNetwork.BTC_DAO_TESTNET;
import static bisq.core.btc.BaseCurrencyNetwork.BTC_MAINNET;
import static bisq.core.btc.BaseCurrencyNetwork.BTC_REGTEST;
import static bisq.core.btc.BaseCurrencyNetwork.BTC_TESTNET;
Expand Down Expand Up @@ -479,7 +480,7 @@ protected void customizeOptionParsing(OptionParser parser) {
format("Base currency network (default: %s)", BisqEnvironment.getDefaultBaseCurrencyNetwork().name()))
.withRequiredArg()
.ofType(String.class)
.describedAs(format("%s|%s|%s", BTC_MAINNET, BTC_TESTNET, BTC_REGTEST));
.describedAs(format("%s|%s|%s|%s", BTC_MAINNET, BTC_TESTNET, BTC_REGTEST, BTC_DAO_TESTNET));

parser.accepts(BtcOptionKeys.REG_TEST_HOST,
format("Bitcoin regtest host when using BTC_REGTEST network (default: %s)", RegTestHost.DEFAULT_HOST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@Slf4j
public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler {
private static final long MAX_MEMORY_MB_DEFAULT = 500;
private static final long CHECK_MEMORY_PERIOD_SEC = 10;
private static final long CHECK_MEMORY_PERIOD_SEC = 300;
private volatile boolean stopped;
private static long maxMemory = MAX_MEMORY_MB_DEFAULT;

Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/bisq/core/btc/BaseCurrencyNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
public enum BaseCurrencyNetwork {
BTC_MAINNET(MainNetParams.get(), "BTC", "MAINNET", "Bitcoin"),
BTC_TESTNET(TestNet3Params.get(), "BTC", "TESTNET", "Bitcoin"),
BTC_REGTEST(RegTestParams.get(), "BTC", "REGTEST", "Bitcoin");
BTC_REGTEST(RegTestParams.get(), "BTC", "REGTEST", "Bitcoin"),
BTC_DAO_TESTNET(RegTestParams.get(), "BTC", "REGTEST", "Bitcoin"); // server side regtest

@Getter
private final NetworkParameters parameters;
Expand All @@ -46,19 +47,19 @@ public enum BaseCurrencyNetwork {
}

public boolean isMainnet() {
return "MAINNET".equals(network);
return "BTC_MAINNET".equals(name());
}

public boolean isTestnet() {
return "TESTNET".equals(network);
return "BTC_TESTNET".equals(name());
}

public boolean isRegtest() {
return "REGTEST".equals(network);
public boolean isDaoTestNet() {
return "BTC_DAO_TESTNET".equals(name());
}

public boolean isBitcoin() {
return "BTC".equals(currencyCode);
public boolean isRegtest() {
return "BTC_REGTEST".equals(name());
}

public long getDefaultMinFeePerByte() {
Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/bisq/core/btc/BitcoinModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.btc;

import bisq.core.app.AppOptionKeys;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.model.AddressEntryList;
import bisq.core.btc.nodes.BtcNodes;
import bisq.core.btc.setup.RegTestHost;
Expand Down Expand Up @@ -53,13 +54,18 @@ public BitcoinModule(Environment environment) {

@Override
protected void configure() {
String regTestHost = environment.getProperty(BtcOptionKeys.REG_TEST_HOST, String.class, RegTestHost.DEFAULT_HOST);
// We we have selected BTC_DAO_TESTNET we use our master regtest node, otherwise the specified host or default
// (localhost)
String regTestHost = BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet() ?
"104.248.31.39" :
environment.getProperty(BtcOptionKeys.REG_TEST_HOST, String.class, RegTestHost.DEFAULT_HOST);

RegTestHost.HOST = regTestHost;
if (Arrays.asList("localhost", "127.0.0.1").contains(regTestHost)) {
bind(RegTestHost.class).toInstance(RegTestHost.LOCALHOST);
} else {
bind(RegTestHost.class).toInstance(RegTestHost.REMOTE_HOST);
}
RegTestHost.HOST = regTestHost;

bindConstant().annotatedWith(named(UserAgent.NAME_KEY)).to(environment.getRequiredProperty(UserAgent.NAME_KEY));
bindConstant().annotatedWith(named(UserAgent.VERSION_KEY)).to(environment.getRequiredProperty(UserAgent.VERSION_KEY));
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/btc/nodes/BtcNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public List<BtcNode> getProvidedBtcNodes() {
}

public boolean useProvidedBtcNodes() {
return BisqEnvironment.getBaseCurrencyNetwork().isBitcoin() && BisqEnvironment.getBaseCurrencyNetwork().isMainnet();
return BisqEnvironment.getBaseCurrencyNetwork().isMainnet();
}

public static List<BtcNodes.BtcNode> toBtcNodesList(Collection<String> nodes) {
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/java/bisq/core/dao/governance/param/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public enum Param {
// but can be also a burner address if we prefer to burn the BTC
RECIPIENT_BTC_ADDRESS(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"1BVxNn3T12veSK6DgqwU4Hdn7QHcDDRag7" : // mainnet
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"2N5J6MyjAsWnashimGiNwoRzUXThsQzRmbv" : // regtest
"2N4mVTpUZAnhm9phnxB7VrHB4aBhnWrcUrV", // testnet
BisqEnvironment.getBaseCurrencyNetwork().isTestnet() ?
"2N4mVTpUZAnhm9phnxB7VrHB4aBhnWrcUrV" : // testnet
"mquz1zFmhs7iy8qJTkhY7C9bhJ5S3g8Xim", // regtest or DAO testnet (regtest)
ParamType.ADDRESS),

// Fee for activating an asset or re-listing after deactivation due lack of trade activity. Fee per day of trial period without activity checks.
Expand All @@ -128,43 +128,43 @@ public enum Param {
"3601" : // mainnet; 24 days
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"4" : // regtest
"380", // testnet; 2.6 days
"380", // testnet or dao testnet (server side regtest); 2.6 days
ParamType.BLOCK, 3, 3),
PHASE_BREAK1(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"149" : // mainnet; 1 day
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"1" : // regtest
"10", // testnet
"10", // testnet or dao testnet (server side regtest)
ParamType.BLOCK, 3, 3),
PHASE_BLIND_VOTE(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"601" : // mainnet; 4 days
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"2" : // regtest
"300", // testnet; 2 days
"300", // testnet or dao testnet (server side regtest); 2 days
ParamType.BLOCK, 3, 3),
PHASE_BREAK2(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"9" : // mainnet
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"1" : // regtest
"10", // testnet
"10", // testnet or dao testnet (server side regtest)
ParamType.BLOCK, 3, 23),
PHASE_VOTE_REVEAL(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"301" : // mainnet; 2 days
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"2" : // regtest
"300", // testnet; 2 days
"300", // testnet or dao testnet (server side regtest); 2 days
ParamType.BLOCK, 3, 3),
PHASE_BREAK3(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"9" : // mainnet
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"1" : // regtest
"10", // testnet
"10", // testnet or dao testnet (server side regtest)
ParamType.BLOCK, 3, 3),
PHASE_RESULT(BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ?
"10" : // mainnet
BisqEnvironment.getBaseCurrencyNetwork().isRegtest() ?
"2" : // regtest
"2", // testnet
"2", // testnet or dao testnet (server side regtest)
ParamType.BLOCK, 3, 3);

@Getter
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ public RpcService(Preferences preferences,
boolean isPortSet = rpcPort != null && !rpcPort.isEmpty();
boolean isMainnet = BisqEnvironment.getBaseCurrencyNetwork().isMainnet();
boolean isTestnet = BisqEnvironment.getBaseCurrencyNetwork().isTestnet();
boolean isDaoTestNet = BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet();
this.rpcPort = isPortSet ? rpcPort :
isMainnet ? "8332" :
isTestnet ? "18332" :
"18443"; // regtest
isDaoTestNet ? "18443" :
"18443"; // regtest
this.rpcBlockPort = rpcBlockPort != null && !rpcBlockPort.isEmpty() ? rpcBlockPort : "5125";

this.dumpBlockchainData = dumpBlockchainData;
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/bisq/core/dao/state/DaoStateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@ public void onNewBlockWithEmptyTxs(Block block) {
if (daoState.getBlocks().isEmpty() && block.getHeight() != getGenesisBlockHeight()) {
log.warn("We don't have any blocks yet and we received a block which is not the genesis block. " +
"We ignore that block as the first block need to be the genesis block. " +
"That might happen in edge cases at reorgs.");
"That might happen in edge cases at reorgs. Received block={}", block);
} else {
daoState.getBlocks().add(block);

log.info("New Block added at blockHeight " + block.getHeight());
log.info("New Block added at blockHeight {}", block.getHeight());
}
}

// Third we get the onParseBlockComplete called after all rawTxs of blocks have been parsed
public void onParseBlockComplete(Block block) {
log.info("Parse block completed: Block height {}, {} BSQ transactions.", block.getHeight(), block.getTxs().size());
// We use 2 different handlers as we don't want to update domain listeners during batch processing of all
// blocks as that cause performance issues. In earlier versions when we updated at each block it took
// 50 sec. for 4000 blocks, after that change it was about 4 sec.
Expand All @@ -218,6 +219,7 @@ public void onParseBlockComplete(Block block) {

// Called after parsing of all pending blocks is completed
public void onParseBlockChainComplete() {
log.info("Parse blockchain completed");
parseBlockChainComplete = true;

getLastBlock().ifPresent(block -> {
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/dao/state/GenesisTxInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class GenesisTxInfo {
private static final String TESTNET_GENESIS_TX_ID = "09e70ce0ab7a962a82a2ca84c9ae8a89140bf1c3fb6f7efad6162e39e4b362ae";
private static final int TESTNET_GENESIS_BLOCK_HEIGHT = 1446300; // 2018-12-02

private static final String DAO_TESTNET_GENESIS_TX_ID = "cb316a186b9e88d1b8e1ce8dc79cc6a2080cc7bbc6df94f2be325d8253417af1";
private static final int DAO_TESTNET_GENESIS_BLOCK_HEIGHT = 104; // 2019-02-19

private static final String REGTEST_GENESIS_TX_ID = "30af0050040befd8af25068cc697e418e09c2d8ebd8d411d2240591b9ec203cf";
private static final int REGTEST_GENESIS_BLOCK_HEIGHT = 111;

Expand Down Expand Up @@ -93,13 +96,16 @@ public GenesisTxInfo(@Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isMainnet = baseCurrencyNetwork.isMainnet();
boolean isTestnet = baseCurrencyNetwork.isTestnet();
boolean isDaoTestNet = baseCurrencyNetwork.isDaoTestNet();
boolean isRegtest = baseCurrencyNetwork.isRegtest();
if (!genesisTxId.isEmpty()) {
this.genesisTxId = genesisTxId;
} else if (isMainnet) {
this.genesisTxId = MAINNET_GENESIS_TX_ID;
} else if (isTestnet) {
this.genesisTxId = TESTNET_GENESIS_TX_ID;
} else if (isDaoTestNet) {
this.genesisTxId = DAO_TESTNET_GENESIS_TX_ID;
} else if (isRegtest) {
this.genesisTxId = REGTEST_GENESIS_TX_ID;
} else {
Expand All @@ -112,6 +118,8 @@ public GenesisTxInfo(@Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
this.genesisBlockHeight = MAINNET_GENESIS_BLOCK_HEIGHT;
} else if (isTestnet) {
this.genesisBlockHeight = TESTNET_GENESIS_BLOCK_HEIGHT;
} else if (isDaoTestNet) {
this.genesisBlockHeight = DAO_TESTNET_GENESIS_BLOCK_HEIGHT;
} else if (isRegtest) {
this.genesisBlockHeight = REGTEST_GENESIS_BLOCK_HEIGHT;
} else {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/locale/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ public static boolean assetMatchesNetworkIfMainnet(Asset asset, BaseCurrencyNetw
// We want all coins available also in testnet or regtest for testing purpose
public static boolean coinMatchesNetworkIfMainnet(Coin coin, BaseCurrencyNetwork baseCurrencyNetwork) {
boolean matchesNetwork = assetMatchesNetwork(coin, baseCurrencyNetwork);
return !baseCurrencyNetwork.isMainnet() ||
matchesNetwork;
return !baseCurrencyNetwork.isMainnet() || matchesNetwork;
}

private static CryptoCurrency assetToCryptoCurrency(Asset asset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class DefaultSeedNodeAddresses {

// BTC testnet
// new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // local dev test
new NodeAddress("fjr5w4eckjghqtnu.onion:8001"), // testnet seed 1
new NodeAddress("74w2sttlo4qk6go3.onion:8001"), // testnet seed 2
//new NodeAddress("fjr5w4eckjghqtnu.onion:8001"), // testnet seed 1
/* new NodeAddress("74w2sttlo4qk6go3.onion:8001"), // testnet seed 2
new NodeAddress("jmc5ajqvtnzqaggm.onion:8001"), // testnet seed 3
new NodeAddress("3d56s6acbi3vk52v.onion:8001"), // testnet seed 4
new NodeAddress("3d56s6acbi3vk52v.onion:8001"), // testnet seed 4*/

// BTC regtest
// For development you need to change that to your local onion addresses
Expand All @@ -80,8 +80,16 @@ class DefaultSeedNodeAddresses {
// 4. Rename the directory with your local onion address
// 5. Edit here your found onion address (new NodeAddress("YOUR_ONION.onion:8002")
new NodeAddress("rxdkppp3vicnbgqt.onion:8002"),
new NodeAddress("4ie52dse64kaarxw.onion:8002")
new NodeAddress("4ie52dse64kaarxw.onion:8002"),

// DAO TESTNET (server side regtest dedicated for DAO testing)
new NodeAddress("fjr5w4eckjghqtnu.onion:8003"), // testnet seed 1
new NodeAddress("74w2sttlo4qk6go3.onion:8003"), // testnet seed 2
new NodeAddress("jmc5ajqvtnzqaggm.onion:8003"), // testnet seed 3
new NodeAddress("3d56s6acbi3vk52v.onion:8003") // testnet seed 4

// explorer
// new NodeAddress("gtif46mfxirv533z.onion:8003")
);

private DefaultSeedNodeAddresses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void onAllServicesInitialized() {
"\n\n" + newAssets.toString() +
"\n\n" + sufficientlyTraded.toString();
// Utilities.copyToClipboard(result);
log.info(result);
log.debug(result);
}

private boolean isWarmingUp(String code) {
Expand Down
27 changes: 20 additions & 7 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -89,8 +90,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
new BlockChainExplorer("SoChain. Wow.", "https://chain.so/tx/BTC/", "https://chain.so/address/BTC/"),
new BlockChainExplorer("Blockchain.info", "https://blockchain.info/tx/", "https://blockchain.info/address/"),
new BlockChainExplorer("Insight", "https://insight.bitpay.com/tx/", "https://insight.bitpay.com/address/")
)
);
));
private static final ArrayList<BlockChainExplorer> BTC_TEST_NET_EXPLORERS = new ArrayList<>(Arrays.asList(
new BlockChainExplorer("Blockstream.info", "https://blockstream.info/testnet/tx/", "https://blockstream.info/testnet/address/"),
new BlockChainExplorer("Blockstream.info Tor V3", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/tx/", "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/address/"),
Expand All @@ -100,6 +100,9 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
new BlockChainExplorer("Smartbit", "https://testnet.smartbit.com.au/tx/", "https://testnet.smartbit.com.au/address/"),
new BlockChainExplorer("SoChain. Wow.", "https://chain.so/tx/BTCTEST/", "https://chain.so/address/BTCTEST/")
));
private static final ArrayList<BlockChainExplorer> BTC_DAO_TEST_NET_EXPLORERS = new ArrayList<>(Collections.singletonList(
new BlockChainExplorer("Bisq.info", "https://bisq.info/dao_testnet/tx/", "https://bisq.info/dao_testnet/address/")
));

public static final BlockChainExplorer BSQ_MAIN_NET_EXPLORER = new BlockChainExplorer("BSQ", "https://explorer.bisq.network/tx.html?tx=",
"https://explorer.bisq.network/Address.html?addr=");
Expand Down Expand Up @@ -639,20 +642,30 @@ public ObservableMap<String, Boolean> getDontShowAgainMapAsObservable() {
}

public BlockChainExplorer getBlockChainExplorer() {
if (BisqEnvironment.getBaseCurrencyNetwork().isMainnet())
return prefPayload.getBlockChainExplorerMainNet();
else
return prefPayload.getBlockChainExplorerTestNet();
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
switch (baseCurrencyNetwork) {
case BTC_MAINNET:
return prefPayload.getBlockChainExplorerMainNet();
case BTC_TESTNET:
case BTC_REGTEST:
return prefPayload.getBlockChainExplorerTestNet();
case BTC_DAO_TESTNET:
return BTC_DAO_TEST_NET_EXPLORERS.get(0);
default:
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
}
}

public ArrayList<BlockChainExplorer> getBlockChainExplorers() {
final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
switch (baseCurrencyNetwork) {
case BTC_MAINNET:
return BTC_MAIN_NET_EXPLORERS;
case BTC_TESTNET:
case BTC_REGTEST:
return BTC_TEST_NET_EXPLORERS;
case BTC_DAO_TESTNET:
return BTC_DAO_TEST_NET_EXPLORERS;
default:
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,8 @@ BTC_MAINNET=Bitcoin Mainnet
BTC_TESTNET=Bitcoin Testnet
# suppress inspection "UnusedProperty"
BTC_REGTEST=Bitcoin Regtest
# suppress inspection "UnusedProperty"
BTC_DAO_TESTNET=Bitcoin DAO Testnet

time.year=Year
time.month=Month
Expand Down
Loading

0 comments on commit d47fec2

Please sign in to comment.