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

[DRAFT] Quit application: Stop P2P faster #10668

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions WalletWasabi.Daemon/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
"resolved": "7.0.0",
"contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ=="
},
"NBitcoin": {
"NBitcoin.Kimi": {
"type": "Transitive",
"resolved": "7.0.24",
"contentHash": "+K8o9WH09/o8oTl0aV/IR2y+1leR7e1vvZ2S6A7IozvMsWGh/Wi3TYWhasAskEYryQJr2f4gQsy67eAO7YExAg==",
"resolved": "7.0.25.1",
"contentHash": "kQECjHNKxSZycPLLuFu9iqtg9IKa12Vhz/b+4Bk6SOQRGxPnsS0Ot7dM8c/7YzbB9f0q+xlDzYQKXqvUbnz6TQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"Newtonsoft.Json": "13.0.1"
Expand Down Expand Up @@ -336,7 +336,7 @@
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": "[7.0.0, )",
"Microsoft.Data.Sqlite": "[7.0.3, )",
"Microsoft.Win32.SystemEvents": "[7.0.0, )",
"NBitcoin": "[7.0.24, )",
"NBitcoin.Kimi": "[7.0.25.1, )",
"WabiSabi": "[1.0.1.2, )"
}
}
Expand Down
8 changes: 4 additions & 4 deletions WalletWasabi.Fluent.Desktop/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@
"resolved": "7.0.0",
"contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ=="
},
"NBitcoin": {
"NBitcoin.Kimi": {
"type": "Transitive",
"resolved": "7.0.24",
"contentHash": "+K8o9WH09/o8oTl0aV/IR2y+1leR7e1vvZ2S6A7IozvMsWGh/Wi3TYWhasAskEYryQJr2f4gQsy67eAO7YExAg==",
"resolved": "7.0.25.1",
"contentHash": "kQECjHNKxSZycPLLuFu9iqtg9IKa12Vhz/b+4Bk6SOQRGxPnsS0Ot7dM8c/7YzbB9f0q+xlDzYQKXqvUbnz6TQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"Newtonsoft.Json": "13.0.1"
Expand Down Expand Up @@ -726,7 +726,7 @@
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": "[7.0.0, )",
"Microsoft.Data.Sqlite": "[7.0.3, )",
"Microsoft.Win32.SystemEvents": "[7.0.0, )",
"NBitcoin": "[7.0.24, )",
"NBitcoin.Kimi": "[7.0.25.1, )",
"WabiSabi": "[1.0.1.2, )"
}
},
Expand Down
8 changes: 4 additions & 4 deletions WalletWasabi.Fluent/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@
"resolved": "7.0.0",
"contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ=="
},
"NBitcoin": {
"NBitcoin.Kimi": {
"type": "Transitive",
"resolved": "7.0.24",
"contentHash": "+K8o9WH09/o8oTl0aV/IR2y+1leR7e1vvZ2S6A7IozvMsWGh/Wi3TYWhasAskEYryQJr2f4gQsy67eAO7YExAg==",
"resolved": "7.0.25.1",
"contentHash": "kQECjHNKxSZycPLLuFu9iqtg9IKa12Vhz/b+4Bk6SOQRGxPnsS0Ot7dM8c/7YzbB9f0q+xlDzYQKXqvUbnz6TQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"Newtonsoft.Json": "13.0.1"
Expand Down Expand Up @@ -644,7 +644,7 @@
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": "[7.0.0, )",
"Microsoft.Data.Sqlite": "[7.0.3, )",
"Microsoft.Win32.SystemEvents": "[7.0.0, )",
"NBitcoin": "[7.0.24, )",
"NBitcoin.Kimi": "[7.0.25.1, )",
"WabiSabi": "[1.0.1.2, )"
}
},
Expand Down
8 changes: 4 additions & 4 deletions WalletWasabi.Packager/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
"resolved": "7.0.0",
"contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ=="
},
"NBitcoin": {
"NBitcoin.Kimi": {
"type": "Transitive",
"resolved": "7.0.24",
"contentHash": "+K8o9WH09/o8oTl0aV/IR2y+1leR7e1vvZ2S6A7IozvMsWGh/Wi3TYWhasAskEYryQJr2f4gQsy67eAO7YExAg==",
"resolved": "7.0.25.1",
"contentHash": "kQECjHNKxSZycPLLuFu9iqtg9IKa12Vhz/b+4Bk6SOQRGxPnsS0Ot7dM8c/7YzbB9f0q+xlDzYQKXqvUbnz6TQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"Newtonsoft.Json": "13.0.1"
Expand Down Expand Up @@ -336,7 +336,7 @@
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": "[7.0.0, )",
"Microsoft.Data.Sqlite": "[7.0.3, )",
"Microsoft.Win32.SystemEvents": "[7.0.0, )",
"NBitcoin": "[7.0.24, )",
"NBitcoin.Kimi": "[7.0.25.1, )",
"WabiSabi": "[1.0.1.2, )"
}
}
Expand Down
13 changes: 9 additions & 4 deletions WalletWasabi/BitcoinP2p/P2pNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public P2pNetwork(Network network, EndPoint fullnodeP2pEndPoint, EndPoint? torSo
BitcoinStore = bitcoinStore;
AddressManagerFilePath = Path.Combine(workDir, $"AddressManager{Network}.dat");

var userAgent = Constants.UserAgents.RandomElement();
var connectionParameters = new NodeConnectionParameters { UserAgent = userAgent };
connectionParameters.ConnectCancellation = ConnectCts.Token;

if (Network == Network.RegTest)
{
AddressManager = new AddressManager();
Logger.LogInfo($"Fake {nameof(AddressManager)} is initialized on the {Network.RegTest}.");

Nodes = new NodesGroup(Network, requirements: Constants.NodeRequirements);
Nodes = new NodesGroup(Network, connectionParameters, requirements: Constants.NodeRequirements);
}
else
{
Expand Down Expand Up @@ -83,9 +87,6 @@ public P2pNetwork(Network network, EndPoint fullnodeP2pEndPoint, EndPoint? torSo
Mode = needsToDiscoverPeers ? AddressManagerBehaviorMode.Discover : AddressManagerBehaviorMode.None
};

var userAgent = Constants.UserAgents.RandomElement();
var connectionParameters = new NodeConnectionParameters { UserAgent = userAgent };

connectionParameters.TemplateBehaviors.Add(BitcoinStore.CreateUntrustedP2pBehavior());
connectionParameters.TemplateBehaviors.Add(addressManagerBehavior);
connectionParameters.EndpointConnector = new BestEffortEndpointConnector(MaximumNodeConnections / 2);
Expand All @@ -110,6 +111,7 @@ public P2pNetwork(Network network, EndPoint fullnodeP2pEndPoint, EndPoint? torSo
private Node? RegTestMempoolServingNode { get; set; }
private string AddressManagerFilePath { get; }
private AddressManager? AddressManager { get; set; }
private CancellationTokenSource ConnectCts { get; } = new();

/// <inheritdoc />
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
Expand Down Expand Up @@ -163,6 +165,8 @@ public override async Task StopAsync(CancellationToken cancellationToken)

cancellationToken.ThrowIfCancellationRequested();

ConnectCts.Cancel();

Nodes.Disconnect();
while (Nodes.ConnectedNodes.Any(x => x.IsConnected))
{
Expand All @@ -189,6 +193,7 @@ public override void Dispose()
}

Nodes.Dispose();
ConnectCts.Dispose();
base.Dispose();
}
}
3 changes: 2 additions & 1 deletion WalletWasabi/WalletWasabi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="7.0.0" />
<PackageReference Include="NBitcoin" Version="7.0.24" />
<PackageReference Include="NBitcoin.Kimi" Version="7.0.25.1" />
<!--<PackageReference Include="NBitcoin" Version="7.0.24" />-->
<PackageReference Include="WabiSabi" Version="1.0.1.2" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions WalletWasabi/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"resolved": "7.0.0",
"contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ=="
},
"NBitcoin": {
"NBitcoin.Kimi": {
"type": "Direct",
"requested": "[7.0.24, )",
"resolved": "7.0.24",
"contentHash": "+K8o9WH09/o8oTl0aV/IR2y+1leR7e1vvZ2S6A7IozvMsWGh/Wi3TYWhasAskEYryQJr2f4gQsy67eAO7YExAg==",
"requested": "[7.0.25.1, )",
"resolved": "7.0.25.1",
"contentHash": "kQECjHNKxSZycPLLuFu9iqtg9IKa12Vhz/b+4Bk6SOQRGxPnsS0Ot7dM8c/7YzbB9f0q+xlDzYQKXqvUbnz6TQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.0.0",
"Newtonsoft.Json": "13.0.1"
Expand Down