Permalink
Browse files

Merge branch 'master' of github.com:zkSNACKs/WalletWasabi into Featur…

…es/Recovery-Wallet-AutoComplete
  • Loading branch information...
lontivero committed Nov 5, 2018
2 parents 5dc35a2 + eaf1400 commit c125592313a56a9350d1e8c4026ac8d019ef4422
@@ -18,7 +18,7 @@ HiddenWallet's code is archived in the [hiddenwallet-v0.6](https://github.com/zk
[9]: https://www.codefactor.io/repository/github/zksnacks/walletwasabi/badge
[10]: https://www.codefactor.io/repository/github/zksnacks/walletwasabi
# [Get The Latest Stable Release](https://github.com/zkSNACKs/WalletWasabi/releases)
# [Download Wasabi](https://github.com/zkSNACKs/WalletWasabi/releases)
# How To Run?
@@ -308,6 +308,7 @@ public async Task ExecuteNextPhaseAsync(CcjRoundPhase expectedPhase)
var builder = Network.CreateTransactionBuilder();
UnsignedCoinJoin = builder
.ContinueToBuild(transaction)
.AddCoins(spentCoins) // It makes sure the UnsignedCoinJoin goes through TransactionBuilder optimizations.
.BuildTransaction(false);
// 8. Try optimize fees.
@@ -274,7 +274,7 @@ private async Task TryProcessRoundStateAsync(long ongoingRoundId)
var toLog = $"{nameof(unsignedCoinJoin)} hex: {unsignedCoinJoin.ToHex()}\n";
foreach (var elem in myDic)
{
toLog += $"\tInput Index: {elem.Key}\t Signature: {elem.Value.ToString()}/n";
toLog += $"\tInput Index: {elem.Key}\t Signature: {elem.Value.ToString()}\n";
}
Logger.LogWarning<CcjClient>(toLog);
@@ -325,12 +325,17 @@ private async Task TryProcessRoundStateAsync(long ongoingRoundId)
throw new NotSupportedException("Coordinator did not add enough value to our outputs in the coinjoin.");
}
var builder = Network.CreateTransactionBuilder();
var signedCoinJoin = builder
.ContinueToBuild(unsignedCoinJoin)
.AddKeys(ongoingRound.CoinsRegistered.Select(x => x.Secret = x.Secret ?? KeyManager.GetSecrets(OnePiece, x.ScriptPubKey).Single()).ToArray())
.AddCoins(ongoingRound.CoinsRegistered.Select(x => x.GetCoin()))
.BuildTransaction(true);
var signedCoinJoin = unsignedCoinJoin.Clone();
signedCoinJoin.Sign(ongoingRound.CoinsRegistered.Select(x => x.Secret = x.Secret ?? KeyManager.GetSecrets(OnePiece, x.ScriptPubKey).Single()).ToArray(), ongoingRound.CoinsRegistered.Select(x => x.GetCoin()).ToArray());
// Old way of signing, which randomly fails! https://github.com/zkSNACKs/WalletWasabi/issues/716#issuecomment-435498906
// Must be fixed in NBitcoin.
//var builder = Network.CreateTransactionBuilder();
//var signedCoinJoin = builder
// .ContinueToBuild(unsignedCoinJoin)
// .AddKeys(ongoingRound.CoinsRegistered.Select(x => x.Secret = x.Secret ?? KeyManager.GetSecrets(OnePiece, x.ScriptPubKey).Single()).ToArray())
// .AddCoins(ongoingRound.CoinsRegistered.Select(x => x.GetCoin()))
// .BuildTransaction(true);
var myDic = new Dictionary<int, WitScript>();
@@ -461,18 +466,18 @@ private async Task TryRegisterCoinsAsync(CcjClientRound inputRegistrableRound)
{
// Find the first one that we did not try to register in the current session.
activeKey = allActiveKeys.FirstOrDefault(x => !AccessCache.ContainsKey(x));
// If there is no such a key, then use the oldest.
// If there is no such a key, then use the oldest, but make sure it's not the same as the change.
if (activeKey == default)
{
activeKey = AccessCache.Where(x => allActiveKeys.Contains(x.Key)).OrderBy(x => x.Value).First().Key;
activeKey = AccessCache.Where(x => allActiveKeys.Contains(x.Key) && changeAddress != x.Key.GetP2wpkhAddress(Network)).OrderBy(x => x.Value).First().Key;
}
activeKey.SetLabel(activeLabel);
activeKey.SetKeyState(KeyState.Locked);
activeAddress = activeKey.GetP2wpkhAddress(Network);
}
else
{
activeKey = internalNotCachedLockedKeys.RandomElement();
activeKey = internalNotCachedLockedKeys.Where(x => changeAddress != x.GetP2wpkhAddress(Network)).RandomElement();
activeKey.SetLabel(activeLabel);
}
activeAddress = activeKey.GetP2wpkhAddress(Network);
@@ -54,7 +54,7 @@ public CcjCoordinator(Network network, string folderPath, RPCClient rpc, CcjRoun
Directory.CreateDirectory(FolderPath);
UtxoReferee = new UtxoReferee(Network, FolderPath, RpcClient);
UtxoReferee = new UtxoReferee(Network, FolderPath, RpcClient, RoundConfig);
// Initialize RsaKey
string rsaKeyPath = Path.Combine(FolderPath, "RsaKey.json");
@@ -9,6 +9,7 @@
using System.Threading.Tasks;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Models.ChaumianCoinJoin;
namespace WalletWasabi.Services
{
@@ -22,16 +23,18 @@ public class UtxoReferee
public string BannedUtxosFilePath => Path.Combine(FolderPath, $"BannedUtxos{Network}.txt");
public RPCClient RpcClient { get; }
public Network Network { get; }
public CcjRoundConfig RoundConfig { get; }
public string FolderPath { get; }
public UtxoReferee(Network network, string folderPath, RPCClient rpc)
public UtxoReferee(Network network, string folderPath, RPCClient rpc, CcjRoundConfig roundConfig)
{
Network = Guard.NotNull(nameof(network), network);
FolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(folderPath), folderPath, trim: true);
RpcClient = Guard.NotNull(nameof(rpc), rpc);
RoundConfig = Guard.NotNull(nameof(roundConfig), roundConfig);
BannedUtxos = new ConcurrentDictionary<OutPoint, (int severity, DateTimeOffset timeOfBan)>();
@@ -85,6 +88,11 @@ public UtxoReferee(Network network, string folderPath, RPCClient rpc)
public async Task BanUtxosAsync(int severity, DateTimeOffset timeOfBan, params OutPoint[] toBan)
{
if (RoundConfig.DosSeverity == 0)
{
return;
}
var lines = new List<string>();
foreach (var utxo in toBan)
{
@@ -94,16 +94,28 @@ internal async Task ConnectAsync()
await TcpClient.ConnectAsync(TorSocks5EndPoint.Address, TorSocks5EndPoint.Port);
}
// ex.Message must be checked, because I'm having difficulty catching SocketExceptionFactory+ExtendedSocketException
// Only works on English Os-es.
catch (Exception ex) when (ex.Message.StartsWith(
"No connection could be made because the target machine actively refused it")
|| ex.Message.StartsWith("Connection refused"))
"No connection could be made because the target machine actively refused it") // Windows
|| ex.Message.StartsWith("Connection refused")) // Linux && OSX
{
error = ex;
}
// "No connection could be made because the target machine actively refused it" for non-English Windows.
catch (SocketException ex) when (ex.ErrorCode == 10061)
{
error = ex;
}
// "Connection refused" for non-English Linux.
catch (SocketException ex) when (ex.ErrorCode == 111)
{
error = ex;
}
// "Connection refused" for non-English OSX.
catch (SocketException ex) when (ex.ErrorCode == 61)
{
error = ex;
}
if (error != null)
throw new ConnectionException(
$"Couldn't connect to Tor SOCKSPort at {TorSocks5EndPoint.Address}:{TorSocks5EndPoint.Port}. Is Tor running?", error);

0 comments on commit c125592

Please sign in to comment.