stop trade protocol if timeout while creating reserve or deposit tx

This commit is contained in:
woodser 2024-03-25 10:31:36 -04:00 committed by GitHub
parent db12f1c2cb
commit 7eabde63f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 100 additions and 92 deletions

View File

@ -58,8 +58,7 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(makerFee, sendAmount, securityDeposit, returnAddress, model.getOpenOffer().isReserveExactAmount(), preferredSubaddressIndex);
// check for error in case creating reserve tx exceeded timeout
// TODO: better way?
// check for error in case creating reserve tx exceeded timeout // TODO: better way?
if (!model.getXmrWalletService().getAddressEntry(offer.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).isPresent()) {
throw new RuntimeException("An error has occurred posting offer " + offer.getId() + " causing its subaddress entry to be deleted");
}

View File

@ -26,6 +26,7 @@ import haveno.core.trade.MakerTrade;
import haveno.core.trade.Trade;
import haveno.core.trade.Trade.State;
import haveno.core.trade.messages.SignContractRequest;
import haveno.core.trade.protocol.TradeProtocol;
import haveno.core.xmr.model.XmrAddressEntry;
import haveno.network.p2p.SendDirectMessageListener;
import lombok.extern.slf4j.Slf4j;
@ -85,6 +86,14 @@ public class MaybeSendSignContractRequest extends TradeTask {
}
MoneroTxWallet depositTx = trade.getXmrWalletService().createDepositTx(trade, reserveExactAmount, subaddressIndex);
// check if trade still exists
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
throw new RuntimeException("Trade protocol has timed out while creating reserve tx, tradeId=" + trade.getId());
}
// reset protocol timeout
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);
// collect reserved key images
List<String> reservedKeyImages = new ArrayList<String>();
for (MoneroOutput input : depositTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());

View File

@ -47,15 +47,15 @@ public class TakerReserveTradeFunds extends TradeTask {
String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(trade.getOffer().getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString();
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, sendAmount, securityDeposit, returnAddress, false, null);
// check if trade still exists
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
throw new RuntimeException("Trade protocol has timed out while creating reserve tx, tradeId=" + trade.getId());
}
// collect reserved key images
List<String> reservedKeyImages = new ArrayList<String>();
for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
// check if trade still exists
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
throw new RuntimeException("Trade protocol no longer exists after creating reserve tx, tradeId=" + trade.getId());
}
// reset protocol timeout
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);