From 068cb580412f731b67e88e93b0997b8c8f37e4c8 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Mon, 14 Oct 2019 15:26:14 +0200 Subject: [PATCH 1/2] Remove dead code --- .../account/witness/AccountAgeWitnessService.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 5c8c2c97965..0ce1bbdc95b 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -285,19 +285,6 @@ public long getWitnessSignAge(Offer offer, Date now) { .orElse(-1L); } - // Return -1 if not signed - public long getWitnessSignAge(Trade trade, Date now) { - TradingPeer tradingPeer = trade.getProcessModel().getTradingPeer(); - if (tradingPeer.getPaymentAccountPayload() == null || tradingPeer.getPubKeyRing() == null) { - // unexpected - return -1; - } - - return findWitness(tradingPeer.getPaymentAccountPayload(), tradingPeer.getPubKeyRing()) - .map(witness -> getWitnessSignAge(witness, now)) - .orElse(-1L); - } - public AccountAge getPeersAccountAgeCategory(long peersAccountAge) { return getAccountAgeCategory(peersAccountAge); } From 34785eeed243b0261dc6ac767cfb04b07c8c8604 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Mon, 14 Oct 2019 15:53:58 +0200 Subject: [PATCH 2/2] Add trade limit exception for accounts signed by arbitrator --- .../witness/AccountAgeWitnessService.java | 17 ++++++++++++----- .../java/bisq/core/payment/PaymentAccounts.java | 12 ++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 0ce1bbdc95b..379dec6989b 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -363,15 +363,22 @@ private long getTradeLimit(Coin maxTradeLimit, } /////////////////////////////////////////////////////////////////////////////////////////// - // Mature witness checks + // Trade limit exceptions /////////////////////////////////////////////////////////////////////////////////////////// private boolean isImmature(AccountAgeWitness accountAgeWitness) { return accountAgeWitness.getDate() > SAFE_ACCOUNT_AGE_DATE; } - public boolean isMyAccountAgeImmature(PaymentAccount myPaymentAccount) { - return isImmature(getMyWitness(myPaymentAccount.getPaymentAccountPayload())); + public boolean myHasTradeLimitException(PaymentAccount myPaymentAccount) { + return hasTradeLimitException(getMyWitness(myPaymentAccount.getPaymentAccountPayload())); + } + + // There are no trade limits on accounts that + // - are mature + // - were signed by an arbitrator + private boolean hasTradeLimitException(AccountAgeWitness accountAgeWitness) { + return !isImmature(accountAgeWitness) || signedWitnessService.isSignedByArbitrator(accountAgeWitness); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -402,7 +409,7 @@ public long getMyTradeLimit(PaymentAccount paymentAccount, String currencyCode, AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccount.getPaymentAccountPayload()); Coin maxTradeLimit = paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin(currencyCode); - if (!isImmature(accountAgeWitness)) { + if (hasTradeLimitException(accountAgeWitness)) { return maxTradeLimit.value; } final long accountSignAge = getWitnessSignAge(accountAgeWitness, new Date()); @@ -528,7 +535,7 @@ private boolean verifyPeersTradeLimit(Offer offer, final String currencyCode = offer.getCurrencyCode(); final Coin defaultMaxTradeLimit = PaymentMethod.getPaymentMethodById(offer.getOfferPayload().getPaymentMethodId()).getMaxTradeLimitAsCoin(currencyCode); long peersCurrentTradeLimit = defaultMaxTradeLimit.value; - if (isImmature(peersWitness)) { + if (!hasTradeLimitException(peersWitness)) { final long accountSignAge = getWitnessSignAge(peersWitness, peersCurrentDate); AccountAge accountAgeCategory = getPeersAccountAgeCategory(accountSignAge); OfferPayload.Direction direction = offer.isMyOffer(keyRing) ? diff --git a/core/src/main/java/bisq/core/payment/PaymentAccounts.java b/core/src/main/java/bisq/core/payment/PaymentAccounts.java index 3a04d637d42..c27c883449d 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccounts.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccounts.java @@ -61,7 +61,7 @@ PaymentAccount getOldestPaymentAccountForOffer(Offer offer) { } private List sortValidAccounts(Offer offer) { - Comparator comparator = this::compareBySignAgeOrMatureAccount; + Comparator comparator = this::compareByTradeLimit; return accounts.stream() .filter(account -> validator.apply(offer, account)) .sorted(comparator.reversed()) @@ -91,13 +91,13 @@ private void logAccounts(List accounts) { } } - // Accounts created before - private int compareBySignAgeOrMatureAccount(PaymentAccount left, PaymentAccount right) { + // Accounts ranked by trade limit + private int compareByTradeLimit(PaymentAccount left, PaymentAccount right) { // Mature accounts count as infinite sign age - if (!accountAgeWitnessService.isMyAccountAgeImmature(left)) { - return accountAgeWitnessService.isMyAccountAgeImmature(right) ? 1 : 0; + if (accountAgeWitnessService.myHasTradeLimitException(left)) { + return !accountAgeWitnessService.myHasTradeLimitException(right) ? 1 : 0; } - if (!accountAgeWitnessService.isMyAccountAgeImmature(right)) { + if (accountAgeWitnessService.myHasTradeLimitException(right)) { return -1; }