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

Shutter: P2P improvements #7545

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
893e790
libp2p pubsub version
Marchhill Oct 2, 2024
0e0f95a
use pubsub peer discovery
Marchhill Oct 2, 2024
60dc7f4
add pubsub stuff to serviceprovider
Marchhill Oct 2, 2024
266f5cc
update p2p version
Marchhill Oct 3, 2024
e078a3a
add nuget staging
Marchhill Oct 16, 2024
e4c4486
libp2p package pattern
Marchhill Oct 16, 2024
368ce48
add test package to docgen solution
Marchhill Oct 16, 2024
1759f59
persist shutter peer id to disk
Marchhill Oct 17, 2024
cbb8eb2
cleanup p2p
Marchhill Oct 18, 2024
2d5962c
update libp2p version
Marchhill Oct 18, 2024
58f801d
add gnosis defaults to ShutterConfig
Marchhill Oct 18, 2024
a977f4b
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Oct 22, 2024
7887203
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Oct 24, 2024
2bd7379
production libp2p package
Marchhill Oct 24, 2024
7d03349
restore staging packages docgen
Marchhill Oct 24, 2024
0289521
remove all docgen changes
Marchhill Oct 24, 2024
23c6573
Update src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs
Marchhill Oct 24, 2024
8cc6b65
move config to gnosis.cfg
Marchhill Oct 25, 2024
a69cbfd
Merge branch 'feature/gnosis-shutter-peer-discovery' of github.com:Ne…
Marchhill Oct 25, 2024
a054e3e
Merge remote-tracking branch 'upstream/master' into feature/gnosis-sh…
Marchhill Oct 25, 2024
f6c82dd
move shutter key file name to shutter config
Marchhill Oct 25, 2024
737f46f
use external ip in p2p id
Marchhill Oct 25, 2024
c2c09b0
fix whitespace
Marchhill Oct 25, 2024
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
3 changes: 2 additions & 1 deletion src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
<PackageVersion Include="Nethermind.DotNetty.Handlers" Version="1.0.1" />
<PackageVersion Include="Nethermind.DotNetty.Transport" Version="1.0.1" />
<PackageVersion Include="Nethermind.Gmp" Version="1.0.1" />
<PackageVersion Include="Nethermind.Libp2p" Version="1.0.0-preview.33" />
<PackageVersion Include="Nethermind.Libp2p" Version="1.0.0-preview.34" />
<PackageVersion Include="Nethermind.Libp2p.Protocols.PubsubPeerDiscovery" Version="1.0.0-preview.34" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.2.0" />
<PackageVersion Include="Nito.Collections.Deque" Version="1.2.1" />
<PackageVersion Include="NLog" Version="5.3.2" />
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.KeyStore/Config/IKeystoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();

Expand Down
7 changes: 2 additions & 5 deletions src/Nethermind/Nethermind.Runner/configs/chiado.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
9 changes: 7 additions & 2 deletions src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using Nethermind.Abi;
Expand All @@ -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;
Expand All @@ -32,11 +34,14 @@ public class ShutterApiSimulator(
ISpecProvider specProvider,
ITimestamper timestamper,
IWorldStateManager worldStateManager,
IFileSystem fileSystem,
IKeyStoreConfig keyStoreConfig,
IShutterConfig cfg,
Dictionary<ulong, byte[]> 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;
Expand Down Expand Up @@ -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<IShutterP2P>();
}
Expand Down
8 changes: 6 additions & 2 deletions src/Nethermind/Nethermind.Shutter.Test/ShutterTestsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using Nethermind.Abi;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Receipts;
using Nethermind.Core;
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;
Expand Down Expand Up @@ -56,15 +58,17 @@ public static ShutterApiSimulator InitApi(Random rnd, ITimestamper? timestamper
eventSimulator ?? InitEventSimulator(rnd),
AbiEncoder, blockTree, Ecdsa, logFinder, receiptStorage,
LogManager, SpecProvider, timestamper ?? Substitute.For<ITimestamper>(),
worldStateManager, Cfg, [], rnd
worldStateManager, Substitute.For<IFileSystem>(),
Substitute.For<IKeyStoreConfig>(), Cfg, [], rnd
);
}

public static ShutterApiSimulator InitApi(Random rnd, MergeTestBlockchain chain, ITimestamper? timestamper = null, ShutterEventSimulator? eventSimulator = null)
=> 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<IFileSystem>(), Substitute.For<IKeyStoreConfig>(), Cfg, [], rnd
);

public static ShutterEventSimulator InitEventSimulator(Random rnd)
Expand Down
27 changes: 10 additions & 17 deletions src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Linq;
using Multiformats.Address;
using Nethermind.Config;
using Nethermind.Core;
Expand All @@ -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";
Marchhill marked this conversation as resolved.
Show resolved Hide resolved

[ConfigItem(Description = "Whether to enable Shutter.", DefaultValue = "false")]
bool Enabled { get; set; }
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.");
Marchhill marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Marchhill marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Shutter/IShutterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

using System.Threading;
using System.Threading.Tasks;
using Multiformats.Address;
using Nethermind.Consensus;

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();
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Shutter/IShutterP2P.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dto.DecryptionKeys, Task> onKeysReceived, CancellationTokenSource? cts = null);
Task Start(Multiaddress[] bootnodeP2PAddresses, Func<Dto.DecryptionKeys, Task> onKeysReceived, CancellationTokenSource? cts = null);
ValueTask DisposeAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<PackageReference Include="Nethermind.Libp2p" />
<PackageReference Include="Nethermind.Libp2p.Protocols.PubsubPeerDiscovery" />
<PackageReference Include="Google.Protobuf" />
</ItemGroup>

Expand Down
19 changes: 14 additions & 5 deletions src/Nethermind/Nethermind.Shutter/ShutterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Threading;
using System.Threading.Tasks;
using Multiformats.Address;
using Nethermind.Abi;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Find;
Expand All @@ -15,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;
Expand All @@ -41,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;

Expand All @@ -54,6 +59,8 @@ public ShutterApi(
ISpecProvider specProvider,
ITimestamper timestamper,
IWorldStateManager worldStateManager,
IFileSystem fileSystem,
IKeyStoreConfig keyStoreConfig,
IShutterConfig cfg,
Dictionary<ulong, byte[]> validatorsInfo,
TimeSpan slotLength
Expand All @@ -65,6 +72,8 @@ TimeSpan slotLength
_abiEncoder = abiEncoder;
_logManager = logManager;
_slotLength = slotLength;
_fileSystem = fileSystem;
_keyStoreConfig = keyStoreConfig;
_blockUpToDateCutoff = slotLength;
_blockWaitCutoff = _slotLength / 3;

Expand Down Expand Up @@ -92,11 +101,11 @@ TimeSpan slotLength

KeyValidator = new ShutterKeyValidator(_cfg, Eon, logManager);

InitP2P(_cfg, logManager);
InitP2P();
}

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)
{
Expand Down Expand Up @@ -138,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()
Expand Down
Loading