Skip to content

Commit

Permalink
Merge branch 'master' into 06-add-remove-evt-order-workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ghubstan committed Jul 18, 2021
2 parents 649c98a + c2b0ca9 commit bf822e7
Show file tree
Hide file tree
Showing 163 changed files with 2,414 additions and 436 deletions.
23 changes: 23 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.core.api.model.PaymentAccountForm;
import bisq.core.payment.F2FAccount;
import bisq.core.payment.NationalBankAccount;
import bisq.core.proto.CoreProtoResolver;

import bisq.common.util.Utilities;
Expand Down Expand Up @@ -133,6 +134,28 @@ protected bisq.core.payment.PaymentAccount createDummyF2FAccount(GrpcClient grpc
return f2FAccount;
}


protected bisq.core.payment.PaymentAccount createDummyBRLAccount(GrpcClient grpcClient,
String holderName,
String nationalAccountId,
String holderTaxId) {
String nationalBankAccountJsonString = "{\n" +
" \"_COMMENTS_\": [ \"Dummy Account\" ],\n" +
" \"paymentMethodId\": \"NATIONAL_BANK\",\n" +
" \"accountName\": \"Banco do Brasil\",\n" +
" \"country\": \"BR\",\n" +
" \"bankName\": \"Banco do Brasil\",\n" +
" \"branchId\": \"456789-10\",\n" +
" \"holderName\": \"" + holderName + "\",\n" +
" \"accountNr\": \"456789-87\",\n" +
" \"nationalAccountId\": \"" + nationalAccountId + "\",\n" +
" \"holderTaxId\": \"" + holderTaxId + "\"\n" +
"}\n";
NationalBankAccount nationalBankAccount =
(NationalBankAccount) createPaymentAccount(grpcClient, nationalBankAccountJsonString);
return nationalBankAccount;
}

protected final bisq.core.payment.PaymentAccount createPaymentAccount(GrpcClient grpcClient, String jsonString) {
// Normally, we do asserts on the protos from the gRPC service, but in this
// case we need a bisq.core.payment.PaymentAccount so it can be cast to its
Expand Down

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions apitest/src/test/java/bisq/apitest/scenario/TradeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import bisq.apitest.method.trade.AbstractTradeTest;
import bisq.apitest.method.trade.TakeBuyBSQOfferTest;
import bisq.apitest.method.trade.TakeBuyBTCOfferTest;
import bisq.apitest.method.trade.TakeBuyBTCOfferWithNationalBankAcctTest;
import bisq.apitest.method.trade.TakeSellBSQOfferTest;
import bisq.apitest.method.trade.TakeSellBTCOfferTest;

Expand Down Expand Up @@ -77,6 +78,17 @@ public void testTakeBuyBSQOffer(final TestInfo testInfo) {

@Test
@Order(4)
public void testTakeBuyBTCOfferWithNationalBankAcct(final TestInfo testInfo) {
TakeBuyBTCOfferWithNationalBankAcctTest test = new TakeBuyBTCOfferWithNationalBankAcctTest();
test.testTakeAlicesBuyOffer(testInfo);
test.testBankAcctDetailsIncludedInContracts(testInfo);
test.testAlicesConfirmPaymentStarted(testInfo);
test.testBobsConfirmPaymentReceived(testInfo);
test.testAlicesKeepFunds(testInfo);
}

@Test
@Order(5)
public void testTakeSellBSQOffer(final TestInfo testInfo) {
TakeSellBSQOfferTest test = new TakeSellBSQOfferTest();
TakeSellBSQOfferTest.createBsqPaymentAccounts();
Expand Down
29 changes: 29 additions & 0 deletions assets/src/main/java/bisq/asset/coins/RSKSmartBitcoin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset.coins;

import bisq.asset.Coin;
import bisq.asset.EtherAddressValidator;
import bisq.asset.I18n;

public class RSKSmartBitcoin extends Coin {

public RSKSmartBitcoin() {
super("RSK Smart Bitcoin", "R-BTC", new EtherAddressValidator(I18n.DISPLAY_STRINGS.getString("account.altcoin.popup.validation.RBTC")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bisq.asset.coins.QMCoin
bisq.asset.coins.Qwertycoin
bisq.asset.coins.Radium
bisq.asset.coins.Remix
bisq.asset.coins.RSKSmartBitcoin
bisq.asset.coins.Ryo
bisq.asset.coins.Siafund
bisq.asset.coins.SiaPrimeCoin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ account.altcoin.popup.validation.XCP=XCP address must start with '1' and must ha
account.altcoin.popup.validation.DCR=DCR address must start with 'Dk' or 'Ds' or 'De' or 'DS' or 'Dc' or 'Pm' and must have 34 characters.
account.altcoin.popup.validation.ETC=ETC address must start with '0x' and made up of letters A to F and numbers which are 40 characters long.
account.altcoin.popup.validation.NMC=NMC address must start with 'N' or 'M' and must be 34 characters long.
account.altcoin.popup.validation.RBTC=RSK Smart Bitcoin address must start with '0x' and must be made up of letters 'A' to 'F' and numbers which are 40 characters long.
account.altcoin.popup.validation.SF= Siafund address must be made up of letters A to F and numbers which are 76 characters long.
account.altcoin.popup.validation.UNO=UNO address must start with 'u' and must have 34 characters.
account.altcoin.popup.validation.XZC=XZC address must start with 'a' and must have 34 characters.
account.altcoin.popup.validation.XZC=XZC address must start with 'a' and must have 34 characters.
41 changes: 41 additions & 0 deletions assets/src/test/java/bisq/asset/coins/RSKSmartBitcoinTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset.coins;

import bisq.asset.AbstractAssetTest;

public class RSKSmartBitcoinTest extends AbstractAssetTest {

public RSKSmartBitcoinTest() {
super(new RSKSmartBitcoin());
}

@Override
public void testValidAddresses() {
assertValidAddress("0x353c13b940aa5eed75aa97d477954289e7880bb8");
assertValidAddress("0x9f5304DA62A5408416Ea58A17a92611019bD5ce3");
assertValidAddress("0x180826b05452ce96E157F0708c43381Fee64a6B8");
}

@Override
public void testInvalidAddresses() {
assertInvalidAddress("MxmFPEPzF19JFPU3VPrRXvUbPjMQXnQerY");
assertInvalidAddress("N22FRU9f3fx7Hty641D5cg95kRK6S3sbf3");
assertInvalidAddress("MxmFPEPzF19JFPU3VPrRXvUbPjMQXnQerY");
}
}
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ configure(project(':desktop')) {
modules = ['javafx.controls', 'javafx.fxml']
}

version = '1.6.5-SNAPSHOT'
version = '1.7.1-SNAPSHOT'

jar.manifest.attributes(
"Implementation-Title": project.name,
Expand Down Expand Up @@ -536,6 +536,7 @@ configure(project(':pricenode')) {
testRuntime("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
}

test {
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/bisq/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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.6.5";
public static final String VERSION = "1.7.1";

/**
* Holds a list of the tagged resource files for optimizing the getData requests.
Expand Down Expand Up @@ -99,7 +99,8 @@ private static int getSubVersion(String version, int index) {
// VERSION = 0.5.0 -> TRADE_PROTOCOL_VERSION = 1
// Version 1.2.2 -> TRADE_PROTOCOL_VERSION = 2
// Version 1.5.0 -> TRADE_PROTOCOL_VERSION = 3
public static final int TRADE_PROTOCOL_VERSION = 3;
// Version 1.7.0 -> TRADE_PROTOCOL_VERSION = 4
public static final int TRADE_PROTOCOL_VERSION = 4;
private static int p2pMessageVersion;

public static final String BSQ_TX_VERSION = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.persistable.PersistableEnvelope;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.util.GcUtil;
import bisq.common.util.Utilities;

import com.google.inject.Inject;
Expand Down Expand Up @@ -319,7 +320,11 @@ public void readPersisted(String fileName, Consumer<T> resultHandler, Runnable o
new Thread(() -> {
T persisted = getPersisted(fileName);
if (persisted != null) {
UserThread.execute(() -> resultHandler.accept(persisted));
UserThread.execute(() -> {
resultHandler.accept(persisted);

GcUtil.maybeReleaseMemory();
});
} else {
UserThread.execute(orElse);
}
Expand Down Expand Up @@ -496,6 +501,8 @@ public void writeToDisk(protobuf.PersistableEnvelope serialized, @Nullable Runna
if (completeHandler != null) {
UserThread.execute(completeHandler);
}

GcUtil.maybeReleaseMemory();
}
}

Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/bisq/common/setup/CommonSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.common.app.Log;
import bisq.common.app.Version;
import bisq.common.config.Config;
import bisq.common.util.GcUtil;
import bisq.common.util.Profiler;
import bisq.common.util.Utilities;

Expand Down Expand Up @@ -54,17 +55,16 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown
Version.printVersion();
maybePrintPathOfCodeSource();
Profiler.printSystemLoad();
Profiler.printSystemLoadPeriodically(10, TimeUnit.MINUTES);

GcUtil.autoReleaseMemory();

setSystemProperties();
setupSigIntHandlers(gracefulShutDownHandler);

DevEnv.setup(config);
}

public static void printSystemLoadPeriodically(int delayMin) {
UserThread.runPeriodically(Profiler::printSystemLoad, delayMin, TimeUnit.MINUTES);
}

public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) {
Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
// Might come from another thread
Expand Down
52 changes: 52 additions & 0 deletions common/src/main/java/bisq/common/util/GcUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.common.util;

import bisq.common.UserThread;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GcUtil {
public static void autoReleaseMemory() {
autoReleaseMemory(1000);
}

/**
* @param trigger Threshold for free memory in MB when we invoke the garbage collector
*/
public static void autoReleaseMemory(long trigger) {
UserThread.runPeriodically(() -> maybeReleaseMemory(trigger), 60);
}

public static void maybeReleaseMemory() {
maybeReleaseMemory(3000);
}

/**
* @param trigger Threshold for free memory in MB when we invoke the garbage collector
*/
public static void maybeReleaseMemory(long trigger) {
long totalMemory = Runtime.getRuntime().totalMemory();
if (totalMemory > trigger * 1024 * 1024) {
log.info("Invoke garbage collector. Total memory: {} {} {}", Utilities.readableFileSize(totalMemory), totalMemory, trigger * 1024 * 1024);
System.gc();
log.info("Total memory after gc() call: {}", Utilities.readableFileSize(Runtime.getRuntime().totalMemory()));
}
}
}
20 changes: 16 additions & 4 deletions common/src/main/java/bisq/common/util/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@

package bisq.common.util;

import bisq.common.UserThread;

import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Profiler {
public static void printSystemLoadPeriodically(long delay, TimeUnit timeUnit) {
UserThread.runPeriodically(Profiler::printSystemLoad, delay, timeUnit);
}

public static void printSystemLoad() {
Runtime runtime = Runtime.getRuntime();
long free = runtime.freeMemory() / 1024 / 1024;
long total = runtime.totalMemory() / 1024 / 1024;
long free = runtime.freeMemory();
long total = runtime.totalMemory();
long used = total - free;

log.info("System report: Used memory: {} MB; Free memory: {} MB; Total memory: {} MB; No. of threads: {}",
used, free, total, Thread.activeCount());
log.info("Total memory: {}; Used memory: {}; Free memory: {}; Max memory: {}; No. of threads: {}",
Utilities.readableFileSize(total),
Utilities.readableFileSize(used),
Utilities.readableFileSize(free),
Utilities.readableFileSize(runtime.maxMemory()),
Thread.activeCount());
}

public static long getUsedMemoryInMB() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ public AccountAgeWitness getNewWitness(PaymentAccountPayload paymentAccountPaylo

Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload,
PubKeyRing pubKeyRing) {
if (paymentAccountPayload == null) {
return Optional.empty();
}

byte[] accountInputDataWithSalt = getAccountInputDataWithSalt(paymentAccountPayload);
byte[] hash = Hash.getSha256Ripemd160hash(Utilities.concatenateByteArrays(accountInputDataWithSalt,
pubKeyRing.getSignaturePubKeyBytes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public PaymentAccountPayloadInfo(String id,
this.address = address;
}

public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(PaymentAccountPayload paymentAccountPayload) {
public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(
@Nullable PaymentAccountPayload paymentAccountPayload) {
if (paymentAccountPayload == null)
return emptyPaymentAccountPayload.get();

Optional<String> address = Optional.empty();
if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload)
address = Optional.of(((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress());
Expand All @@ -58,7 +62,7 @@ else if (paymentAccountPayload instanceof InstantCryptoCurrencyPayload)
address.orElse(""));
}

// For transmitting TradeInfo messages when no contract & payloads are available.
// For transmitting TradeInfo messages when the contract or the contract's payload is not yet available.
public static Supplier<PaymentAccountPayloadInfo> emptyPaymentAccountPayload = () ->
new PaymentAccountPayloadInfo("", "", "");

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ protected void addCapabilities() {
// Headless versions can call inside launchApplication the onApplicationLaunched() manually
protected void onApplicationLaunched() {
configUserThread();
CommonSetup.printSystemLoadPeriodically(10);
// As the handler method might be overwritten by subclasses and they use the application as handler
// we need to setup the handler after the application is created.
CommonSetup.setupUncaughtExceptionHandler(this);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected void setupHandlers() {
gracefulShutDownHandler.gracefulShutDown(() -> {
});
});
bisqSetup.setTorAddressUpgradeHandler(() -> log.info("setTorAddressUpgradeHandler"));

corruptedStorageFileHandler.getFiles().ifPresent(files -> log.warn("getCorruptedDatabaseFiles. files={}", files));
tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> log.error("onTakeOfferRequestErrorMessageHandler"));
Expand Down
Loading

0 comments on commit bf822e7

Please sign in to comment.