Skip to content

Commit

Permalink
ERA history import/export start
Browse files Browse the repository at this point in the history
R#eceipt decoder
  • Loading branch information
ak88 committed Oct 9, 2023
1 parent a09b867 commit 301180c
Show file tree
Hide file tree
Showing 28 changed files with 1,395 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageVersion Include="Grpc" Version="2.46.6" />
<PackageVersion Include="Grpc.Tools" Version="2.56.2" />
<PackageVersion Include="HexMate" Version="0.0.3" />
<PackageVersion Include="IronSnappy" Version="1.3.1" />
<PackageVersion Include="Jint" Version="2.11.58" />
<PackageVersion Include="MathNet.Numerics.FSharp" Version="5.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection" Version="7.0.9" />
Expand Down Expand Up @@ -67,6 +68,7 @@
<PackageVersion Include="SCrypt" Version="2.0.0.2" />
<PackageVersion Include="Seq.Api" Version="2023.3.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="Snappier" Version="1.1.1" />
<PackageVersion Include="Snappy.Standard" Version="0.2.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageVersion Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

global using NUnit.Framework;
68 changes: 68 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/Nethermind.Era1.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Snappier" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Nethermind.History.Era1\Nethermind.Era1.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="data\checksums.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00000-096013b1.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00001-440820aa.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00002-f324ec16.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00003-627b9dce.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00004-08ecec94.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00005-e2d2b70f.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00006-286c2ca5.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00007-c9075184.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\mainnet-00008-bfd52f39.era1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\raw">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Era1;
using Nethermind.Serialization.Rlp;
using NUnit.Framework.Constraints;
using Snappier;
namespace Nethermind.Era.Test;

public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public async Task Test1()
{
var ms = new MemoryStream();
var sut = await E2Store.FromStream(ms);

sut.WriteEntry(E2Store.TypeVersion, Array.Empty<byte>());
}

[Test]
public async Task TestHistoryImport()
{
var sut = await EraIterator.Create("data/mainnet-00000-096013b1.era1");

await foreach ((Block b, TxReceipt[] r) in sut)
{
}
}

[Test]
public async Task TestE2Store()
{
var sut = await E2Store.FromStream(File.OpenRead("data/mainnet-00000-096013b1.era1"));

var testData = Convert.FromHexString("FF060000734E6150705900B00000FCED3AFBFB0310F901F8A0007A010088A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934794004A4200F043A09F88BE00EEE1114EDFD9372F52560AAB3980A142EFE8B5B39A09644075084275A056E81F171BCC55A6FF8345E692C0F86E5B48E01B996CADC001622FB5E363B421A0567A210004B9014A7800FE0100FE0100FE0100B601002C83020000808347E7C480808082C90134880000000000000000843B9ACA00");

var compressedHeaders = await sut.FindAll(E2Store.TypeCompressedHeader);

foreach (var cb in compressedHeaders)
{
try
{
void Test()
{
var output = new byte[1000];
var decompressionStream = new SnappyStream(cb.ValueAsStream(), System.IO.Compression.CompressionMode.Decompress);
var x = decompressionStream.Read(output, 0, output.Length);
var s = new Span<byte>(output, 0, x);
var decoded = Rlp.Decode<BlockHeader>(s);

}
Test();

}
catch (InvalidDataException)
{
continue;
}

}
}

}
9 changes: 9 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/data/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0x4c098bf3d1e599a2657ca2856811d885afd2ff3417f073348a0b3ba0989d0a23
0xeb76936ffb61580f077d6c5145575dc1326b1f21aed8ddd04430c9c726ad823f
0x67a1a249dd63ac7fab0292a27c210597cb053afb87d859f70d8470958f50910b
0x2d96d98253775ba8ea505622634a31b44fc7333e564f9c1f40beba44864cb170
0x5f58d700d9374e61283c7f2b463130e11347da23c4682e69972605a2ca637fe0
0x86390cdd139909397b7003aef2ad1863f65cfe2626aeb105ef1cb24e06c37d69
0xe82aec7edfdb310a1259c251af5ae3697194aa30537bd825d97970525a6a4dd0
0x1d20d98da322db6ff5caaa699ffaf1fe5b3ef8e9cd9188d44500633e0814ed9c
0x8fce912ffcdda36a0408cf2bf0777f576624f8b4e1547f2dd59656c0d29dde06
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/Nethermind/Nethermind.Era.Test/data/raw
Binary file not shown.

0 comments on commit 301180c

Please sign in to comment.