check for trade timeout after arbitrator request and reserve tx

This commit is contained in:
woodser 2024-03-22 09:57:06 -04:00
parent 9661e6fba8
commit 10a5b55dfe
4 changed files with 24 additions and 6 deletions

View File

@ -133,7 +133,7 @@ public class MakerSendSignOfferRequest extends Task<PlaceOfferModel> {
// if unavailable, try alternative arbitrator
@Override
public void onFault(String errorMessage) {
log.warn("Arbitrator unavailable: address={}: {}", arbitratorNodeAddress, errorMessage);
log.warn("Arbitrator unavailable: address={}, error={}", arbitratorNodeAddress, errorMessage);
excludedArbitrators.add(arbitratorNodeAddress);
// get alternative arbitrator

View File

@ -1217,6 +1217,12 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
}
}
public boolean hasOpenTrade(Trade trade) {
synchronized (tradableList) {
return tradableList.contains(trade);
}
}
public Optional<Trade> getOpenTradeByUid(String tradeUid) {
synchronized (tradableList) {
return tradableList.stream().filter(e -> e.getUid().equals(tradeUid)).findFirst();

View File

@ -51,10 +51,9 @@ public class TakerReserveTradeFunds extends TradeTask {
List<String> reservedKeyImages = new ArrayList<String>();
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");
// 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

View File

@ -70,14 +70,27 @@ public class TakerSendInitTradeRequestToArbitrator extends TradeTask {
@Override
public void onArrived() {
log.info("{} arrived at arbitrator: offerId={}", InitTradeRequest.class.getSimpleName(), trade.getId());
// check if trade still exists
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
errorMessageHandler.handleErrorMessage("Trade protocol no longer exists, tradeId=" + trade.getId());
return;
}
resultHandler.handleResult();
}
// if unavailable, try alternative arbitrator
@Override
public void onFault(String errorMessage) {
log.warn("Arbitrator {} unavailable: {}", arbitratorNodeAddress, errorMessage);
log.warn("Arbitrator unavailable: address={}, error={}", arbitratorNodeAddress, errorMessage);
excludedArbitrators.add(arbitratorNodeAddress);
// check if trade still exists
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
errorMessageHandler.handleErrorMessage("Trade protocol no longer exists, tradeId=" + trade.getId());
return;
}
Arbitrator altArbitrator = DisputeAgentSelection.getLeastUsedArbitrator(processModel.getTradeStatisticsManager(), processModel.getArbitratorManager(), excludedArbitrators);
if (altArbitrator == null) {
errorMessageHandler.handleErrorMessage("Cannot take offer because no arbitrators are available");