mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-24 14:50:28 -04:00
schedule import multisig hex on deposit confirmation msg
This commit is contained in:
parent
cb69d06468
commit
d4eb30bb97
4 changed files with 43 additions and 19 deletions
|
@ -143,6 +143,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
private static final long DELETE_AFTER_NUM_BLOCKS = 2; // if deposit requested but not published
|
private static final long DELETE_AFTER_NUM_BLOCKS = 2; // if deposit requested but not published
|
||||||
private static final long EXTENDED_RPC_TIMEOUT = 600000; // 10 minutes
|
private static final long EXTENDED_RPC_TIMEOUT = 600000; // 10 minutes
|
||||||
private static final long DELETE_AFTER_MS = TradeProtocol.TRADE_STEP_TIMEOUT_SECONDS;
|
private static final long DELETE_AFTER_MS = TradeProtocol.TRADE_STEP_TIMEOUT_SECONDS;
|
||||||
|
private static final int NUM_CONFIRMATIONS_FOR_SCHEDULED_IMPORT = 10;
|
||||||
protected final Object pollLock = new Object();
|
protected final Object pollLock = new Object();
|
||||||
protected static final Object importMultisigLock = new Object();
|
protected static final Object importMultisigLock = new Object();
|
||||||
private boolean pollInProgress;
|
private boolean pollInProgress;
|
||||||
|
@ -741,6 +742,11 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle confirmations
|
||||||
|
walletHeight.addListener((observable, oldValue, newValue) -> {
|
||||||
|
importMultisigHexIfScheduled();
|
||||||
|
});
|
||||||
|
|
||||||
// trade is initialized
|
// trade is initialized
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
|
|
||||||
|
@ -1077,6 +1083,26 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scheduleImportMultisigHex() {
|
||||||
|
processModel.setImportMultisigHexScheduled(true);
|
||||||
|
requestPersistence();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importMultisigHexIfScheduled() {
|
||||||
|
if (!isInitialized || isShutDownStarted) return;
|
||||||
|
if (!isDepositsConfirmed() || getMaker().getDepositTx() == null) return;
|
||||||
|
if (walletHeight.get() - getMaker().getDepositTx().getHeight() < NUM_CONFIRMATIONS_FOR_SCHEDULED_IMPORT) return;
|
||||||
|
ThreadUtils.execute(() -> {
|
||||||
|
if (!isInitialized || isShutDownStarted) return;
|
||||||
|
synchronized (getLock()) {
|
||||||
|
if (processModel.isImportMultisigHexScheduled()) {
|
||||||
|
processModel.setImportMultisigHexScheduled(false);
|
||||||
|
ThreadUtils.submitToPool(() -> importMultisigHex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, getId());
|
||||||
|
}
|
||||||
|
|
||||||
public void importMultisigHex() {
|
public void importMultisigHex() {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
synchronized (HavenoUtils.getDaemonLock()) { // lock on daemon because import calls full refresh
|
synchronized (HavenoUtils.getDaemonLock()) { // lock on daemon because import calls full refresh
|
||||||
|
@ -1141,6 +1167,9 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
if (removed) wallet.importMultisigHex(multisigHexes.toArray(new String[0]));
|
if (removed) wallet.importMultisigHex(multisigHexes.toArray(new String[0]));
|
||||||
if (wallet.isMultisigImportNeeded()) throw new IllegalStateException(errorMessage);
|
if (wallet.isMultisigImportNeeded()) throw new IllegalStateException(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove scheduled import
|
||||||
|
processModel.setImportMultisigHexScheduled(false);
|
||||||
} catch (MoneroError e) {
|
} catch (MoneroError e) {
|
||||||
|
|
||||||
// import multisig hex individually if one is invalid
|
// import multisig hex individually if one is invalid
|
||||||
|
@ -2350,7 +2379,12 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
return tradeAmountTransferred();
|
return tradeAmountTransferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tradeAmountTransferred() {
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Private
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private boolean tradeAmountTransferred() {
|
||||||
return isPaymentReceived() || (getDisputeResult() != null && getDisputeResult().getWinner() == DisputeResult.Winner.SELLER);
|
return isPaymentReceived() || (getDisputeResult() != null && getDisputeResult().getWinner() == DisputeResult.Winner.SELLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2366,11 +2400,6 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Private
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// lazy initialization
|
// lazy initialization
|
||||||
private ObjectProperty<BigInteger> getAmountProperty() {
|
private ObjectProperty<BigInteger> getAmountProperty() {
|
||||||
if (tradeAmountProperty == null)
|
if (tradeAmountProperty == null)
|
||||||
|
|
|
@ -158,6 +158,9 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private long tradeProtocolErrorHeight;
|
private long tradeProtocolErrorHeight;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean importMultisigHexScheduled;
|
||||||
|
|
||||||
// We want to indicate the user the state of the message delivery of the
|
// We want to indicate the user the state of the message delivery of the
|
||||||
// PaymentSentMessage. As well we do an automatic re-send in case it was not ACKed yet.
|
// PaymentSentMessage. As well we do an automatic re-send in case it was not ACKed yet.
|
||||||
|
@ -207,7 +210,8 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
.setPaymentSentMessageStateArbitrator(paymentSentMessageStatePropertyArbitrator.get().name())
|
.setPaymentSentMessageStateArbitrator(paymentSentMessageStatePropertyArbitrator.get().name())
|
||||||
.setBuyerPayoutAmountFromMediation(buyerPayoutAmountFromMediation)
|
.setBuyerPayoutAmountFromMediation(buyerPayoutAmountFromMediation)
|
||||||
.setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation)
|
.setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation)
|
||||||
.setTradeProtocolErrorHeight(tradeProtocolErrorHeight);
|
.setTradeProtocolErrorHeight(tradeProtocolErrorHeight)
|
||||||
|
.setImportMultisigHexScheduled(importMultisigHexScheduled);
|
||||||
Optional.ofNullable(maker).ifPresent(e -> builder.setMaker((protobuf.TradePeer) maker.toProtoMessage()));
|
Optional.ofNullable(maker).ifPresent(e -> builder.setMaker((protobuf.TradePeer) maker.toProtoMessage()));
|
||||||
Optional.ofNullable(taker).ifPresent(e -> builder.setTaker((protobuf.TradePeer) taker.toProtoMessage()));
|
Optional.ofNullable(taker).ifPresent(e -> builder.setTaker((protobuf.TradePeer) taker.toProtoMessage()));
|
||||||
Optional.ofNullable(arbitrator).ifPresent(e -> builder.setArbitrator((protobuf.TradePeer) arbitrator.toProtoMessage()));
|
Optional.ofNullable(arbitrator).ifPresent(e -> builder.setArbitrator((protobuf.TradePeer) arbitrator.toProtoMessage()));
|
||||||
|
@ -231,6 +235,7 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||||
processModel.setBuyerPayoutAmountFromMediation(proto.getBuyerPayoutAmountFromMediation());
|
processModel.setBuyerPayoutAmountFromMediation(proto.getBuyerPayoutAmountFromMediation());
|
||||||
processModel.setSellerPayoutAmountFromMediation(proto.getSellerPayoutAmountFromMediation());
|
processModel.setSellerPayoutAmountFromMediation(proto.getSellerPayoutAmountFromMediation());
|
||||||
processModel.setTradeProtocolErrorHeight(proto.getTradeProtocolErrorHeight());
|
processModel.setTradeProtocolErrorHeight(proto.getTradeProtocolErrorHeight());
|
||||||
|
processModel.setImportMultisigHexScheduled(proto.getImportMultisigHexScheduled());
|
||||||
|
|
||||||
// nullable
|
// nullable
|
||||||
processModel.setPayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getPayoutTxSignature()));
|
processModel.setPayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getPayoutTxSignature()));
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
package haveno.core.trade.protocol.tasks;
|
package haveno.core.trade.protocol.tasks;
|
||||||
|
|
||||||
|
|
||||||
import haveno.common.ThreadUtils;
|
|
||||||
import haveno.common.taskrunner.TaskRunner;
|
import haveno.common.taskrunner.TaskRunner;
|
||||||
import haveno.core.trade.Trade;
|
import haveno.core.trade.Trade;
|
||||||
import haveno.core.trade.messages.DepositsConfirmedMessage;
|
import haveno.core.trade.messages.DepositsConfirmedMessage;
|
||||||
|
@ -63,17 +62,7 @@ public class ProcessDepositsConfirmedMessage extends TradeTask {
|
||||||
// update multisig hex
|
// update multisig hex
|
||||||
if (sender.getUpdatedMultisigHex() == null) {
|
if (sender.getUpdatedMultisigHex() == null) {
|
||||||
sender.setUpdatedMultisigHex(request.getUpdatedMultisigHex());
|
sender.setUpdatedMultisigHex(request.getUpdatedMultisigHex());
|
||||||
|
trade.scheduleImportMultisigHex();
|
||||||
// try to import multisig hex (retry later)
|
|
||||||
if (!trade.isPayoutPublished()) {
|
|
||||||
ThreadUtils.submitToPool(() -> {
|
|
||||||
try {
|
|
||||||
trade.importMultisigHex();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("Error importing multisig hex on deposits confirmed for trade " + trade.getId() + ": " + e.getMessage() + "\n", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist
|
// persist
|
||||||
|
|
|
@ -1581,6 +1581,7 @@ message ProcessModel {
|
||||||
int64 seller_payout_amount_from_mediation = 17;
|
int64 seller_payout_amount_from_mediation = 17;
|
||||||
int64 trade_protocol_error_height = 18;
|
int64 trade_protocol_error_height = 18;
|
||||||
string trade_fee_address = 19;
|
string trade_fee_address = 19;
|
||||||
|
bool import_multisig_hex_scheduled = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TradePeer {
|
message TradePeer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue