From 893e790b73b6ebdb0d8b030efd12c1255f983c5f Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 2 Oct 2024 14:28:08 +0100 Subject: [PATCH 01/19] libp2p pubsub version --- src/Nethermind/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Directory.Packages.props b/src/Nethermind/Directory.Packages.props index 253c598a39d..be5bb6023c8 100644 --- a/src/Nethermind/Directory.Packages.props +++ b/src/Nethermind/Directory.Packages.props @@ -51,7 +51,7 @@ - + From 0e0f95a8fb8a5656005d24898cd29629e21608fb Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 2 Oct 2024 15:33:59 +0100 Subject: [PATCH 02/19] use pubsub peer discovery --- src/Nethermind/Directory.Packages.props | 1 + .../Nethermind.Runner/configs/chiado.cfg | 7 +--- .../Config/IShutterConfig.cs | 27 +++++------- .../Nethermind.Shutter/IShutterApi.cs | 3 +- .../Nethermind.Shutter/IShutterP2P.cs | 3 +- .../Nethermind.Shutter.csproj | 1 + .../Nethermind.Shutter/ShutterApi.cs | 5 ++- .../Nethermind.Shutter/ShutterP2P.cs | 41 ++++--------------- .../Nethermind.Shutter/ShutterPlugin.cs | 6 ++- 9 files changed, 33 insertions(+), 61 deletions(-) diff --git a/src/Nethermind/Directory.Packages.props b/src/Nethermind/Directory.Packages.props index be5bb6023c8..6fd8414efbe 100644 --- a/src/Nethermind/Directory.Packages.props +++ b/src/Nethermind/Directory.Packages.props @@ -52,6 +52,7 @@ + diff --git a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg index 2caeddda453..bbe7ba14703 100644 --- a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg @@ -37,11 +37,8 @@ "KeyBroadcastContractAddress": "0x9D31865BEffcE842FBd36CDA587aDDA8bef804B7", "KeyperSetManagerContractAddress": "0xC4DE9FAf4ec882b33dA0162CBE628B0D8205D0c0", "BootnodeP2PAddresses": [ - "/ip4/157.230.104.246/tcp/23003/p2p/12D3KooWFUYoPd3bdPuRi6FXkEQRSw7FRf2e23NAypjfDVYuvBAV", - "/ip4/134.209.225.234/tcp/23003/p2p/12D3KooWAsBKAj1NEtvu7wcLiEVU49N6Z9GPK3tZ87m17tFdWdNE", - "/ip4/157.230.114.117/tcp/23003/p2p/12D3KooWEDk8XJdxHjCHh9wTGVRXtpyCvCP4N4Jztr8zTJd4rMVX", - "/ip4/64.225.104.2/tcp/23003/p2p/12D3KooWMXTYrwEz4v5aGa7chYHjVVpjzzkq9JSjZzxbdh9YgAQS", - "/ip4/157.230.111.142/tcp/23003/p2p/12D3KooWA3FPqxV8whaFPbLzwbyDEWML4y73D6RJqb2mn7SHz6fg" + "/ip4/167.99.177.227/tcp/23005/p2p/12D3KooWSdm5guPBdn8DSaBphVBzUUgPLg9sZLnazEUrcbtLy254", + "/ip4/159.89.15.119/tcp/23005/p2p/12D3KooWPP6bp2PJQR8rUvG1SD4qNH4WFrKve6DMgWThyKxwNbbH" ], "InstanceID": "102000" }, diff --git a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs index 7bc477ae4c8..12d19cab484 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Linq; using Multiformats.Address; using Nethermind.Config; using Nethermind.Core; @@ -11,14 +12,9 @@ namespace Nethermind.Shutter.Config; public interface IShutterConfig : IConfig { - // todo: replace with bootnodes when peer discovery added private const string DefaultP2PAddresses = -@"/ip4/139.59.130.109/tcp/23003/p2p/12D3KooWRZoofMsnpsjkgvfPQUyGXZQnn7EVnb4tw4ghNfwMnnsj, -/ip4/167.71.169.248/tcp/23003/p2p/12D3KooWGH3VxoSQXZ6wUuCmsv5caGQnhwfGejbkXH6uS2r7sehA, -/ip4/139.59.130.109/tcp/23003/p2p/12D3KooWNxTiw7CvD1fuyye5P8qPhKTTrRBW6wwZwMdqdTxjYF2H, -/ip4/178.128.192.239/tcp/23003/p2p/12D3KooWCdpkipTiuzVMfkV7yLLgqbFeAL8WmEP78hCoBGBYLugN, -/ip4/45.55.192.248/tcp/23003/p2p/12D3KooWMPuubKqksfMxvLwEBDScaopTdvPLr5J5SMmBEo2zkcMz, -/ip4/178.128.126.237/tcp/23003/p2p/12D3KooWAg1pGUDAfFWSZftpN3JjBfLUCGLQcZApJHv2VntdMS9U"; +@"/ip4/167.99.177.227/tcp/23003/p2p/12D3KooWD35AESYCttDEi3J5WnQdTFuM5JNtmuXEb1x4eQ28gb1s, +/ip4/159.89.15.119/tcp/23003/p2p/12D3KooWRzAhgPA16DiBQhiuYoasYzJaQSAbtc5i5FvgTi9ZDQtS"; [ConfigItem(Description = "Whether to enable Shutter.", DefaultValue = "false")] bool Enabled { get; set; } @@ -80,7 +76,7 @@ public interface IShutterConfig : IConfig DefaultValue = "true", HiddenFromDocs = true)] bool Validator { get; set; } - public void Validate() + public void Validate(out Multiaddress[] bootnodeP2PAddresses) { if (Validator && ValidatorInfoFile is null) { @@ -127,16 +123,13 @@ public void Validate() throw new ArgumentNullException(nameof(BootnodeP2PAddresses)); } - foreach (string addr in BootnodeP2PAddresses) + try { - try - { - Multiaddress.Decode(addr); - } - catch (NotSupportedException) - { - throw new ArgumentException($"Could not decode Shutter keyper p2p address \"{addr}\"."); - } + bootnodeP2PAddresses = BootnodeP2PAddresses.Select(addr => Multiaddress.Decode(addr)).ToArray(); + } + catch (NotSupportedException) + { + throw new ArgumentException($"Could not decode Shutter bootnode p2p addresses."); } } } diff --git a/src/Nethermind/Nethermind.Shutter/IShutterApi.cs b/src/Nethermind/Nethermind.Shutter/IShutterApi.cs index c6ed5544372..4fff37c21bf 100644 --- a/src/Nethermind/Nethermind.Shutter/IShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/IShutterApi.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; +using Multiformats.Address; using Nethermind.Consensus; namespace Nethermind.Shutter; @@ -10,7 +11,7 @@ namespace Nethermind.Shutter; public interface IShutterApi { ShutterTxSource TxSource { get; } - Task StartP2P(CancellationTokenSource? cancellationTokenSource = null); + Task StartP2P(Multiaddress[] bootnodeP2PAddresses, CancellationTokenSource? cancellationTokenSource = null); ShutterBlockImprovementContextFactory GetBlockImprovementContextFactory(IBlockProducer blockProducer); ValueTask DisposeAsync(); } diff --git a/src/Nethermind/Nethermind.Shutter/IShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/IShutterP2P.cs index 43f6bdb38e1..d72baa359c4 100644 --- a/src/Nethermind/Nethermind.Shutter/IShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/IShutterP2P.cs @@ -4,11 +4,12 @@ using System; using System.Threading; using System.Threading.Tasks; +using Multiformats.Address; namespace Nethermind.Shutter; public interface IShutterP2P { - Task Start(Func onKeysReceived, CancellationTokenSource? cts = null); + Task Start(Multiaddress[] bootnodeP2PAddresses, Func onKeysReceived, CancellationTokenSource? cts = null); ValueTask DisposeAsync(); } diff --git a/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj b/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj index 2e34e8434b8..a68f0816eec 100644 --- a/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj +++ b/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs index 91b53f6a17d..32112776f12 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Multiformats.Address; using Nethermind.Abi; using Nethermind.Blockchain; using Nethermind.Blockchain.Find; @@ -95,8 +96,8 @@ TimeSpan slotLength InitP2P(_cfg, logManager); } - public Task StartP2P(CancellationTokenSource? cancellationTokenSource = null) - => P2P!.Start(OnKeysReceived, cancellationTokenSource); + public Task StartP2P(Multiaddress[] bootnodeP2PAddresses, CancellationTokenSource? cancellationTokenSource = null) + => P2P!.Start(bootnodeP2PAddresses, OnKeysReceived, cancellationTokenSource); public ShutterBlockImprovementContextFactory GetBlockImprovementContextFactory(IBlockProducer blockProducer) { diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index 6bd04185038..73f8b829c38 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -10,11 +10,9 @@ using System.Threading.Tasks; using System.Threading; using Microsoft.Extensions.DependencyInjection; -using System.Collections.Generic; using Multiformats.Address; using Nethermind.Shutter.Config; using Nethermind.Logging; -using Nethermind.Core.Extensions; using ILogger = Nethermind.Logging.ILogger; using System.Threading.Channels; using Google.Protobuf; @@ -27,6 +25,8 @@ public class ShutterP2P : IShutterP2P private readonly IShutterConfig _cfg; private readonly Channel _msgQueue = Channel.CreateBounded(1000); private readonly PubsubRouter _router; + private readonly PubSubDiscoveryProtocol _disc; + private readonly PeerStore _peerStore; private readonly ILocalPeer _peer; private readonly ServiceProvider _serviceProvider; private CancellationTokenSource? _cts; @@ -69,7 +69,8 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) IPeerFactory peerFactory = _serviceProvider!.GetService()!; _peer = peerFactory.Create(new Identity(), "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); _router = _serviceProvider!.GetService()!; - ITopic topic = _router.Subscribe("decryptionKeys"); + _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubSubDiscoverySettings() { Interval = 300 }, _peer); + ITopic topic = _router.GetTopic("decryptionKeys"); topic.OnMessage += (byte[] msg) => { @@ -78,13 +79,12 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) }; } - public async Task Start(Func onKeysReceived, CancellationTokenSource? cts = null) + public async Task Start(Multiaddress[] bootnodeP2PAddresses, Func onKeysReceived, CancellationTokenSource? cts = null) { - MyProto proto = new(); _cts = cts ?? new(); - _ = _router!.RunAsync(_peer, proto, token: _cts.Token); - proto.SetupFinished().GetAwaiter().GetResult(); - ConnectToPeers(proto, _cfg.BootnodeP2PAddresses!); + _ = _router!.RunAsync(_peer, token: _cts.Token); + _ = _disc.DiscoverAsync(_peer.Address, _cts.Token); + _peerStore.Discover(bootnodeP2PAddresses); if (_logger.IsInfo) _logger.Info($"Started Shutter P2P: {_peer.Address}"); @@ -128,21 +128,6 @@ public async ValueTask DisposeAsync() await (_cts?.CancelAsync() ?? Task.CompletedTask); } - private class MyProto : IDiscoveryProtocol - { - private readonly TaskCompletionSource taskCompletionSource = new(); - public Func? OnAddPeer { get; set; } - public Func? OnRemovePeer { get; set; } - - public Task SetupFinished() => taskCompletionSource.Task; - - public Task DiscoverAsync(Multiaddress localPeerAddr, CancellationToken token = default) - { - taskCompletionSource.TrySetResult(); - return Task.CompletedTask; - } - } - private void ProcessP2PMessage(byte[] msg, Func onKeysReceived) { if (_logger.IsTrace) _logger.Trace("Processing Shutter P2P message."); @@ -164,14 +149,4 @@ private void ProcessP2PMessage(byte[] msg, Func onKeys if (_logger.IsDebug) _logger.Warn($"Could not parse Shutter decryption keys: {e}"); } } - - private static void ConnectToPeers(MyProto proto, IEnumerable p2pAddresses) - { - // shuffle peers to connect to random subset of keypers - int seed = (int)(DateTimeOffset.Now.ToUnixTimeSeconds() % int.MaxValue); - foreach (string addr in p2pAddresses.Shuffle(new Random(seed))) - { - proto.OnAddPeer?.Invoke([addr]); - } - } } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs index 04b6a444699..468280908ad 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs @@ -16,6 +16,7 @@ using Nethermind.Serialization.Json; using System.Threading; using Nethermind.Config; +using Multiformats.Address; namespace Nethermind.Shutter; @@ -73,9 +74,10 @@ public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, I if (_logger.IsInfo) _logger.Info("Initializing Shutter block producer."); + Multiaddress[] bootnodeP2PAddresses; try { - _shutterConfig!.Validate(); + _shutterConfig!.Validate(out bootnodeP2PAddresses); } catch (ArgumentException e) { @@ -110,7 +112,7 @@ public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, I TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot) ); - _ = _shutterApi.StartP2P(_cts); + _ = _shutterApi.StartP2P(bootnodeP2PAddresses, _cts); } return consensusPlugin.InitBlockProducer(_shutterApi is null ? txSource : _shutterApi.TxSource.Then(txSource)); From 60dc7f436a38c344766ac5c2f58a92ae59dcaa7b Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 2 Oct 2024 15:57:25 +0100 Subject: [PATCH 03/19] add pubsub stuff to serviceprovider --- src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index 73f8b829c38..c4d67b768df 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -55,6 +55,9 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) HighestDegree = 6, LazyDegree = 3 }) + .AddSingleton() + .AddSingleton() + .AddSingleton(sp => sp.GetService()!.Build()) //.AddSingleton(new NethermindLoggerFactory(logManager)) // .AddLogging(builder => // builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace) From 266f5ccb981afe6bc9e8ffe9daece49d844c59de Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 3 Oct 2024 11:08:16 +0100 Subject: [PATCH 04/19] update p2p version --- src/Nethermind/Directory.Packages.props | 4 ++-- src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj | 2 +- src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Directory.Packages.props b/src/Nethermind/Directory.Packages.props index 6fd8414efbe..3eded3155e9 100644 --- a/src/Nethermind/Directory.Packages.props +++ b/src/Nethermind/Directory.Packages.props @@ -51,8 +51,8 @@ - - + + diff --git a/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj b/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj index a68f0816eec..1f52340eba3 100644 --- a/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj +++ b/src/Nethermind/Nethermind.Shutter/Nethermind.Shutter.csproj @@ -30,7 +30,7 @@ - + diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index c4d67b768df..e43b535095c 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -25,7 +25,7 @@ public class ShutterP2P : IShutterP2P private readonly IShutterConfig _cfg; private readonly Channel _msgQueue = Channel.CreateBounded(1000); private readonly PubsubRouter _router; - private readonly PubSubDiscoveryProtocol _disc; + private readonly PubsubPeerDiscoveryProtocol _disc; private readonly PeerStore _peerStore; private readonly ILocalPeer _peer; private readonly ServiceProvider _serviceProvider; @@ -72,7 +72,7 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) IPeerFactory peerFactory = _serviceProvider!.GetService()!; _peer = peerFactory.Create(new Identity(), "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); _router = _serviceProvider!.GetService()!; - _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubSubDiscoverySettings() { Interval = 300 }, _peer); + _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubsubPeerDiscoverySettings() { Interval = 300 }, _peer); ITopic topic = _router.GetTopic("decryptionKeys"); topic.OnMessage += (byte[] msg) => From e078a3a91aefe45d7546b5e0aa285002aa0ea3bb Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 16 Oct 2024 11:45:32 +0100 Subject: [PATCH 05/19] add nuget staging --- src/Nethermind/nuget.config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/nuget.config b/src/Nethermind/nuget.config index 84c8ccf735e..08dcfe6ac71 100644 --- a/src/Nethermind/nuget.config +++ b/src/Nethermind/nuget.config @@ -3,14 +3,14 @@ - + - + From e4c44863fc73b387dc39228a447f660002079cdc Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 16 Oct 2024 11:51:57 +0100 Subject: [PATCH 06/19] libp2p package pattern --- src/Nethermind/nuget.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/nuget.config b/src/Nethermind/nuget.config index 08dcfe6ac71..8d246048111 100644 --- a/src/Nethermind/nuget.config +++ b/src/Nethermind/nuget.config @@ -10,7 +10,7 @@ - + From 368ce4844cd54b0f755df5f94aded3c12896847c Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 16 Oct 2024 11:57:39 +0100 Subject: [PATCH 07/19] add test package to docgen solution --- tools/DocGen/nuget.config | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/DocGen/nuget.config b/tools/DocGen/nuget.config index 765346e5343..8d246048111 100644 --- a/tools/DocGen/nuget.config +++ b/tools/DocGen/nuget.config @@ -3,5 +3,14 @@ + + + + + + + + + From 1759f594db07a6469b28541e2654d5ebf6229118 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 17 Oct 2024 14:52:46 +0100 Subject: [PATCH 08/19] persist shutter peer id to disk --- .../Config/IKeystoreConfig.cs | 3 ++ .../Config/KeystoreConfig.cs | 1 + .../ShutterApiSimulator.cs | 9 +++-- .../ShutterTestsCommon.cs | 8 +++-- .../Nethermind.Shutter/ShutterApi.cs | 14 ++++++-- .../Nethermind.Shutter/ShutterP2P.cs | 33 +++++++++++++++++-- .../Nethermind.Shutter/ShutterPlugin.cs | 3 ++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs b/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs index 379301d3545..a5830217079 100644 --- a/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs +++ b/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs @@ -62,6 +62,9 @@ public interface IKeyStoreConfig : IConfig [ConfigItem(Description = $"The path to the key file to use by for networking (enode). If neither this nor the `{nameof(EnodeAccount)}` is specified, the key is autogenerated in `node.key.plain` file.")] string EnodeKeyFile { get; set; } + [ConfigItem(Description = "The path to the key file to use by for connecting to Shutter P2P network. If this not specified, the key is autogenerated in `shutter.key.plain` file.")] + string ShutterKeyFile { get; set; } + [ConfigItem(Description = $"An array of passwords used to unlock the accounts set with `{nameof(UnlockAccounts)}`.", DefaultValue = "[]")] string[] Passwords { get; set; } diff --git a/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs b/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs index ea48cc24df7..6800a74025c 100644 --- a/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs +++ b/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs @@ -42,6 +42,7 @@ public class KeyStoreConfig : IKeyStoreConfig public string EnodeAccount { get; set; } public string EnodeKeyFile { get; set; } + public string ShutterKeyFile { get; set; } = "shutter.key.plain"; public string[] Passwords { get; set; } = Array.Empty(); diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs index c1709d2879c..8e755db821d 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Abstractions; using System.Linq; using System.Threading.Tasks; using Nethermind.Abi; @@ -14,6 +15,7 @@ using Nethermind.Core.Test.Builders; using Nethermind.Crypto; using Nethermind.Facade.Find; +using Nethermind.KeyStore.Config; using Nethermind.Logging; using Nethermind.Shutter.Config; using Nethermind.State; @@ -32,11 +34,14 @@ public class ShutterApiSimulator( ISpecProvider specProvider, ITimestamper timestamper, IWorldStateManager worldStateManager, + IFileSystem fileSystem, + IKeyStoreConfig keyStoreConfig, IShutterConfig cfg, Dictionary validatorsInfo, Random rnd ) : ShutterApi(abiEncoder, blockTree, ecdsa, logFinder, receiptStorage, - logManager, specProvider, timestamper, worldStateManager, cfg, validatorsInfo, ShutterTestsCommon.SlotLength) + logManager, specProvider, timestamper, worldStateManager, fileSystem, + keyStoreConfig, cfg, validatorsInfo, ShutterTestsCommon.SlotLength) { public int EonUpdateCalled = 0; public int KeysValidated = 0; @@ -110,7 +115,7 @@ protected override async Task OnKeysReceived(Dto.DecryptionKeys decryptionKeys) // fake out P2P module - protected override void InitP2P(IShutterConfig cfg, ILogManager logManager) + protected override void InitP2P() { P2P = Substitute.For(); } diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterTestsCommon.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterTestsCommon.cs index 03b157963df..612414beca8 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterTestsCommon.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterTestsCommon.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.IO.Abstractions; using Nethermind.Abi; using Nethermind.Blockchain; using Nethermind.Blockchain.Receipts; @@ -11,6 +12,7 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Facade.Find; +using Nethermind.KeyStore.Config; using Nethermind.Logging; using Nethermind.Shutter.Config; using Nethermind.Specs; @@ -56,7 +58,8 @@ public static ShutterApiSimulator InitApi(Random rnd, ITimestamper? timestamper eventSimulator ?? InitEventSimulator(rnd), AbiEncoder, blockTree, Ecdsa, logFinder, receiptStorage, LogManager, SpecProvider, timestamper ?? Substitute.For(), - worldStateManager, Cfg, [], rnd + worldStateManager, Substitute.For(), + Substitute.For(), Cfg, [], rnd ); } @@ -64,7 +67,8 @@ public static ShutterApiSimulator InitApi(Random rnd, MergeTestBlockchain chain, => new( eventSimulator ?? InitEventSimulator(rnd), AbiEncoder, chain.BlockTree.AsReadOnly(), chain.EthereumEcdsa, chain.LogFinder, chain.ReceiptStorage, - chain.LogManager, chain.SpecProvider, timestamper ?? chain.Timestamper, chain.WorldStateManager, Cfg, [], rnd + chain.LogManager, chain.SpecProvider, timestamper ?? chain.Timestamper, chain.WorldStateManager, + Substitute.For(), Substitute.For(), Cfg, [], rnd ); public static ShutterEventSimulator InitEventSimulator(Random rnd) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs index 32112776f12..b92788c8e09 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO.Abstractions; using System.Threading; using System.Threading.Tasks; using Multiformats.Address; @@ -16,6 +17,7 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Facade.Find; +using Nethermind.KeyStore.Config; using Nethermind.Logging; using Nethermind.Shutter.Config; using Nethermind.State; @@ -42,6 +44,8 @@ public class ShutterApi : IShutterApi private readonly ReadOnlyTxProcessingEnvFactory _txProcessingEnvFactory; private readonly IAbiEncoder _abiEncoder; private readonly ILogManager _logManager; + private readonly IFileSystem _fileSystem; + private readonly IKeyStoreConfig _keyStoreConfig; private readonly IShutterConfig _cfg; private readonly TimeSpan _blockWaitCutoff; @@ -55,6 +59,8 @@ public ShutterApi( ISpecProvider specProvider, ITimestamper timestamper, IWorldStateManager worldStateManager, + IFileSystem fileSystem, + IKeyStoreConfig keyStoreConfig, IShutterConfig cfg, Dictionary validatorsInfo, TimeSpan slotLength @@ -66,6 +72,8 @@ TimeSpan slotLength _abiEncoder = abiEncoder; _logManager = logManager; _slotLength = slotLength; + _fileSystem = fileSystem; + _keyStoreConfig = keyStoreConfig; _blockUpToDateCutoff = slotLength; _blockWaitCutoff = _slotLength / 3; @@ -93,7 +101,7 @@ TimeSpan slotLength KeyValidator = new ShutterKeyValidator(_cfg, Eon, logManager); - InitP2P(_cfg, logManager); + InitP2P(); } public Task StartP2P(Multiaddress[] bootnodeP2PAddresses, CancellationTokenSource? cancellationTokenSource = null) @@ -139,9 +147,9 @@ protected virtual async Task OnKeysReceived(Dto.DecryptionKeys decryptionKeys) TxSource.LoadTransactions(head, parentHeader, keys.Value); } - protected virtual void InitP2P(IShutterConfig cfg, ILogManager logManager) + protected virtual void InitP2P() { - P2P = new ShutterP2P(cfg, logManager); + P2P = new ShutterP2P(_cfg, _logManager, _fileSystem, _keyStoreConfig); } protected virtual IShutterEon InitEon() diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index e43b535095c..2c5cf6bb43c 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -16,6 +16,10 @@ using ILogger = Nethermind.Logging.ILogger; using System.Threading.Channels; using Google.Protobuf; +using Nethermind.Db; +using System.Text; +using System.IO.Abstractions; +using Nethermind.KeyStore.Config; namespace Nethermind.Shutter; @@ -24,6 +28,7 @@ public class ShutterP2P : IShutterP2P private readonly ILogger _logger; private readonly IShutterConfig _cfg; private readonly Channel _msgQueue = Channel.CreateBounded(1000); + private static readonly byte[] _peerIdDbKey = Encoding.UTF8.GetBytes("shutterPeerIdPrivateKey"); private readonly PubsubRouter _router; private readonly PubsubPeerDiscoveryProtocol _disc; private readonly PeerStore _peerStore; @@ -35,7 +40,7 @@ public class ShutterP2P : IShutterP2P public class ShutterP2PException(string message, Exception? innerException = null) : Exception(message, innerException); - public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) + public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSystem fileSystem, IKeyStoreConfig keyStoreConfig) { _logger = logManager.GetClassLogger(); _cfg = shutterConfig; @@ -70,7 +75,9 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager) .BuildServiceProvider(); IPeerFactory peerFactory = _serviceProvider!.GetService()!; - _peer = peerFactory.Create(new Identity(), "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); + + Identity identity = GetPeerIdentity(fileSystem, keyStoreConfig); + _peer = peerFactory.Create(identity, "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); _router = _serviceProvider!.GetService()!; _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubsubPeerDiscoverySettings() { Interval = 300 }, _peer); ITopic topic = _router.GetTopic("decryptionKeys"); @@ -131,6 +138,28 @@ public async ValueTask DisposeAsync() await (_cts?.CancelAsync() ?? Task.CompletedTask); } + private Identity GetPeerIdentity(IFileSystem fileSystem, IKeyStoreConfig cfg) + { + string fp = cfg.ShutterKeyFile.GetApplicationResourcePath(cfg.KeyStoreDirectory); + Identity identity; + + if (fileSystem.File.Exists(fp)) + { + if (_logger.IsInfo) _logger.Info("Loading Shutter P2P identity from disk."); + identity = new(fileSystem.File.ReadAllBytes(fp)); + } + else + { + if (_logger.IsInfo) _logger.Info("Generating new Shutter P2P identity."); + identity = new(); + string keyStoreDirectory = cfg.KeyStoreDirectory.GetApplicationResourcePath(); + fileSystem.Directory.CreateDirectory(keyStoreDirectory); + fileSystem.File.WriteAllBytes(fp, identity.PrivateKey!.Data.ToByteArray()); + } + + return identity; + } + private void ProcessP2PMessage(byte[] msg, Func onKeysReceived) { if (_logger.IsTrace) _logger.Trace("Processing Shutter P2P message."); diff --git a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs index 468280908ad..15e2bc23fc6 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs @@ -17,6 +17,7 @@ using System.Threading; using Nethermind.Config; using Multiformats.Address; +using Nethermind.KeyStore.Config; namespace Nethermind.Shutter; @@ -107,6 +108,8 @@ public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, I _api.SpecProvider, _api.Timestamper, _api.WorldStateManager, + _api.FileSystem, + _api.Config(), _shutterConfig, validatorsInfo, TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot) From cbb8eb2a247913e2ebbfcad89f1823e62d7db570 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 18 Oct 2024 11:07:16 +0100 Subject: [PATCH 09/19] cleanup p2p --- src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index 2c5cf6bb43c..af35fb0cd57 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -16,8 +16,6 @@ using ILogger = Nethermind.Logging.ILogger; using System.Threading.Channels; using Google.Protobuf; -using Nethermind.Db; -using System.Text; using System.IO.Abstractions; using Nethermind.KeyStore.Config; @@ -28,7 +26,6 @@ public class ShutterP2P : IShutterP2P private readonly ILogger _logger; private readonly IShutterConfig _cfg; private readonly Channel _msgQueue = Channel.CreateBounded(1000); - private static readonly byte[] _peerIdDbKey = Encoding.UTF8.GetBytes("shutterPeerIdPrivateKey"); private readonly PubsubRouter _router; private readonly PubsubPeerDiscoveryProtocol _disc; private readonly PeerStore _peerStore; From 2d5962c9d0f6537662c42f34db1a9c419e3b4738 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 18 Oct 2024 11:07:32 +0100 Subject: [PATCH 10/19] update libp2p version --- src/Nethermind/Directory.Packages.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Directory.Packages.props b/src/Nethermind/Directory.Packages.props index 3eded3155e9..ed55108954c 100644 --- a/src/Nethermind/Directory.Packages.props +++ b/src/Nethermind/Directory.Packages.props @@ -51,8 +51,8 @@ - - + + From 58f801dc6e7d5198ddfe2ecde05f3a76185c0cea Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 18 Oct 2024 15:47:26 +0100 Subject: [PATCH 11/19] add gnosis defaults to ShutterConfig --- .../Nethermind.Shutter/Config/ShutterConfig.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs index 1e0e9c662f3..d22b9784996 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs @@ -7,17 +7,17 @@ public class ShutterConfig : IShutterConfig { public bool Enabled { get; set; } public bool Validator { get; set; } = true; - public string? SequencerContractAddress { get; set; } - public string? ValidatorRegistryContractAddress { get; set; } - public string? KeyBroadcastContractAddress { get; set; } - public string? KeyperSetManagerContractAddress { get; set; } + public string? SequencerContractAddress { get; set; } = "0xc5C4b277277A1A8401E0F039dfC49151bA64DC2E"; + public string? ValidatorRegistryContractAddress { get; set; } = "0xefCC23E71f6bA9B22C4D28F7588141d44496A6D6"; + public string? KeyBroadcastContractAddress { get; set; } = "0x626dB87f9a9aC47070016A50e802dd5974341301"; + public string? KeyperSetManagerContractAddress { get; set; } = "0x7C2337f9bFce19d8970661DA50dE8DD7d3D34abb"; public string[]? BootnodeP2PAddresses { get; set; } = []; public int P2PPort { get; set; } = 23102; public string? ValidatorInfoFile { get; set; } public string? P2PProtocolVersion { get; set; } = "/shutter/0.1.0"; public string? P2PAgentVersion { get; set; } = "github.com/shutter-network/rolling-shutter/rolling-shutter"; public ulong ValidatorRegistryMessageVersion { get; set; } = 0; - public ulong InstanceID { get; set; } = 0; + public ulong InstanceID { get; set; } = 1000; public int EncryptedGasLimit { get; set; } = 10000000; public ushort MaxKeyDelay { get; set; } = 1666; } From 2bd7379a17f31704c6f83ddbc3073c3929cfecc0 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 24 Oct 2024 12:04:38 +0100 Subject: [PATCH 12/19] production libp2p package --- src/Nethermind/nuget.config | 8 ++++---- tools/DocGen/nuget.config | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/nuget.config b/src/Nethermind/nuget.config index 8d246048111..84c8ccf735e 100644 --- a/src/Nethermind/nuget.config +++ b/src/Nethermind/nuget.config @@ -3,14 +3,14 @@ - + - + diff --git a/tools/DocGen/nuget.config b/tools/DocGen/nuget.config index 8d246048111..84c8ccf735e 100644 --- a/tools/DocGen/nuget.config +++ b/tools/DocGen/nuget.config @@ -3,14 +3,14 @@ - + - + From 7d033495ab065298cd6d7d33b9e4e325c3055784 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 24 Oct 2024 12:17:28 +0100 Subject: [PATCH 13/19] restore staging packages docgen --- tools/DocGen/nuget.config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/DocGen/nuget.config b/tools/DocGen/nuget.config index 84c8ccf735e..08dcfe6ac71 100644 --- a/tools/DocGen/nuget.config +++ b/tools/DocGen/nuget.config @@ -3,14 +3,14 @@ - + - + From 0289521225e494b0e2b111e9b9616e6bae282241 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 24 Oct 2024 12:22:43 +0100 Subject: [PATCH 14/19] remove all docgen changes --- tools/DocGen/nuget.config | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tools/DocGen/nuget.config b/tools/DocGen/nuget.config index 08dcfe6ac71..765346e5343 100644 --- a/tools/DocGen/nuget.config +++ b/tools/DocGen/nuget.config @@ -3,14 +3,5 @@ - - - - - - - - - From 23c65735df3fdcb22bc3d1910deaf0eab87032f9 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 24 Oct 2024 13:42:25 +0100 Subject: [PATCH 15/19] Update src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs Co-authored-by: Lukasz Rozmej --- src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs index 12d19cab484..93f153d327b 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs @@ -127,9 +127,9 @@ public void Validate(out Multiaddress[] bootnodeP2PAddresses) { bootnodeP2PAddresses = BootnodeP2PAddresses.Select(addr => Multiaddress.Decode(addr)).ToArray(); } - catch (NotSupportedException) + catch (NotSupportedException e) { - throw new ArgumentException($"Could not decode Shutter bootnode p2p addresses."); + throw new ArgumentException($"Could not decode Shutter bootnode p2p addresses.", e); } } } From 8cc6b6519700b5caec1aaba9d461767385347d26 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 25 Oct 2024 18:07:08 +0100 Subject: [PATCH 16/19] move config to gnosis.cfg --- .../Nethermind.Runner/configs/chiado.cfg | 2 +- .../Nethermind.Runner/configs/gnosis.cfg | 11 +++++++++++ .../Nethermind.Shutter/Config/IShutterConfig.cs | 16 ++++++---------- .../Nethermind.Shutter/Config/ShutterConfig.cs | 10 +++++----- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg index 8af5378872a..ea1634e1b24 100644 --- a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg @@ -32,8 +32,8 @@ "ForceSealing": true }, "Shutter": { - "ValidatorRegistryContractAddress": "0xa9289A3Dd14FEBe10611119bE81E5d35eAaC3084", "SequencerContractAddress": "0x2aD8E2feB0ED5b2EC8e700edB725f120576994ed", + "ValidatorRegistryContractAddress": "0xa9289A3Dd14FEBe10611119bE81E5d35eAaC3084", "KeyBroadcastContractAddress": "0x9D31865BEffcE842FBd36CDA587aDDA8bef804B7", "KeyperSetManagerContractAddress": "0xC4DE9FAf4ec882b33dA0162CBE628B0D8205D0c0", "BootnodeP2PAddresses": [ diff --git a/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg b/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg index e98e44b71a9..768621bd8d7 100644 --- a/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg @@ -24,6 +24,17 @@ "BlockProductionTimeoutMs": 3000, "TargetBlockGasLimit": 17000000 }, + "Shutter": { + "SequencerContractAddress": "0x2aD8E2feB00xc5C4b277277A1A8401E0F039dfC49151bA64DC2ED5b2EC8e700edB725f120576994ed", + "ValidatorRegistryContractAddress": "0xefCC23E71f6bA9B22C4D28F7588141d44496A6D6", + "KeyBroadcastContractAddress": "0x626dB87f9a9aC47070016A50e802dd5974341301", + "KeyperSetManagerContractAddress": "0x7C2337f9bFce19d8970661DA50dE8DD7d3D34abb", + "BootnodeP2PAddresses": [ + "/ip4/167.99.177.227/tcp/23003/p2p/12D3KooWD35AESYCttDEi3J5WnQdTFuM5JNtmuXEb1x4eQ28gb1s", + "/ip4/159.89.15.119/tcp/23003/p2p/12D3KooWRzAhgPA16DiBQhiuYoasYzJaQSAbtc5i5FvgTi9ZDQtS" + ], + "InstanceID": "1000" + }, "Mining": { "MinGasPrice": "1000000000" }, diff --git a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs index 12d19cab484..9703fe5ce37 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs @@ -12,10 +12,6 @@ namespace Nethermind.Shutter.Config; public interface IShutterConfig : IConfig { - private const string DefaultP2PAddresses = -@"/ip4/167.99.177.227/tcp/23003/p2p/12D3KooWD35AESYCttDEi3J5WnQdTFuM5JNtmuXEb1x4eQ28gb1s, -/ip4/159.89.15.119/tcp/23003/p2p/12D3KooWRzAhgPA16DiBQhiuYoasYzJaQSAbtc5i5FvgTi9ZDQtS"; - [ConfigItem(Description = "Whether to enable Shutter.", DefaultValue = "false")] bool Enabled { get; set; } @@ -24,27 +20,27 @@ public interface IShutterConfig : IConfig string? ValidatorInfoFile { get; set; } [ConfigItem(Description = "The address of the Shutter sequencer contract.", - DefaultValue = "0xc5C4b277277A1A8401E0F039dfC49151bA64DC2E")] + DefaultValue = "null")] string? SequencerContractAddress { get; set; } [ConfigItem(Description = "The address of the Shutter validator registry contract.", - DefaultValue = "0xefCC23E71f6bA9B22C4D28F7588141d44496A6D6")] + DefaultValue = "null")] string? ValidatorRegistryContractAddress { get; set; } [ConfigItem(Description = "The address of the Shutter key broadcast contract.", - DefaultValue = "0x626dB87f9a9aC47070016A50e802dd5974341301")] + DefaultValue = "null")] string? KeyBroadcastContractAddress { get; set; } [ConfigItem(Description = "The address of the Shutter keyper set manager contract.", - DefaultValue = "0x7C2337f9bFce19d8970661DA50dE8DD7d3D34abb")] + DefaultValue = "null")] string? KeyperSetManagerContractAddress { get; set; } [ConfigItem(Description = "The p2p addresses of the Shutter Keyper network bootnodes.", - DefaultValue = DefaultP2PAddresses)] + DefaultValue = null)] string[]? BootnodeP2PAddresses { get; set; } [ConfigItem(Description = "Instance ID of Shutter keyper set.", - DefaultValue = "1000")] + DefaultValue = "0")] ulong InstanceID { get; set; } [ConfigItem(Description = "The port to connect to Shutter P2P network with.", diff --git a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs index d22b9784996..1e0e9c662f3 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs @@ -7,17 +7,17 @@ public class ShutterConfig : IShutterConfig { public bool Enabled { get; set; } public bool Validator { get; set; } = true; - public string? SequencerContractAddress { get; set; } = "0xc5C4b277277A1A8401E0F039dfC49151bA64DC2E"; - public string? ValidatorRegistryContractAddress { get; set; } = "0xefCC23E71f6bA9B22C4D28F7588141d44496A6D6"; - public string? KeyBroadcastContractAddress { get; set; } = "0x626dB87f9a9aC47070016A50e802dd5974341301"; - public string? KeyperSetManagerContractAddress { get; set; } = "0x7C2337f9bFce19d8970661DA50dE8DD7d3D34abb"; + public string? SequencerContractAddress { get; set; } + public string? ValidatorRegistryContractAddress { get; set; } + public string? KeyBroadcastContractAddress { get; set; } + public string? KeyperSetManagerContractAddress { get; set; } public string[]? BootnodeP2PAddresses { get; set; } = []; public int P2PPort { get; set; } = 23102; public string? ValidatorInfoFile { get; set; } public string? P2PProtocolVersion { get; set; } = "/shutter/0.1.0"; public string? P2PAgentVersion { get; set; } = "github.com/shutter-network/rolling-shutter/rolling-shutter"; public ulong ValidatorRegistryMessageVersion { get; set; } = 0; - public ulong InstanceID { get; set; } = 1000; + public ulong InstanceID { get; set; } = 0; public int EncryptedGasLimit { get; set; } = 10000000; public ushort MaxKeyDelay { get; set; } = 1666; } From f6c82ddab2ffff6eaf7f1a85ae42d50cbf3b6269 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 25 Oct 2024 20:15:01 +0100 Subject: [PATCH 17/19] move shutter key file name to shutter config --- .../Nethermind.KeyStore/Config/IKeystoreConfig.cs | 3 --- .../Nethermind.KeyStore/Config/KeystoreConfig.cs | 1 - .../Nethermind.Shutter/Config/IShutterConfig.cs | 3 +++ src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs | 1 + src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs b/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs index a5830217079..379301d3545 100644 --- a/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs +++ b/src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs @@ -62,9 +62,6 @@ public interface IKeyStoreConfig : IConfig [ConfigItem(Description = $"The path to the key file to use by for networking (enode). If neither this nor the `{nameof(EnodeAccount)}` is specified, the key is autogenerated in `node.key.plain` file.")] string EnodeKeyFile { get; set; } - [ConfigItem(Description = "The path to the key file to use by for connecting to Shutter P2P network. If this not specified, the key is autogenerated in `shutter.key.plain` file.")] - string ShutterKeyFile { get; set; } - [ConfigItem(Description = $"An array of passwords used to unlock the accounts set with `{nameof(UnlockAccounts)}`.", DefaultValue = "[]")] string[] Passwords { get; set; } diff --git a/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs b/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs index 6800a74025c..ea48cc24df7 100644 --- a/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs +++ b/src/Nethermind/Nethermind.KeyStore/Config/KeystoreConfig.cs @@ -42,7 +42,6 @@ public class KeyStoreConfig : IKeyStoreConfig public string EnodeAccount { get; set; } public string EnodeKeyFile { get; set; } - public string ShutterKeyFile { get; set; } = "shutter.key.plain"; public string[] Passwords { get; set; } = Array.Empty(); diff --git a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs index 1fa10ded6ac..f96b1b8c0dc 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs @@ -56,6 +56,9 @@ public interface IShutterConfig : IConfig HiddenFromDocs = true)] string? P2PAgentVersion { get; set; } + [ConfigItem(Description = "The filename to use for the Shutter P2P key. If this not specified, the key is autogenerated in `shutter.key.plain` file.")] + string ShutterKeyFile { get; set; } + [ConfigItem(Description = "The Shutter validator registry message version.", DefaultValue = "0", HiddenFromDocs = true)] ulong ValidatorRegistryMessageVersion { get; set; } diff --git a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs index 1e0e9c662f3..a8ed781e0a8 100644 --- a/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs +++ b/src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs @@ -16,6 +16,7 @@ public class ShutterConfig : IShutterConfig public string? ValidatorInfoFile { get; set; } public string? P2PProtocolVersion { get; set; } = "/shutter/0.1.0"; public string? P2PAgentVersion { get; set; } = "github.com/shutter-network/rolling-shutter/rolling-shutter"; + public string ShutterKeyFile { get; set; } = "shutter.key.plain"; public ulong ValidatorRegistryMessageVersion { get; set; } = 0; public ulong InstanceID { get; set; } = 0; public int EncryptedGasLimit { get; set; } = 10000000; diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index af35fb0cd57..15f05d27043 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -73,7 +73,7 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSys IPeerFactory peerFactory = _serviceProvider!.GetService()!; - Identity identity = GetPeerIdentity(fileSystem, keyStoreConfig); + Identity identity = GetPeerIdentity(fileSystem, _cfg, keyStoreConfig); _peer = peerFactory.Create(identity, "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); _router = _serviceProvider!.GetService()!; _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubsubPeerDiscoverySettings() { Interval = 300 }, _peer); @@ -135,9 +135,9 @@ public async ValueTask DisposeAsync() await (_cts?.CancelAsync() ?? Task.CompletedTask); } - private Identity GetPeerIdentity(IFileSystem fileSystem, IKeyStoreConfig cfg) + private Identity GetPeerIdentity(IFileSystem fileSystem, IShutterConfig shutterConfig, IKeyStoreConfig keyStoreConfig) { - string fp = cfg.ShutterKeyFile.GetApplicationResourcePath(cfg.KeyStoreDirectory); + string fp = shutterConfig.ShutterKeyFile.GetApplicationResourcePath(keyStoreConfig.KeyStoreDirectory); Identity identity; if (fileSystem.File.Exists(fp)) @@ -149,7 +149,7 @@ private Identity GetPeerIdentity(IFileSystem fileSystem, IKeyStoreConfig cfg) { if (_logger.IsInfo) _logger.Info("Generating new Shutter P2P identity."); identity = new(); - string keyStoreDirectory = cfg.KeyStoreDirectory.GetApplicationResourcePath(); + string keyStoreDirectory = keyStoreConfig.KeyStoreDirectory.GetApplicationResourcePath(); fileSystem.Directory.CreateDirectory(keyStoreDirectory); fileSystem.File.WriteAllBytes(fp, identity.PrivateKey!.Data.ToByteArray()); } From 737f46f151f5af02eda3f61e282035e19119f75f Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Sat, 26 Oct 2024 00:52:23 +0100 Subject: [PATCH 18/19] use external ip in p2p id --- .../Nethermind.Shutter.Test/ShutterApiSimulator.cs | 5 +++-- src/Nethermind/Nethermind.Shutter/ShutterApi.cs | 14 +++++++------- src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 5 +++-- src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs | 4 +++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs index 8e755db821d..8f8d8ceb00c 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; +using System.Net; using System.Threading.Tasks; using Nethermind.Abi; using Nethermind.Blockchain; @@ -41,7 +42,7 @@ public class ShutterApiSimulator( Random rnd ) : ShutterApi(abiEncoder, blockTree, ecdsa, logFinder, receiptStorage, logManager, specProvider, timestamper, worldStateManager, fileSystem, - keyStoreConfig, cfg, validatorsInfo, ShutterTestsCommon.SlotLength) + keyStoreConfig, cfg, validatorsInfo, ShutterTestsCommon.SlotLength, IPAddress.None) { public int EonUpdateCalled = 0; public int KeysValidated = 0; @@ -115,7 +116,7 @@ protected override async Task OnKeysReceived(Dto.DecryptionKeys decryptionKeys) // fake out P2P module - protected override void InitP2P() + protected override void InitP2P(IPAddress _) { P2P = Substitute.For(); } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs index b92788c8e09..7c87a7bf7a7 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO.Abstractions; +using System.Net; using System.Threading; using System.Threading.Tasks; using Multiformats.Address; @@ -63,7 +64,8 @@ public ShutterApi( IKeyStoreConfig keyStoreConfig, IShutterConfig cfg, Dictionary validatorsInfo, - TimeSpan slotLength + TimeSpan slotLength, + IPAddress ip ) { _cfg = cfg; @@ -101,7 +103,7 @@ TimeSpan slotLength KeyValidator = new ShutterKeyValidator(_cfg, Eon, logManager); - InitP2P(); + InitP2P(ip); } public Task StartP2P(Multiaddress[] bootnodeP2PAddresses, CancellationTokenSource? cancellationTokenSource = null) @@ -147,16 +149,14 @@ protected virtual async Task OnKeysReceived(Dto.DecryptionKeys decryptionKeys) TxSource.LoadTransactions(head, parentHeader, keys.Value); } - protected virtual void InitP2P() + protected virtual void InitP2P(IPAddress ip) { - P2P = new ShutterP2P(_cfg, _logManager, _fileSystem, _keyStoreConfig); + P2P = new ShutterP2P(_cfg, _logManager, _fileSystem, _keyStoreConfig, ip); } protected virtual IShutterEon InitEon() => new ShutterEon(_readOnlyBlockTree, _txProcessingEnvFactory, _abiEncoder, _cfg, _logManager); protected virtual ShutterTime InitTime(ISpecProvider specProvider, ITimestamper timestamper) - { - return new(specProvider.BeaconChainGenesisTimestamp!.Value * 1000, timestamper, _slotLength, _blockUpToDateCutoff); - } + => new(specProvider.BeaconChainGenesisTimestamp!.Value * 1000, timestamper, _slotLength, _blockUpToDateCutoff); } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index 15f05d27043..ce0cf6558d2 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -18,6 +18,7 @@ using Google.Protobuf; using System.IO.Abstractions; using Nethermind.KeyStore.Config; +using System.Net; namespace Nethermind.Shutter; @@ -37,7 +38,7 @@ public class ShutterP2P : IShutterP2P public class ShutterP2PException(string message, Exception? innerException = null) : Exception(message, innerException); - public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSystem fileSystem, IKeyStoreConfig keyStoreConfig) + public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSystem fileSystem, IKeyStoreConfig keyStoreConfig, IPAddress ip) { _logger = logManager.GetClassLogger(); _cfg = shutterConfig; @@ -74,7 +75,7 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSys IPeerFactory peerFactory = _serviceProvider!.GetService()!; Identity identity = GetPeerIdentity(fileSystem, _cfg, keyStoreConfig); - _peer = peerFactory.Create(identity, "/ip4/0.0.0.0/tcp/" + _cfg.P2PPort); + _peer = peerFactory.Create(identity, $"/ip4/{ip}/tcp/{ _cfg.P2PPort}"); _router = _serviceProvider!.GetService()!; _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubsubPeerDiscoverySettings() { Interval = 300 }, _peer); ITopic topic = _router.GetTopic("decryptionKeys"); diff --git a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs index 15e2bc23fc6..bc75443016c 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs @@ -72,6 +72,7 @@ public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, I if (_api.SpecProvider is null) throw new ArgumentNullException(nameof(_api.SpecProvider)); if (_api.ReceiptFinder is null) throw new ArgumentNullException(nameof(_api.ReceiptFinder)); if (_api.WorldStateManager is null) throw new ArgumentNullException(nameof(_api.WorldStateManager)); + if (_api.IpResolver is null) throw new ArgumentNullException(nameof(_api.IpResolver)); if (_logger.IsInfo) _logger.Info("Initializing Shutter block producer."); @@ -112,7 +113,8 @@ public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, I _api.Config(), _shutterConfig, validatorsInfo, - TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot) + TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot), + _api.IpResolver.ExternalIp ); _ = _shutterApi.StartP2P(bootnodeP2PAddresses, _cts); From c2c09b05a0bc4dc58933e55725e7b21d3647a995 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Sat, 26 Oct 2024 00:54:02 +0100 Subject: [PATCH 19/19] fix whitespace --- src/Nethermind/Nethermind.Shutter/ShutterP2P.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs index ce0cf6558d2..726df4f29db 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterP2P.cs @@ -75,7 +75,7 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSys IPeerFactory peerFactory = _serviceProvider!.GetService()!; Identity identity = GetPeerIdentity(fileSystem, _cfg, keyStoreConfig); - _peer = peerFactory.Create(identity, $"/ip4/{ip}/tcp/{ _cfg.P2PPort}"); + _peer = peerFactory.Create(identity, $"/ip4/{ip}/tcp/{_cfg.P2PPort}"); _router = _serviceProvider!.GetService()!; _disc = new(_router, _peerStore = _serviceProvider.GetService()!, new PubsubPeerDiscoverySettings() { Interval = 300 }, _peer); ITopic topic = _router.GetTopic("decryptionKeys");