synchronize on lock to prepare payment sent or received

This commit is contained in:
woodser 2024-10-25 11:35:55 -04:00
parent 5c4fa7a53f
commit 6db4812f06
2 changed files with 45 additions and 31 deletions

View File

@ -36,6 +36,7 @@ package haveno.core.trade.protocol.tasks;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import haveno.common.taskrunner.TaskRunner; import haveno.common.taskrunner.TaskRunner;
import haveno.core.trade.HavenoUtils;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import monero.wallet.MoneroWallet; import monero.wallet.MoneroWallet;
@ -79,6 +80,10 @@ public class BuyerPreparePaymentSentMessage extends TradeTask {
// create payout tx if we have seller's updated multisig hex // create payout tx if we have seller's updated multisig hex
if (trade.getSeller().getUpdatedMultisigHex() != null) { if (trade.getSeller().getUpdatedMultisigHex() != null) {
// synchronize on lock for wallet operations
synchronized (trade.getWalletLock()) {
synchronized (HavenoUtils.getWalletFunctionLock()) {
// import multisig hex // import multisig hex
trade.importMultisigHex(); trade.importMultisigHex();
@ -89,6 +94,8 @@ public class BuyerPreparePaymentSentMessage extends TradeTask {
trade.getSelf().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex()); trade.getSelf().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex());
trade.requestPersistence(); trade.requestPersistence();
} }
}
}
complete(); complete();
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -19,6 +19,7 @@ package haveno.core.trade.protocol.tasks;
import haveno.common.taskrunner.TaskRunner; import haveno.common.taskrunner.TaskRunner;
import haveno.core.support.dispute.Dispute; import haveno.core.support.dispute.Dispute;
import haveno.core.trade.HavenoUtils;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import monero.wallet.model.MoneroTxWallet; import monero.wallet.model.MoneroTxWallet;
@ -49,6 +50,10 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask {
trade.setPayoutTxHex(null); trade.setPayoutTxHex(null);
} }
// synchronize on lock for wallet operations
synchronized (trade.getWalletLock()) {
synchronized (HavenoUtils.getWalletFunctionLock()) {
// import multisig hex unless already signed // import multisig hex unless already signed
if (trade.getPayoutTxHex() == null) { if (trade.getPayoutTxHex() == null) {
trade.importMultisigHex(); trade.importMultisigHex();
@ -65,7 +70,7 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask {
trade.processPayoutTx(trade.getPayoutTxHex(), false, true); trade.processPayoutTx(trade.getPayoutTxHex(), false, true);
} }
} catch (IllegalArgumentException | IllegalStateException e) { } catch (IllegalArgumentException | IllegalStateException e) {
log.warn("Illegal state or argument verifying, signing, and publishing payout tx for {} {}: {}. Creating new unsigned payout tx", trade.getClass().getSimpleName(), trade.getId(), e.getMessage(), e); log.warn("Illegal state or argument verifying, signing, and publishing payout tx for {} {}. Creating new unsigned payout tx. error={}. ", trade.getClass().getSimpleName(), trade.getId(), e.getMessage(), e);
createUnsignedPayoutTx(); createUnsignedPayoutTx();
} catch (Exception e) { } catch (Exception e) {
log.warn("Error verifying, signing, and publishing payout tx for trade {}: {}", trade.getId(), e.getMessage(), e); log.warn("Error verifying, signing, and publishing payout tx for trade {}: {}", trade.getId(), e.getMessage(), e);
@ -77,6 +82,8 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask {
else if (trade.getSelf().getUnsignedPayoutTxHex() == null) { else if (trade.getSelf().getUnsignedPayoutTxHex() == null) {
createUnsignedPayoutTx(); createUnsignedPayoutTx();
} }
}
}
} else if (trade.getArbitrator().getPaymentReceivedMessage().getSignedPayoutTxHex() != null && !trade.isPayoutPublished()) { } else if (trade.getArbitrator().getPaymentReceivedMessage().getSignedPayoutTxHex() != null && !trade.isPayoutPublished()) {
// republish payout tx from previous message // republish payout tx from previous message