From 9dc79fdcd4c0eca5adfa7641f3c2353b41a4c049 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 10:03:39 -0500 Subject: [PATCH 1/4] Add checks if hot fix is activated for 2 other changes made since 1.9.8 Signed-off-by: HenrikJannsen --- .../core/dao/burningman/DelayedPayoutTxReceiverService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java index 4d2df54ad69..bfe714b56fb 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -71,7 +71,7 @@ public static boolean isHotfixActivated() { // than DPT_MIN_REMAINDER_TO_LEGACY_BM, otherwise we spend it as miner fee. // 25000 sat is about 5 USD @ 20k price. We use a rather high value as we want to avoid that the legacy BM // gets still payouts. - private static final long DPT_MIN_REMAINDER_TO_LEGACY_BM = 25000; + private static final long DPT_MIN_REMAINDER_TO_LEGACY_BM = isHotfixActivated() ? 25000 : 50000; // Min. fee rate for DPT. If fee rate used at take offer time was higher we use that. // We prefer a rather high fee rate to not risk that the DPT gets stuck if required fee rate would @@ -151,7 +151,9 @@ public List> getReceivers(int burningManSelectionHeight, // If we remove outputs it will be spent as miner fee. long minOutputAmount = Math.max(DPT_MIN_OUTPUT_AMOUNT, txFeePerVbyte * 32 * 2); // Sanity check that max share of a non-legacy BM is 20% over MAX_BURN_SHARE (taking into account potential increase due adjustment) - long maxOutputAmount = Math.round(spendableAmount * (BurningManService.MAX_BURN_SHARE * 1.2)); + long maxOutputAmount = isHotfixActivated() ? + Math.round(spendableAmount * (BurningManService.MAX_BURN_SHARE * 1.2)) : + Math.round(inputAmount * (BurningManService.MAX_BURN_SHARE * 1.2)); // We accumulate small amounts which gets filtered out and subtract it from 1 to get an adjustment factor // used later to be applied to the remaining burningmen share. double adjustment = 1 - burningManCandidates.stream() From b872683b60b80b829d67c42e60c36dfa89c585ef Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 13:10:12 -0500 Subject: [PATCH 2/4] Use trade date for check if hotfix is activated at refund managers DPT verification Signed-off-by: HenrikJannsen --- .../burningman/DelayedPayoutTxReceiverService.java | 13 ++++++++++--- .../core/support/dispute/refund/RefundManager.java | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java index bfe714b56fb..46aedd69779 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -52,7 +52,7 @@ @Slf4j @Singleton public class DelayedPayoutTxReceiverService implements DaoStateListener { - private static final Date HOTFIX_ACTIVATION_DATE = Utilities.getUTCDate(2023, GregorianCalendar.JANUARY, 10); + public static final Date HOTFIX_ACTIVATION_DATE = Utilities.getUTCDate(2023, GregorianCalendar.JANUARY, 10); public static boolean isHotfixActivated() { return new Date().after(HOTFIX_ACTIVATION_DATE); @@ -121,8 +121,15 @@ public int getBurningManSelectionHeight() { public List> getReceivers(int burningManSelectionHeight, long inputAmount, long tradeTxFee) { + return getReceivers(burningManSelectionHeight, inputAmount, tradeTxFee, isHotfixActivated()); + } + + public List> getReceivers(int burningManSelectionHeight, + long inputAmount, + long tradeTxFee, + boolean isHotfixActivated) { checkArgument(burningManSelectionHeight >= MIN_SNAPSHOT_HEIGHT, "Selection height must be >= " + MIN_SNAPSHOT_HEIGHT); - Collection burningManCandidates = isHotfixActivated() ? + Collection burningManCandidates = isHotfixActivated ? burningManService.getActiveBurningManCandidates(burningManSelectionHeight) : burningManService.getBurningManCandidatesByName(burningManSelectionHeight).values(); @@ -151,7 +158,7 @@ public List> getReceivers(int burningManSelectionHeight, // If we remove outputs it will be spent as miner fee. long minOutputAmount = Math.max(DPT_MIN_OUTPUT_AMOUNT, txFeePerVbyte * 32 * 2); // Sanity check that max share of a non-legacy BM is 20% over MAX_BURN_SHARE (taking into account potential increase due adjustment) - long maxOutputAmount = isHotfixActivated() ? + long maxOutputAmount = isHotfixActivated ? Math.round(spendableAmount * (BurningManService.MAX_BURN_SHARE * 1.2)) : Math.round(inputAmount * (BurningManService.MAX_BURN_SHARE * 1.2)); // We accumulate small amounts which gets filtered out and subtract it from 1 to get an adjustment factor diff --git a/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java b/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java index 06fdc0bdfb5..0ec75e3277c 100644 --- a/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java +++ b/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java @@ -320,10 +320,13 @@ public void verifyDelayedPayoutTxReceivers(Transaction delayedPayoutTx, Dispute Transaction depositTx = dispute.findDepositTx(btcWalletService).orElseThrow(); long inputAmount = depositTx.getOutput(0).getValue().value; int selectionHeight = dispute.getBurningManSelectionHeight(); + + boolean wasHotfixActivatedAtTradeDate = dispute.getTradeDate().after(DelayedPayoutTxReceiverService.HOTFIX_ACTIVATION_DATE); List> delayedPayoutTxReceivers = delayedPayoutTxReceiverService.getReceivers( selectionHeight, inputAmount, - dispute.getTradeTxFee()); + dispute.getTradeTxFee(), + wasHotfixActivatedAtTradeDate); log.info("Verify delayedPayoutTx using selectionHeight {} and receivers {}", selectionHeight, delayedPayoutTxReceivers); checkArgument(delayedPayoutTx.getOutputs().size() == delayedPayoutTxReceivers.size(), "Size of outputs and delayedPayoutTxReceivers must be the same"); From fa82990e6e13d69634b846a90577cc432afe5a61 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 13:19:59 -0500 Subject: [PATCH 3/4] Handle DPT_MIN_REMAINDER_TO_LEGACY_BM with isHotfixActivated param Signed-off-by: HenrikJannsen --- .../core/dao/burningman/DelayedPayoutTxReceiverService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java index 46aedd69779..3cce568ab6b 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -71,7 +71,7 @@ public static boolean isHotfixActivated() { // than DPT_MIN_REMAINDER_TO_LEGACY_BM, otherwise we spend it as miner fee. // 25000 sat is about 5 USD @ 20k price. We use a rather high value as we want to avoid that the legacy BM // gets still payouts. - private static final long DPT_MIN_REMAINDER_TO_LEGACY_BM = isHotfixActivated() ? 25000 : 50000; + private static final long DPT_MIN_REMAINDER_TO_LEGACY_BM = 25000; // Min. fee rate for DPT. If fee rate used at take offer time was higher we use that. // We prefer a rather high fee rate to not risk that the DPT gets stuck if required fee rate would @@ -189,7 +189,8 @@ public List> getReceivers(int burningManSelectionHeight, long available = spendableAmount - totalOutputValue; // If the available is larger than DPT_MIN_REMAINDER_TO_LEGACY_BM we send it to legacy BM // Otherwise we use it as miner fee - if (available > DPT_MIN_REMAINDER_TO_LEGACY_BM) { + long dptMinRemainderToLegacyBm = isHotfixActivated ? DPT_MIN_REMAINDER_TO_LEGACY_BM : 50000; + if (available > dptMinRemainderToLegacyBm) { receivers.add(new Tuple2<>(available, burningManService.getLegacyBurningManAddress(burningManSelectionHeight))); } } From bc5045dd2805381a075b33d368977aae036b18b2 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Fri, 6 Jan 2023 13:24:17 -0500 Subject: [PATCH 4/4] Force rebuild at CI Signed-off-by: HenrikJannsen --- .../core/dao/burningman/DelayedPayoutTxReceiverService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java index 3cce568ab6b..71576ad567e 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -200,8 +200,8 @@ public List> getReceivers(int burningManSelectionHeight, private static long getSpendableAmount(int numOutputs, long inputAmount, long txFeePerVbyte) { // Output size: 32 bytes // Tx size without outputs: 51 bytes - int txSize = 51 + numOutputs * 32; // min value: txSize=83 - long minerFee = txFeePerVbyte * txSize; // min value: minerFee=830 + int txSize = 51 + numOutputs * 32; // Min value: txSize=83 + long minerFee = txFeePerVbyte * txSize; // Min value: minerFee=830 // We need to make sure we have at least 1000 sat as defined in TradeWalletService minerFee = Math.max(TradeWalletService.MIN_DELAYED_PAYOUT_TX_FEE.value, minerFee); return inputAmount - minerFee;