Skip to content

Commit

Permalink
Shutter: P2P improvements (#7545)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
  • Loading branch information
Marchhill and LukaszRozmej authored Oct 28, 2024
1 parent 3138f0a commit bc95db2
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 79 deletions.
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
9 changes: 3 additions & 6 deletions src/Nethermind/Nethermind.Runner/configs/chiado.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@
"ForceSealing": true
},
"Shutter": {
"ValidatorRegistryContractAddress": "0xa9289A3Dd14FEBe10611119bE81E5d35eAaC3084",
"SequencerContractAddress": "0x2aD8E2feB0ED5b2EC8e700edB725f120576994ed",
"ValidatorRegistryContractAddress": "0xa9289A3Dd14FEBe10611119bE81E5d35eAaC3084",
"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
11 changes: 11 additions & 0 deletions src/Nethermind/Nethermind.Runner/configs/gnosis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
"TargetBlockGasLimit": 17000000,
"GasToken": "XDAI"
},
"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"
},
Expand Down
10 changes: 8 additions & 2 deletions src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Nethermind.Abi;
using Nethermind.Blockchain;
Expand All @@ -14,6 +16,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 +35,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, IPAddress.None)
{
public int EonUpdateCalled = 0;
public int KeysValidated = 0;
Expand Down Expand Up @@ -110,7 +116,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(IPAddress _)
{
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
42 changes: 17 additions & 25 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,15 +12,6 @@ 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";

[ConfigItem(Description = "Whether to enable Shutter.", DefaultValue = "false")]
bool Enabled { get; set; }

Expand All @@ -28,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.",
Expand All @@ -64,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; }
Expand All @@ -80,7 +75,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 +122,13 @@ public void Validate()
throw new ArgumentNullException(nameof(BootnodeP2PAddresses));
}

foreach (string addr in BootnodeP2PAddresses)
try
{
bootnodeP2PAddresses = BootnodeP2PAddresses.Select(addr => Multiaddress.Decode(addr)).ToArray();
}
catch (NotSupportedException e)
{
try
{
Multiaddress.Decode(addr);
}
catch (NotSupportedException)
{
throw new ArgumentException($"Could not decode Shutter keyper p2p address \"{addr}\".");
}
throw new ArgumentException($"Could not decode Shutter bootnode p2p addresses.", e);
}
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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
27 changes: 18 additions & 9 deletions src/Nethermind/Nethermind.Shutter/ShutterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Multiformats.Address;
using Nethermind.Abi;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Find;
Expand All @@ -15,6 +18,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 +45,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,9 +60,12 @@ public ShutterApi(
ISpecProvider specProvider,
ITimestamper timestamper,
IWorldStateManager worldStateManager,
IFileSystem fileSystem,
IKeyStoreConfig keyStoreConfig,
IShutterConfig cfg,
Dictionary<ulong, byte[]> validatorsInfo,
TimeSpan slotLength
TimeSpan slotLength,
IPAddress ip
)
{
_cfg = cfg;
Expand All @@ -65,6 +74,8 @@ TimeSpan slotLength
_abiEncoder = abiEncoder;
_logManager = logManager;
_slotLength = slotLength;
_fileSystem = fileSystem;
_keyStoreConfig = keyStoreConfig;
_blockUpToDateCutoff = slotLength;
_blockWaitCutoff = _slotLength / 3;

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

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

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

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,16 +149,14 @@ 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(IPAddress ip)
{
P2P = new ShutterP2P(cfg, logManager);
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);
}
Loading

0 comments on commit bc95db2

Please sign in to comment.