Skip to content

Commit

Permalink
Nostr coordinator publisher (WalletWasabi#13138)
Browse files Browse the repository at this point in the history
* add NNostr.client package

* add option to config

* Add logic for managing key for nostr

* add extension methods

* add periodic runner for publishing

* add logic for Global

* Update deps.nix

* make broadcast data configurable

* only init NostKeyManager when needed.

* rename

* review fixes

* disconnect explicitly

* add success log

* add uri array to config

* rename folder

* unify Announcer config

* move key management to config

* cleanup

* store the key based NIP19

* review comment fixes

* Tags for coordinatorfee, absolutemininputcount, readmore

* update deps-all.nix file

* throw ex on RegTest, feature is not supported

* Simplify implementation

* Add coordinator name

---------

Co-authored-by: Turbolay <[email protected]>
Co-authored-by: Lucas Ontivero <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent cae7456 commit a4c55d5
Show file tree
Hide file tree
Showing 14 changed files with 588 additions and 21 deletions.
24 changes: 13 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<AvaloniaVersion>11.0.999-cibuild0044755-beta</AvaloniaVersion>
<AvaloniaVersion>11.0.999-cibuild0044755-beta</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<!-- AspNetCore. -->
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<!-- AspNetCore. -->
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="NNostr.Client" Version="0.0.49" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<!-- JSON. -->
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<!-- SQLite. -->
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
<!-- C# analysis. -->
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" /> <!-- Version 4.3.0 contains a vulnerability, manually bumped to 4.3.2. -->
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<!-- Version 4.3.0 contains a vulnerability, manually bumped to 4.3.2. -->
<!-- Core libraries. -->
<PackageVersion Include="WabiSabi" Version="1.0.1.2" />
<PackageVersion Include="NBitcoin" Version="7.0.27" />
Expand Down Expand Up @@ -55,4 +57,4 @@
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions WalletWasabi.Backend/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Net;
using WalletWasabi.Bases;
using WalletWasabi.Discoverability;
using WalletWasabi.Exceptions;
using WalletWasabi.Helpers;
using WalletWasabi.JsonConverters;
Expand Down Expand Up @@ -75,6 +76,9 @@ public Config(
[JsonConverter(typeof(EndPointJsonConverter), Constants.DefaultRegTestBitcoinCoreRpcPort)]
public EndPoint RegTestBitcoinCoreRpcEndPoint { get; internal set; } = Constants.DefaultRegTestBitcoinCoreRpcEndPoint;

[JsonProperty(PropertyName = "AnnouncerConfig")]
public AnnouncerConfig AnnouncerConfig { get; internal set; } = new();

public EndPoint GetBitcoinP2pEndPoint()
{
if (Network == Network.Main)
Expand Down
8 changes: 8 additions & 0 deletions WalletWasabi.Backend/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.Blockchain.BlockFilters;
using WalletWasabi.Blockchain.Blocks;
using WalletWasabi.Discoverability;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Services;
Expand Down Expand Up @@ -36,6 +37,13 @@ public Global(string dataDir, IRPCClient rpcClient, Config config, IHttpClientFa
CoordinatorParameters = new(DataDir);
CoinJoinIdStore = CoinJoinIdStore.Create(CoordinatorParameters.CoinJoinIdStoreFilePath);

// Add Nostr publisher if enabled
if (Config.AnnouncerConfig.IsEnabled && config.Network != Network.RegTest)
{
HostedServices.Register<CoordinatorAnnouncer>(
() => new CoordinatorAnnouncer(TimeSpan.FromMinutes(15), Config.AnnouncerConfig, Config.Network), "Nostr Coordinator Publisher");
}

// We have to find it, because it's cloned by the node and not perfectly cloned (event handlers cannot be cloned.)
P2pNode = new(config.Network, config.GetBitcoinP2pEndPoint(), new(), $"/WasabiCoordinator:{Constants.BackendMajorVersion}/");
HostedServices.Register<BlockNotifier>(() => new BlockNotifier(TimeSpan.FromSeconds(7), rpcClient, P2pNode), "Block Notifier");
Expand Down
87 changes: 85 additions & 2 deletions WalletWasabi.Daemon/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"Microsoft.Extensions.Primitives": "8.0.0"
}
},
"LinqKit.Core": {
"type": "Transitive",
"resolved": "1.2.5",
"contentHash": "+5UKyagtVX33TSeOGorYzDXus/ypAISfM7HFfrix4BEmuuGF+nhSjf8P9csejLQ79ny5ms33M5/lQ2SkwC0Jxw=="
},
"Microsoft.Bcl.AsyncInterfaces": {
"type": "Transitive",
"resolved": "6.0.0",
"contentHash": "UcSjPsst+DfAdJGVDsu346FX0ci0ah+lw3WRtn18NUwEqRt70HaOQ7lI72vy3+1LxtqI3T5GWwV39rQSrCzAeg=="
},
"Microsoft.Data.Sqlite.Core": {
"type": "Transitive",
"resolved": "8.0.0",
Expand Down Expand Up @@ -149,8 +159,8 @@
},
"NBitcoin.Secp256k1": {
"type": "Transitive",
"resolved": "3.1.0",
"contentHash": "DVJbhT1plnBqPNnl5MNW1Aw5DCdfQ7MwlcL6PKcBIWPlQUO4T1FZRC4g2Axp9fd40eDKkyhq9MHlN9EeO09sGw=="
"resolved": "3.1.4",
"contentHash": "23N1DCusSRCx1hoNiIMl3JnMZrdY78a/WcsiN1LIAg6sq8MiC7mszDiUgHKD6txm+m9PxJBigBLH7MPBQCRCDQ=="
},
"Newtonsoft.Json": {
"type": "Transitive",
Expand Down Expand Up @@ -192,11 +202,45 @@
"resolved": "8.0.0",
"contentHash": "c9xLpVz6PL9lp/djOWtk5KPDZq3cSYpmXoJQY524EOtuFl5z9ZtsotpsyrDW40U1DRnQSYvcPKEUV0X//u6gkQ=="
},
"System.Interactive.Async": {
"type": "Transitive",
"resolved": "6.0.1",
"contentHash": "f8H1O4ZWDQo344y5NQU76G4SIjWMuKDVXL9OM1dg6K5YZnLkc8iCdQDybBvMcC6ufk61jzXGVAX6UCDu0qDSjA==",
"dependencies": {
"System.Linq.Async": "6.0.1"
}
},
"System.Linq.Async": {
"type": "Transitive",
"resolved": "6.0.1",
"contentHash": "0YhHcaroWpQ9UCot3Pizah7ryAzQhNvobLMSxeDIGmnXfkQn8u5owvpOH0K6EVB+z9L7u6Cc4W17Br/+jyttEQ==",
"dependencies": {
"Microsoft.Bcl.AsyncInterfaces": "6.0.0"
}
},
"System.Memory": {
"type": "Transitive",
"resolved": "4.5.3",
"contentHash": "3oDzvc/zzetpTKWMShs1AADwZjQ/36HnsufHRPcOjyRAAMLDlu2iD33MBI2opxnezcVUtXyqDXXjoFMOU9c7SA=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"System.Text.Json": {
"type": "Transitive",
"resolved": "8.0.3",
"contentHash": "hpagS9joOwv6efWfrMmV9MjQXpiXZH72PgN067Ysfr6AWMSD1/1hEcvh/U5mUpPLezEWsOJSuVrmqDIVD958iA==",
"dependencies": {
"System.Text.Encodings.Web": "8.0.0"
}
},
"System.Threading.Channels": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "CMaFr7v+57RW7uZfZkPExsPB6ljwzhjACWW1gfU35Y56rk72B/Wu+sTqxVmGSk4SFUlPc3cjeKND0zktziyjBA=="
},
"walletwasabi": {
"type": "Project",
"dependencies": {
Expand All @@ -207,6 +251,7 @@
"Microsoft.Extensions.Http": "[8.0.0, )",
"Microsoft.Win32.SystemEvents": "[8.0.0, )",
"NBitcoin": "[7.0.27, )",
"NNostr.Client": "[0.0.49, )",
"System.IO.Pipelines": "[8.0.0, )",
"WabiSabi": "[1.0.1.2, )"
}
Expand Down Expand Up @@ -283,6 +328,19 @@
"Newtonsoft.Json": "13.0.1"
}
},
"NNostr.Client": {
"type": "CentralTransitive",
"requested": "[0.0.49, )",
"resolved": "0.0.49",
"contentHash": "UqmOBSCuUxw6qTk5+3TTWWtlyetx1btEuBJIS9beidviV45iMjlgOMK0ThB1CrYuPfg4DDzMu5rpzRYnM8eHWA==",
"dependencies": {
"LinqKit.Core": "1.2.5",
"NBitcoin.Secp256k1": "3.1.4",
"System.Interactive.Async": "6.0.1",
"System.Text.Json": "8.0.3",
"System.Threading.Channels": "8.0.0"
}
},
"System.IO.Pipelines": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand All @@ -305,6 +363,11 @@
"resolved": "2.1.6",
"contentHash": "2ObJJLkIUIxRpOUlZNGuD4rICpBnrBR5anjyfUFQep4hMOIeqW+XGQYzrNmHSVz5xSWZ3klSbh7sFR6UyDj68Q=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"Microsoft.Win32.SystemEvents": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand All @@ -318,6 +381,11 @@
"resolved": "2.1.6",
"contentHash": "2ObJJLkIUIxRpOUlZNGuD4rICpBnrBR5anjyfUFQep4hMOIeqW+XGQYzrNmHSVz5xSWZ3klSbh7sFR6UyDj68Q=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"Microsoft.Win32.SystemEvents": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand All @@ -331,6 +399,11 @@
"resolved": "2.1.6",
"contentHash": "2ObJJLkIUIxRpOUlZNGuD4rICpBnrBR5anjyfUFQep4hMOIeqW+XGQYzrNmHSVz5xSWZ3klSbh7sFR6UyDj68Q=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"Microsoft.Win32.SystemEvents": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand All @@ -344,6 +417,11 @@
"resolved": "2.1.6",
"contentHash": "2ObJJLkIUIxRpOUlZNGuD4rICpBnrBR5anjyfUFQep4hMOIeqW+XGQYzrNmHSVz5xSWZ3klSbh7sFR6UyDj68Q=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"Microsoft.Win32.SystemEvents": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand All @@ -357,6 +435,11 @@
"resolved": "2.1.6",
"contentHash": "2ObJJLkIUIxRpOUlZNGuD4rICpBnrBR5anjyfUFQep4hMOIeqW+XGQYzrNmHSVz5xSWZ3klSbh7sFR6UyDj68Q=="
},
"System.Text.Encodings.Web": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ=="
},
"Microsoft.Win32.SystemEvents": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Loading

0 comments on commit a4c55d5

Please sign in to comment.