mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-23 04:29:22 +00:00
open trades in parallel on startup
This commit is contained in:
parent
6e21508a94
commit
f8fa838a9b
2 changed files with 29 additions and 4 deletions
|
@ -111,7 +111,7 @@ public class XmrWalletService {
|
||||||
.setPath(path)
|
.setPath(path)
|
||||||
.setPassword("abctesting123"));
|
.setPassword("abctesting123"));
|
||||||
multisigWallets.put(tradeId, multisigWallet);
|
multisigWallets.put(tradeId, multisigWallet);
|
||||||
multisigWallet.startSyncing(5000l);
|
multisigWallet.startSyncing(5000l); // TODO (woodser): apps stall if too many multisig wallets and too short sync period
|
||||||
return multisigWallet;
|
return multisigWallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,10 +94,14 @@ import org.bouncycastle.crypto.params.KeyParameter;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -307,7 +311,28 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void initPersistedTrades() {
|
private void initPersistedTrades() {
|
||||||
tradableList.forEach(this::initPersistedTrade);
|
|
||||||
|
// open trades in parallel since each may open a multisig wallet
|
||||||
|
List<Trade> trades = tradableList.getList();
|
||||||
|
if (!trades.isEmpty()) {
|
||||||
|
ExecutorService pool = Executors.newFixedThreadPool(Math.min(10, trades.size()));
|
||||||
|
for (Trade trade : trades) {
|
||||||
|
pool.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
initPersistedTrade(trade);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
pool.shutdown();
|
||||||
|
try {
|
||||||
|
if (!pool.awaitTermination(60000, TimeUnit.SECONDS)) pool.shutdownNow();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
pool.shutdownNow();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
persistedTradesInitialized.set(true);
|
persistedTradesInitialized.set(true);
|
||||||
|
|
||||||
// We do not include failed trades as they should not be counted anyway in the trade statistics
|
// We do not include failed trades as they should not be counted anyway in the trade statistics
|
||||||
|
@ -320,14 +345,14 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
||||||
|
|
||||||
private void initPersistedTrade(Trade trade) {
|
private void initPersistedTrade(Trade trade) {
|
||||||
initTradeAndProtocol(trade, getTradeProtocol(trade));
|
initTradeAndProtocol(trade, getTradeProtocol(trade));
|
||||||
trade.updateDepositTxFromWallet();
|
trade.updateDepositTxFromWallet(); // TODO (woodser): this re-opens all multisig wallets. only open active wallets
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTradeAndProtocol(Trade trade, TradeProtocol tradeProtocol) {
|
private void initTradeAndProtocol(Trade trade, TradeProtocol tradeProtocol) {
|
||||||
tradeProtocol.initialize(processModelServiceProvider, this, trade.getOffer());
|
tradeProtocol.initialize(processModelServiceProvider, this, trade.getOffer());
|
||||||
trade.initialize(processModelServiceProvider);
|
trade.initialize(processModelServiceProvider);
|
||||||
requestPersistence();
|
requestPersistence(); // TODO requesting persistence twice with initPersistedTrade()
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestPersistence() {
|
public void requestPersistence() {
|
||||||
|
|
Loading…
Reference in a new issue