diff --git a/core/src/main/java/bisq/core/provider/mempool/MempoolService.java b/core/src/main/java/bisq/core/provider/mempool/MempoolService.java index d0dcf806e36..d86b052683f 100644 --- a/core/src/main/java/bisq/core/provider/mempool/MempoolService.java +++ b/core/src/main/java/bisq/core/provider/mempool/MempoolService.java @@ -96,26 +96,36 @@ public void validateOfferMakerTx(OfferPayload offerPayload, Consumer resultHandler) { - if (!isServiceSupported()) { - UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult("mempool request not supported, bypassing", true)), 1); - return; + if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) { + if (!isServiceSupported()) { + UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult("mempool request not supported, bypassing", true)), 1); + return; + } + MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider); + validateOfferMakerTx(mempoolRequest, txValidator, resultHandler); + } else { + // using BSQ for fees + UserThread.runAfter(() -> resultHandler.accept(txValidator.validateBsqFeeTx(true)), 1); } - MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider); - validateOfferMakerTx(mempoolRequest, txValidator, resultHandler); } public void validateOfferTakerTx(Trade trade, Consumer resultHandler) { validateOfferTakerTx(new TxValidator(daoStateService, trade.getTakerFeeTxId(), trade.getAmount(), - trade.isCurrencyForTakerFeeBtc(), filterManager), resultHandler); + trade.isCurrencyForTakerFeeBtc(), trade.getLockTime(), filterManager), resultHandler); } public void validateOfferTakerTx(TxValidator txValidator, Consumer resultHandler) { - if (!isServiceSupported()) { - UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult("mempool request not supported, bypassing", true)), 1); - return; + if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) { + if (!isServiceSupported()) { + UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult("mempool request not supported, bypassing", true)), 1); + return; + } + MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider); + validateOfferTakerTx(mempoolRequest, txValidator, resultHandler); + } else { + // using BSQ for fees + resultHandler.accept(txValidator.validateBsqFeeTx(false)); } - MempoolRequest mempoolRequest = new MempoolRequest(preferences, socks5ProxyProvider); - validateOfferTakerTx(mempoolRequest, txValidator, resultHandler); } public void checkTxIsConfirmed(String txId, Consumer resultHandler) { diff --git a/core/src/main/java/bisq/core/provider/mempool/TxValidator.java b/core/src/main/java/bisq/core/provider/mempool/TxValidator.java index 566253eddca..0d71fd55f1b 100644 --- a/core/src/main/java/bisq/core/provider/mempool/TxValidator.java +++ b/core/src/main/java/bisq/core/provider/mempool/TxValidator.java @@ -19,6 +19,7 @@ import bisq.core.dao.governance.param.Param; import bisq.core.dao.state.DaoStateService; +import bisq.core.dao.state.model.blockchain.Tx; import bisq.core.filter.FilterManager; import bisq.common.util.Tuple2; @@ -56,12 +57,12 @@ public class TxValidator { private final DaoStateService daoStateService; private final FilterManager filterManager; - private long blockHeightAtOfferCreation; // Only set for maker. + private long feePaymentBlockHeight; // applicable to maker and taker fees private final List errorList; private final String txId; private Coin amount; @Nullable - private Boolean isFeeCurrencyBtc = null; + private Boolean isFeeCurrencyBtc; @Nullable private Long chainHeight; @Setter @@ -70,28 +71,14 @@ public class TxValidator { public TxValidator(DaoStateService daoStateService, String txId, Coin amount, - @Nullable Boolean isFeeCurrencyBtc, + boolean isFeeCurrencyBtc, + long feePaymentBlockHeight, FilterManager filterManager) { this.daoStateService = daoStateService; this.txId = txId; this.amount = amount; this.isFeeCurrencyBtc = isFeeCurrencyBtc; - this.filterManager = filterManager; - this.errorList = new ArrayList<>(); - this.jsonTxt = ""; - } - - public TxValidator(DaoStateService daoStateService, - String txId, - Coin amount, - @Nullable Boolean isFeeCurrencyBtc, - long blockHeightAtOfferCreation, - FilterManager filterManager) { - this.daoStateService = daoStateService; - this.txId = txId; - this.amount = amount; - this.isFeeCurrencyBtc = isFeeCurrencyBtc; - this.blockHeightAtOfferCreation = blockHeightAtOfferCreation; + this.feePaymentBlockHeight = feePaymentBlockHeight; this.filterManager = filterManager; this.errorList = new ArrayList<>(); this.jsonTxt = ""; @@ -119,8 +106,6 @@ public TxValidator parseJsonValidateMakerFeeTx(String jsonTxt, List btcF if (checkNotNull(isFeeCurrencyBtc)) { status = checkFeeAddressBTC(jsonTxt, btcFeeReceivers) && checkFeeAmountBTC(jsonTxt, amount, true, getBlockHeightForFeeCalculation(jsonTxt)); - } else { - status = checkFeeAmountBSQ(jsonTxt, amount, true, getBlockHeightForFeeCalculation(jsonTxt)); } } } catch (JsonSyntaxException e) { @@ -132,6 +117,17 @@ public TxValidator parseJsonValidateMakerFeeTx(String jsonTxt, List btcF return endResult("Maker tx validation", status); } + public TxValidator validateBsqFeeTx(boolean isMaker) { + Optional tx = daoStateService.getTx(txId); + String statusStr = isMaker ? "Maker" : "Taker" + " tx validation"; + if (tx.isEmpty()) { + log.info("DAO does not yet have the tx {}, bypassing check of burnt BSQ amount.", txId); + return endResult(statusStr, true); + } else { + return endResult(statusStr, checkFeeAmountBSQ(tx.get(), amount, isMaker, feePaymentBlockHeight)); + } + } + public TxValidator parseJsonValidateTakerFeeTx(String jsonTxt, List btcFeeReceivers) { this.jsonTxt = jsonTxt; boolean status = initialSanityChecks(txId, jsonTxt); @@ -143,8 +139,6 @@ public TxValidator parseJsonValidateTakerFeeTx(String jsonTxt, List btcF if (isFeeCurrencyBtc) { status = checkFeeAddressBTC(jsonTxt, btcFeeReceivers) && checkFeeAmountBTC(jsonTxt, amount, false, getBlockHeightForFeeCalculation(jsonTxt)); - } else { - status = checkFeeAmountBSQ(jsonTxt, amount, false, getBlockHeightForFeeCalculation(jsonTxt)); } } } catch (JsonSyntaxException e) { @@ -250,28 +244,16 @@ private boolean checkFeeAmountBTC(String jsonTxt, Coin tradeAmount, boolean isMa return false; } - // I think its better to postpone BSQ fee check once the BSQ trade fee tx is confirmed and then use the BSQ explorer to request the - // BSQ fee to check if it is correct. - // Otherwise the requirements here become very complicated and potentially impossible to verify as we don't know - // if inputs and outputs are valid BSQ without the BSQ parser and confirmed transactions. - private boolean checkFeeAmountBSQ(String jsonTxt, Coin tradeAmount, boolean isMaker, long blockHeight) { - JsonArray jsonVin = getVinAndVout(jsonTxt).first; - JsonArray jsonVout = getVinAndVout(jsonTxt).second; - JsonObject jsonVin0 = jsonVin.get(0).getAsJsonObject(); - JsonObject jsonVout0 = jsonVout.get(0).getAsJsonObject(); - JsonElement jsonVIn0Value = jsonVin0.getAsJsonObject("prevout").get("value"); - JsonElement jsonVOut0Value = jsonVout0.getAsJsonObject().get("value"); - if (jsonVIn0Value == null || jsonVOut0Value == null) { - throw new JsonSyntaxException("vin/vout missing data"); - } + private boolean checkFeeAmountBSQ(Tx bsqTx, Coin tradeAmount, boolean isMaker, long blockHeight) { Param minFeeParam = isMaker ? Param.MIN_MAKER_FEE_BSQ : Param.MIN_TAKER_FEE_BSQ; long expectedFeeAsLong = calculateFee(tradeAmount, isMaker ? getMakerFeeRateBsq(blockHeight) : getTakerFeeRateBsq(blockHeight), minFeeParam).getValue(); - long feeValue = getBsqBurnt(jsonVin, jsonVOut0Value.getAsLong(), expectedFeeAsLong); + + long feeValue = bsqTx.getBurntBsq(); log.debug("BURNT BSQ maker fee: {} BSQ ({} sats)", (double) feeValue / 100.0, feeValue); - String description = String.format("Expected fee: %.2f BSQ, actual fee paid: %.2f BSQ", - (double) expectedFeeAsLong / 100.0, (double) feeValue / 100.0); + String description = String.format("Expected fee: %.2f BSQ, actual fee paid: %.2f BSQ, Trade amount: %s", + (double) expectedFeeAsLong / 100.0, (double) feeValue / 100.0, tradeAmount.toPlainString()); if (expectedFeeAsLong == feeValue) { log.debug("The fee matched. " + description); @@ -279,7 +261,7 @@ private boolean checkFeeAmountBSQ(String jsonTxt, Coin tradeAmount, boolean isMa } if (expectedFeeAsLong < feeValue) { - log.info("The fee was more than what we expected. " + description); + log.info("The fee was more than what we expected. " + description + " Tx:" + bsqTx.getId()); return true; } @@ -350,39 +332,6 @@ private static boolean initialSanityChecks(String txId, String jsonTxt) { // we don't care if it is confirmed or not, just that it exists. } - // a BSQ maker/taker fee transaction looks like this: - // BSQ INPUT 1 BSQ OUTPUT - // BSQ INPUT 2 BTC OUTPUT FOR RESERVED AMOUNT - // BSQ INPUT n BTC OUTPUT FOR CHANGE - // BTC INPUT 1 - // BTC INPUT 2 - // BTC INPUT n - // there can be any number of BSQ inputs and BTC inputs - // BSQ inputs always come first in the tx, followed by BTC for the collateral. - // the sum of all BSQ inputs minus the BSQ output is the burnt amount, or trading fee. - long getBsqBurnt(JsonArray jsonVin, long bsqOutValue, long expectedFee) { - // sum consecutive inputs until we have accumulated enough to cover the output + burnt amount - long bsqInValue = 0; - for (int txIndex = 0; txIndex < jsonVin.size() - 1; txIndex++) { - bsqInValue += jsonVin.get(txIndex).getAsJsonObject().getAsJsonObject("prevout").get("value").getAsLong(); - if (bsqInValue - expectedFee >= bsqOutValue) { - break; // target reached - bsq input exceeds the output and expected burn amount - } - } - // guard against negative burn amount (i.e. only 1 tx input, or first in < first out) - long burntAmount = Math.max(0, bsqInValue - bsqOutValue); - // since we do not know which of the first 'n' are definitively BSQ inputs, sanity-check that the burnt amount - // is not too ridiculously high, as that would imply that we counted a BTC input. - if (burntAmount > 10 * expectedFee) { - log.error("The apparent BSQ fee burnt seems ridiculously high ({}) compared to expected ({})", burntAmount, expectedFee); - burntAmount = 0; // returning zero will flag the trade for manual review - } - if (burntAmount == 0) { - log.error("Could not obtain the burnt BSQ amount, trade will be flagged for manual review."); - } - return burntAmount; - } - private static long getTxConfirms(String jsonTxt, long chainHeight) { long blockHeight = getTxBlockHeight(jsonTxt); if (blockHeight > 0) { @@ -395,8 +344,8 @@ private static long getTxConfirms(String jsonTxt, long chainHeight) { // if the tx is not yet confirmed, use current block tip, if tx is confirmed use the block it was confirmed at. private long getBlockHeightForFeeCalculation(String jsonTxt) { // For the maker we set the blockHeightAtOfferCreation from the offer - if (blockHeightAtOfferCreation > 0) { - return blockHeightAtOfferCreation; + if (feePaymentBlockHeight > 0) { + return feePaymentBlockHeight; } long txBlockHeight = getTxBlockHeight(jsonTxt); diff --git a/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java b/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java index 35b6048eccd..67face6768a 100644 --- a/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java +++ b/core/src/main/java/bisq/core/trade/model/bisq_v1/Trade.java @@ -897,6 +897,10 @@ public Date getMaxTradePeriodDate() { return new Date(getTradeStartTime() + getMaxTradePeriod()); } + public long getTradeAge() { + return System.currentTimeMillis() - getTradeStartTime(); + } + private long getMaxTradePeriod() { return offer.getPaymentMethod().getMaxTradePeriod(); } diff --git a/core/src/test/java/bisq/core/provider/mempool/TxValidatorTest.java b/core/src/test/java/bisq/core/provider/mempool/TxValidatorTest.java index 793941e35ae..105c3cdb5b1 100644 --- a/core/src/test/java/bisq/core/provider/mempool/TxValidatorTest.java +++ b/core/src/test/java/bisq/core/provider/mempool/TxValidatorTest.java @@ -19,6 +19,7 @@ import bisq.core.dao.governance.param.Param; import bisq.core.dao.state.DaoStateService; +import bisq.core.dao.state.model.blockchain.Tx; import bisq.core.filter.Filter; import bisq.core.filter.FilterManager; import bisq.core.trade.DelayedPayoutAddressProvider; @@ -39,6 +40,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.slf4j.Logger; @@ -77,30 +79,35 @@ public TxValidatorTest() { public void testMakerTx() { String mempoolData, offerData; + log.info("checking issue from user 2022-10-07"); + offerData = "1322804,5bec4007de1cb8cf18a5fa859d80d66031b8c78cfd99674e09ffd65cf23b50fc,9630000,137,0,757500"; + mempoolData = "{\"txid\":\"5bec4007de1cb8cf18a5fa859d80d66031b8c78cfd99674e09ffd65cf23b50fc\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":8921}},{\"vout\":1,\"prevout\":{\"value\":12155000}},{\"vout\":1,\"prevout\":{\"value\":2967000}}],\"vout\":[{\"scriptpubkey_address\":\"bc1qtyl6dququ2amxtsh4f3kx5rk9f5w9cuscz7ugm\",\"value\":8784},{\"scriptpubkey_address\":\"bc1qwj0jktuyjwj2ecwp9wgcrztxhve0hwn7n5lnxg\",\"value\":12519000},{\"scriptpubkey_address\":\"bc1qn3rd52mzkp6mgduz5wxprjw4rk9xpft6kga2mk\",\"value\":2600037}],\"size\":551,\"weight\":1229,\"fee\":3100,\"status\":{\"confirmed\":true,\"block_height\":757528,\"block_hash\":\"00000000000000000006b4426a0d2688a7e933e563e4d4fd80f572d935b12ae9\",\"block_time\":1665150690}}"; + Assert.assertTrue(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + log.info("expected: paid the correct amount of BSQ fees"); offerData = "msimscqb,0636bafb14890edfb95465e66e2b1e15915f7fb595f9b653b9129c15ef4c1c4b,1000000,10,0,662390"; mempoolData = "{\"txid\":\"0636bafb14890edfb95465e66e2b1e15915f7fb595f9b653b9129c15ef4c1c4b\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":7899}},{\"vout\":2,\"prevout\":{\"value\":54877439}}],\"vout\":[{\"scriptpubkey_address\":\"1FCUu7hqKCSsGhVJaLbGEoCWdZRJRNqq8w\",\"value\":7889},{\"scriptpubkey_address\":\"bc1qkj5l4wxl00ufdx6ygcnrck9fz5u927gkwqcgey\",\"value\":1600000},{\"scriptpubkey_address\":\"bc1qkw4a8u9l5w9fhdh3ue9v7e7celk4jyudzg5gk5\",\"value\":53276799}],\"size\":405,\"weight\":1287,\"fee\":650,\"status\":{\"confirmed\":true,\"block_height\":663140}}"; Assert.assertTrue(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); log.info("expected: paid the correct amount of BSQ fees with two UTXOs"); - offerData = "qmmtead,94b2589f3270caa0df63437707d4442cae34498ee5b0285090deed9c0ce8584d,800000,10,0,705301"; + offerData = "qmmtead,94b2589f3270caa0df63437707d4442cae34498ee5b0285090deed9c0ce8584d,800000,11,0,705301"; mempoolData = "{\"txid\":\"94b2589f3270caa0df63437707d4442cae34498ee5b0285090deed9c0ce8584d\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":577}},{\"vout\":0,\"prevout\":{\"value\":19989}},{\"vout\":2,\"prevout\":{\"value\":3008189}}],\"vout\":[{\"scriptpubkey_address\":\"bc1q48p2nvqf3tepjy7x33c5sfx3tp89e8c05z46cs\",\"value\":20555},{\"scriptpubkey_address\":\"bc1q9h69k8l0vy2yv3c72lw2cgn95sd7hlwjjzul05\",\"value\":920000},{\"scriptpubkey_address\":\"bc1qxmwscy2krw7zzfryw5g8868dexfy6pnq9yx3rv\",\"value\":2085750}],\"size\":550,\"weight\":1228,\"fee\":2450,\"status\":{\"confirmed\":true,\"block_height\":705301}}"; Assert.assertTrue(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); log.info("expected: UNDERPAID expected 1.01 BSQ, actual fee paid 0.80 BSQ (USED 8.00 RATE INSTEAD OF 10.06 RATE"); offerData = "48067552,3b6009da764b71d79a4df8e2d8960b6919cae2e9bdccd5ef281e261fa9cd31b3,10000000,80,0,667656"; - mempoolData = "{\"txid\":\"3b6009da764b71d79a4df8e2d8960b6919cae2e9bdccd5ef281e261fa9cd31b3\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":9717}},{\"vout\":0,\"prevout\":{\"value\":4434912}},{\"vout\":2,\"prevout\":{\"value\":12809932}}],\"vout\":[{\"scriptpubkey_address\":\"1Nzqa4J7ck5bgz7QNXKtcjZExAvReozFo4\",\"value\":9637},{\"scriptpubkey_address\":\"bc1qhmmulf5prreqhccqy2wqpxxn6dcye7ame9dd57\",\"value\":11500000},{\"scriptpubkey_address\":\"bc1qx6hg8km2jdjc5ukhuedmkseu9wlsjtd8zeajpj\",\"value\":5721894}],\"size\":553,\"weight\":1879,\"fee\":23030,\"status\":{\"confirmed\":true,\"block_height\":667660}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + //mempoolData = "{\"txid\":\"3b6009da764b71d79a4df8e2d8960b6919cae2e9bdccd5ef281e261fa9cd31b3\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":9717}},{\"vout\":0,\"prevout\":{\"value\":4434912}},{\"vout\":2,\"prevout\":{\"value\":12809932}}],\"vout\":[{\"scriptpubkey_address\":\"1Nzqa4J7ck5bgz7QNXKtcjZExAvReozFo4\",\"value\":9637},{\"scriptpubkey_address\":\"bc1qhmmulf5prreqhccqy2wqpxxn6dcye7ame9dd57\",\"value\":11500000},{\"scriptpubkey_address\":\"bc1qx6hg8km2jdjc5ukhuedmkseu9wlsjtd8zeajpj\",\"value\":5721894}],\"size\":553,\"weight\":1879,\"fee\":23030,\"status\":{\"confirmed\":true,\"block_height\":667660}}"; + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(true).getResult()); log.info("expected: UNDERPAID Expected fee: 0.61 BSQ, actual fee paid: 0.35 BSQ (USED 5.75 RATE INSTEAD OF 10.06 RATE"); offerData = "am7DzIv,4cdea8872a7d96210f378e0221dc1aae8ee9abb282582afa7546890fb39b7189,6100000,35,0,668195"; - mempoolData = "{\"txid\":\"4cdea8872a7d96210f378e0221dc1aae8ee9abb282582afa7546890fb39b7189\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":23893}},{\"vout\":1,\"prevout\":{\"value\":1440000}},{\"vout\":2,\"prevout\":{\"value\":16390881}}],\"vout\":[{\"scriptpubkey_address\":\"1Kmrzq3WGCQsZw5kroEphuk1KgsEr65yB7\",\"value\":23858},{\"scriptpubkey_address\":\"bc1qyw5qql9m7rkse9mhcun225nrjpwycszsa5dpjg\",\"value\":7015000},{\"scriptpubkey_address\":\"bc1q90y3p6mg0pe3rvvzfeudq4mfxafgpc9rulruff\",\"value\":10774186}],\"size\":554,\"weight\":1559,\"fee\":41730,\"status\":{\"confirmed\":true,\"block_height\":668198}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + //mempoolData = "{\"txid\":\"4cdea8872a7d96210f378e0221dc1aae8ee9abb282582afa7546890fb39b7189\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":23893}},{\"vout\":1,\"prevout\":{\"value\":1440000}},{\"vout\":2,\"prevout\":{\"value\":16390881}}],\"vout\":[{\"scriptpubkey_address\":\"1Kmrzq3WGCQsZw5kroEphuk1KgsEr65yB7\",\"value\":23858},{\"scriptpubkey_address\":\"bc1qyw5qql9m7rkse9mhcun225nrjpwycszsa5dpjg\",\"value\":7015000},{\"scriptpubkey_address\":\"bc1q90y3p6mg0pe3rvvzfeudq4mfxafgpc9rulruff\",\"value\":10774186}],\"size\":554,\"weight\":1559,\"fee\":41730,\"status\":{\"confirmed\":true,\"block_height\":668198}}"; + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(true).getResult()); log.info("expected: UNDERPAID expected 0.11 BSQ, actual fee paid 0.08 BSQ (USED 5.75 RATE INSTEAD OF 7.53"); offerData = "F1dzaFNQ,f72e263947c9dee6fbe7093fc85be34a149ef5bcfdd49b59b9cc3322fea8967b,1440000,8,0,670822, bsq paid too little"; - mempoolData = "{\"txid\":\"f72e263947c9dee6fbe7093fc85be34a149ef5bcfdd49b59b9cc3322fea8967b\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":15163}},{\"vout\":2,\"prevout\":{\"value\":6100000}}],\"vout\":[{\"scriptpubkey_address\":\"1MEsc2m4MSomNJWSr1p6fhnUQMyA3DRGrN\",\"value\":15155},{\"scriptpubkey_address\":\"bc1qztgwe9ry9a9puchjuscqdnv4v9lsm2ut0jtfec\",\"value\":2040000},{\"scriptpubkey_address\":\"bc1q0nstwxc0vqkj4x000xt328mfjapvlsd56nn70h\",\"value\":4048308}],\"size\":406,\"weight\":1291,\"fee\":11700,\"status\":{\"confirmed\":true,\"block_height\":670823}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateMakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + //mempoolData = "{\"txid\":\"f72e263947c9dee6fbe7093fc85be34a149ef5bcfdd49b59b9cc3322fea8967b\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":15163}},{\"vout\":2,\"prevout\":{\"value\":6100000}}],\"vout\":[{\"scriptpubkey_address\":\"1MEsc2m4MSomNJWSr1p6fhnUQMyA3DRGrN\",\"value\":15155},{\"scriptpubkey_address\":\"bc1qztgwe9ry9a9puchjuscqdnv4v9lsm2ut0jtfec\",\"value\":2040000},{\"scriptpubkey_address\":\"bc1q0nstwxc0vqkj4x000xt328mfjapvlsd56nn70h\",\"value\":4048308}],\"size\":406,\"weight\":1291,\"fee\":11700,\"status\":{\"confirmed\":true,\"block_height\":670823}}"; + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(true).getResult()); } @Test @@ -115,22 +122,17 @@ public void testTakerTx() { log.info("========== test case: The fee matched what we expected (BSQ)"); offerData = "00072328,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,188,0,615955"; mempoolData = "{\"txid\":\"12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":19980}},{\"vout\":2,\"prevout\":{\"value\":2086015}},{\"vout\":0,\"prevout\":{\"value\":1100000}},{\"vout\":2,\"prevout\":{\"value\":938200}}],\"vout\":[{\"scriptpubkey_address\":\"17qiF1TYgT1YvsCPJyXQoKMtBZ7YJBW9GH\",\"value\":19792},{\"scriptpubkey_address\":\"16aFKD5hvEjJgPme5yRNJT2rAPdTXzdQc2\",\"value\":3768432},{\"scriptpubkey_address\":\"1D5V3QW8f5n4PhwfPgNkW9eWZwNJFyVU8n\",\"value\":346755}],\"size\":701,\"weight\":2804,\"fee\":9216,\"status\":{\"confirmed\":true,\"block_height\":615955}}"; - Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertTrue(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: No BSQ was burnt (error)"); - offerData = "NOBURN,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,188,0,615955"; + offerData = "NOBURN,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,0,0,615955"; mempoolData = "{\"txid\":\"12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":19980}},{\"vout\":2,\"prevout\":{\"value\":2086015}},{\"vout\":0,\"prevout\":{\"value\":1100000}},{\"vout\":2,\"prevout\":{\"value\":938200}}],\"vout\":[{\"scriptpubkey_address\":\"17qiF1TYgT1YvsCPJyXQoKMtBZ7YJBW9GH\",\"value\":19980},{\"scriptpubkey_address\":\"16aFKD5hvEjJgPme5yRNJT2rAPdTXzdQc2\",\"value\":3768432},{\"scriptpubkey_address\":\"1D5V3QW8f5n4PhwfPgNkW9eWZwNJFyVU8n\",\"value\":346755}],\"size\":701,\"weight\":2804,\"fee\":9216,\"status\":{\"confirmed\":true,\"block_height\":615955}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: No BSQ input (error)"); - offerData = "NOBSQ,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,188,0,615955"; + offerData = "NOBSQ,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,0,0,615955"; mempoolData = "{\"txid\":\"12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":2,\"prevout\":{\"value\":2086015}},{\"vout\":0,\"prevout\":{\"value\":1100000}},{\"vout\":2,\"prevout\":{\"value\":938200}}],\"vout\":[{\"scriptpubkey_address\":\"16aFKD5hvEjJgPme5yRNJT2rAPdTXzdQc2\",\"value\":3768432},{\"scriptpubkey_address\":\"1D5V3QW8f5n4PhwfPgNkW9eWZwNJFyVU8n\",\"value\":346755}],\"size\":701,\"weight\":2804,\"fee\":9216,\"status\":{\"confirmed\":true,\"block_height\":615955}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); - - log.info("========== test case: only one input (error)"); - offerData = "1INPUT,12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166,6250000,188,0,615955"; - mempoolData = "{\"txid\":\"12f658954890d38ce698355be0b27fdd68d092c7b1b7475381918db060f46166\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":2,\"prevout\":{\"value\":4186015}}],\"vout\":[{\"scriptpubkey_address\":\"16aFKD5hvEjJgPme5yRNJT2rAPdTXzdQc2\",\"value\":3768432},{\"scriptpubkey_address\":\"1D5V3QW8f5n4PhwfPgNkW9eWZwNJFyVU8n\",\"value\":346755}],\"size\":701,\"weight\":2804,\"fee\":9216,\"status\":{\"confirmed\":true,\"block_height\":615955}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: The fee was what we expected: (7000 sats)"); offerData = "bsqtrade,dfa4555ab78c657cad073e3f29c38c563d9dafc53afaa8c6af28510c734305c4,1000000,10,1,662390"; @@ -138,14 +140,14 @@ public void testTakerTx() { Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); log.info("========== test case: The fee matched what we expected"); - offerData = "89284,e1269aad63b3d894f5133ad658960971ef5c0fce6a13ad10544dc50fa3360588,900000,9,0,666473"; + offerData = "89284,e1269aad63b3d894f5133ad658960971ef5c0fce6a13ad10544dc50fa3360588,900000,47,0,666473"; mempoolData = "{\"txid\":\"e1269aad63b3d894f5133ad658960971ef5c0fce6a13ad10544dc50fa3360588\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":72738}},{\"vout\":0,\"prevout\":{\"value\":1600000}}],\"vout\":[{\"scriptpubkey_address\":\"17Kh5Ype9yNomqRrqu2k1mdV5c6FcKfGwQ\",\"value\":72691},{\"scriptpubkey_address\":\"bc1qdr9zcw7gf2sehxkux4fmqujm5uguhaqz7l9lca\",\"value\":629016},{\"scriptpubkey_address\":\"bc1qgqrrqv8q6l5d3t52fe28ghuhz4xqrsyxlwn03z\",\"value\":956523}],\"size\":404,\"weight\":1286,\"fee\":14508,\"status\":{\"confirmed\":true,\"block_height\":672388}}"; Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); log.info("========== test case for UNDERPAID: Expected fee: 7.04 BSQ, actual fee paid: 1.01 BSQ"); offerData = "VOxRS,e99ea06aefc824fd45031447f7a0b56efb8117a09f9b8982e2c4da480a3a0e91,10000000,101,0,669129"; mempoolData = "{\"txid\":\"e99ea06aefc824fd45031447f7a0b56efb8117a09f9b8982e2c4da480a3a0e91\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":16739}},{\"vout\":2,\"prevout\":{\"value\":113293809}}],\"vout\":[{\"scriptpubkey_address\":\"1F14nF6zoUfJkqZrFgdmK5VX5QVwEpAnKW\",\"value\":16638},{\"scriptpubkey_address\":\"bc1q80y688ev7u43vqy964yf7feqddvt2mkm8977cm\",\"value\":11500000},{\"scriptpubkey_address\":\"bc1q9whgyc2du9mrgnxz0nl0shwpw8ugrcae0j0w8p\",\"value\":101784485}],\"size\":406,\"weight\":1291,\"fee\":9425,\"status\":{\"confirmed\":true,\"block_height\":669134}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case for UNDERPAID: Expected fee: 1029000 sats BTC, actual fee paid: 441000 sats BTC because they used the default rate of 0.003 should have been 0.007 per BTC"); // after 1.6.0 we introduce additional leniency to allow the default rate (which is not stored in the DAO param change list) @@ -155,29 +157,29 @@ public void testTakerTx() { Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); log.info("========== test case for UNDERPAID: Expected fee: 2.12 BSQ, actual fee paid: 0.03 BSQ -- this is the example from the BSQ fee scammer Oct 2021"); - offerData = "957500,26e1a5e1f842cb7baa18bd197bd084e7f043d07720b9853e947158eb0a32677d,2000000,101,0,709426"; + offerData = "957500,26e1a5e1f842cb7baa18bd197bd084e7f043d07720b9853e947158eb0a32677d,2000000,101,3,709426"; mempoolData = "{\"txid\":\"26e1a5e1f842cb7baa18bd197bd084e7f043d07720b9853e947158eb0a32677d\",\"version\":1,\"locktime\":0,\"vin\":[{\"txid\":\"\",\"vout\":0,\"prevout\":{\"scriptpubkey\":\"\",\"scriptpubkey_asm\":\"\",\"scriptpubkey_type\":\"v0_p2wpkh\",\"scriptpubkey_address\":\"\",\"value\":3688},\"scriptsig\":\"\",\"scriptsig_asm\":\"\",\"witness\":[\"\",\"\"],\"is_coinbase\":false,\"sequence\":4294967295},{\"txid\":\"\",\"vout\":2,\"prevout\":{\"scriptpubkey\":\"\",\"scriptpubkey_asm\":\"\",\"scriptpubkey_type\":\"v0_p2wpkh\",\"scriptpubkey_address\":\"\",\"value\":796203},\"scriptsig\":\"\",\"scriptsig_asm\":\"\",\"witness\":[\"\",\"\"],\"is_coinbase\":false,\"sequence\":4294967295}],\"vout\":[{\"scriptpubkey\":\"\",\"scriptpubkey_asm\":\"\",\"scriptpubkey_type\":\"v0_p2wpkh\",\"scriptpubkey_address\":\"bc1qydcyfe7kp6968hywcp0uek2xvgem3nlx0x0hfy\",\"value\":3685},{\"scriptpubkey\":\"\",\"scriptpubkey_asm\":\"\",\"scriptpubkey_type\":\"v0_p2wpkh\",\"scriptpubkey_address\":\"bc1qc4amk6sd3c4gzxjgd5sdlaegt0r5juq54vnrll\",\"value\":503346},{\"scriptpubkey\":\"\",\"scriptpubkey_asm\":\"\",\"scriptpubkey_type\":\"v0_p2wpkh\",\"scriptpubkey_address\":\"bc1q66e7m8y5lzfk5smg2a80xeaqzhslgeavg9y70t\",\"value\":291187}],\"size\":403,\"weight\":958,\"fee\":1673,\"status\":{\"confirmed\":true,\"block_height\":709426,\"block_hash\":\"\",\"block_time\":1636751288}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: expected fee paid using two BSQ UTXOs"); - offerData = "ZHNYCAE,a91c6f1cb62721a7943678547aa814d6f29125ed63ad076073eb5ae7f16a76e9,83000000,101,0,717000"; + offerData = "ZHNYCAE,a91c6f1cb62721a7943678547aa814d6f29125ed63ad076073eb5ae7f16a76e9,83000000,8796,0,717000"; mempoolData = "{\"txid\":\"a91c6f1cb62721a7943678547aa814d6f29125ed63ad076073eb5ae7f16a76e9\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":3510}},{\"vout\":0,\"prevout\":{\"value\":6190}},{\"vout\":0,\"prevout\":{\"value\":46000000}}],\"vout\":[{\"scriptpubkey_address\":\"bc1qmqphx028eu4tzdvgccf5re52qtv6pmjanrpq29\",\"value\":904},{\"scriptpubkey_address\":\"bc1qtkvu4zeh0g0pce452335tgnswxd8ayxlktfj2s\",\"value\":30007648},{\"scriptpubkey_address\":\"bc1qdatwgzrrntp2m53tpzmax4dxu6md2c0c9vj8ut\",\"value\":15997324}],\"size\":549,\"weight\":1227,\"fee\":3824,\"status\":{\"confirmed\":true,\"block_height\":716444}}"; - Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertTrue(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: expected fee paid using three BSQ UTXOs"); - offerData = "3UTXOGOOD,c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262,200000000,101,0,733715"; + offerData = "3UTXOGOOD,c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262,200000000,17888,0,733715"; mempoolData = "{\"txid\":\"c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":9833}},{\"vout\":0,\"prevout\":{\"value\":1362}},{vout\":0,\"prevout\":{\"value\":17488}},{\"vout\":2,\"prevout\":{\"value\":573360131}}],\"vout\":[{\"scriptpubkey_address\":\"bc1qvwpm87kmrlgave9srxk6nfwleehll0kxetu5j0\",\"value\":10795},{\"scriptpubkey_address\":\"bc1qz5n83ppfpdznnzff4e7tjep5c6f6jce9mqnrzh\",\"value\":230004780},{\"scriptpubkey_address\":\"bc1qcfyjajhuv55fyu6g5ug664r57u9a7qg55cgt5p\",\"value\":343370849}],\"size\":699,\"weight\":1500,\"fee\":2390,\"status\":{\"confirmed\":true,\"block_height\":733715}}"; - Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertTrue(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: expected fee paid using four BSQ UTXOs"); - offerData = "4UTXOGOOD,c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262,200000000,101,0,733715"; + offerData = "4UTXOGOOD,c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262,200000000,17888,0,733715"; mempoolData = "{\"txid\":\"c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":4833}},{\"vout\":0,\"prevout\":{\"value\":5000}},{\"vout\":0,\"prevout\":{\"value\":1362}},{vout\":0,\"prevout\":{\"value\":17488}},{\"vout\":2,\"prevout\":{\"value\":573360131}}],\"vout\":[{\"scriptpubkey_address\":\"bc1qvwpm87kmrlgave9srxk6nfwleehll0kxetu5j0\",\"value\":10795},{\"scriptpubkey_address\":\"bc1qz5n83ppfpdznnzff4e7tjep5c6f6jce9mqnrzh\",\"value\":230004780},{\"scriptpubkey_address\":\"bc1qcfyjajhuv55fyu6g5ug664r57u9a7qg55cgt5p\",\"value\":343370849}],\"size\":699,\"weight\":1500,\"fee\":2390,\"status\":{\"confirmed\":true,\"block_height\":733715}}"; - Assert.assertTrue(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertTrue(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); log.info("========== test case: three BSQ UTXOs, but fee paid is too low"); offerData = "3UTXOLOWFEE,c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262,200000000,101,0,733715"; mempoolData = "{\"txid\":\"c7dddc267a366fa1d87840eeb0dcd89918a886ccb9aabee80f667635a5d4e262\",\"version\":1,\"locktime\":0,\"vin\":[{\"vout\":0,\"prevout\":{\"value\":9833}},{\"vout\":0,\"prevout\":{\"value\":1362}},{vout\":0,\"prevout\":{\"value\":1362}},{\"vout\":2,\"prevout\":{\"value\":573360131}}],\"vout\":[{\"scriptpubkey_address\":\"bc1qvwpm87kmrlgave9srxk6nfwleehll0kxetu5j0\",\"value\":10795},{\"scriptpubkey_address\":\"bc1qz5n83ppfpdznnzff4e7tjep5c6f6jce9mqnrzh\",\"value\":230004780},{\"scriptpubkey_address\":\"bc1qcfyjajhuv55fyu6g5ug664r57u9a7qg55cgt5p\",\"value\":343370849}],\"size\":699,\"weight\":1500,\"fee\":2390,\"status\":{\"confirmed\":true,\"block_height\":733715}}"; - Assert.assertFalse(createTxValidator(offerData).parseJsonValidateTakerFeeTx(mempoolData, btcFeeReceivers).getResult()); + Assert.assertFalse(createTxValidator(offerData).validateBsqFeeTx(false).getResult()); } @@ -207,12 +209,17 @@ private void testOfferSet(Map offers, Map mempoo knownValuesList.forEach(offerData -> { TxValidator txValidator = createTxValidator(offerData); log.warn("TESTING {}", txValidator.getTxId()); - String jsonTxt = mempoolData.get(txValidator.getTxId()); - if (jsonTxt == null || jsonTxt.isEmpty()) { - log.warn("{} was not found in the mempool", txValidator.getTxId()); - Assert.assertFalse(expectedResult); // tx was not found in explorer + if (txValidator.getIsFeeCurrencyBtc() != null && txValidator.getIsFeeCurrencyBtc()) { + String jsonTxt = mempoolData.get(txValidator.getTxId()); + if (jsonTxt == null || jsonTxt.isEmpty()) { + log.warn("{} was not found in the mempool", txValidator.getTxId()); + Assert.assertFalse(expectedResult); // tx was not found in explorer + } else { + txValidator.parseJsonValidateMakerFeeTx(jsonTxt, btcFeeReceivers); + Assert.assertTrue(expectedResult == txValidator.getResult()); + } } else { - txValidator.parseJsonValidateMakerFeeTx(jsonTxt, btcFeeReceivers); + txValidator.validateBsqFeeTx(true); Assert.assertTrue(expectedResult == txValidator.getResult()); } }); @@ -236,8 +243,11 @@ private TxValidator createTxValidator(String offerData) { String[] y = offerData.split(","); String txId = y[1]; long amount = Long.parseLong(y[2]); + long feePaid = Long.parseLong(y[3]); boolean isCurrencyForMakerFeeBtc = Long.parseLong(y[4]) > 0; + long feePaymentBlockHeight = Long.parseLong(y[5]); DaoStateService mockedDaoStateService = mock(DaoStateService.class); + Tx mockedTx = mock(Tx.class); Answer mockGetFeeRate = invocation -> { return mockedLookupFeeRate(invocation.getArgument(0), invocation.getArgument(1)); @@ -248,9 +258,17 @@ private TxValidator createTxValidator(String offerData) { Answer> mockGetParamChangeList = invocation -> { return mockedGetParamChangeList(invocation.getArgument(0)); }; + Answer> mockGetBsqTx = invocation -> { + return Optional.of(mockedTx); + }; + Answer mockGetBurntBsq = invocation -> { + return feePaid; + }; when(mockedDaoStateService.getParamValueAsCoin(Mockito.any(Param.class), Mockito.anyInt())).thenAnswer(mockGetFeeRate); when(mockedDaoStateService.getParamValueAsCoin(Mockito.any(Param.class), Mockito.anyString())).thenAnswer(mockGetParamValueAsCoin); when(mockedDaoStateService.getParamChangeList(Mockito.any())).thenAnswer(mockGetParamChangeList); + when(mockedDaoStateService.getTx(Mockito.any())).thenAnswer(mockGetBsqTx); + when(mockedTx.getBurntBsq()).thenAnswer(mockGetBurntBsq); Answer getMakerFeeBsq = invocation -> 1514L; Answer getTakerFeeBsq = invocation -> 10597L; @@ -263,7 +281,7 @@ private TxValidator createTxValidator(String offerData) { when(mockedFilter.getTakerFeeBtc()).thenAnswer(getTakerFeeBtc); FilterManager filterManager = mock(FilterManager.class); when(filterManager.getFilter()).thenReturn(mockedFilter); - TxValidator txValidator = new TxValidator(mockedDaoStateService, txId, Coin.valueOf(amount), isCurrencyForMakerFeeBtc, filterManager); + TxValidator txValidator = new TxValidator(mockedDaoStateService, txId, Coin.valueOf(amount), isCurrencyForMakerFeeBtc, feePaymentBlockHeight, filterManager); return txValidator; } catch (RuntimeException ignore) { // If input format is not as expected we ignore entry @@ -291,6 +309,8 @@ Coin mockedLookupFeeRate(Param param, int blockHeight) { private LinkedHashMap mockedGetFeeRateMap(Param param) { LinkedHashMap feeMap = new LinkedHashMap<>(); if (param == Param.DEFAULT_MAKER_FEE_BSQ) { + feeMap.put(754620L, "14.21"); // https://github.com/bisq-network/proposals/issues/380 + feeMap.put(750000L, "17.19"); // https://github.com/bisq-network/proposals/issues/379 feeMap.put(721063L, "12.78"); // https://github.com/bisq-network/proposals/issues/357 feeMap.put(706305L, "15.14"); // https://github.com/bisq-network/proposals/issues/345 feeMap.put(697011L, "13.16"); // https://github.com/bisq-network/proposals/issues/339 @@ -308,8 +328,10 @@ private LinkedHashMap mockedGetFeeRateMap(Param param) { feeMap.put(585787L, "8.0"); feeMap.put(581107L, "1.6"); } else if (param == Param.DEFAULT_TAKER_FEE_BSQ) { + feeMap.put(754620L, "104.24"); // https://github.com/bisq-network/proposals/issues/380 + feeMap.put(750000L, "126.02"); // https://github.com/bisq-network/proposals/issues/379 feeMap.put(721063L, "89.44"); // https://github.com/bisq-network/proposals/issues/357 - feeMap.put(706305L, "105.97"); // https://github.com/bisq-network/proposals/issues/345 + feeMap.put(706305L, "105.97"); // https://github.com/bisq-network/proposals/issues/345 feeMap.put(697011L, "92.15"); // https://github.com/bisq-network/proposals/issues/339 feeMap.put(682901L, "80.13"); // https://github.com/bisq-network/proposals/issues/333 feeMap.put(677862L, "69.68"); // https://github.com/bisq-network/proposals/issues/325 diff --git a/core/src/test/resources/bisq/core/provider/mempool/badOfferTestData.json b/core/src/test/resources/bisq/core/provider/mempool/badOfferTestData.json index c48788399a0..836b4711046 100644 --- a/core/src/test/resources/bisq/core/provider/mempool/badOfferTestData.json +++ b/core/src/test/resources/bisq/core/provider/mempool/badOfferTestData.json @@ -2,9 +2,7 @@ "ef1ea38b46402deb7df08c13a6dc379a65542a6940ac9d4ba436641ffd4bcb6e": "FQ0A7G,ef1ea38b46402deb7df08c13a6dc379a65542a6940ac9d4ba436641ffd4bcb6e,15970000,92,0,640438, underpaid but accepted due to use of different DAO parameter", "4cdea8872a7d96210f378e0221dc1aae8ee9abb282582afa7546890fb39b7189": "am7DzIv,4cdea8872a7d96210f378e0221dc1aae8ee9abb282582afa7546890fb39b7189,6100000,35,0,668195, underpaid but accepted due to use of different DAO parameter", "051770f8d7f43a9b6ca10fefa6cdf4cb124a81eed26dc8af2e40f57d2589107b": "046698,051770f8d7f43a9b6ca10fefa6cdf4cb124a81eed26dc8af2e40f57d2589107b,15970000,92,0,667927, bsq fee underpaid using 5.75 rate for some weird reason", - "37fba8bf119c289481eef031c0a35e126376f71d13d7cce35eb0d5e05799b5da": "hUWPf,37fba8bf119c289481eef031c0a35e126376f71d13d7cce35eb0d5e05799b5da,19910000,200,0,668994, tx_missing_from_blockchain_for_4_days", "b3bc726aa2aa6533cb1e61901ce351eecde234378fe650aee267388886aa6e4b": "ebdttmzh,b3bc726aa2aa6533cb1e61901ce351eecde234378fe650aee267388886aa6e4b,4000000,5000,1,669137, tx_missing_from_blockchain_for_2_days", - "10f32fe53081466f003185a9ef0324d6cbe3f59334ee9ccb2f7155cbfad9c1de": "kmbyoexc,10f32fe53081466f003185a9ef0324d6cbe3f59334ee9ccb2f7155cbfad9c1de,33000000,332,0,668954, tx_not_found", "cd99836ac4246c3e3980edf95773060481ce52271b74dadeb41e18c42ed21188": "nlaIlAvE,cd99836ac4246c3e3980edf95773060481ce52271b74dadeb41e18c42ed21188,5000000,546,1,669262, invalid_missing_fee_address", "fc3cb16293895fea8ea5d2d8ab4e39d1b27f583e2c160468b586789a861efa74": "feescammer,fc3cb16293895fea8ea5d2d8ab4e39d1b27f583e2c160468b586789a861efa74,1000000,546,1,669442, invalid_missing_fee_address", "72cabb5c323c923b43c7f6551974f591dcee148778ee34f9131011ea0ca82813": "PBFICEAS,72cabb5c323c923b43c7f6551974f591dcee148778ee34f9131011ea0ca82813,2000000,546,1,672969, dust_fee_scammer", diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index 6237fa14509..176dd14c4f5 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -211,26 +211,29 @@ private void onMessageStateChanged(MessageState messageState) { public void checkTakerFeeTx(Trade trade) { mempoolStatus.setValue(-1); - mempoolService.validateOfferTakerTx(trade, (txValidator -> { - mempoolStatus.setValue(txValidator.isFail() ? 0 : 1); - if (txValidator.isFail()) { - String errorMessage = "Validation of Taker Tx returned: " + txValidator.toString(); - log.warn(errorMessage); - // prompt user to open mediation - if (trade.getDisputeState() == Trade.DisputeState.NO_DISPUTE) { - UserThread.runAfter(() -> { - Popup popup = new Popup(); - popup.headLine(Res.get("portfolio.pending.openSupportTicket.headline")) - .message(Res.get("portfolio.pending.invalidTx", errorMessage)) - .actionButtonText(Res.get("portfolio.pending.openSupportTicket.headline")) - .onAction(dataModel::onOpenSupportTicket) - .closeButtonText(Res.get("shared.cancel")) - .onClose(popup::hide) - .show(); - }, 100, TimeUnit.MILLISECONDS); + UserThread.runAfter(() -> { + mempoolService.validateOfferTakerTx(trade, (txValidator -> { + mempoolStatus.setValue(txValidator.isFail() ? 0 : 1); + if (txValidator.isFail()) { + String errorMessage = "Validation of Taker Tx returned: " + txValidator.toString(); + log.warn(errorMessage); + // prompt user to open mediation + if (trade.getDisputeState() == Trade.DisputeState.NO_DISPUTE) { + UserThread.runAfter(() -> { + Popup popup = new Popup(); + popup.headLine(Res.get("portfolio.pending.openSupportTicket.headline")) + .message(Res.get("portfolio.pending.invalidTx", errorMessage)) + .actionButtonText(Res.get("portfolio.pending.openSupportTicket.headline")) + .onAction(dataModel::onOpenSupportTicket) + .closeButtonText(Res.get("shared.cancel")) + .onClose(popup::hide) + .show(); + }, 100, TimeUnit.MILLISECONDS); + } } - } - })); + })); + }, Math.max(5000 - trade.getTradeAge(), 100), TimeUnit.MILLISECONDS); + // we wait until the trade has confirmed for at least 5 seconds to allow for DAO to process the block } ///////////////////////////////////////////////////////////////////////////////////////////