Skip to content

Commit

Permalink
Create consensus plugin (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Jan 14, 2021
1 parent 4b11178 commit 2942a29
Show file tree
Hide file tree
Showing 20 changed files with 1,810 additions and 4 deletions.
13 changes: 10 additions & 3 deletions neo-modules.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Expand All @@ -24,9 +24,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Network.RPC.Tests", "te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StateService", "src\StateService\StateService.csproj", "{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StateService", "src\StateService\StateService.csproj", "{A0F4A66F-6F87-4B99-B8BE-A779BC002F47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Plugins.StateService.Tests", "tests\Neo.Plugins.StateService.Tests\Neo.Plugins.StateService.Tests.csproj", "{149822EC-4E0C-425F-A032-4196B615BFEB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.StateService.Tests", "tests\Neo.Plugins.StateService.Tests\Neo.Plugins.StateService.Tests.csproj", "{149822EC-4E0C-425F-A032-4196B615BFEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dBFT", "src\dBFT\dBFT.csproj", "{90185D3E-4813-4BC1-98FE-26FD34311403}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -78,6 +80,10 @@ Global
{149822EC-4E0C-425F-A032-4196B615BFEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{149822EC-4E0C-425F-A032-4196B615BFEB}.Release|Any CPU.Build.0 = Release|Any CPU
{90185D3E-4813-4BC1-98FE-26FD34311403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90185D3E-4813-4BC1-98FE-26FD34311403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90185D3E-4813-4BC1-98FE-26FD34311403}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90185D3E-4813-4BC1-98FE-26FD34311403}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -94,6 +100,7 @@ Global
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{A0F4A66F-6F87-4B99-B8BE-A779BC002F47} = {97E81C78-1637-481F-9485-DA1225E94C23}
{149822EC-4E0C-425F-A032-4196B615BFEB} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{90185D3E-4813-4BC1-98FE-26FD34311403} = {97E81C78-1637-481F-9485-DA1225E94C23}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61D3ADE6-BBFC-402D-AB42-1C71C9F9EDE3}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01148" />
<PackageReference Include="Neo" Version="3.0.0-CI01152" />
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions src/dBFT/ChangeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.IO;

namespace Neo.Consensus
{
public class ChangeView : ConsensusMessage
{
/// <summary>
/// NewViewNumber is always set to the current ViewNumber asking changeview + 1
/// </summary>
public byte NewViewNumber => (byte)(ViewNumber + 1);

/// <summary>
/// Timestamp of when the ChangeView message was created. This allows receiving nodes to ensure
/// they only respond once to a specific ChangeView request (it thus prevents replay of the ChangeView
/// message from repeatedly broadcasting RecoveryMessages).
/// </summary>
public ulong Timestamp;

/// <summary>
/// Reason
/// </summary>
public ChangeViewReason Reason;

public override int Size => base.Size +
sizeof(ulong) + // Timestamp
sizeof(ChangeViewReason); // Reason

public ChangeView() : base(ConsensusMessageType.ChangeView) { }

public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);
Timestamp = reader.ReadUInt64();
Reason = (ChangeViewReason)reader.ReadByte();
}

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
writer.Write(Timestamp);
writer.Write((byte)Reason);
}
}
}
12 changes: 12 additions & 0 deletions src/dBFT/ChangeViewReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Neo.Consensus
{
public enum ChangeViewReason : byte
{
Timeout = 0x0,
ChangeAgreement = 0x1,
TxNotFound = 0x2,
TxRejectedByPolicy = 0x3,
TxInvalid = 0x4,
BlockRejectedByPolicy = 0x5
}
}
26 changes: 26 additions & 0 deletions src/dBFT/Commit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Neo.IO;
using System.IO;

namespace Neo.Consensus
{
public class Commit : ConsensusMessage
{
public byte[] Signature;

public override int Size => base.Size + Signature.Length;

public Commit() : base(ConsensusMessageType.Commit) { }

public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);
Signature = reader.ReadFixedBytes(64);
}

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
writer.Write(Signature);
}
}
}
Loading

0 comments on commit 2942a29

Please sign in to comment.