Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from Wasabi #17

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Models/Wallets/WalletLoadWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public WalletLoadWorkflow(Wallet wallet)
Observable.FromEventPattern<WalletState>(_wallet, nameof(Wallet.StateChanged))
.ObserveOn(RxApp.MainThreadScheduler)
.Select(x => x.EventArgs)
.Where(x => x == WalletState.Started || (x == WalletState.Starting && wallet.KeyManager.SkipSynchronization))
.Where(x => x == WalletState.Started)
.ToSignal();
}

Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Views/Wallets/LoadingView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
TextAlignment="Center" TextWrapping="Wrap" Opacity="0.6" />

<TextBlock
Text="This process may take some time depending on the size of your wallet."
Text="This process will be longer on first launch, with larger wallets, or after long gaps between synchronizations."
TextAlignment="Center" TextWrapping="Wrap" Opacity="0.6" />

<ProgressBar Value="{Binding Percent}" IsIndeterminate="{Binding !Percent}" Margin="0 20 0 0" />
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Tests/Helpers/ServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static KeyManager CreateKeyManager(string password = "blahblahblah", bool
taprootExtPubKey = extKey.Derive(taprootAccountKeyPath).Neuter();
}

return new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, skipSynchronization: true, 21, blockchainState, null, segwitAccountKeyPath, null);
return new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, 21, blockchainState, null, segwitAccountKeyPath, null);
}

public static KeyManager CreateWatchOnlyKeyManager()
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Tests/UnitTests/KeyManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CanCreateNew()
Assert.NotNull(manager3.SegwitExtPubKey);
Assert.NotNull(manager3.TaprootExtPubKey);

var sameManager = new KeyManager(manager.EncryptedSecret, manager.ChainCode, manager.MasterFingerprint, manager.SegwitExtPubKey, manager.TaprootExtPubKey, true, null, new BlockchainState(Network.Main));
var sameManager = new KeyManager(manager.EncryptedSecret, manager.ChainCode, manager.MasterFingerprint, manager.SegwitExtPubKey, manager.TaprootExtPubKey, null, new BlockchainState(Network.Main));
var sameManager2 = new KeyManager(manager.EncryptedSecret, manager.ChainCode, password, Network.Main);
Logger.TurnOff();
Assert.Throws<SecurityException>(() => new KeyManager(manager.EncryptedSecret, manager.ChainCode, "differentPassword", Network.Main));
Expand Down
15 changes: 5 additions & 10 deletions WalletWasabi/Blockchain/Keys/KeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ public class KeyManager
};

[JsonConstructor]
public KeyManager(BitcoinEncryptedSecretNoEC? encryptedSecret, byte[]? chainCode, HDFingerprint? masterFingerprint, ExtPubKey extPubKey, ExtPubKey? taprootExtPubKey, bool skipSynchronization, int? minGapLimit, BlockchainState blockchainState, string? filePath = null, KeyPath? segwitAccountKeyPath = null, KeyPath? taprootAccountKeyPath = null)
public KeyManager(BitcoinEncryptedSecretNoEC? encryptedSecret, byte[]? chainCode, HDFingerprint? masterFingerprint, ExtPubKey extPubKey, ExtPubKey? taprootExtPubKey, int? minGapLimit, BlockchainState blockchainState, string? filePath = null, KeyPath? segwitAccountKeyPath = null, KeyPath? taprootAccountKeyPath = null)
{
EncryptedSecret = encryptedSecret;
ChainCode = chainCode;
MasterFingerprint = masterFingerprint;
SegwitExtPubKey = Guard.NotNull(nameof(extPubKey), extPubKey);
TaprootExtPubKey = taprootExtPubKey;

SkipSynchronization = skipSynchronization;
MinGapLimit = Math.Max(AbsoluteMinGapLimit, minGapLimit ?? 0);

BlockchainState = blockchainState;
Expand Down Expand Up @@ -158,9 +157,6 @@ public WpkhDescriptors GetOutputDescriptors(string password, Network network)
[JsonProperty(PropertyName = "TaprootExtPubKey")]
public ExtPubKey? TaprootExtPubKey { get; private set; }

[JsonProperty(PropertyName = "SkipSynchronization")]
public bool SkipSynchronization { get; private set; } = false;

[JsonProperty(PropertyName = "UseTurboSync")]
public bool UseTurboSync { get; private set; } = true;

Expand Down Expand Up @@ -258,17 +254,17 @@ public static KeyManager CreateNew(Mnemonic mnemonic, string password, Network n
KeyPath taprootAccountKeyPath = GetAccountKeyPath(network, ScriptPubKeyType.TaprootBIP86);
ExtPubKey taprootExtPubKey = extKey.Derive(taprootAccountKeyPath).Neuter();

return new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, skipSynchronization: true, AbsoluteMinGapLimit, blockchainState, filePath, segwitAccountKeyPath, taprootAccountKeyPath);
return new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, AbsoluteMinGapLimit, blockchainState, filePath, segwitAccountKeyPath, taprootAccountKeyPath);
}

public static KeyManager CreateNewWatchOnly(ExtPubKey segwitExtPubKey, ExtPubKey taprootExtPubKey, string? filePath = null, int? minGapLimit = null)
{
return new KeyManager(null, null, null, segwitExtPubKey, taprootExtPubKey, skipSynchronization: false, minGapLimit ?? AbsoluteMinGapLimit, new BlockchainState(), filePath);
return new KeyManager(null, null, null, segwitExtPubKey, taprootExtPubKey, minGapLimit ?? AbsoluteMinGapLimit, new BlockchainState(), filePath);
}

public static KeyManager CreateNewHardwareWalletWatchOnly(HDFingerprint masterFingerprint, ExtPubKey segwitExtPubKey, ExtPubKey? taprootExtPubKey, Network network, string? filePath = null)
{
return new KeyManager(null, null, masterFingerprint, segwitExtPubKey, taprootExtPubKey, skipSynchronization: false, AbsoluteMinGapLimit, new BlockchainState(network), filePath);
return new KeyManager(null, null, masterFingerprint, segwitExtPubKey, taprootExtPubKey, AbsoluteMinGapLimit, new BlockchainState(network), filePath);
}

public static KeyManager Recover(Mnemonic mnemonic, string password, Network network, KeyPath swAccountKeyPath, KeyPath? trAccountKeyPath = null, string? filePath = null, int minGapLimit = AbsoluteMinGapLimit)
Expand All @@ -286,7 +282,7 @@ public static KeyManager Recover(Mnemonic mnemonic, string password, Network net
KeyPath taprootAccountKeyPath = trAccountKeyPath ?? GetAccountKeyPath(network, ScriptPubKeyType.TaprootBIP86);
ExtPubKey taprootExtPubKey = extKey.Derive(taprootAccountKeyPath).Neuter();

var km = new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, skipSynchronization: false, minGapLimit, new BlockchainState(network), filePath, segwitAccountKeyPath, taprootAccountKeyPath);
var km = new KeyManager(encryptedSecret, extKey.ChainCode, masterFingerprint, segwitExtPubKey, taprootExtPubKey, minGapLimit, new BlockchainState(network), filePath, segwitAccountKeyPath, taprootAccountKeyPath);
km.AssertCleanKeysIndexed();
return km;
}
Expand Down Expand Up @@ -349,7 +345,6 @@ public HdPubKey GetNextReceiveKey(LabelsArray labels, ScriptPubKeyType scriptPub
};

newKey.SetLabel(labels);
SkipSynchronization = false;

ToFile();
return newKey;
Expand Down
18 changes: 15 additions & 3 deletions WalletWasabi/Wallets/SpecificNodeBlockProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Exceptions;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Models;
Expand Down Expand Up @@ -129,13 +130,13 @@ Wasabi could not complete the handshake with the node '{BitcoinCoreEndPoint}'. P
""";

Logger.LogWarning(message);
logWarningOnConnectionEx = false;
}
else
else if(!(ex is SocketException && IsDefaultP2pEndpoint(BitcoinCoreEndPoint, Network)))
{
Logger.LogWarning($"Failed to establish a connection to the node '{BitcoinCoreEndPoint}'. Exception: {ex}");
logWarningOnConnectionEx = false;
}

logWarningOnConnectionEx = false;
}

// Failing to connect leads to exponential slowdown.
Expand Down Expand Up @@ -205,6 +206,17 @@ internal virtual async Task<ConnectedNode> ConnectAsync(CancellationToken cancel
return new ConnectedNode(node);
}

private static bool IsDefaultP2pEndpoint(EndPoint endpoint, Network network)
{
return network switch
{
{ } n when n == Network.Main => Equals(endpoint, new IPEndPoint(IPAddress.Loopback, Constants.DefaultMainNetBitcoinP2pPort)),
{ } n when n == Network.TestNet => Equals(endpoint, new IPEndPoint(IPAddress.Loopback, Constants.DefaultTestNetBitcoinP2pPort)),
{ } n when n == Network.RegTest => Equals(endpoint, new IPEndPoint(IPAddress.Loopback, Constants.DefaultRegTestBitcoinP2pPort)),
_ => throw new NotSupportedNetworkException(network)
};
}

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
Expand Down
4 changes: 2 additions & 2 deletions WalletWasabi/Wallets/WalletFilterProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)

if (lastHeight == BitcoinStore.SmartHeaderChain.TipHeight)
{
request.Tcs.SetResult();
lock (Lock)
{
request.Tcs.SetResult();
SynchronizationRequests.Dequeue();
}
continue;
Expand All @@ -149,9 +149,9 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)

if (reachedBlockChainTip)
{
request.Tcs.SetResult();
lock (Lock)
{
request.Tcs.SetResult();
SynchronizationRequests.Dequeue();
}
}
Expand Down