Skip to content

Commit

Permalink
Do not commit delayedPayoutTx to avoid publishing at restart
Browse files Browse the repository at this point in the history
Fixes #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).
  • Loading branch information
chimp1984 committed Oct 25, 2019
1 parent f0242bf commit 62bc004
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 12 additions & 8 deletions core/src/main/java/bisq/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt
@Nullable
@Getter
@Setter
private String delayedPayoutTxId;
private byte[] delayedPayoutTxBytes;
@Nullable
@Getter
@Setter
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,7 +65,6 @@ protected void run() {
sellerSignature);

trade.applyDelayedPayoutTx(signedDelayedPayoutTx);
WalletService.maybeAddSelfTxToWallet(signedDelayedPayoutTx, processModel.getBtcWalletService().getWallet());

complete();
} catch (Throwable t) {
Expand Down

0 comments on commit 62bc004

Please sign in to comment.