avoid persisting when maybe sending deposits confirmed message

This commit is contained in:
woodser 2023-05-29 11:48:13 -04:00
parent 870630b381
commit c197ffb282
3 changed files with 26 additions and 2 deletions

View File

@ -413,6 +413,11 @@ public class PersistenceManager<T extends PersistableEnvelope> {
public void requestPersistence() {
if (flushAtShutdownCalled) {
log.warn("We have started the shut down routine already. We ignore that requestPersistence call.");
try {
throw new RuntimeException("We have started the shut down routine already. We ignore that requestPersistence call.");
} catch (Exception e) {
e.printStackTrace();
}
return;
}

View File

@ -1359,6 +1359,15 @@ public abstract class Trade implements Tradable, Model {
throw new RuntimeException("Trade is not maker, taker, or arbitrator");
}
private List<TradePeer> getPeers() {
List<TradePeer> peers = new ArrayList<TradePeer>();
peers.add(getMaker());
peers.add(getTaker());
peers.add(getArbitrator());
if (!peers.remove(getSelf())) throw new IllegalStateException("Failed to remove self from list of peers");
return peers;
}
public TradePeer getArbitrator() {
return processModel.getArbitrator();
}
@ -1522,6 +1531,16 @@ public abstract class Trade implements Tradable, Model {
return isDepositsPublished() && getState().getPhase().ordinal() >= Phase.DEPOSITS_CONFIRMED.ordinal();
}
// TODO: hacky way to check for deposits confirmed acks, redundant with getDepositsConfirmedTasks()
public boolean isDepositsConfirmedAcked() {
if (this instanceof BuyerTrade) {
return getArbitrator().isDepositsConfirmedMessageAcked();
} else {
for (TradePeer peer : getPeers()) if (!peer.isDepositsConfirmedMessageAcked()) return false;
return true;
}
}
public boolean isDepositsUnlocked() {
return isDepositsPublished() && getState().getPhase().ordinal() >= Phase.DEPOSITS_UNLOCKED.ordinal();
}

View File

@ -863,9 +863,9 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
}
public void maybeSendDepositsConfirmedMessages() {
if (trade.isShutDownStarted()) return;
synchronized (trade) {
if (!trade.isInitialized()) return; // skip if shutting down
if (trade.isDepositsConfirmedAcked()) return;
if (!trade.isInitialized() || trade.isShutDownStarted()) return; // skip if shutting down
latchTrade();
expect(new Condition(trade))
.setup(tasks(getDepositsConfirmedTasks())