Skip to content

Commit

Permalink
Merge pull request #1726 from ManfredKarrer/master
Browse files Browse the repository at this point in the history
Small improvements
  • Loading branch information
ripcurlx committed Sep 26, 2018
2 parents 5d46a99 + b1182e9 commit ede4203
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 56 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

import bisq.core.arbitration.ArbitratorManager;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.btc.setup.RegTestHost;
import bisq.core.btc.setup.WalletsSetup;
Expand Down Expand Up @@ -208,7 +209,11 @@ protected void applyInjector() {

protected void setupDevEnv() {
DevEnv.setDevMode(injector.getInstance(Key.get(Boolean.class, Names.named(CommonOptionKeys.USE_DEV_MODE))));
DevEnv.setDaoActivated(injector.getInstance(Key.get(Boolean.class, Names.named(DaoOptionKeys.DAO_ACTIVATED))));

BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isRegTestOrTestNet = (baseCurrencyNetwork.isTestnet() || baseCurrencyNetwork.isRegtest());
boolean isDaoActivatedOptionSet = injector.getInstance(Key.get(Boolean.class, Names.named(DaoOptionKeys.DAO_ACTIVATED)));
DevEnv.setDaoActivated(isDaoActivatedOptionSet || isRegTestOrTestNet);
}

private void setCorruptedDataBaseFilesHandler() {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/btc/BaseCurrencyNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public boolean isMainnet() {
return "MAINNET".equals(network);
}

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

public boolean isRegtest() {
return "REGTEST".equals(network);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Block parseBlock(RawBlock rawBlock) throws BlockNotConnectingException {
private void validateIfBlockIsConnecting(RawBlock rawBlock) throws BlockNotConnectingException {
LinkedList<Block> blocks = bsqStateService.getBlocks();
if (!isBlockConnecting(rawBlock, blocks)) {
final Block last = blocks.getLast();
Block last = blocks.getLast();
log.warn("addBlock called with a not connecting block. New block:\n" +
"height()={}, hash()={}, lastBlock.height()={}, lastBlock.hash()={}",
rawBlock.getHeight(),
Expand Down
42 changes: 29 additions & 13 deletions core/src/main/java/bisq/core/dao/state/GenesisTxInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.core.dao.state;

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.core.dao.DaoOptionKeys;

import org.bitcoinj.core.Coin;
Expand Down Expand Up @@ -45,8 +47,11 @@ public class GenesisTxInfo {

public static final Coin GENESIS_TOTAL_SUPPLY = Coin.parseCoin("2.5");

private static final String DEFAULT_GENESIS_TX_ID = "81855816eca165f17f0668898faa8724a105196e90ffc4993f4cac980176674e";
private static final int DEFAULT_GENESIS_BLOCK_HEIGHT = 524717; // 2018-05-27
private static final String MAINNET_GENESIS_TX_ID = "81855816eca165f17f0668898faa8724a105196e90ffc4993f4cac980176674e";
private static final int MAINNET_GENESIS_BLOCK_HEIGHT = 524717; // 2018-05-27

private static final String TESTNET_GENESIS_TX_ID = "7085539068b4fc27dfc6c39b0feae2adc7fe20f925e79ca0ba064725fe6c9991";
private static final int TESTNET_GENESIS_BLOCK_HEIGHT = 1414332; // 2018-09-25


///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -60,14 +65,6 @@ public class GenesisTxInfo {
@Getter
private final int genesisBlockHeight;


//TODO not sure if we will use that
/* private static final int ISSUANCE_MATURITY = 144 * 30; // 30 days
static int getIssuanceMaturity() {
return ISSUANCE_MATURITY;
}*/

// mainnet
// this tx has a lot of outputs
// https://blockchain.info/de/tx/ee921650ab3f978881b8fe291e0c025e0da2b7dc684003d7a03d9649dfee2e15
Expand All @@ -85,15 +82,34 @@ static int getIssuanceMaturity() {
// private static final String DEFAULT_GENESIS_TX_ID = "--";
// private static final int DEFAULT_GENESIS_BLOCK_HEIGHT = 499000; // recursive test 137298, 499000 dec 2017


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////

@Inject
public GenesisTxInfo(@Nullable @Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
this.genesisTxId = genesisTxId != null ? genesisTxId : DEFAULT_GENESIS_TX_ID;
this.genesisBlockHeight = genesisBlockHeight != 0 ? genesisBlockHeight : DEFAULT_GENESIS_BLOCK_HEIGHT;
BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
boolean isMainnet = baseCurrencyNetwork.isMainnet();
boolean isTestnet = baseCurrencyNetwork.isTestnet();
if (genesisTxId != null && !genesisTxId.isEmpty()) {
this.genesisTxId = genesisTxId;
} else if (isMainnet) {
this.genesisTxId = MAINNET_GENESIS_TX_ID;
} else if (isTestnet) {
this.genesisTxId = TESTNET_GENESIS_TX_ID;
} else {
this.genesisTxId = "genesisTxId is undefined";
}

if (genesisBlockHeight != 0) {
this.genesisBlockHeight = genesisBlockHeight;
} else if (isMainnet) {
this.genesisBlockHeight = MAINNET_GENESIS_BLOCK_HEIGHT;
} else if (isTestnet) {
this.genesisBlockHeight = TESTNET_GENESIS_BLOCK_HEIGHT;
} else {
this.genesisBlockHeight = 0;
}
}
}
9 changes: 7 additions & 2 deletions core/src/main/java/bisq/core/dao/state/SnapshotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SnapshotManager implements BsqStateListener {

private final BsqState bsqState;
private final BsqStateService bsqStateService;
private final GenesisTxInfo genesisTxInfo;
private final Storage<BsqState> storage;

private BsqState snapshotCandidate;
Expand All @@ -53,9 +54,11 @@ public class SnapshotManager implements BsqStateListener {
public SnapshotManager(BsqState bsqState,
BsqStateService bsqStateService,
PersistenceProtoResolver persistenceProtoResolver,
GenesisTxInfo genesisTxInfo,
@Named(Storage.STORAGE_DIR) File storageDir) {
this.bsqState = bsqState;
this.bsqStateService = bsqStateService;
this.genesisTxInfo = genesisTxInfo;
storage = new Storage<>(storageDir, persistenceProtoResolver);

this.bsqStateService.addBsqStateListener(this);
Expand All @@ -80,7 +83,8 @@ public void onParseTxsComplete(Block block) {
if (snapshotCandidate != null) {
// We clone because storage is in a threaded context
final BsqState cloned = bsqState.getClone(snapshotCandidate);
storage.queueUpForSave(cloned);
if (cloned.getBlocks().getLast().getHeight() >= genesisTxInfo.getGenesisBlockHeight())
storage.queueUpForSave(cloned);
log.info("Saved snapshotCandidate to Disc at height " + chainHeadHeight);
}
// Now we clone and keep it in memory for the next trigger
Expand All @@ -104,7 +108,8 @@ public void applySnapshot() {
BsqState persisted = storage.initAndGetPersisted(bsqState, 100);
if (persisted != null) {
log.info("applySnapshot persisted.chainHeadHeight=" + new LinkedList<>(persisted.getBlocks()).getLast().getHeight());
bsqStateService.applySnapshot(persisted);
if (persisted.getBlocks().getLast().getHeight() >= genesisTxInfo.getGenesisBlockHeight())
bsqStateService.applySnapshot(persisted);
} else {
log.info("Try to apply snapshot but no stored snapshot available");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@

package bisq.core.dao.state.period;

import bisq.core.dao.DaoOptionKeys;
import bisq.core.dao.DaoSetupService;
import bisq.core.dao.state.BsqStateListener;
import bisq.core.dao.state.BsqStateService;
import bisq.core.dao.state.GenesisTxInfo;
import bisq.core.dao.state.blockchain.Block;
import bisq.core.dao.state.governance.Param;

import com.google.inject.Inject;

import javax.inject.Named;

import com.google.common.collect.ImmutableList;

import java.util.Arrays;
Expand All @@ -51,9 +49,9 @@ public class CycleService implements BsqStateListener, DaoSetupService {

@Inject
public CycleService(BsqStateService bsqStateService,
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
GenesisTxInfo genesisTxInfo) {
this.bsqStateService = bsqStateService;
this.genesisBlockHeight = genesisBlockHeight;
this.genesisBlockHeight = genesisTxInfo.getGenesisBlockHeight();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class DefaultSeedNodeAddresses {
// new NodeAddress("uqxi3zrpobhtoes6.onion:8000"),

// BTC testnet
new NodeAddress("nbphlanpgbei4okt.onion:8001"),
// new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // dev test
new NodeAddress("nbphlanpgbei4okt.onion:8001"), // 88.99.216.98
new NodeAddress("o5qw2hy6l7jsf654.onion:8001"), // explorer node
new NodeAddress("vjkh4ykq7x5skdlt.onion:8001"), // local dev test

// BTC regtest
// For development you need to change that to your local onion addresses
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ setting.preferences.resetAllFlags=Reset all \"Don't show again\" flags:
setting.preferences.reset=Reset
settings.preferences.languageChange=To apply the language change to all screens requires a restart.
settings.preferences.arbitrationLanguageWarning=In case of a dispute, please note that arbitration is handled in {0}.
settings.preferences.selectCurrencyNetwork=Select base currency
settings.preferences.selectCurrencyNetwork=Select network

settings.net.btcHeader=Bitcoin network
settings.net.p2pHeader=P2P network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void setup() {
snapshotManager = new SnapshotManager(mock(BsqState.class),
mock(BsqStateService.class),
mock(PersistenceProtoResolver.class),
mock(GenesisTxInfo.class),
mock(File.class));
}

Expand Down
6 changes: 5 additions & 1 deletion desktop/src/main/java/bisq/desktop/app/BisqApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package bisq.desktop.app;

import bisq.desktop.SystemTray;
import bisq.desktop.common.view.CachingViewLoader;
import bisq.desktop.common.view.View;
import bisq.desktop.common.view.ViewLoader;
Expand All @@ -35,6 +34,7 @@
import bisq.core.alert.AlertManager;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyMode;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.filter.FilterManager;
Expand Down Expand Up @@ -219,6 +219,10 @@ private void setupStage(Scene scene) {

// configure the primary stage
String appName = injector.getInstance(Key.get(String.class, Names.named(AppOptionKeys.APP_NAME_KEY)));
if (BisqEnvironment.getBaseCurrencyNetwork().isTestnet())
appName += " [TESTNET]";
else if (BisqEnvironment.getBaseCurrencyNetwork().isRegtest())
appName += " [REGTEST]";
stage.setTitle(appName);
stage.setScene(scene);
stage.setMinWidth(1020);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop;
package bisq.desktop.app;

import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.ImageUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class CycleListItem {

public String getCycle() {
int displayIndex = resultsOfCycle.getCycleIndex() + 1;
String dateTime = bsqFormatter.formatDateTime(new Date(resultsOfCycle.getCycleStartTime()));
long cycleStartTime = resultsOfCycle.getCycleStartTime();
String dateTime = cycleStartTime > 0 ? bsqFormatter.formatDateTime(new Date(cycleStartTime)) : Res.get("shared.na");
return Res.get("dao.results.results.table.item.cycle", displayIndex, dateTime);
}

Expand Down
Loading

0 comments on commit ede4203

Please sign in to comment.