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 // if unavailable, try alternative arbitrator
@Override @Override
public void onFault(String errorMessage) { public void onFault(String errorMessage) {
log.warn("Arbitrator unavailable: address={}: {}", arbitratorNodeAddress, errorMessage); log.warn("Arbitrator unavailable: address={}, error={}", arbitratorNodeAddress, errorMessage);
excludedArbitrators.add(arbitratorNodeAddress); excludedArbitrators.add(arbitratorNodeAddress);
// get alternative arbitrator // 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) { public Optional<Trade> getOpenTradeByUid(String tradeUid) {
synchronized (tradableList) { synchronized (tradableList) {
return tradableList.stream().filter(e -> e.getUid().equals(tradeUid)).findFirst(); 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>(); 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 // check if trade still exists
// TODO: better way? if (!processModel.getTradeManager().hasOpenTrade(trade)) {
if (!model.getXmrWalletService().getAddressEntry(trade.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).isPresent()) { throw new RuntimeException("Trade protocol no longer exists after creating reserve tx, tradeId=" + trade.getId());
throw new RuntimeException("An error has occurred taking trade " + trade.getId() + " causing its subaddress entry to be deleted");
} }
// reset protocol timeout // reset protocol timeout

View File

@ -70,14 +70,27 @@ public class TakerSendInitTradeRequestToArbitrator extends TradeTask {
@Override @Override
public void onArrived() { public void onArrived() {
log.info("{} arrived at arbitrator: offerId={}", InitTradeRequest.class.getSimpleName(), trade.getId()); 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(); resultHandler.handleResult();
} }
// if unavailable, try alternative arbitrator // if unavailable, try alternative arbitrator
@Override @Override
public void onFault(String errorMessage) { public void onFault(String errorMessage) {
log.warn("Arbitrator {} unavailable: {}", arbitratorNodeAddress, errorMessage); log.warn("Arbitrator unavailable: address={}, error={}", arbitratorNodeAddress, errorMessage);
excludedArbitrators.add(arbitratorNodeAddress); 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); Arbitrator altArbitrator = DisputeAgentSelection.getLeastUsedArbitrator(processModel.getTradeStatisticsManager(), processModel.getArbitratorManager(), excludedArbitrators);
if (altArbitrator == null) { if (altArbitrator == null) {
errorMessageHandler.handleErrorMessage("Cannot take offer because no arbitrators are available"); errorMessageHandler.handleErrorMessage("Cannot take offer because no arbitrators are available");