Skip to content

Commit

Permalink
Merge pull request #4655 from bisq-network/release/v1.4.0
Browse files Browse the repository at this point in the history
Release/v1.4.0 and v1.4.1
  • Loading branch information
ripcurlx authored Oct 20, 2020
2 parents 4a20cc8 + b1fb571 commit ebe4618
Show file tree
Hide file tree
Showing 151 changed files with 4,903 additions and 2,564 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ configure(subprojects) {

ext { // in alphabetical order
bcVersion = '1.63'
bitcoinjVersion = '44ddbdc'
bitcoinjVersion = 'a733034'
btcdCli4jVersion = '27b94333'
codecVersion = '1.13'
easybindVersion = '1.0.3'
Expand Down Expand Up @@ -385,7 +385,7 @@ configure(project(':desktop')) {
apply plugin: 'witness'
apply from: '../gradle/witness/gradle-witness.gradle'

version = '1.3.9-SNAPSHOT'
version = '1.4.1-SNAPSHOT'

mainClassName = 'bisq.desktop.app.BisqAppMain'

Expand Down
18 changes: 18 additions & 0 deletions common/src/main/java/bisq/common/app/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public boolean containsAll(Capability... capabilities) {
return this.capabilities.containsAll(Arrays.asList(capabilities));
}

public boolean contains(Capability capability) {
return this.capabilities.contains(capability);
}

public boolean isEmpty() {
return capabilities.isEmpty();
}
Expand Down Expand Up @@ -180,4 +184,18 @@ public String prettyPrint() {
public int size() {
return capabilities.size();
}

// We return true if our capabilities have less capabilities than the parameter value
public boolean hasLess(Capabilities other) {
return findHighestCapability(this) < findHighestCapability(other);
}

// We use the sum of all capabilities. Alternatively we could use the highest entry.
// Neither would support removal of past capabilities, a use case we never had so far and which might have
// backward compatibility issues, so we should treat capabilities as an append-only data structure.
public int findHighestCapability(Capabilities capabilities) {
return (int) capabilities.capabilities.stream()
.mapToLong(e -> (long) e.ordinal())
.sum();
}
}
4 changes: 3 additions & 1 deletion common/src/main/java/bisq/common/app/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public enum Capability {
SIGNED_ACCOUNT_AGE_WITNESS, // Supports the signed account age witness feature
MEDIATION, // Supports mediation feature
REFUND_AGENT, // Supports refund agents
TRADE_STATISTICS_HASH_UPDATE // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
TRADE_STATISTICS_HASH_UPDATE, // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
NO_ADDRESS_PRE_FIX, // At 1.4.0 we removed the prefix filter for mailbox messages. If a peer has that capability we do not sent the prefix.
TRADE_STATISTICS_3 // We used a new reduced trade statistics model from v1.4.0 on
}
5 changes: 2 additions & 3 deletions common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class Version {
// VERSION = 0.5.0 introduces proto buffer for the P2P network and local DB and is a not backward compatible update
// Therefore all sub versions start again with 1
// We use semantic versioning with major, minor and patch
public static final String VERSION = "1.3.9";
public static final String VERSION = "1.4.1";

/**
* Holds a list of the versions of tagged resource files for optimizing the getData requests.
*/
public static final List<String> HISTORY = Arrays.asList("1.4.0");
public static final List<String> HISTORY = Arrays.asList("1.4.1");

public static int getMajorVersion(String version) {
return getSubVersion(version, 0);
Expand Down Expand Up @@ -128,7 +128,6 @@ public static void printVersion() {
'}');
}

//TODO move to consensus area
public static final byte COMPENSATION_REQUEST = (byte) 0x01;
public static final byte REIMBURSEMENT_REQUEST = (byte) 0x01;
public static final byte PROPOSAL = (byte) 0x01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@
* Better to use the excludeFromJsonDataMap (annotated with @JsonExclude; used in PaymentAccountPayload) to
* add a key/value pair.
*/
// TODO PubKeyRing and NodeAddress (network) are using UsedForTradeContractJson that is why it is in common module,
// which is a bit weird... Maybe we need either rename common or split it to util and common where common is common code
// used in network and core?
public interface UsedForTradeContractJson {
}
1 change: 0 additions & 1 deletion common/src/main/java/bisq/common/crypto/Encryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO is Hmac needed/make sense?
public class Encryption {
private static final Logger log = LoggerFactory.getLogger(Encryption.class);

Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/bisq/common/crypto/KeyStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

import static bisq.common.util.Preconditions.checkDir;

// TODO: use a password protection for key storage
@Singleton
public class KeyStorage {
private static final Logger log = LoggerFactory.getLogger(KeyStorage.class);
Expand Down
103 changes: 63 additions & 40 deletions common/src/main/java/bisq/common/file/JsonFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,26 @@
import java.io.File;
import java.io.PrintWriter;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Slf4j
public class JsonFileManager {
private final ThreadPoolExecutor executor = Utilities.getThreadPoolExecutor("JsonFileManagerExecutor", 5, 50, 60);
private final static List<JsonFileManager> INSTANCES = new ArrayList<>();

public static void shutDownAllInstances() {
INSTANCES.forEach(JsonFileManager::shutDown);
}


@Nullable
private ThreadPoolExecutor executor;
private final File dir;


Expand All @@ -41,52 +54,62 @@ public class JsonFileManager {
public JsonFileManager(File dir) {
this.dir = dir;

if (!dir.exists())
if (!dir.mkdir())
log.warn("make dir failed");
if (!dir.exists() && !dir.mkdir()) {
log.warn("make dir failed");
}

INSTANCES.add(this);
}

Runtime.getRuntime().addShutdownHook(new Thread(JsonFileManager.this::shutDown,
"JsonFileManager.ShutDownHook"));
@NotNull
protected ThreadPoolExecutor getExecutor() {
if (executor == null) {
executor = Utilities.getThreadPoolExecutor("JsonFileManagerExecutor", 5, 50, 60);
}
return executor;
}

public void shutDown() {
executor.shutdown();
if (executor != null) {
executor.shutdown();
}
}

public void writeToDisc(String json, String fileName) {
executor.execute(() -> {
File jsonFile = new File(Paths.get(dir.getAbsolutePath(), fileName + ".json").toString());
File tempFile = null;
PrintWriter printWriter = null;
try {
tempFile = File.createTempFile("temp", null, dir);
if (!executor.isShutdown() && !executor.isTerminated() && !executor.isTerminating())
tempFile.deleteOnExit();

printWriter = new PrintWriter(tempFile);
printWriter.println(json);

// This close call and comment is borrowed from FileManager. Not 100% sure it that is really needed but
// seems that had fixed in the past and we got reported issues on Windows so that fix might be still
// required.
// Close resources before replacing file with temp file because otherwise it causes problems on windows
// when rename temp file
printWriter.close();
public void writeToDiscThreaded(String json, String fileName) {
getExecutor().execute(() -> writeToDisc(json, fileName));
}

FileUtil.renameFile(tempFile, jsonFile);
} catch (Throwable t) {
log.error("storageFile " + jsonFile.toString());
t.printStackTrace();
} finally {
if (tempFile != null && tempFile.exists()) {
log.warn("Temp file still exists after failed save. We will delete it now. storageFile=" + fileName);
if (!tempFile.delete())
log.error("Cannot delete temp file.");
}

if (printWriter != null)
printWriter.close();
public void writeToDisc(String json, String fileName) {
File jsonFile = new File(Paths.get(dir.getAbsolutePath(), fileName + ".json").toString());
File tempFile = null;
PrintWriter printWriter = null;
try {
tempFile = File.createTempFile("temp", null, dir);
tempFile.deleteOnExit();

printWriter = new PrintWriter(tempFile);
printWriter.println(json);

// This close call and comment is borrowed from FileManager. Not 100% sure it that is really needed but
// seems that had fixed in the past and we got reported issues on Windows so that fix might be still
// required.
// Close resources before replacing file with temp file because otherwise it causes problems on windows
// when rename temp file
printWriter.close();

FileUtil.renameFile(tempFile, jsonFile);
} catch (Throwable t) {
log.error("storageFile " + jsonFile.toString());
t.printStackTrace();
} finally {
if (tempFile != null && tempFile.exists()) {
log.warn("Temp file still exists after failed save. We will delete it now. storageFile=" + fileName);
if (!tempFile.delete())
log.error("Cannot delete temp file.");
}
});

if (printWriter != null)
printWriter.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void writeToDisk(protobuf.PersistableEnvelope serialized, @Nullable Runna

tempFile = usedTempFilePath != null
? FileUtil.createNewFile(usedTempFilePath)
: File.createTempFile("temp", null, dir);
: File.createTempFile("temp_" + fileName, null, dir);
// Don't use a new temp file path each time, as that causes the delete-on-exit hook to leak memory:
tempFile.deleteOnExit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public Message toProtoMessage() {
return getNetworkEnvelopeBuilder().build();
}

// todo remove
public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
return getNetworkEnvelopeBuilder().build();
}
Expand Down
42 changes: 42 additions & 0 deletions common/src/test/java/bisq/common/app/CapabilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.junit.Test;

import static bisq.common.app.Capability.DAO_FULL_NODE;
import static bisq.common.app.Capability.SEED_NODE;
import static bisq.common.app.Capability.TRADE_STATISTICS;
import static bisq.common.app.Capability.TRADE_STATISTICS_2;
Expand All @@ -40,6 +41,47 @@ public void testNoCapabilitiesAvailable() {
assertFalse(DUT.containsAll(new Capabilities(SEED_NODE)));
}

@Test
public void testHasLess() {
assertTrue(new Capabilities().hasLess(new Capabilities(SEED_NODE)));
assertFalse(new Capabilities().hasLess(new Capabilities()));
assertFalse(new Capabilities(SEED_NODE).hasLess(new Capabilities()));
assertTrue(new Capabilities(SEED_NODE).hasLess(new Capabilities(DAO_FULL_NODE)));
assertFalse(new Capabilities(DAO_FULL_NODE).hasLess(new Capabilities(SEED_NODE)));

Capabilities all = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE
);
Capabilities other = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE,
Capability.NO_ADDRESS_PRE_FIX
);

assertTrue(all.hasLess(other));
}

@Test
public void testO() {
Capabilities DUT = new Capabilities(TRADE_STATISTICS);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.payment.PaymentAccount;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatisticsManager;

import bisq.common.app.Version;
Expand Down Expand Up @@ -200,7 +200,7 @@ public void removeWalletPassword(String password) {
walletsService.removeWalletPassword(password);
}

public List<TradeStatistics2> getTradeStatistics() {
public List<TradeStatistics3> getTradeStatistics() {
return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet());
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.setup.CorePersistedDataHost;
import bisq.core.setup.CoreSetup;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.trade.txproof.xmr.XmrTxProofService;

import bisq.network.p2p.P2PService;
Expand Down Expand Up @@ -220,6 +221,7 @@ public void gracefulShutDown(ResultHandler resultHandler) {

try {
injector.getInstance(ArbitratorManager.class).shutDown();
injector.getInstance(TradeStatisticsManager.class).shutDown();
injector.getInstance(XmrTxProofService.class).shutDown();
injector.getInstance(DaoSetup.class).shutDown();
injector.getInstance(AvoidStandbyModeService.class).shutDown();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ private void initWallet() {
if (requestWalletPasswordHandler != null) {
requestWalletPasswordHandler.accept(aesKey -> {
walletsManager.setAesKey(aesKey);
walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().btcWallet(),
aesKey);
if (preferences.isResyncSpvRequested()) {
if (showFirstPopupIfResyncSPVRequestedHandler != null)
showFirstPopupIfResyncSPVRequestedHandler.run();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
Runnable downloadCompleteHandler,
Runnable walletInitializedHandler) {
log.info("Initialize WalletAppSetup with BitcoinJ version {} and hash of BitcoinJ commit {}",
VersionMessage.BITCOINJ_VERSION, "44ddbdc");
VersionMessage.BITCOINJ_VERSION, "a733034");

ObjectProperty<Throwable> walletServiceException = new SimpleObjectProperty<>();
btcInfoBinding = EasyBind.combine(walletsSetup.downloadPercentageProperty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.dao.DaoSetup;
import bisq.core.offer.OpenOfferManager;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;

Expand All @@ -31,6 +32,7 @@
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.config.Config;
import bisq.common.file.JsonFileManager;
import bisq.common.handlers.ResultHandler;
import bisq.common.persistence.PersistenceManager;
import bisq.common.setup.GracefulShutDownHandler;
Expand Down Expand Up @@ -83,6 +85,8 @@ public void gracefulShutDown(ResultHandler resultHandler) {
log.info("gracefulShutDown");
try {
if (injector != null) {
JsonFileManager.shutDownAllInstances();
injector.getInstance(DaoSetup.class).shutDown();
injector.getInstance(ArbitratorManager.class).shutDown();
injector.getInstance(OpenOfferManager.class).shutDown(() -> injector.getInstance(P2PService.class).shutDown(() -> {
injector.getInstance(WalletsSetup.class).shutDownComplete.addListener((ov, o, n) -> {
Expand Down
Loading

0 comments on commit ebe4618

Please sign in to comment.