From 20f26ea6234fc68a66af3077475530349f2dec2e Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 15 Aug 2023 15:44:15 -0400 Subject: [PATCH] reduce penalty fee to trade fee --- .../haveno/core/offer/OpenOfferManager.java | 5 ++-- .../ArbitratorProcessDepositRequest.java | 3 +-- .../tasks/ArbitratorProcessReserveTx.java | 3 +-- .../core/xmr/wallet/XmrWalletService.java | 26 +++++++++---------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index c9b89141..50d4dad9 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -1168,8 +1168,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe request.getReserveTxHash(), request.getReserveTxHex(), request.getReserveTxKey(), - request.getReserveTxKeyImages(), - true); + request.getReserveTxKeyImages()); // arbitrator signs offer to certify they have valid reserve tx byte[] signature = HavenoUtils.signOffer(request.getOfferPayload(), keyRing); @@ -1182,7 +1181,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe signedOfferPayload.getPubKeyRing().hashCode(), // trader id signedOfferPayload.getId(), offer.getAmount().longValueExact(), - txResult.second.longValueExact(), + tradeFee.longValueExact(), request.getReserveTxHash(), request.getReserveTxHex(), request.getReserveTxKeyImages(), diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java index 56c33d95..2235397e 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java @@ -96,8 +96,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask { trader.getDepositTxHash(), request.getDepositTxHex(), request.getDepositTxKey(), - null, - false); + null); } catch (Exception e) { throw new RuntimeException("Error processing deposit tx from " + (isFromTaker ? "taker " : "maker ") + trader.getNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage()); } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java index ff109056..4843cf5a 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java @@ -68,8 +68,7 @@ public class ArbitratorProcessReserveTx extends TradeTask { request.getReserveTxHash(), request.getReserveTxHex(), request.getReserveTxKey(), - null, - true); + null); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Error processing reserve tx from " + (isFromTaker ? "taker " : "maker ") + request.getSenderNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage()); diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 96f82c76..e0fd3f2d 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -353,7 +353,7 @@ public class XmrWalletService { public MoneroTxWallet createReserveTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String returnAddress, boolean reserveExactAmount, Integer preferredSubaddressIndex) { log.info("Creating reserve tx with preferred subaddress index={}, return address={}", preferredSubaddressIndex, returnAddress); long time = System.currentTimeMillis(); - MoneroTxWallet reserveTx = createTradeTx(tradeFee, sendAmount, securityDeposit, returnAddress, true, reserveExactAmount, preferredSubaddressIndex); + MoneroTxWallet reserveTx = createTradeTx(tradeFee, sendAmount, securityDeposit, returnAddress, reserveExactAmount, preferredSubaddressIndex); log.info("Done creating reserve tx in {} ms", System.currentTimeMillis() - time); return reserveTx; } @@ -382,13 +382,13 @@ public class XmrWalletService { BigInteger securityDeposit = trade instanceof BuyerTrade ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit(); long time = System.currentTimeMillis(); log.info("Creating deposit tx with multisig address={}", multisigAddress); - MoneroTxWallet depositTx = createTradeTx(tradeFee, sendAmount, securityDeposit, multisigAddress, false, reserveExactAmount, preferredSubaddressIndex); + MoneroTxWallet depositTx = createTradeTx(tradeFee, sendAmount, securityDeposit, multisigAddress, reserveExactAmount, preferredSubaddressIndex); log.info("Done creating deposit tx for trade {} {} in {} ms", trade.getClass().getSimpleName(), trade.getId(), System.currentTimeMillis() - time); return depositTx; } } - private MoneroTxWallet createTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean isReserveTx, boolean reserveExactAmount, Integer preferredSubaddressIndex) { + private MoneroTxWallet createTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean reserveExactAmount, Integer preferredSubaddressIndex) { synchronized (walletLock) { MoneroWallet wallet = getWallet(); @@ -413,26 +413,26 @@ public class XmrWalletService { // first try preferred subaddressess for (int i = 0; i < subaddressIndices.size(); i++) { try { - return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, isReserveTx, reserveExactAmount, subaddressIndices.get(i)); + return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, reserveExactAmount, subaddressIndices.get(i)); } catch (Exception e) { if (i == subaddressIndices.size() - 1 && reserveExactAmount) throw e; // throw if no subaddress with exact output } } // try any subaddress - return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, isReserveTx, reserveExactAmount, null); + return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, reserveExactAmount, null); } } - private MoneroTxWallet createTradeTxFromSubaddress(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean isReserveTx, boolean reserveExactAmount, Integer subaddressIndex) { + private MoneroTxWallet createTradeTxFromSubaddress(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean reserveExactAmount, Integer subaddressIndex) { // create tx MoneroTxWallet tradeTx = wallet.createTx(new MoneroTxConfig() .setAccountIndex(0) .setSubaddressIndices(subaddressIndex) - .addDestination(HavenoUtils.getTradeFeeAddress(), isReserveTx ? securityDeposit : tradeFee) // reserve tx charges security deposit if published - .addDestination(address, sendAmount.add(isReserveTx ? tradeFee : securityDeposit)) - .setSubtractFeeFrom(isReserveTx ? 0 : 1)); // pay fee from same destination as security deposit + .addDestination(HavenoUtils.getTradeFeeAddress(), tradeFee) + .addDestination(address, sendAmount.add(securityDeposit)) + .setSubtractFeeFrom(1)); // pay fee from security deposit // check if tx uses exact input, since wallet2 can prefer to spend 2 outputs if (reserveExactAmount) { @@ -466,7 +466,7 @@ public class XmrWalletService { * @param keyImages expected key images of inputs, ignored if null * @return tuple with the verified tx and its actual security deposit */ - public Tuple2 verifyTradeTx(String offerId, BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List keyImages, boolean isReserveTx) { + public Tuple2 verifyTradeTx(String offerId, BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List keyImages) { if (txHash == null) throw new IllegalArgumentException("Cannot verify trade tx with null id"); MoneroDaemonRpc daemon = getDaemon(); MoneroWallet wallet = getWallet(); @@ -512,9 +512,9 @@ public class XmrWalletService { if (!transferCheck.isGood()) throw new RuntimeException("Invalid proof to transfer address"); // collect actual trade fee, send amount, and security deposit - BigInteger actualTradeFee = isReserveTx ? transferCheck.getReceivedAmount().subtract(sendAmount) : tradeFeeCheck.getReceivedAmount(); - actualSecurityDeposit = isReserveTx ? tradeFeeCheck.getReceivedAmount() : transferCheck.getReceivedAmount().subtract(sendAmount); - BigInteger actualSendAmount = transferCheck.getReceivedAmount().subtract(isReserveTx ? actualTradeFee : actualSecurityDeposit); + BigInteger actualTradeFee = tradeFeeCheck.getReceivedAmount(); + actualSecurityDeposit = transferCheck.getReceivedAmount().subtract(sendAmount); + BigInteger actualSendAmount = transferCheck.getReceivedAmount().subtract(actualSecurityDeposit); // verify trade fee if (actualTradeFee.compareTo(tradeFee) < 0) {