From 62bc004d195b245f784c0b45c32927e150c4741e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 24 Oct 2019 22:45:27 -0500 Subject: [PATCH] Do not commit delayedPayoutTx to avoid publishing at restart Fixes https://github.com/bisq-network/bisq/issues/3463 BitcoinJ publishes automatically committed transactions. We committed it to the wallet to be able to access it later after a restart. We stored the txId in Trade and used that to request the tx from the wallet (as it was committed). Now we store the bitcoin serialized bytes of the tx and do not commit the tx before broadcasting it (if a trader opens refund agent ticket). --- common/src/main/proto/pb.proto | 2 +- core/src/main/java/bisq/core/trade/Trade.java | 20 +++++++++++-------- ...essDepositTxAndDelayedPayoutTxMessage.java | 8 +++----- .../SellerFinalizesDelayedPayoutTx.java | 2 -- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/src/main/proto/pb.proto b/common/src/main/proto/pb.proto index b8c9a2b4c5d..340be39a106 100644 --- a/common/src/main/proto/pb.proto +++ b/common/src/main/proto/pb.proto @@ -1375,7 +1375,7 @@ message Trade { repeated ChatMessage chat_message = 29; MediationResultState mediation_result_state = 30; int64 lock_time = 31; - string delayed_payout_tx_id = 32; + bytes delayed_payout_tx_bytes = 32; NodeAddress refund_agent_node_address = 33; PubKeyRing refund_agent_pub_key_ring = 34; RefundResultState refund_result_state = 35; diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index fa06ff8219a..854f276436f 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -404,7 +404,7 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Nullable @Getter @Setter - private String delayedPayoutTxId; + private byte[] delayedPayoutTxBytes; @Nullable @Getter @Setter @@ -525,7 +525,7 @@ public Message toProtoMessage() { Optional.ofNullable(counterCurrencyTxId).ifPresent(e -> builder.setCounterCurrencyTxId(counterCurrencyTxId)); Optional.ofNullable(mediationResultState).ifPresent(e -> builder.setMediationResultState(MediationResultState.toProtoMessage(mediationResultState))); Optional.ofNullable(refundResultState).ifPresent(e -> builder.setRefundResultState(RefundResultState.toProtoMessage(refundResultState))); - Optional.ofNullable(delayedPayoutTxId).ifPresent(e -> builder.setDelayedPayoutTxId(delayedPayoutTxId)); + Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); return builder.build(); } @@ -555,8 +555,7 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv trade.setCounterCurrencyTxId(proto.getCounterCurrencyTxId().isEmpty() ? null : proto.getCounterCurrencyTxId()); trade.setMediationResultState(MediationResultState.fromProto(proto.getMediationResultState())); trade.setRefundResultState(RefundResultState.fromProto(proto.getRefundResultState())); - String delayedPayoutTxId = proto.getDelayedPayoutTxId(); - trade.setDelayedPayoutTxId(delayedPayoutTxId.isEmpty() ? null : delayedPayoutTxId); + trade.setDelayedPayoutTxBytes(ProtoUtil.byteArrayOrNullFromProto(proto.getDelayedPayoutTxBytes())); trade.setLockTime(proto.getLockTime()); trade.chatMessages.addAll(proto.getChatMessageList().stream() @@ -667,14 +666,19 @@ public Transaction getDepositTx() { public void applyDelayedPayoutTx(Transaction delayedPayoutTx) { this.delayedPayoutTx = delayedPayoutTx; - delayedPayoutTxId = delayedPayoutTx.getHashAsString(); + persist(); + } + + public void applyDelayedPayoutTxBytes(byte[] delayedPayoutTxBytes) { + this.delayedPayoutTxBytes = delayedPayoutTxBytes; persist(); } @Nullable public Transaction getDelayedPayoutTx() { - if (delayedPayoutTx == null) - delayedPayoutTx = delayedPayoutTxId != null ? btcWalletService.getTransaction(delayedPayoutTxId) : null; + if (delayedPayoutTx == null) { + delayedPayoutTx = delayedPayoutTxBytes != null ? processModel.getBtcWalletService().getTxFromSerializedTx(delayedPayoutTxBytes) : null; + } return delayedPayoutTx; } @@ -1118,7 +1122,7 @@ public String toString() { ",\n mediationResultState=" + mediationResultState + ",\n mediationResultStateProperty=" + mediationResultStateProperty + ",\n lockTime=" + lockTime + - ",\n delayedPayoutTxId='" + delayedPayoutTxId + '\'' + + ",\n delayedPayoutTxBytes=" + Utilities.bytesAsHexString(delayedPayoutTxBytes) + ",\n refundAgentNodeAddress=" + refundAgentNodeAddress + ",\n refundAgentPubKeyRing=" + refundAgentPubKeyRing + ",\n refundResultState=" + refundResultState + diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java index 7c0e3c7b3b2..509bfc7f163 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java @@ -58,11 +58,9 @@ protected void run() { BtcWalletService.printTx("depositTx received from peer", committedDepositTx); // To access tx confidence we need to add that tx into our wallet. - Transaction delayedPayoutTx = processModel.getBtcWalletService().getTxFromSerializedTx(message.getDelayedPayoutTx()); - trade.applyDelayedPayoutTx(delayedPayoutTx); - BtcWalletService.printTx("delayedPayoutTx received from peer", delayedPayoutTx); - - WalletService.maybeAddSelfTxToWallet(delayedPayoutTx, processModel.getBtcWalletService().getWallet()); + byte[] delayedPayoutTxBytes = message.getDelayedPayoutTx(); + trade.applyDelayedPayoutTxBytes(delayedPayoutTxBytes); + BtcWalletService.printTx("delayedPayoutTx received from peer", trade.getDelayedPayoutTx()); // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerFinalizesDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerFinalizesDelayedPayoutTx.java index f615bad0c44..c43dc9da4d5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerFinalizesDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerFinalizesDelayedPayoutTx.java @@ -19,7 +19,6 @@ import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.btc.wallet.WalletService; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.TradeTask; @@ -66,7 +65,6 @@ protected void run() { sellerSignature); trade.applyDelayedPayoutTx(signedDelayedPayoutTx); - WalletService.maybeAddSelfTxToWallet(signedDelayedPayoutTx, processModel.getBtcWalletService().getWallet()); complete(); } catch (Throwable t) {