check and extend timeout after taker creates reserve tx

This commit is contained in:
woodser 2023-12-16 10:13:09 -05:00
parent fe70a087c4
commit e11d65c038
2 changed files with 11 additions and 1 deletions

View File

@ -716,7 +716,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
// Timeout // Timeout
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
protected synchronized void startTimeout(long timeoutSec) { public synchronized void startTimeout(long timeoutSec) {
synchronized (timeoutTimerLock) { synchronized (timeoutTimerLock) {
stopTimeout(); stopTimeout();
timeoutTimer = UserThread.runAfter(() -> { timeoutTimer = UserThread.runAfter(() -> {

View File

@ -20,6 +20,7 @@ package haveno.core.trade.protocol.tasks;
import haveno.common.taskrunner.TaskRunner; import haveno.common.taskrunner.TaskRunner;
import haveno.core.offer.OfferDirection; import haveno.core.offer.OfferDirection;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import haveno.core.trade.protocol.TradeProtocol;
import haveno.core.xmr.model.XmrAddressEntry; import haveno.core.xmr.model.XmrAddressEntry;
import monero.daemon.model.MoneroOutput; import monero.daemon.model.MoneroOutput;
import monero.wallet.model.MoneroTxWallet; import monero.wallet.model.MoneroTxWallet;
@ -50,6 +51,15 @@ public class TakerReserveTradeFunds extends TradeTask {
List<String> reservedKeyImages = new ArrayList<String>(); List<String> reservedKeyImages = new ArrayList<String>();
for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex()); for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
// check for error in case creating reserve tx exceeded timeout
// TODO: better way?
if (!model.getXmrWalletService().getAddressEntry(trade.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).isPresent()) {
throw new RuntimeException("An error has occurred taking trade " + trade.getId() + " causing its subaddress entry to be deleted");
}
// extend protocol timeout
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);
// save process state // save process state
processModel.setReserveTx(reserveTx); processModel.setReserveTx(reserveTx);
processModel.getTaker().setReserveTxKeyImages(reservedKeyImages); processModel.getTaker().setReserveTxKeyImages(reservedKeyImages);