From 02093b986b3c8a113034ab8f65ffb44c8836c22b Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 10:06:49 -0500 Subject: [PATCH 01/13] Improve log Signed-off-by: HenrikJannsen --- core/src/main/java/bisq/core/btc/wallet/WalletService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/WalletService.java b/core/src/main/java/bisq/core/btc/wallet/WalletService.java index 8cd19d7dcb3..f2c3d251c6d 100644 --- a/core/src/main/java/bisq/core/btc/wallet/WalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/WalletService.java @@ -291,7 +291,8 @@ public static void signTx(Wallet wallet, continue; } if (!connectedOutput.isMine(wallet)) { - log.error("connectedOutput is not mine"); + log.info("ConnectedOutput is not mine. This can be the case for BSQ transactions where the " + + "input gets signed by the other wallet. connectedOutput={}", connectedOutput); continue; } From f4d335b62462c02c28a937817a6c3d030328ea48 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 10:18:42 -0500 Subject: [PATCH 02/13] Improve logs Signed-off-by: HenrikJannsen --- .../tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java | 10 +++++++--- .../buyer/BuyerVerifiesPreparedDelayedPayoutTx.java | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java index ba05dacec97..969edf5c5b0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java @@ -32,7 +32,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -74,8 +73,13 @@ protected void run() { depositTx, delayedPayoutTxReceivers, lockTime); - checkArgument(buyersDelayedPayoutTx.getTxId().equals(finalDelayedPayoutTx.getTxId()), - "TxIds of buyersDelayedPayoutTx and finalDelayedPayoutTx must be the same"); + + if (!buyersDelayedPayoutTx.getTxId().equals(finalDelayedPayoutTx.getTxId())) { + String errorMsg = "TxIds of buyersDelayedPayoutTx and finalDelayedPayoutTx must be the same."; + log.error("{} \nbuyersDelayedPayoutTx={}, \nfinalDelayedPayoutTx={}", + errorMsg, buyersDelayedPayoutTx, finalDelayedPayoutTx); + throw new IllegalArgumentException(errorMsg); + } } complete(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java index 9f7e9c0d5fe..a1563e06425 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java @@ -32,7 +32,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -66,8 +65,12 @@ protected void run() { preparedDepositTx, delayedPayoutTxReceivers, lockTime); - checkArgument(buyersPreparedDelayedPayoutTx.getTxId().equals(sellersPreparedDelayedPayoutTx.getTxId()), - "TxIds of buyersPreparedDelayedPayoutTx and sellersPreparedDelayedPayoutTx must be the same"); + if (!buyersPreparedDelayedPayoutTx.getTxId().equals(sellersPreparedDelayedPayoutTx.getTxId())) { + String errorMsg = "TxIds of buyersPreparedDelayedPayoutTx and sellersPreparedDelayedPayoutTx must be the same."; + log.error("{} \nbuyersPreparedDelayedPayoutTx={}, \nsellersPreparedDelayedPayoutTx={}", + errorMsg, buyersPreparedDelayedPayoutTx, sellersPreparedDelayedPayoutTx); + throw new IllegalArgumentException(errorMsg); + } } // If the deposit tx is non-malleable, we already know its final ID, so should check that now From be33aa5236662c88abe62cdb9eb0ad68681af2b5 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 10:22:50 -0500 Subject: [PATCH 03/13] Add chain heights to logs Signed-off-by: HenrikJannsen --- .../tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java | 8 ++++++-- .../tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java index 969edf5c5b0..56f8ba7c44c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java @@ -76,8 +76,12 @@ protected void run() { if (!buyersDelayedPayoutTx.getTxId().equals(finalDelayedPayoutTx.getTxId())) { String errorMsg = "TxIds of buyersDelayedPayoutTx and finalDelayedPayoutTx must be the same."; - log.error("{} \nbuyersDelayedPayoutTx={}, \nfinalDelayedPayoutTx={}", - errorMsg, buyersDelayedPayoutTx, finalDelayedPayoutTx); + log.error("{} \nbuyersDelayedPayoutTx={}, \nfinalDelayedPayoutTx={}, " + + "\nBtcWalletService.chainHeight={}, \nDaoState.chainHeight={}", + errorMsg, buyersDelayedPayoutTx, finalDelayedPayoutTx, + processModel.getBtcWalletService().getBestChainHeight(), + processModel.getDaoFacade().getChainHeight()); + throw new IllegalArgumentException(errorMsg); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java index a1563e06425..d55690b640a 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java @@ -67,8 +67,11 @@ protected void run() { lockTime); if (!buyersPreparedDelayedPayoutTx.getTxId().equals(sellersPreparedDelayedPayoutTx.getTxId())) { String errorMsg = "TxIds of buyersPreparedDelayedPayoutTx and sellersPreparedDelayedPayoutTx must be the same."; - log.error("{} \nbuyersPreparedDelayedPayoutTx={}, \nsellersPreparedDelayedPayoutTx={}", - errorMsg, buyersPreparedDelayedPayoutTx, sellersPreparedDelayedPayoutTx); + log.error("{} \nbuyersPreparedDelayedPayoutTx={}, \nsellersPreparedDelayedPayoutTx={}, " + + "\nBtcWalletService.chainHeight={}, \nDaoState.chainHeight={}", + errorMsg, buyersPreparedDelayedPayoutTx, sellersPreparedDelayedPayoutTx, + processModel.getBtcWalletService().getBestChainHeight(), + processModel.getDaoFacade().getChainHeight()); throw new IllegalArgumentException(errorMsg); } } From b33c61001541d3cf3a0fb4eed7796a38dafc3a95 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 10:28:59 -0500 Subject: [PATCH 04/13] Add CheckIfDaoStateIsInSync task in trade protocol as first task Add ifDaoStateIsInSync method to DaoFacade Add ifDaoStateIsInSync to logs if DPT verification fails --- .../main/java/bisq/core/dao/DaoFacade.java | 5 +++ .../bisq_v1/BuyerAsMakerProtocol.java | 2 + .../bisq_v1/BuyerAsTakerProtocol.java | 2 + .../bisq_v1/SellerAsMakerProtocol.java | 2 + .../bisq_v1/SellerAsTakerProtocol.java | 2 + .../tasks/CheckIfDaoStateIsInSync.java | 45 +++++++++++++++++++ .../BuyerVerifiesFinalDelayedPayoutTx.java | 8 +++- .../BuyerVerifiesPreparedDelayedPayoutTx.java | 7 ++- 8 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java diff --git a/core/src/main/java/bisq/core/dao/DaoFacade.java b/core/src/main/java/bisq/core/dao/DaoFacade.java index b4729179d2a..51f6b94aa1b 100644 --- a/core/src/main/java/bisq/core/dao/DaoFacade.java +++ b/core/src/main/java/bisq/core/dao/DaoFacade.java @@ -813,4 +813,9 @@ public Set getAllDonationAddresses() { public boolean isParseBlockChainComplete() { return daoStateService.isParseBlockChainComplete(); } + + public boolean isDaoStateIsInSync() { + return !daoStateMonitoringService.isInConflictWithSeedNode() && + !daoStateMonitoringService.isDaoStateBlockChainNotConnecting(); + } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsMakerProtocol.java index 8f161351aa9..83bda8ac8bf 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsMakerProtocol.java @@ -25,6 +25,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest; import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; +import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest; @@ -71,6 +72,7 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, .with(message) .from(peer)) .setup(tasks( + CheckIfDaoStateIsInSync.class, MakerProcessesInputsForDepositTxRequest.class, ApplyFilter.class, getVerifyPeersFeePaymentClass(), diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsTakerProtocol.java index 8a1d927eef4..d7b9413db59 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/BuyerAsTakerProtocol.java @@ -27,6 +27,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxResponse; import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; +import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest; @@ -77,6 +78,7 @@ public void onTakeOffer() { expect(phase(Trade.Phase.INIT) .with(TakerEvent.TAKE_OFFER)) .setup(tasks( + CheckIfDaoStateIsInSync.class, ApplyFilter.class, getVerifyPeersFeePaymentClass(), CreateTakerFeeTx.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsMakerProtocol.java index 1da30e3e0d8..c88e7de0f87 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsMakerProtocol.java @@ -27,6 +27,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.DepositTxMessage; import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; +import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerCreateAndSignContract; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerProcessesInputsForDepositTxRequest; @@ -73,6 +74,7 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, .with(message) .from(peer)) .setup(tasks( + CheckIfDaoStateIsInSync.class, MaybeCreateSubAccount.class, MakerProcessesInputsForDepositTxRequest.class, ApplyFilter.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsTakerProtocol.java index fae836be769..42804e7cd3d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/SellerAsTakerProtocol.java @@ -26,6 +26,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxResponse; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; +import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v1.tasks.seller.MaybeCreateSubAccount; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerCreatesDelayedPayoutTx; @@ -73,6 +74,7 @@ public void onTakeOffer() { .with(TakerEvent.TAKE_OFFER) .from(trade.getTradingPeerNodeAddress())) .setup(tasks( + CheckIfDaoStateIsInSync.class, MaybeCreateSubAccount.class, ApplyFilter.class, getVerifyPeersFeePaymentClass(), diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java new file mode 100644 index 00000000000..e70e7e9caea --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +package bisq.core.trade.protocol.bisq_v1.tasks; + +import bisq.core.trade.model.bisq_v1.Trade; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkArgument; + +@Slf4j +public class CheckIfDaoStateIsInSync extends TradeTask { + public CheckIfDaoStateIsInSync(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + checkArgument(processModel.getDaoFacade().isDaoStateIsInSync(), "DAO state is not in sync with seed nodes"); + } catch (Throwable t) { + failed(t); + } + } +} + diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java index 56f8ba7c44c..66e8361d88b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java @@ -75,12 +75,16 @@ protected void run() { lockTime); if (!buyersDelayedPayoutTx.getTxId().equals(finalDelayedPayoutTx.getTxId())) { + String errorMsg = "TxIds of buyersDelayedPayoutTx and finalDelayedPayoutTx must be the same."; log.error("{} \nbuyersDelayedPayoutTx={}, \nfinalDelayedPayoutTx={}, " + - "\nBtcWalletService.chainHeight={}, \nDaoState.chainHeight={}", + "\nBtcWalletService.chainHeight={}, " + + "\nDaoState.chainHeight={}, " + + "\nisDaoStateIsInSync={}", errorMsg, buyersDelayedPayoutTx, finalDelayedPayoutTx, processModel.getBtcWalletService().getBestChainHeight(), - processModel.getDaoFacade().getChainHeight()); + processModel.getDaoFacade().getChainHeight(), + processModel.getDaoFacade().isDaoStateIsInSync()); throw new IllegalArgumentException(errorMsg); } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java index d55690b640a..fe3e5800865 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java @@ -68,10 +68,13 @@ protected void run() { if (!buyersPreparedDelayedPayoutTx.getTxId().equals(sellersPreparedDelayedPayoutTx.getTxId())) { String errorMsg = "TxIds of buyersPreparedDelayedPayoutTx and sellersPreparedDelayedPayoutTx must be the same."; log.error("{} \nbuyersPreparedDelayedPayoutTx={}, \nsellersPreparedDelayedPayoutTx={}, " + - "\nBtcWalletService.chainHeight={}, \nDaoState.chainHeight={}", + "\nBtcWalletService.chainHeight={}, " + + "\nDaoState.chainHeight={}, " + + "\nisDaoStateIsInSync={}", errorMsg, buyersPreparedDelayedPayoutTx, sellersPreparedDelayedPayoutTx, processModel.getBtcWalletService().getBestChainHeight(), - processModel.getDaoFacade().getChainHeight()); + processModel.getDaoFacade().getChainHeight(), + processModel.getDaoFacade().isDaoStateIsInSync()); throw new IllegalArgumentException(errorMsg); } } From 1e2f48b9bc555080520418cbb5310be11f911f25 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 10:42:59 -0500 Subject: [PATCH 05/13] Rename isDaoStateIsInSync to isDaoStateReadyAndInSync Add daoStateService.isParseBlockChainComplete() check Signed-off-by: HenrikJannsen --- core/src/main/java/bisq/core/dao/DaoFacade.java | 5 +++-- .../protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java | 2 +- .../tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java | 4 +--- .../tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/DaoFacade.java b/core/src/main/java/bisq/core/dao/DaoFacade.java index 51f6b94aa1b..ce445c53af9 100644 --- a/core/src/main/java/bisq/core/dao/DaoFacade.java +++ b/core/src/main/java/bisq/core/dao/DaoFacade.java @@ -814,8 +814,9 @@ public boolean isParseBlockChainComplete() { return daoStateService.isParseBlockChainComplete(); } - public boolean isDaoStateIsInSync() { - return !daoStateMonitoringService.isInConflictWithSeedNode() && + public boolean isDaoStateReadyAndInSync() { + return daoStateService.isParseBlockChainComplete() && + !daoStateMonitoringService.isInConflictWithSeedNode() && !daoStateMonitoringService.isDaoStateBlockChainNotConnecting(); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java index e70e7e9caea..519c5b47a81 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java @@ -36,7 +36,7 @@ protected void run() { try { runInterceptHook(); - checkArgument(processModel.getDaoFacade().isDaoStateIsInSync(), "DAO state is not in sync with seed nodes"); + checkArgument(processModel.getDaoFacade().isDaoStateReadyAndInSync(), "DAO state is not in sync with seed nodes"); } catch (Throwable t) { failed(t); } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java index 66e8361d88b..3bf644b1fdb 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesFinalDelayedPayoutTx.java @@ -75,7 +75,6 @@ protected void run() { lockTime); if (!buyersDelayedPayoutTx.getTxId().equals(finalDelayedPayoutTx.getTxId())) { - String errorMsg = "TxIds of buyersDelayedPayoutTx and finalDelayedPayoutTx must be the same."; log.error("{} \nbuyersDelayedPayoutTx={}, \nfinalDelayedPayoutTx={}, " + "\nBtcWalletService.chainHeight={}, " + @@ -84,8 +83,7 @@ protected void run() { errorMsg, buyersDelayedPayoutTx, finalDelayedPayoutTx, processModel.getBtcWalletService().getBestChainHeight(), processModel.getDaoFacade().getChainHeight(), - processModel.getDaoFacade().isDaoStateIsInSync()); - + processModel.getDaoFacade().isDaoStateReadyAndInSync()); throw new IllegalArgumentException(errorMsg); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java index fe3e5800865..6fe2321d072 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/buyer/BuyerVerifiesPreparedDelayedPayoutTx.java @@ -74,7 +74,7 @@ protected void run() { errorMsg, buyersPreparedDelayedPayoutTx, sellersPreparedDelayedPayoutTx, processModel.getBtcWalletService().getBestChainHeight(), processModel.getDaoFacade().getChainHeight(), - processModel.getDaoFacade().isDaoStateIsInSync()); + processModel.getDaoFacade().isDaoStateReadyAndInSync()); throw new IllegalArgumentException(errorMsg); } } From 13180ddc30835e9c72aac55791b0b457e3b1540e Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 11:21:01 -0500 Subject: [PATCH 06/13] Improve DaoPresentation and add handler for daoStateHash updates Signed-off-by: HenrikJannsen --- .../main/java/bisq/core/dao/DaoFacade.java | 13 +-- .../java/bisq/desktop/main/MainViewModel.java | 8 +- .../main/presentation/DaoPresentation.java | 95 ++++++++++--------- .../main/java/bisq/desktop/util/GUIUtil.java | 16 ---- 4 files changed, 59 insertions(+), 73 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/DaoFacade.java b/core/src/main/java/bisq/core/dao/DaoFacade.java index ce445c53af9..c014016947d 100644 --- a/core/src/main/java/bisq/core/dao/DaoFacade.java +++ b/core/src/main/java/bisq/core/dao/DaoFacade.java @@ -531,10 +531,13 @@ public Optional getBlockAtHeight(int chainHeight) { return daoStateService.getBlockAtHeight(chainHeight); } - public boolean daoStateNeedsRebuilding() { - return daoStateMonitoringService.isInConflictWithSeedNode() || daoStateMonitoringService.isDaoStateBlockChainNotConnecting(); + public boolean isDaoStateReadyAndInSync() { + return daoStateService.isParseBlockChainComplete() && + !daoStateMonitoringService.isInConflictWithSeedNode() && + !daoStateMonitoringService.isDaoStateBlockChainNotConnecting(); } + /////////////////////////////////////////////////////////////////////////////////////////// // Use case: Bonding /////////////////////////////////////////////////////////////////////////////////////////// @@ -813,10 +816,4 @@ public Set getAllDonationAddresses() { public boolean isParseBlockChainComplete() { return daoStateService.isParseBlockChainComplete(); } - - public boolean isDaoStateReadyAndInSync() { - return daoStateService.isParseBlockChainComplete() && - !daoStateMonitoringService.isInConflictWithSeedNode() && - !daoStateMonitoringService.isDaoStateBlockChainNotConnecting(); - } } diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 3eb0283a320..4c132613c37 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -310,7 +310,7 @@ public void onSetupComplete() { setupClockWatcherPopup(); marketPricePresentation.setup(); - daoPresentation.setup(); + daoPresentation.init(); accountPresentation.setup(); settingsPresentation.setup(); @@ -505,7 +505,7 @@ private void setupHandlers() { .show()); bisqSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress()); - daoPresentation.getBsqSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress()); + daoPresentation.getDaoStateSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress()); bisqSetup.setFilterWarningHandler(warning -> new Popup().warning(warning).show()); @@ -704,7 +704,7 @@ private void updateBtcSyncProgress() { if (btcSyncProgress.doubleValue() < 1) { combinedSyncProgress.set(btcSyncProgress.doubleValue()); } else { - combinedSyncProgress.set(daoPresentation.getBsqSyncProgress().doubleValue()); + combinedSyncProgress.set(daoPresentation.getDaoStateSyncProgress().doubleValue()); } } @@ -783,7 +783,7 @@ StringProperty getBtcInfo() { StringProperty getCombinedFooterInfo() { final StringProperty combinedInfo = new SimpleStringProperty(); - combinedInfo.bind(Bindings.concat(this.footerVersionInfo, " ", daoPresentation.getBsqInfo())); + combinedInfo.bind(Bindings.concat(this.footerVersionInfo, " ", daoPresentation.getDaoStateInfo())); return combinedInfo; } diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java index 0afda183c6c..5c441ac363d 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java @@ -1,11 +1,15 @@ package bisq.desktop.main.presentation; import bisq.desktop.Navigation; -import bisq.desktop.util.GUIUtil; +import bisq.desktop.main.MainView; +import bisq.desktop.main.dao.DaoView; +import bisq.desktop.main.dao.monitor.MonitorView; +import bisq.desktop.main.dao.monitor.daostate.DaoStateMonitorView; +import bisq.desktop.main.overlays.popups.Popup; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.dao.DaoFacade; +import bisq.core.dao.monitoring.DaoStateMonitoringService; import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.DaoStateService; import bisq.core.dao.state.model.blockchain.Block; @@ -28,24 +32,21 @@ import lombok.Getter; @Singleton -public class DaoPresentation implements DaoStateListener { +public class DaoPresentation implements DaoStateListener, DaoStateMonitoringService.Listener { public static final String DAO_NEWS = "daoNews"; - private final Preferences preferences; private final Navigation navigation; private final BtcWalletService btcWalletService; - private final DaoFacade daoFacade; + private final DaoStateMonitoringService daoStateMonitoringService; private final BsqWalletService bsqWalletService; private final DaoStateService daoStateService; private final ChangeListener walletChainHeightListener; - @Getter - private final DoubleProperty bsqSyncProgress = new SimpleDoubleProperty(-1); + private final DoubleProperty daoStateSyncProgress = new SimpleDoubleProperty(-1); @Getter - private final StringProperty bsqInfo = new SimpleStringProperty(""); + private final StringProperty daoStateInfo = new SimpleStringProperty(""); private final SimpleBooleanProperty showNotification = new SimpleBooleanProperty(false); - private boolean daoConflictWarningShown = false; // allow only one conflict warning per session @Inject public DaoPresentation(Preferences preferences, @@ -53,12 +54,11 @@ public DaoPresentation(Preferences preferences, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, DaoStateService daoStateService, - DaoFacade daoFacade) { - this.preferences = preferences; + DaoStateMonitoringService daoStateMonitoringService) { this.navigation = navigation; this.btcWalletService = btcWalletService; this.bsqWalletService = bsqWalletService; - this.daoFacade = daoFacade; + this.daoStateMonitoringService = daoStateMonitoringService; this.daoStateService = daoStateService; preferences.getDontShowAgainMapAsObservable().addListener((MapChangeListener) change -> { @@ -69,38 +69,30 @@ public DaoPresentation(Preferences preferences, } }); + daoStateService.addDaoStateListener(this); + daoStateMonitoringService.addListener(this); + walletChainHeightListener = (observable, oldValue, newValue) -> onUpdateAnyChainHeight(); } /////////////////////////////////////////////////////////////////////////////////////////// - // Private + // Public /////////////////////////////////////////////////////////////////////////////////////////// - private void onUpdateAnyChainHeight() { - final int bsqBlockChainHeight = daoFacade.getChainHeight(); - final int bsqWalletChainHeight = bsqWalletService.getBestChainHeight(); - if (bsqWalletChainHeight > 0) { - final boolean synced = bsqWalletChainHeight == bsqBlockChainHeight; - if (bsqBlockChainHeight != bsqWalletChainHeight) { - bsqSyncProgress.set(-1); - } else { - bsqSyncProgress.set(0); - } + public void init() { + showNotification.set(false); - if (synced) { - bsqInfo.set(""); - if (daoFacade.daoStateNeedsRebuilding() && !daoConflictWarningShown) { - daoConflictWarningShown = true; // only warn max 1 time per session so as not to annoy - GUIUtil.showDaoNeedsResyncPopup(navigation); - } - } else { - bsqInfo.set(Res.get("mainView.footer.bsqInfo.synchronizing")); - } - } else { - bsqInfo.set(Res.get("mainView.footer.bsqInfo.synchronizing")); - } + btcWalletService.getChainHeightProperty().addListener(walletChainHeightListener); + daoStateService.addDaoStateListener(this); + + onUpdateAnyChainHeight(); + } + + public BooleanProperty getShowDaoUpdatesNotification() { + return showNotification; } + /////////////////////////////////////////////////////////////////////////////////////////// // DaoStateListener /////////////////////////////////////////////////////////////////////////////////////////// @@ -110,22 +102,35 @@ public void onParseBlockCompleteAfterBatchProcessing(Block block) { onUpdateAnyChainHeight(); } + /////////////////////////////////////////////////////////////////////////////////////////// - // Public + // DaoStateMonitoringService.Listener /////////////////////////////////////////////////////////////////////////////////////////// - public BooleanProperty getShowDaoUpdatesNotification() { - return showNotification; + @Override + public void onDaoStateHashesChanged() { + if (daoStateService.isParseBlockChainComplete()) { + if (daoStateMonitoringService.isInConflictWithSeedNode() || + daoStateMonitoringService.isDaoStateBlockChainNotConnecting()) { + new Popup().warning(Res.get("popup.warning.daoNeedsResync")) + .actionButtonTextWithGoTo("navigation.dao.networkMonitor") + .onAction(() -> navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class)) + .show(); + } + } } - public void setup() { - // devs enable this when a news badge is required - //showNotification.set(DevEnv.isDaoActivated() && preferences.showAgain(DAO_NEWS)); - showNotification.set(false); - this.btcWalletService.getChainHeightProperty().addListener(walletChainHeightListener); - daoStateService.addDaoStateListener(this); + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// - onUpdateAnyChainHeight(); + private void onUpdateAnyChainHeight() { + int bsqWalletChainHeight = bsqWalletService.getBestChainHeight(); + int daoStateChainHeight = daoStateService.getChainHeight(); + boolean chainHeightsInSync = bsqWalletChainHeight > 0 && bsqWalletChainHeight == daoStateChainHeight; + boolean isDaoStateReady = chainHeightsInSync && daoStateService.isParseBlockChainComplete(); + daoStateSyncProgress.set(isDaoStateReady ? 0 : -1); + daoStateInfo.set(isDaoStateReady ? "" : Res.get("mainView.footer.bsqInfo.synchronizing")); } } diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 9c64ca9dc82..8c9406795a3 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -27,9 +27,6 @@ import bisq.desktop.main.MainView; import bisq.desktop.main.account.AccountView; import bisq.desktop.main.account.content.fiataccounts.FiatAccountsView; -import bisq.desktop.main.dao.DaoView; -import bisq.desktop.main.dao.monitor.MonitorView; -import bisq.desktop.main.dao.monitor.daostate.DaoStateMonitorView; import bisq.desktop.main.overlays.popups.Popup; import bisq.core.account.witness.AccountAgeWitness; @@ -806,19 +803,6 @@ public static boolean isBootstrappedOrShowPopup(P2PService p2PService) { return false; } - public static void showDaoNeedsResyncPopup(Navigation navigation) { - String key = "showDaoNeedsResyncPopup"; - if (DontShowAgainLookup.showAgain(key)) { - UserThread.runAfter(() -> new Popup().warning(Res.get("popup.warning.daoNeedsResync")) - .dontShowAgainId(key) - .actionButtonTextWithGoTo("navigation.dao.networkMonitor") - .onAction(() -> { - navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class); - }) - .show(), 5, TimeUnit.SECONDS); - } - } - public static boolean isReadyForTxBroadcastOrShowPopup(P2PService p2PService, WalletsSetup walletsSetup) { if (!GUIUtil.isBootstrappedOrShowPopup(p2PService)) { return false; From 093e8f99f43a8a53907a4999ddfe70b3d4645d4f Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 11:41:11 -0500 Subject: [PATCH 07/13] Remove unused methods Signed-off-by: HenrikJannsen --- core/src/main/java/bisq/core/dao/DaoFacade.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/DaoFacade.java b/core/src/main/java/bisq/core/dao/DaoFacade.java index c014016947d..a3ccb9377e6 100644 --- a/core/src/main/java/bisq/core/dao/DaoFacade.java +++ b/core/src/main/java/bisq/core/dao/DaoFacade.java @@ -57,7 +57,6 @@ import bisq.core.dao.state.DaoStateListener; import bisq.core.dao.state.DaoStateService; import bisq.core.dao.state.model.blockchain.BaseTx; -import bisq.core.dao.state.model.blockchain.BaseTxOutput; import bisq.core.dao.state.model.blockchain.Block; import bisq.core.dao.state.model.blockchain.Tx; import bisq.core.dao.state.model.blockchain.TxOutput; @@ -581,10 +580,6 @@ public long getTotalAmountOfConfiscatedTxOutputs() { return daoStateService.getTotalAmountOfConfiscatedTxOutputs(); } - public long getTotalAmountOfInvalidatedBsq() { - return daoStateService.getTotalAmountOfInvalidatedBsq(); - } - // Contains burned fee and invalidated bsq due invalid txs public long getTotalAmountOfBurntBsq() { return daoStateService.getTotalAmountOfBurntBsq(); @@ -598,11 +593,6 @@ public List getIrregularTxs() { return daoStateService.getIrregularTxs(); } - public long getTotalAmountOfUnspentTxOutputs() { - // Does not consider confiscated outputs (they stay as utxo) - return daoStateService.getUnspentTxOutputMap().values().stream().mapToLong(BaseTxOutput::getValue).sum(); - } - public Optional getLockTime(String txId) { return daoStateService.getLockTime(txId); } From cdfa3fa141db2ae1e64e37ab68656b1273905c7a Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 12:20:09 -0500 Subject: [PATCH 08/13] Return if !isParseBlockChainComplete Signed-off-by: HenrikJannsen --- .../main/presentation/DaoPresentation.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java index 5c441ac363d..344f71951d3 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java @@ -109,14 +109,16 @@ public void onParseBlockCompleteAfterBatchProcessing(Block block) { @Override public void onDaoStateHashesChanged() { - if (daoStateService.isParseBlockChainComplete()) { - if (daoStateMonitoringService.isInConflictWithSeedNode() || - daoStateMonitoringService.isDaoStateBlockChainNotConnecting()) { - new Popup().warning(Res.get("popup.warning.daoNeedsResync")) - .actionButtonTextWithGoTo("navigation.dao.networkMonitor") - .onAction(() -> navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class)) - .show(); - } + if (!daoStateService.isParseBlockChainComplete()) { + return; + } + + if (daoStateMonitoringService.isInConflictWithSeedNode() || + daoStateMonitoringService.isDaoStateBlockChainNotConnecting()) { + new Popup().warning(Res.get("popup.warning.daoNeedsResync")) + .actionButtonTextWithGoTo("navigation.dao.networkMonitor") + .onAction(() -> navigation.navigateTo(MainView.class, DaoView.class, MonitorView.class, DaoStateMonitorView.class)) + .show(); } } From bc91914cb0680799fd1751fbb583a565c2f95f65 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 14:48:51 -0500 Subject: [PATCH 09/13] Change log level Signed-off-by: HenrikJannsen --- .../bisq/core/dao/node/full/network/FullNodeNetworkService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java b/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java index 20583433cb5..430426dba5c 100644 --- a/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java +++ b/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java @@ -206,7 +206,7 @@ public void onFault(String errorMessage, @Nullable Connection connection) { } private void handleRepublishGovernanceDataRequest() { - log.warn("We received a RepublishGovernanceDataRequest and re-published all proposalPayloads and " + + log.info("We received a RepublishGovernanceDataRequest and re-published all proposalPayloads and " + "blindVotePayloads to the P2P network."); missingDataRequestService.reRepublishAllGovernanceData(); } From aa514b37da65a27a8ddee731d859d96a474124b3 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 22:02:57 -0500 Subject: [PATCH 10/13] Add listeners at init Remove duplicated listener registration Signed-off-by: HenrikJannsen --- .../java/bisq/desktop/main/presentation/DaoPresentation.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java index 344f71951d3..a0d0da6afa4 100644 --- a/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/presentation/DaoPresentation.java @@ -69,9 +69,6 @@ public DaoPresentation(Preferences preferences, } }); - daoStateService.addDaoStateListener(this); - daoStateMonitoringService.addListener(this); - walletChainHeightListener = (observable, oldValue, newValue) -> onUpdateAnyChainHeight(); } @@ -84,6 +81,7 @@ public void init() { btcWalletService.getChainHeightProperty().addListener(walletChainHeightListener); daoStateService.addDaoStateListener(this); + daoStateMonitoringService.addListener(this); onUpdateAnyChainHeight(); } From bb06f64049deb91ea0ef5a99d54dcf25f82b7812 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 15:46:59 -0500 Subject: [PATCH 11/13] Add complete call Signed-off-by: HenrikJannsen --- .../trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java index 519c5b47a81..180f9dca9b5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/CheckIfDaoStateIsInSync.java @@ -37,6 +37,7 @@ protected void run() { runInterceptHook(); checkArgument(processModel.getDaoFacade().isDaoStateReadyAndInSync(), "DAO state is not in sync with seed nodes"); + complete(); } catch (Throwable t) { failed(t); } From 41a63cc8a50009adf2213a267d42a908a4583749 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 15:57:27 -0500 Subject: [PATCH 12/13] Add handling of miner fee in case there is only the legacy BM Use spendableAmount instead of inputAmount at maxOutputAmount Signed-off-by: HenrikJannsen --- .../DelayedPayoutTxReceiverService.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 661189daf8b..1a1512938fe 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -127,12 +127,6 @@ public List> getReceivers(int burningManSelectionHeight, burningManService.getActiveBurningManCandidates(burningManSelectionHeight) : burningManService.getBurningManCandidatesByName(burningManSelectionHeight).values(); - - if (burningManCandidates.isEmpty()) { - // If there are no compensation requests (e.g. at dev testing) we fall back to the legacy BM - return List.of(new Tuple2<>(inputAmount, burningManService.getLegacyBurningManAddress(burningManSelectionHeight))); - } - // We need to use the same txFeePerVbyte value for both traders. // We use the tradeTxFee value which is calculated from the average of taker fee tx size and deposit tx size. // Otherwise, we would need to sync the fee rate of both traders. @@ -146,12 +140,19 @@ public List> getReceivers(int burningManSelectionHeight, // Smallest tx size is 246. With additional change output we add 32. To be safe we use the largest expected size. double txSize = 278; long txFeePerVbyte = Math.max(DPT_MIN_TX_FEE_RATE, Math.round(tradeTxFee / txSize)); + + if (burningManCandidates.isEmpty()) { + // If there are no compensation requests (e.g. at dev testing) we fall back to the legacy BM + long spendableAmount = getSpendableAmount(1, inputAmount, txFeePerVbyte); + return List.of(new Tuple2<>(spendableAmount, burningManService.getLegacyBurningManAddress(burningManSelectionHeight))); + } + long spendableAmount = getSpendableAmount(burningManCandidates.size(), inputAmount, txFeePerVbyte); // We only use outputs > 1000 sat or at least 2 times the cost for the output (32 bytes). // 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(inputAmount * (BurningManService.MAX_BURN_SHARE * 1.2)); + long maxOutputAmount = Math.round(spendableAmount * (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 7977c8670aa420583c03633aa912ad60649f277b Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 5 Jan 2023 22:25:31 -0500 Subject: [PATCH 13/13] Cleanup Signed-off-by: HenrikJannsen --- .../bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java | 1 - 1 file changed, 1 deletion(-) 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 1a1512938fe..4d2df54ad69 100644 --- a/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java +++ b/core/src/main/java/bisq/core/dao/burningman/DelayedPayoutTxReceiverService.java @@ -78,7 +78,6 @@ public static boolean isHotfixActivated() { // spike when opening arbitration. private static final long DPT_MIN_TX_FEE_RATE = 10; - private final DaoStateService daoStateService; private final BurningManService burningManService; private int currentChainHeight;