Skip to content
Permalink
Browse files

Speed up enqueue process

  • Loading branch information...
nopara73 committed Nov 20, 2018
1 parent 2b07ebb commit debd4c1abe7e2258063cbc3f987777680c6eeed8
Showing with 19 additions and 5 deletions.
  1. +8 −3 WalletWasabi/KeyManagement/KeyManager.cs
  2. +11 −2 WalletWasabi/Services/CcjClient.cs
@@ -270,6 +270,11 @@ public HdPubKey GetKeyForScriptPubKey(Script scriptPubkey)
}

public IEnumerable<ExtKey> GetSecrets(string password, params Script[] scripts)
{
return GetSecretsAndPubKeyPairs(password, scripts).Select(x => x.secret);
}

public IEnumerable<(ExtKey secret, HdPubKey pubKey)> GetSecretsAndPubKeyPairs(string password, params Script[] scripts)
{
Key secret;
try
@@ -281,7 +286,7 @@ public IEnumerable<ExtKey> GetSecrets(string password, params Script[] scripts)
throw new SecurityException("Invalid password.", ex);
}
var extKey = new ExtKey(secret, ChainCode);
var extKeys = new List<ExtKey>();
var extKeysAndPubs = new List<(ExtKey secret, HdPubKey pubKey)>();

lock (HdPubKeysLock)
{
@@ -292,9 +297,9 @@ public IEnumerable<ExtKey> GetSecrets(string password, params Script[] scripts)
|| scripts.Contains(x.GetP2pkScript())))
{
ExtKey ek = extKey.Derive(key.FullKeyPath);
extKeys.Add(ek);
extKeysAndPubs.Add((ek, key));
}
return extKeys;
return extKeysAndPubs;
}
}

@@ -681,22 +681,31 @@ public async Task<IEnumerable<SmartCoin>> QueueCoinsToMixAsync(string password,
await DequeueCoinsFromMixNoLockAsync(State.GetSpentCoins().ToArray());

var successful = new List<SmartCoin>();
var except = new List<SmartCoin>();

foreach (SmartCoin coin in coins)
{
if (State.Contains(coin))
{
successful.Add(coin);
except.Add(coin);
continue;
}

if (coin.SpentOrCoinJoinInProgress)
{
except.Add(coin);
continue;
}
}

var coinsExcept = coins.Except(except);
var secPubs = KeyManager.GetSecretsAndPubKeyPairs(password, coinsExcept.Select(x => x.ScriptPubKey).ToArray());
OnePiece = OnePiece ?? password;

coin.Secret = KeyManager.GetSecrets(password, coin.ScriptPubKey).Single();
OnePiece = OnePiece ?? password;
foreach (SmartCoin coin in coinsExcept)
{
coin.Secret = secPubs.Single(x => x.pubKey.GetP2wpkhScript() == coin.ScriptPubKey).secret;

coin.CoinJoinInProgress = true;

0 comments on commit debd4c1

Please sign in to comment.
You can’t perform that action at this time.