do not process trade messages if trade already failed

start monero-wallet-rpc without connection
add logging
This commit is contained in:
woodser 2023-03-08 10:49:27 -05:00
parent 5b8f9237ce
commit 8ea556fa4f
6 changed files with 43 additions and 8 deletions

View File

@ -699,7 +699,9 @@ public abstract class Trade implements Tradable, Model {
public MoneroWallet createWallet() {
synchronized (walletLock) {
if (walletExists()) throw new RuntimeException("Cannot create trade wallet because it already exists");
long time = System.currentTimeMillis();
wallet = xmrWalletService.createWallet(getWalletName());
log.info("{} {} created multisig wallet in {} ms", getClass().getSimpleName(), getId(), System.currentTimeMillis() - time);
return wallet;
}
}

View File

@ -287,8 +287,16 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void handleInitMultisigRequest(InitMultisigRequest request, NodeAddress sender) {
System.out.println(getClass().getSimpleName() + ".handleInitMultisigRequest()");
synchronized (trade) {
latchTrade();
// check trade
if (trade.hasFailed()) {
log.warn("{} {} ignoring {} from {} because trade failed with previous error: {}", trade.getClass().getSimpleName(), trade.getId(), request.getClass().getSimpleName(), sender, trade.getErrorMessage());
return;
}
Validator.checkTradeId(processModel.getOfferId(), request);
// proocess message
latchTrade();
processModel.setTradeMessage(request);
expect(anyPhase(Trade.Phase.INIT)
.with(request)
@ -313,7 +321,15 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void handleSignContractRequest(SignContractRequest message, NodeAddress sender) {
System.out.println(getClass().getSimpleName() + ".handleSignContractRequest() " + trade.getId());
synchronized (trade) {
// check trade
if (trade.hasFailed()) {
log.warn("{} {} ignoring {} from {} because trade failed with previous error: {}", trade.getClass().getSimpleName(), trade.getId(), message.getClass().getSimpleName(), sender, trade.getErrorMessage());
return;
}
Validator.checkTradeId(processModel.getOfferId(), message);
// process message
if (trade.getState() == Trade.State.MULTISIG_COMPLETED || trade.getState() == Trade.State.CONTRACT_SIGNATURE_REQUESTED) {
latchTrade();
Validator.checkTradeId(processModel.getOfferId(), message);
@ -347,7 +363,15 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void handleSignContractResponse(SignContractResponse message, NodeAddress sender) {
System.out.println(getClass().getSimpleName() + ".handleSignContractResponse() " + trade.getId());
synchronized (trade) {
// check trade
if (trade.hasFailed()) {
log.warn("{} {} ignoring {} from {} because trade failed with previous error: {}", trade.getClass().getSimpleName(), trade.getId(), message.getClass().getSimpleName(), sender, trade.getErrorMessage());
return;
}
Validator.checkTradeId(processModel.getOfferId(), message);
// process message
if (trade.getState() == Trade.State.CONTRACT_SIGNED) {
latchTrade();
Validator.checkTradeId(processModel.getOfferId(), message);
@ -381,8 +405,16 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
public void handleDepositResponse(DepositResponse response, NodeAddress sender) {
System.out.println(getClass().getSimpleName() + ".handleDepositResponse()");
synchronized (trade) {
latchTrade();
// check trade
if (trade.hasFailed()) {
log.warn("{} {} ignoring {} from {} because trade failed with previous error: {}", trade.getClass().getSimpleName(), trade.getId(), response.getClass().getSimpleName(), sender, trade.getErrorMessage());
return;
}
Validator.checkTradeId(processModel.getOfferId(), response);
// process message
latchTrade();
processModel.setTradeMessage(response);
expect(anyState(Trade.State.SENT_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.ARBITRATOR_PUBLISHED_DEPOSIT_TXS, Trade.State.DEPOSIT_TXS_SEEN_IN_NETWORK)
.with(response)

View File

@ -77,7 +77,7 @@ public class ProcessInitMultisigRequest extends TradeTask {
// prepare multisig if applicable
boolean updateParticipants = false;
if (trade.getSelf().getPreparedMultisigHex() == null) {
log.info("Preparing multisig wallet for trade {}", trade.getId());
log.info("Preparing multisig wallet for {} {}", trade.getClass().getSimpleName(), trade.getId());
multisigWallet = trade.createWallet();
trade.getSelf().setPreparedMultisigHex(multisigWallet.prepareMultisig());
trade.setStateIfValidTransitionTo(Trade.State.MULTISIG_PREPARED);
@ -89,7 +89,7 @@ public class ProcessInitMultisigRequest extends TradeTask {
// make multisig if applicable
TradePeer[] peers = getMultisigPeers();
if (trade.getSelf().getMadeMultisigHex() == null && peers[0].getPreparedMultisigHex() != null && peers[1].getPreparedMultisigHex() != null) {
log.info("Making multisig wallet for trade {}", trade.getId());
log.info("Making multisig wallet for {} {}", trade.getClass().getSimpleName(), trade.getId());
String multisigHex = multisigWallet.makeMultisig(Arrays.asList(peers[0].getPreparedMultisigHex(), peers[1].getPreparedMultisigHex()), 2, xmrWalletService.getWalletPassword()); // TODO (woodser): xmrWalletService.makeMultisig(tradeId, multisigHexes, threshold)?
trade.getSelf().setMadeMultisigHex(multisigHex);
trade.setStateIfValidTransitionTo(Trade.State.MULTISIG_MADE);
@ -98,7 +98,7 @@ public class ProcessInitMultisigRequest extends TradeTask {
// import made multisig keys if applicable
if (trade.getSelf().getExchangedMultisigHex() == null && peers[0].getMadeMultisigHex() != null && peers[1].getMadeMultisigHex() != null) {
log.info("Importing made multisig hex for trade {}", trade.getId());
log.info("Importing made multisig hex for {} {}", trade.getClass().getSimpleName(), trade.getId());
MoneroMultisigInitResult result = multisigWallet.exchangeMultisigKeys(Arrays.asList(peers[0].getMadeMultisigHex(), peers[1].getMadeMultisigHex()), xmrWalletService.getWalletPassword());
trade.getSelf().setExchangedMultisigHex(result.getMultisigHex());
trade.setStateIfValidTransitionTo(Trade.State.MULTISIG_EXCHANGED);
@ -144,6 +144,8 @@ public class ProcessInitMultisigRequest extends TradeTask {
if (peer2Address == null) throw new RuntimeException("Peer2 address is null");
if (peer2PubKeyRing == null) throw new RuntimeException("Peer2 pub key ring null");
log.info("{} {} sending InitMultisigRequests", trade.getClass().getSimpleName(), trade.getId());
// send to peer 1
sendInitMultisigRequest(peer1Address, peer1PubKeyRing, new SendDirectMessageListener() {
@Override

View File

@ -34,7 +34,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static haveno.core.util.Validator.checkTradeId;
import static haveno.core.util.Validator.nonEmptyStringOf;
import java.math.BigInteger;
import java.util.Date;
@Slf4j

View File

@ -574,7 +574,7 @@ public class XmrWalletService {
private MoneroWalletRpc createWallet(MoneroWalletConfig config, Integer port, boolean sync) {
// start monero-wallet-rpc instance
MoneroWalletRpc walletRpc = startWalletRpcInstance(port, sync);
MoneroWalletRpc walletRpc = startWalletRpcInstance(port, false);
// must be connected to daemon
MoneroRpcConnection connection = connectionsService.getConnection();