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

Exp/libp2p #3996

Draft
wants to merge 28 commits into
base: 5.3-maintenance
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7ae48cf
Added dotnet-libp2p as submodule
greymistcube Oct 29, 2024
c36b208
Patched dotnet-libp2p
greymistcube Oct 29, 2024
c92a752
Removed Exception serialization
greymistcube Oct 29, 2024
142d5a7
Build fix
greymistcube Oct 29, 2024
06f348e
Remove BinaryFormatter serialization
greymistcube Oct 29, 2024
e135e36
Added CryptoKeyConverter helper class
greymistcube Oct 30, 2024
567da63
Initial implementation of Libp2pPeer
greymistcube Nov 1, 2024
90ed73b
Refactored BoundPeer
greymistcube Nov 4, 2024
52f6e40
Changed IProtocol to IPeerDiscoveryProtocol to avoid name collision
greymistcube Nov 7, 2024
99c9b97
Changed IMessageCodec to make it more symmetrical
greymistcube Nov 11, 2024
eb4021f
Changed Message encoding to be flat
greymistcube Nov 12, 2024
c181443
Cleanup
greymistcube Nov 12, 2024
d516159
Fixed flaky tests
greymistcube Nov 12, 2024
0c1882d
AsyncDelegate updated
greymistcube Nov 18, 2024
7f549c4
Transport updated
greymistcube Nov 18, 2024
cb5704c
Updated Kademlia
greymistcube Nov 18, 2024
7218fd0
Updated Swarm
greymistcube Nov 18, 2024
d90acf6
Updated Gossip
greymistcube Nov 18, 2024
dafaf03
Updated TestTransport
greymistcube Nov 18, 2024
cdf3cb7
Initial implementation
greymistcube Nov 18, 2024
bab045e
Cleanup
greymistcube Nov 18, 2024
04a6d36
Added tests for Libp2pTransport
greymistcube Nov 21, 2024
3f82877
Fixed transport; more cleanup
greymistcube Nov 21, 2024
0f51c43
Patched dotnet-libp2p
greymistcube Nov 21, 2024
273487c
Validate message
greymistcube Nov 21, 2024
158ac72
Fixed CryptoKeyConverter
greymistcube Nov 22, 2024
bff5f7f
Cleanup
greymistcube Nov 22, 2024
58a4a6b
Added tests
greymistcube Nov 22, 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: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dotnet-libp2p"]
path = dotnet-libp2p
url = https://github.com/greymistcube/dotnet-libp2p
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<TargetFrameworks Condition="'$(_IsPacking)'=='true'">net6.0</TargetFrameworks>
<TargetFramework Condition="'$(_IsPacking)'!='true'">net6.0</TargetFramework>
<TargetFrameworks Condition="'$(_IsPacking)'=='true'">net8.0</TargetFrameworks>
<TargetFramework Condition="'$(_IsPacking)'!='true'">net8.0</TargetFramework>
<LangVersion>10</LangVersion>
<VersionPrefix>5.3.2</VersionPrefix>
<!-- Note: don't be confused by the word "prefix" here. It's merely a
Expand Down
50 changes: 50 additions & 0 deletions Libplanet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B9C00FAF-3
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{88E7FAF4-CEEC-48B6-9114-71CFE3FC0F50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet-libp2p", "dotnet-libp2p", "{D65E4287-0EBF-4A3E-99D0-2D299418FFE4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F79F050E-5A74-4FE3-AF50-EDFD810A86F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libp2p", "libp2p", "{B793DB10-93BF-4FB5-AF31-FB5C8A8C066A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libp2p", "dotnet-libp2p\src\libp2p\Libp2p\Libp2p.csproj", "{19282D40-B700-4B3E-B749-42EAA39BC46B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libp2p.Core", "dotnet-libp2p\src\libp2p\Libp2p.Core\Libp2p.Core.csproj", "{F78A59DF-6A02-407C-BDAE-E852F6562240}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -613,6 +623,42 @@ Global
{46C1A70D-D1DE-4173-A8C0-00F680F026E3}.ReleaseMono|x64.Build.0 = Debug|Any CPU
{46C1A70D-D1DE-4173-A8C0-00F680F026E3}.ReleaseMono|x86.ActiveCfg = Debug|Any CPU
{46C1A70D-D1DE-4173-A8C0-00F680F026E3}.ReleaseMono|x86.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|x64.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|x64.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|x86.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Debug|x86.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|Any CPU.Build.0 = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|x64.ActiveCfg = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|x64.Build.0 = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|x86.ActiveCfg = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.Release|x86.Build.0 = Release|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|Any CPU.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|Any CPU.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|x64.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|x64.Build.0 = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|x86.ActiveCfg = Debug|Any CPU
{19282D40-B700-4B3E-B749-42EAA39BC46B}.ReleaseMono|x86.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|x64.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|x64.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|x86.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Debug|x86.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|Any CPU.Build.0 = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|x64.ActiveCfg = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|x64.Build.0 = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|x86.ActiveCfg = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.Release|x86.Build.0 = Release|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|Any CPU.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|Any CPU.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|x64.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|x64.Build.0 = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|x86.ActiveCfg = Debug|Any CPU
{F78A59DF-6A02-407C-BDAE-E852F6562240}.ReleaseMono|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -648,6 +694,10 @@ Global
{CF31204A-12CF-43C0-9054-B9AF98EC83BD} = {AC908E33-B856-4E23-9F81-B7F7C97A07F9}
{97F29346-636E-4BCA-B33D-6D0DB26A5AA6} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{46C1A70D-D1DE-4173-A8C0-00F680F026E3} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{F79F050E-5A74-4FE3-AF50-EDFD810A86F6} = {D65E4287-0EBF-4A3E-99D0-2D299418FFE4}
{B793DB10-93BF-4FB5-AF31-FB5C8A8C066A} = {F79F050E-5A74-4FE3-AF50-EDFD810A86F6}
{19282D40-B700-4B3E-B749-42EAA39BC46B} = {B793DB10-93BF-4FB5-AF31-FB5C8A8C066A}
{F78A59DF-6A02-407C-BDAE-E852F6562240} = {B793DB10-93BF-4FB5-AF31-FB5C8A8C066A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB552D2A-94E1-4A1C-9F3E-E0097C6158CD}
Expand Down
1 change: 1 addition & 0 deletions dotnet-libp2p
Submodule dotnet-libp2p added at f7f957
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.0",
"version": "8.0.0",
"rollForward": "minor"
}
}
17 changes: 0 additions & 17 deletions src/Libplanet.Action/BlockProtocolVersionNotSupportedException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;
using Libplanet.Types.Blocks;

namespace Libplanet.Action
Expand Down Expand Up @@ -27,26 +26,10 @@ public BlockProtocolVersionNotSupportedException(
BlockProtocolVersion = blockProtocolVersion;
}

private BlockProtocolVersionNotSupportedException(
SerializationInfo info,
StreamingContext context)
: base(info, context)
{
BlockProtocolVersion = (int)info.GetValue(
nameof(BlockProtocolVersion),
typeof(int))!;
}

/// <summary>
/// The <see cref="Block.ProtocolVersion"/> of the <see cref="Block"/> that is
/// not supported by an implementation of <see cref="IActionEvaluator"/>.
/// </summary>
public int BlockProtocolVersion { get; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(BlockProtocolVersion), BlockProtocolVersion, typeof(int));
}
}
}
17 changes: 0 additions & 17 deletions src/Libplanet.Action/State/InsufficientBalanceException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Runtime.Serialization;
using Libplanet.Common.Serialization;
using Libplanet.Crypto;
using Libplanet.Types.Assets;

Expand Down Expand Up @@ -34,13 +32,6 @@ FungibleAssetValue balance
Balance = balance;
}

private InsufficientBalanceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Address = info.GetValue<Address>(nameof(Address));
Balance = info.GetValue<FungibleAssetValue>(nameof(Balance));
}

/// <summary>
/// The owner of the insufficient <see cref="Balance"/>.
/// </summary>
Expand All @@ -50,13 +41,5 @@ private InsufficientBalanceException(SerializationInfo info, StreamingContext co
/// The account's current balance.
/// </summary>
public FungibleAssetValue Balance { get; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);

info.AddValue(nameof(Address), Address);
info.AddValue(nameof(Balance), Balance);
}
}
}
15 changes: 0 additions & 15 deletions src/Libplanet.Action/State/SupplyOverflowException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Runtime.Serialization;
using Libplanet.Common.Serialization;
using Libplanet.Types.Assets;

namespace Libplanet.Action.State
Expand Down Expand Up @@ -28,22 +26,9 @@ FungibleAssetValue amount
Amount = amount;
}

private SupplyOverflowException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Amount = info.GetValue<FungibleAssetValue>(nameof(Amount));
}

/// <summary>
/// The attempted amount to be minted.
/// </summary>
public FungibleAssetValue Amount { get; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);

info.AddValue(nameof(Amount), Amount);
}
}
}
88 changes: 0 additions & 88 deletions src/Libplanet.Action/UnexpectedlyTerminatedActionException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using Bencodex;
using Bencodex.Types;
using Libplanet.Common;
using Libplanet.Common.Serialization;
using Libplanet.Types.Blocks;
using Libplanet.Types.Tx;

Expand Down Expand Up @@ -55,68 +53,6 @@ Exception innerException
Action = action;
}

private UnexpectedlyTerminatedActionException(
SerializationInfo info,
StreamingContext context
)
: base(info, context)
{
if (info.TryGetValue(nameof(PreEvaluationHash), out byte[] blockHash))
{
PreEvaluationHash = new HashDigest<SHA256>(blockHash);
}

if (info.TryGetValue(nameof(BlockIndex), out long blockIndex))
{
BlockIndex = blockIndex;
}

if (info.TryGetValue(nameof(TxId), out byte[] txId))
{
TxId = new TxId(txId);
}

if (info.TryGetValue(nameof(PreviousStateRootHash), out byte[] previousStateRootHash))
{
PreviousStateRootHash = new HashDigest<SHA256>(previousStateRootHash);
}

string actionKey = $"{nameof(Action)}_type";
if (info.TryGetValue(actionKey, out string actionType))
{
string valuesKey = $"{nameof(Action)}_values";
if (!(info.GetValue<byte[]>(valuesKey) is byte[] valuesBytes))
{
throw new SerializationException($"Missing the {valuesKey} field.");
}

if (!(new Codec().Decode(valuesBytes) is Dictionary values))
{
throw new SerializationException(
$"{valuesKey} field must be a Bencodex dictionary."
);
}

Type type = Type.GetType(actionType, true, true)
?? throw new SerializationException($"Failed to find the type: {actionType}.");
if (Activator.CreateInstance(type) is IAction action)
{
Action = action;
Action.LoadPlainValue(values);
}
else
{
throw new SerializationException(
$"Failed to instantiate the action: {actionType}."
);
}
}
else
{
throw new SerializationException($"Missing the {actionKey} field.");
}
}

/// <summary>
/// The <see cref="Block.PreEvaluationHash"/> of the <see cref="Block"/> that
/// <see cref="Action"/> belongs to.
Expand All @@ -143,29 +79,5 @@ StreamingContext context
public IAction Action { get; }

public HashDigest<SHA256>? PreviousStateRootHash { get; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);

info.AddValue(nameof(PreEvaluationHash), PreEvaluationHash.ToByteArray());
info.AddValue(nameof(BlockIndex), BlockIndex);

if (TxId is TxId txId)
{
info.AddValue(nameof(TxId), txId.ToByteArray());
}

if (PreviousStateRootHash is HashDigest<SHA256> previousStateRootHash)
{
info.AddValue(nameof(PreviousStateRootHash), previousStateRootHash.ToByteArray());
}

if (!(Action is null))
{
info.AddValue($"{nameof(Action)}_type", Action.GetType().AssemblyQualifiedName);
info.AddValue($"{nameof(Action)}_values", new Codec().Encode(Action.PlainValue));
}
}
}
}
17 changes: 1 addition & 16 deletions src/Libplanet.Common/HashDigest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#if NETSTANDARD2_0
using System.Runtime.CompilerServices;
#endif
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using Bencodex;
using Bencodex.Types;
using Libplanet.Common.Serialization;

namespace Libplanet.Common
{
Expand All @@ -38,7 +36,7 @@ namespace Libplanet.Common
[TypeConverter(typeof(HashDigestTypeConverter))]
[JsonConverter(typeof(HashDigestJsonConverter))]
[Serializable]
public readonly struct HashDigest<T> : ISerializable, IEquatable<HashDigest<T>>, IBencodable
public readonly struct HashDigest<T> : IEquatable<HashDigest<T>>, IBencodable
where T : HashAlgorithm
{
/// <summary>
Expand Down Expand Up @@ -131,13 +129,6 @@ private HashDigest(Binary binary)
{
}

private HashDigest(
SerializationInfo info,
StreamingContext context)
: this(info.GetValue<byte[]>(nameof(HashDigest<T>)))
{
}

/// <summary>
/// A bare immutable <see cref="byte"/> array of the digest.
/// </summary>
Expand Down Expand Up @@ -316,12 +307,6 @@ public bool Equals(HashDigest<T> other)
[Pure]
public override bool Equals(object? obj) =>
obj is IEquatable<HashDigest<T>> other && other.Equals(this);

/// <inheritdoc cref="ISerializable.GetObjectData(SerializationInfo, StreamingContext)"/>
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(HashDigest<T>), ToByteArray());
}
}

/// <summary>
Expand Down
29 changes: 0 additions & 29 deletions src/Libplanet.Common/Serialization/SerializationInfoExtensions.cs

This file was deleted.

Loading
Loading