mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-11-17 00:07:49 +00:00
do not resend payment sent message to arbitrator after ack
This commit is contained in:
parent
857179f42d
commit
947caca647
7 changed files with 58 additions and 14 deletions
|
@ -144,6 +144,8 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
// To enable that even after restart we persist the state.
|
// To enable that even after restart we persist the state.
|
||||||
@Setter
|
@Setter
|
||||||
private ObjectProperty<MessageState> paymentSentMessageStateProperty = new SimpleObjectProperty<>(MessageState.UNDEFINED);
|
private ObjectProperty<MessageState> paymentSentMessageStateProperty = new SimpleObjectProperty<>(MessageState.UNDEFINED);
|
||||||
|
@Setter
|
||||||
|
private ObjectProperty<MessageState> paymentSentMessageStatePropertyArbitrator = new SimpleObjectProperty<>(MessageState.UNDEFINED);
|
||||||
|
|
||||||
public ProcessModel(String offerId, String accountId, PubKeyRing pubKeyRing) {
|
public ProcessModel(String offerId, String accountId, PubKeyRing pubKeyRing) {
|
||||||
this(offerId, accountId, pubKeyRing, new TradePeer(), new TradePeer(), new TradePeer());
|
this(offerId, accountId, pubKeyRing, new TradePeer(), new TradePeer(), new TradePeer());
|
||||||
|
@ -181,6 +183,7 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
.setUseSavingsWallet(useSavingsWallet)
|
.setUseSavingsWallet(useSavingsWallet)
|
||||||
.setFundsNeededForTrade(fundsNeededForTrade)
|
.setFundsNeededForTrade(fundsNeededForTrade)
|
||||||
.setPaymentSentMessageState(paymentSentMessageStateProperty.get().name())
|
.setPaymentSentMessageState(paymentSentMessageStateProperty.get().name())
|
||||||
|
.setPaymentSentMessageStateArbitrator(paymentSentMessageStatePropertyArbitrator.get().name())
|
||||||
.setBuyerPayoutAmountFromMediation(buyerPayoutAmountFromMediation)
|
.setBuyerPayoutAmountFromMediation(buyerPayoutAmountFromMediation)
|
||||||
.setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation)
|
.setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation)
|
||||||
.setDeleteBackupsHeight(deleteBackupsHeight);
|
.setDeleteBackupsHeight(deleteBackupsHeight);
|
||||||
|
@ -218,6 +221,10 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
MessageState paymentSentMessageState = ProtoUtil.enumFromProto(MessageState.class, paymentSentMessageStateString);
|
MessageState paymentSentMessageState = ProtoUtil.enumFromProto(MessageState.class, paymentSentMessageStateString);
|
||||||
processModel.setPaymentSentMessageState(paymentSentMessageState);
|
processModel.setPaymentSentMessageState(paymentSentMessageState);
|
||||||
|
|
||||||
|
String paymentSentMessageStateArbitratorString = ProtoUtil.stringOrNullFromProto(proto.getPaymentSentMessageStateArbitrator());
|
||||||
|
MessageState paymentSentMessageStateArbitrator = ProtoUtil.enumFromProto(MessageState.class, paymentSentMessageStateArbitratorString);
|
||||||
|
processModel.setPaymentSentMessageStateArbitrator(paymentSentMessageStateArbitrator);
|
||||||
|
|
||||||
return processModel;
|
return processModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +258,13 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
setPaymentSentMessageState(messageState);
|
setPaymentSentMessageState(messageState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPaymentSentAckMessageArbitrator(AckMessage ackMessage) {
|
||||||
|
MessageState messageState = ackMessage.isSuccess() ?
|
||||||
|
MessageState.ACKNOWLEDGED :
|
||||||
|
MessageState.FAILED;
|
||||||
|
setPaymentSentMessageStateArbitrator(messageState);
|
||||||
|
}
|
||||||
|
|
||||||
public void setPaymentSentMessageState(MessageState paymentSentMessageStateProperty) {
|
public void setPaymentSentMessageState(MessageState paymentSentMessageStateProperty) {
|
||||||
this.paymentSentMessageStateProperty.set(paymentSentMessageStateProperty);
|
this.paymentSentMessageStateProperty.set(paymentSentMessageStateProperty);
|
||||||
if (tradeManager != null) {
|
if (tradeManager != null) {
|
||||||
|
@ -258,6 +272,13 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPaymentSentMessageStateArbitrator(MessageState paymentSentMessageStateProperty) {
|
||||||
|
this.paymentSentMessageStatePropertyArbitrator.set(paymentSentMessageStateProperty);
|
||||||
|
if (tradeManager != null) {
|
||||||
|
tradeManager.requestPersistence();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setDepositTxSentAckMessage(AckMessage ackMessage) {
|
void setDepositTxSentAckMessage(AckMessage ackMessage) {
|
||||||
MessageState messageState = ackMessage.isSuccess() ?
|
MessageState messageState = ackMessage.isSuccess() ?
|
||||||
MessageState.ACKNOWLEDGED :
|
MessageState.ACKNOWLEDGED :
|
||||||
|
|
|
@ -663,6 +663,8 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
||||||
if (ackMessage.getSourceMsgClassName().equals(PaymentSentMessage.class.getSimpleName())) {
|
if (ackMessage.getSourceMsgClassName().equals(PaymentSentMessage.class.getSimpleName())) {
|
||||||
if (trade.getTradePeer(sender) == trade.getSeller()) {
|
if (trade.getTradePeer(sender) == trade.getSeller()) {
|
||||||
processModel.setPaymentSentAckMessage(ackMessage);
|
processModel.setPaymentSentAckMessage(ackMessage);
|
||||||
|
} else if (trade.getTradePeer(sender) == trade.getArbitrator()) {
|
||||||
|
processModel.setPaymentSentAckMessageArbitrator(ackMessage);
|
||||||
} else if (!ackMessage.isSuccess()) {
|
} else if (!ackMessage.isSuccess()) {
|
||||||
String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ sender + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage();
|
String err = "Received AckMessage with error state for " + ackMessage.getSourceMsgClassName() + " from "+ sender + " with tradeId " + trade.getId() + " and errorMessage=" + ackMessage.getErrorMessage();
|
||||||
log.warn(err);
|
log.warn(err);
|
||||||
|
|
|
@ -73,6 +73,13 @@ public abstract class BuyerSendPaymentSentMessage extends SendMailboxMessageTask
|
||||||
protected void run() {
|
protected void run() {
|
||||||
try {
|
try {
|
||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
|
|
||||||
|
// skip if already acked by receiver
|
||||||
|
if (isAckedByReceiver()) {
|
||||||
|
if (!isCompleted()) complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
super.run();
|
super.run();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
failed(t);
|
failed(t);
|
||||||
|
@ -153,7 +160,7 @@ public abstract class BuyerSendPaymentSentMessage extends SendMailboxMessageTask
|
||||||
private void tryToSendAgainLater() {
|
private void tryToSendAgainLater() {
|
||||||
|
|
||||||
// skip if already acked
|
// skip if already acked
|
||||||
if (trade.getState().ordinal() >= Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG.ordinal()) return;
|
if (isAckedByReceiver()) return;
|
||||||
|
|
||||||
if (resendCounter >= MAX_RESEND_ATTEMPTS) {
|
if (resendCounter >= MAX_RESEND_ATTEMPTS) {
|
||||||
cleanup();
|
cleanup();
|
||||||
|
@ -185,4 +192,6 @@ public abstract class BuyerSendPaymentSentMessage extends SendMailboxMessageTask
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract boolean isAckedByReceiver();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package haveno.core.trade.protocol.tasks;
|
package haveno.core.trade.protocol.tasks;
|
||||||
|
|
||||||
import haveno.common.taskrunner.TaskRunner;
|
import haveno.common.taskrunner.TaskRunner;
|
||||||
|
import haveno.core.network.MessageState;
|
||||||
import haveno.core.trade.Trade;
|
import haveno.core.trade.Trade;
|
||||||
import haveno.core.trade.protocol.TradePeer;
|
import haveno.core.trade.protocol.TradePeer;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -55,4 +56,9 @@ public class BuyerSendPaymentSentMessageToArbitrator extends BuyerSendPaymentSen
|
||||||
protected void setStateArrived() {
|
protected void setStateArrived() {
|
||||||
// state only updated on seller message
|
// state only updated on seller message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isAckedByReceiver() {
|
||||||
|
return trade.getProcessModel().getPaymentSentMessageStatePropertyArbitrator().get() == MessageState.ACKNOWLEDGED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,9 @@ public class BuyerSendPaymentSentMessageToSeller extends BuyerSendPaymentSentMes
|
||||||
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
|
||||||
complete();
|
complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isAckedByReceiver() {
|
||||||
|
return trade.getState().ordinal() >= Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG.ordinal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas
|
||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
|
|
||||||
// skip if already acked by receiver
|
// skip if already acked by receiver
|
||||||
if (ackedByReceiver()) {
|
if (isAckedByReceiver()) {
|
||||||
if (!isCompleted()) complete();
|
if (!isCompleted()) complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas
|
||||||
private void tryToSendAgainLater() {
|
private void tryToSendAgainLater() {
|
||||||
|
|
||||||
// skip if already acked or payout published
|
// skip if already acked or payout published
|
||||||
if (ackedByReceiver() || trade.isPayoutPublished()) return;
|
if (isAckedByReceiver() || trade.isPayoutPublished()) return;
|
||||||
|
|
||||||
if (resendCounter >= MAX_RESEND_ATTEMPTS) {
|
if (resendCounter >= MAX_RESEND_ATTEMPTS) {
|
||||||
cleanup();
|
cleanup();
|
||||||
|
@ -151,7 +151,7 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas
|
||||||
resendCounter++;
|
resendCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ackedByReceiver() {
|
private boolean isAckedByReceiver() {
|
||||||
TradePeer peer = trade.getTradePeer(getReceiverNodeAddress());
|
TradePeer peer = trade.getTradePeer(getReceiverNodeAddress());
|
||||||
return peer.isDepositsConfirmedMessageAcked();
|
return peer.isDepositsConfirmedMessageAcked();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1538,16 +1538,17 @@ message ProcessModel {
|
||||||
bool use_savings_wallet = 5;
|
bool use_savings_wallet = 5;
|
||||||
int64 funds_needed_for_trade = 6;
|
int64 funds_needed_for_trade = 6;
|
||||||
string payment_sent_message_state = 7;
|
string payment_sent_message_state = 7;
|
||||||
bytes maker_signature = 8;
|
string payment_sent_message_state_arbitrator = 8;
|
||||||
TradePeer maker = 9;
|
bytes maker_signature = 9;
|
||||||
TradePeer taker = 10;
|
TradePeer maker = 10;
|
||||||
TradePeer arbitrator = 11;
|
TradePeer taker = 11;
|
||||||
NodeAddress temp_trade_peer_node_address = 12;
|
TradePeer arbitrator = 12;
|
||||||
string multisig_address = 13;
|
NodeAddress temp_trade_peer_node_address = 13;
|
||||||
bytes mediated_payout_tx_signature = 17; // placeholder if mediation used in future
|
string multisig_address = 14;
|
||||||
int64 buyer_payout_amount_from_mediation = 18;
|
bytes mediated_payout_tx_signature = 15; // placeholder if mediation used in future
|
||||||
int64 seller_payout_amount_from_mediation = 19;
|
int64 buyer_payout_amount_from_mediation = 16;
|
||||||
int64 delete_backups_height = 31;
|
int64 seller_payout_amount_from_mediation = 17;
|
||||||
|
int64 delete_backups_height = 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TradePeer {
|
message TradePeer {
|
||||||
|
|
Loading…
Reference in a new issue