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

Feature/Era1 import/export #6547

Open
wants to merge 248 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 239 commits
Commits
Show all changes
248 commits
Select commit Hold shift + click to select a range
301180c
ERA history import/export start
ak88 Sep 26, 2023
5a0b8c4
Rename in unit test
ak88 Oct 9, 2023
04209fb
Fix block index not set
ak88 Oct 9, 2023
4b10a61
Start export
ak88 Oct 10, 2023
bfcbfb5
Era builder
ak88 Oct 13, 2023
e9d91b6
Accumulator calculation
ak88 Oct 17, 2023
7b88e17
ERA history import/export
ak88 Sep 26, 2023
1543a39
Rename in unit test
ak88 Oct 9, 2023
e07cca5
Fix block index not set
ak88 Oct 9, 2023
42131e6
Start export
ak88 Oct 10, 2023
551d974
Era builder
ak88 Oct 13, 2023
aba6cfb
Accumulator calculation
ak88 Oct 17, 2023
65a9225
Builder finalize
ak88 Oct 18, 2023
d0741e5
Merge branch 'feature/era-history' of https://github.com/ak88/netherm…
ak88 Oct 18, 2023
508f1ae
Unit tests
ak88 Oct 23, 2023
c7636c2
Unit tests
ak88 Oct 24, 2023
ee53da7
import geth files
ak88 Nov 1, 2023
8503f08
Reader with netty
ak88 Nov 2, 2023
66eacd1
1mb read buffer
ak88 Nov 2, 2023
8d48264
refactor test and use of netty
ak88 Nov 3, 2023
904ecab
Big blocks test
ak88 Nov 4, 2023
74d14ad
Change to IByteBuffer
ak88 Nov 4, 2023
e1e86ae
buffer allocater injected
ak88 Nov 4, 2023
d8f4ad8
Merge branch 'NettyBuffers' into feature/era-history
ak88 Nov 4, 2023
539423b
module
ak88 Nov 5, 2023
c27adf6
Squashed commit of the following:
ak88 Nov 5, 2023
27fc5cd
Merge from master
ak88 Nov 5, 2023
756b170
assert files exist
ak88 Nov 5, 2023
e3a6647
reverted
ak88 Nov 6, 2023
f18e742
rollback gitbook
ak88 Nov 6, 2023
7066e64
Merge branch 'master' into feature/era-history
ak88 Nov 6, 2023
d2656d8
revert gitbook
ak88 Nov 6, 2023
5d43047
revert launchsettings
ak88 Nov 6, 2023
6a25125
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 6, 2023
dedba82
Delete from this pr
ak88 Nov 6, 2023
764512c
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 6, 2023
49b0920
Rlp db separate header and body
ak88 Nov 6, 2023
f2f03db
format whitespace
ak88 Nov 6, 2023
58f8a06
small fix
ak88 Nov 7, 2023
7148a8f
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 7, 2023
f089911
accumulator test
ak88 Nov 7, 2023
e097de6
start cli era
ak88 Nov 7, 2023
5c9f698
Squashed commit of the following:
ak88 Nov 9, 2023
ce691f0
ReceiptMessageDecoder cleanup
ak88 Nov 9, 2023
b3356ae
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 9, 2023
407c4eb
era service start
ak88 Nov 9, 2023
c618d97
Squashed commit of the following:
ak88 Nov 10, 2023
c3e6df8
no seeking to index
ak88 Nov 10, 2023
c0640ed
reuse compression streams
ak88 Nov 10, 2023
85dfb85
format
ak88 Nov 10, 2023
6330162
Performance optimization
ak88 Nov 10, 2023
d1b58ab
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 10, 2023
3fed302
avoid a copy and dispose on ex
ak88 Nov 11, 2023
ac304c3
export in admin module
ak88 Nov 13, 2023
132322a
Export and exit token
ak88 Nov 22, 2023
6226bad
Checksums and import start
ak88 Nov 28, 2023
e6270dd
build fix
ak88 Nov 28, 2023
b49d0ad
Merge branch 'master' into feature/era-cli
ak88 Nov 28, 2023
1900b69
Merge branch 'feature/era-history' of https://github.com/ak88/netherm…
ak88 Nov 28, 2023
169a821
Merge branch 'feature/era-history' into feature/era-cli
ak88 Nov 28, 2023
23e4904
pass chain name
ak88 Nov 28, 2023
f737e30
Merge branch 'master' into feature/era-cli
ak88 Dec 8, 2023
67e954e
import with archive node
ak88 Dec 11, 2023
a1dec67
merged master
ak88 Dec 18, 2023
6b19d32
era import in init network
ak88 Dec 18, 2023
3029604
import pivot
ak88 Dec 19, 2023
fa9cbd0
Squashed commit of the following:
ak88 Dec 29, 2023
f931861
guard index length
ak88 Dec 29, 2023
08ea0b8
rename
ak88 Jan 3, 2024
20a92ef
removed import
ak88 Jan 5, 2024
6989eb7
Merge branch 'feature/era-cli' of https://github.com/nethermindeth/ne…
ak88 Jan 8, 2024
1324ccc
reset cfg and launchsettings
ak88 Jan 8, 2024
7e59edd
Squashed commit of the following:
ak88 Jan 8, 2024
835e83b
Squashed commit of the following:
ak88 Jan 8, 2024
362c805
import from genesis
ak88 Jan 9, 2024
a2205ef
do not reuse compressor
ak88 Jan 10, 2024
eca49ef
do not reuse compressor
ak88 Jan 10, 2024
b06fddc
Merge branch 'master' into feature/era-cli
ak88 Jan 10, 2024
5e08c9c
build fix
ak88 Jan 10, 2024
9b42260
build fix
ak88 Jan 10, 2024
90d57a0
removed checksumming
ak88 Jan 10, 2024
3464926
refactor export
ak88 Jan 11, 2024
fecd8a3
eraexporter unittests
ak88 Jan 11, 2024
4ae0c08
EraAdminService
ak88 Jan 14, 2024
bcfcf4f
Merge branch 'feature/era-cli' into feature/era-import
ak88 Jan 14, 2024
b806a23
missing files
ak88 Jan 14, 2024
1e9a490
era import test
ak88 Jan 15, 2024
5706897
update snappier
ak88 Jan 15, 2024
4668b49
include epoch in progress
ak88 Jan 16, 2024
8a78aad
revert LoadGenesisBlock
ak88 Jan 16, 2024
1c5c16d
remove ancient dir
ak88 Jan 16, 2024
76b6149
Merge branch 'master' into feature/era-import
ak88 Jan 16, 2024
7ec3697
Update src/Nethermind/Nethermind.Era.Test/Nethermind.Era1.Test.csproj
ak88 Jan 16, 2024
7d2079d
Update src/Nethermind/Nethermind.Era.Test/Nethermind.Era1.Test.csproj
ak88 Jan 16, 2024
1521c3f
Update src/Nethermind/Nethermind.Era1/Nethermind.Era1.csproj
ak88 Jan 16, 2024
15b7fa5
Update src/Nethermind/Nethermind.Era.Test/Nethermind.Era1.Test.csproj
ak88 Jan 16, 2024
2965f71
Update src/Nethermind/Nethermind.Era1/E2Store.cs
ak88 Jan 16, 2024
1f8bcc3
Update src/Nethermind/Directory.Packages.props
ak88 Jan 16, 2024
ac2a68c
Update src/Nethermind/Directory.Packages.props
ak88 Jan 16, 2024
4382d07
build fix
ak88 Jan 16, 2024
37fc0f7
format whitespace
ak88 Jan 16, 2024
7c714a4
fix unittest
ak88 Jan 16, 2024
858061b
revert deployment scripts
ak88 Jan 16, 2024
81a93d1
Merge branch 'master' into feature/era-import
ak88 Jul 9, 2024
5d98dbe
fixes
ak88 Jul 9, 2024
40c554a
Merge branch 'master' into feature/era-import
ak88 Jul 19, 2024
edeb3af
refactor continued
ak88 Jul 31, 2024
9f1e7aa
refactor
ak88 Aug 2, 2024
e75d8d1
Merge branch 'master' into feature/era-import
ak88 Aug 2, 2024
9453950
fix
ak88 Aug 2, 2024
3de43a3
refactor conti.
ak88 Aug 6, 2024
5d66d34
barrier on header sync
ak88 Aug 10, 2024
4d7529b
Test fix
ak88 Aug 13, 2024
879a968
revert launch
ak88 Aug 13, 2024
d487bca
format
ak88 Aug 13, 2024
edb03fd
rpc docs
ak88 Aug 13, 2024
043daa8
roll back header barriers
ak88 Oct 1, 2024
f9c523d
format whitespace
ak88 Oct 1, 2024
a271354
fix era test
ak88 Oct 1, 2024
0d8eea4
Merge branch 'master' into fix/era-branch
ak88 Oct 1, 2024
5d65d39
fix build
ak88 Oct 1, 2024
e6220d4
test fixes
ak88 Oct 1, 2024
5c32db9
Dont specify potision direcctly
asdacap Oct 9, 2024
a47c884
Move metadata out
asdacap Oct 9, 2024
2f987b2
Use entry
asdacap Oct 9, 2024
5d6dbf3
Smaller interface
asdacap Oct 9, 2024
fc358e1
More cutting things off
asdacap Oct 9, 2024
50eb83b
Minor cleanup
asdacap Oct 9, 2024
e1f19a3
Fix index
asdacap Oct 9, 2024
61b6d22
Fix more tests
asdacap Oct 9, 2024
4cf444c
Fix some tests broke some tests.
asdacap Oct 9, 2024
e934d34
Use BinaryPrimitives
asdacap Oct 9, 2024
b97e6bb
Add different test case
asdacap Oct 9, 2024
f0eaf5e
Deduplicate code
asdacap Oct 9, 2024
6a06d76
Use valuehash directly
asdacap Oct 9, 2024
b264253
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Oct 10, 2024
1f44275
Fix build
asdacap Oct 10, 2024
27ed9be
Reducing changes
asdacap Oct 10, 2024
96e862b
Reducing changes
asdacap Oct 10, 2024
da987e2
Reducing change
asdacap Oct 10, 2024
2c38b45
Remove cortex
asdacap Oct 11, 2024
b823ec6
Fix span index
asdacap Oct 11, 2024
81977d0
Remove unnecessary change
asdacap Oct 11, 2024
b9e309c
Fix build
asdacap Oct 11, 2024
3928574
Add mainnet test
asdacap Oct 15, 2024
2b1a2f4
Log directly
asdacap Oct 15, 2024
9b2a3a5
Log progress directly
asdacap Oct 15, 2024
33b0079
Remove more unnecessary code
asdacap Oct 15, 2024
8bc7b8f
Move to its own step
asdacap Oct 16, 2024
cf06f45
Remove StreamSegment
asdacap Oct 16, 2024
7b9076d
Use same block body decoder as eth
asdacap Oct 16, 2024
621d176
Consolidate block body logic
asdacap Oct 16, 2024
4d28304
Whitespace
asdacap Oct 16, 2024
854c372
Fix test
asdacap Oct 16, 2024
ec7d908
Merge branch 'refactor/consolidate-block-body-logic' into feature/era…
asdacap Oct 18, 2024
b1e6eeb
Using memory mapped file now
asdacap Oct 19, 2024
17e5fd0
Remove EraMetadata
asdacap Oct 19, 2024
841dedf
Rename classes
asdacap Oct 19, 2024
884c4b7
Minor test cleanup
asdacap Oct 21, 2024
f35d1bb
Simplify era writer
asdacap Oct 21, 2024
86ad9d1
No need to add total difficulty inside
asdacap Oct 21, 2024
8b0addf
No need to have separate total difficulty
asdacap Oct 21, 2024
0156b88
Simplify tsets
asdacap Oct 21, 2024
f7e756d
Read and verify in one method
asdacap Oct 21, 2024
bf82a66
Slight cleanup
asdacap Oct 21, 2024
e70aaaf
Minor cleanup
asdacap Oct 21, 2024
2f6a8d4
Mode files to era package
asdacap Oct 21, 2024
20695e0
Move more code into era package
asdacap Oct 21, 2024
da6081f
Minor cli remove
asdacap Oct 21, 2024
933f068
Create a dedicated cconfig for era
asdacap Oct 21, 2024
d29eb72
Reduce missed change
asdacap Oct 21, 2024
db95f85
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Oct 21, 2024
7f2870a
Minor cleanup
asdacap Oct 21, 2024
16dda05
Whitespace
asdacap Oct 21, 2024
79adc94
Export via cli
asdacap Oct 23, 2024
f28e315
Parallel exporter
asdacap Oct 23, 2024
c3139e5
Disable receipt recovery
asdacap Oct 23, 2024
2a946dd
Fix accumulator missing
asdacap Oct 23, 2024
4e13cac
Suggest
asdacap Oct 24, 2024
6fe233c
Blocktree suggest pacer
asdacap Oct 24, 2024
ba0272d
Dispose properly
asdacap Oct 24, 2024
2a789df
Merge branch 'feature/blocking-blocktree-suggester' into feature/era-…
asdacap Oct 24, 2024
9976f5a
Fix premature dispose
asdacap Oct 24, 2024
51261e0
Add pacer
asdacap Oct 24, 2024
2beda2c
Simplify interface
asdacap Oct 24, 2024
eb08363
Verify as part of import
asdacap Oct 24, 2024
8cdd97f
Reduce test slightly
asdacap Oct 24, 2024
2f9142a
Not sure if this helps
asdacap Oct 24, 2024
54c72be
No need to recalculate header hash
asdacap Oct 24, 2024
d3bc0b4
Probably not needed
asdacap Oct 24, 2024
aacfd59
Slight change to log
asdacap Oct 24, 2024
dbfb04f
No need to verify here
asdacap Oct 24, 2024
413f33a
Parallelize verification
asdacap Oct 24, 2024
e39c688
Combine the two import
asdacap Oct 24, 2024
8d08603
Enable heavy write when importing
asdacap Oct 24, 2024
d7918c7
Parallelize
asdacap Oct 25, 2024
bddd941
Fix export
asdacap Oct 25, 2024
fb87aab
Fix log
asdacap Oct 25, 2024
ec85308
Do not redownload unneded block
asdacap Oct 26, 2024
a9f509e
Separate block store and badd block store
asdacap Oct 26, 2024
0b1c573
Separate block store and bad block store
asdacap Oct 26, 2024
4d11ef5
Fix test
asdacap Oct 26, 2024
b67f9f1
MMeerge branch 'refactor/separate-block-store' into feature/dont-down…
asdacap Oct 26, 2024
f2ba192
Dont' redownload existing blocks
asdacap Oct 28, 2024
e648304
Fix build
asdacap Oct 28, 2024
c80ea79
Merge branch 'refactor/separate-block-store' into feature/dont-downlo…
asdacap Oct 28, 2024
7c54f94
Bodies sync feed unit test
asdacap Oct 28, 2024
f0c862f
Maybe add it to IBlockFinder
asdacap Oct 28, 2024
39f8da4
Unit tests
asdacap Oct 28, 2024
43ab1ff
Disalbe optimize filter for hits
asdacap Oct 28, 2024
14d5a90
Whitespace
asdacap Oct 28, 2024
93a0224
Merge branch 'feature/dont-download-existing-block' into feature/era-…
asdacap Oct 28, 2024
a84ecdf
Fix conflict
asdacap Oct 28, 2024
5bf4b93
Fastsync test
asdacap Oct 29, 2024
0924c52
Clean admin, change encoding again
asdacap Oct 29, 2024
5832483
Match geth epoch behaviour
asdacap Oct 29, 2024
c3c5802
Era store factory
asdacap Oct 29, 2024
5bb8cde
Network name from config
asdacap Oct 29, 2024
617d0ff
Add comments
asdacap Oct 29, 2024
fddcc6d
Checksum support
asdacap Oct 29, 2024
203159a
Cli runner test
asdacap Oct 29, 2024
36b39d8
Minor comment
asdacap Oct 29, 2024
df8a91b
Move admin era service to era directory
asdacap Oct 29, 2024
d66eb61
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Oct 29, 2024
f89e644
Whitespace
asdacap Oct 29, 2024
67e2a8c
Fix test
asdacap Oct 29, 2024
31b469f
Add option to not recover sender
asdacap Oct 29, 2024
a654d9a
Merge branch 'feature/allow-skipping-sender-recovery' into feature/er…
asdacap Oct 29, 2024
4d5944e
Fix tests, disable sender ccalculatioon
asdacap Oct 29, 2024
7028b52
Add option to specify write flags
asdacap Oct 29, 2024
3833ff5
Merge branch 'feature/allow-skipping-sender-recovery' into feature/er…
asdacap Oct 29, 2024
d417ac0
More robust validation
asdacap Oct 29, 2024
4df3719
Whitespace
asdacap Oct 30, 2024
097fd7a
Add tests for admin era service
asdacap Oct 30, 2024
d9e5f0e
More consistent name
asdacap Oct 30, 2024
69fbf66
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Nov 1, 2024
1683e87
Whitespace
asdacap Nov 1, 2024
a6a4fb9
Cleanup
asdacap Nov 1, 2024
a8e8154
Fix misleading cli
asdacap Nov 1, 2024
2476a51
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Nov 9, 2024
240f5c8
Update src/Nethermind/Nethermind.Era1/E2StoreWriter.cs
asdacap Nov 9, 2024
4f0021e
Update src/Nethermind/Nethermind.Era1/E2StoreWriter.cs
asdacap Nov 9, 2024
08cf69c
Update src/Nethermind/Nethermind.Era1/AccumulatorCalculator.cs
asdacap Nov 9, 2024
f6aca3d
Fix build
asdacap Nov 17, 2024
3fa9295
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Nov 17, 2024
d9afb87
Use RandomAccessFile
asdacap Nov 17, 2024
338f969
Fix test
asdacap Nov 18, 2024
f58a4c5
Missed log
asdacap Nov 18, 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
1 change: 1 addition & 0 deletions src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageVersion Include="Ckzg.Bindings" Version="1.0.2.855" />
<PackageVersion Include="Colorful.Console" Version="1.2.15" />
<PackageVersion Include="CommunityToolkit.HighPerformance" Version="8.3.2" />
<PackageVersion Include="ConcurrentHashSet" Version="1.3.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Crc32.NET" Version="1.2.0" />
Expand Down
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Api/IBasicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Nethermind.Core.Timers;
using Nethermind.Crypto;
using Nethermind.Db;
using Nethermind.Era1;
using Nethermind.KeyStore;
using Nethermind.Logging;
using Nethermind.Serialization.Json;
Expand Down Expand Up @@ -63,7 +64,8 @@ public ContainerBuilder ConfigureContainerBuilderFromBasicApi(ContainerBuilder b
{
builder
.AddPropertiesFrom<IBasicApi>(this)
.AddSingleton(ConfigProvider.GetConfig<ISyncConfig>());
.AddSingleton(ConfigProvider.GetConfig<ISyncConfig>())
.AddSingleton(ConfigProvider.GetConfig<IEraConfig>());

DbProvider!.ConfigureServiceCollection(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BlockTreeSuggestPacer : IDisposable
private readonly long _resumeBatchSize;
private readonly IBlockTree _blockTree;

public BlockTreeSuggestPacer(IBlockTree blockTree, long stopBatchSize, long resumeBatchSize)
public BlockTreeSuggestPacer(IBlockTree blockTree, long stopBatchSize = 4096, long resumeBatchSize = 2048)
{
blockTree.NewHeadBlock += BlockTreeOnNewHeadBlock;
_blockTree = blockTree;
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Linq;
using Nethermind.Blockchain;
using Nethermind.Core.ConsensusRequests;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
Expand Down Expand Up @@ -193,6 +194,7 @@ public BlockBuilder WithUncles(params BlockHeader[] uncles)
{
TestObjectInternal = TestObjectInternal.WithReplacedBody(
TestObjectInternal.Body.WithChangedUncles(uncles));
TestObjectInternal.Header.UnclesHash = UnclesHash.Calculate(uncles);
return this;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,12 @@ public static byte[] GenerateIndexedAccountRlp(int index, AccountDecoder? accoun
byte[] value = accountDecoder.Encode(account).Bytes;
return value;
}

public static UInt256 GetRandomAmount(Random? random = null)
{
Span<byte> buffer = stackalloc byte[32];
(random ?? Random).NextBytes(buffer);
return new UInt256(buffer);
}
}
}
14 changes: 9 additions & 5 deletions src/Nethermind/Nethermind.Core/ContainerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static ContainerBuilder AddPropertiesFrom<T>(this ContainerBuilder config
object? val = propertyInfo.GetValue(source);
if (val != null)
{
configuration.RegisterInstance(val).As(propertyInfo.PropertyType);
configuration.RegisterInstance(val)
.As(propertyInfo.PropertyType)
.ExternallyOwned();
}
}

Expand All @@ -55,7 +57,8 @@ public static ContainerBuilder AddSingleton<T>(this ContainerBuilder builder, T
{
builder.RegisterInstance(instance)
.As<T>()
.SingleInstance();
.SingleInstance()
.ExternallyOwned();

return builder;
}
Expand All @@ -71,11 +74,12 @@ public static ContainerBuilder AddSingleton<T, TImpl>(this ContainerBuilder buil
return builder;
}

public static ContainerBuilder AddKeyedSingleton<T>(this ContainerBuilder builder, string key, T instance) where T : class
public static ContainerBuilder AddKeyedSingleton<T>(this ContainerBuilder builder, object key, T instance) where T : class
{
builder.RegisterInstance(instance)
.Named<T>(key)
.SingleInstance();
.Keyed<T>(key)
.SingleInstance()
.ExternallyOwned();

return builder;
}
Expand Down
46 changes: 46 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/AccumulatorCalculatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using System.Threading.Tasks;
using Nethermind.Core.Crypto;

namespace Nethermind.Era1.Test;
public class AccumulatorCalculatorTests
{
[Test]
public void Add_AddOneHashAndUInt256_DoesNotThrow()
{
using var sut = new AccumulatorCalculator();

Assert.That(() => sut.Add(Keccak.Zero, 0), Throws.Nothing);
}
[Test]
public void ComputeRoot_AddValues_ReturnsExpectedResult()
{
using var sut = new AccumulatorCalculator();
sut.Add(Keccak.Zero, 1);
sut.Add(Keccak.MaxValue, 2);

var result = sut.ComputeRoot().ToByteArray();

Assert.That(result, Is.EquivalentTo(new[] { 0x3E, 0xD6, 0x26, 0x52, 0xDF, 0xB7, 0xE1, 0x07, 0x2D, 0x0F, 0x04, 0x0F, 0xEB, 0x6D, 0x00, 0x2A, 0x9F, 0x7C, 0xE3, 0x7C, 0xF8, 0xDD, 0xB1, 0x65, 0x49, 0xA7, 0xAC, 0x5C, 0xF8, 0xE3, 0xB7, 0x91 }));
}

[Test]
public void ComputeRoot_AddOneHashAndUInt256_DoesNotThrow()
{
using var sut = new AccumulatorCalculator();
sut.Add(Keccak.Zero, 1);
sut.Add(Keccak.MaxValue, 2);

var result = sut.ComputeRoot().ToByteArray();

Assert.That(result, Is.EquivalentTo(new[] { 0x3E, 0xD6, 0x26, 0x52, 0xDF, 0xB7, 0xE1, 0x07, 0x2D, 0x0F, 0x04, 0x0F, 0xEB, 0x6D, 0x00, 0x2A, 0x9F, 0x7C, 0xE3, 0x7C, 0xF8, 0xDD, 0xB1, 0x65, 0x49, 0xA7, 0xAC, 0x5C, 0xF8, 0xE3, 0xB7, 0x91 }));
}
}
83 changes: 83 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/AdminEraServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Config;
using Nethermind.Logging;
using NSubstitute;

namespace Nethermind.Era1.Test;

public class AdminEraServiceTests
{
[Test]
public void CanCallcExport()
{
IEraImporter importer = Substitute.For<IEraImporter>();
AdminEraService adminEraService = new AdminEraService(
importer,
Substitute.For<IEraExporter>(),
Substitute.For<IProcessExitSource>(),
LimboLogs.Instance);

adminEraService.ImportHistory("somewhere", 99, 999, null);
importer.Received().Import("somewhere", 99, 999, null);
}

[Test]
public void ThrowsWhenExistingImportIsRunning()
{
IEraImporter importer = Substitute.For<IEraImporter>();
TaskCompletionSource importTcs = new TaskCompletionSource();
importer.Import("somewhere", 99, 999, null).Returns(importTcs.Task);
AdminEraService adminEraService = new AdminEraService(
importer,
Substitute.For<IEraExporter>(),
Substitute.For<IProcessExitSource>(),
LimboLogs.Instance);

adminEraService.ImportHistory("somewhere", 99, 999, null);

Assert.That(() => adminEraService.ImportHistory("somewhere", 99, 999, null), Throws.Exception);

importTcs.TrySetResult();

// Not throw
adminEraService.ImportHistory("somewhere", 99, 999, null);
}

[Test]
public void CanCallExport()
{
IEraExporter exporter = Substitute.For<IEraExporter>();
AdminEraService adminEraService = new AdminEraService(
Substitute.For<IEraImporter>(),
exporter,
Substitute.For<IProcessExitSource>(),
LimboLogs.Instance);

adminEraService.ExportHistory("somewhere", 99, 999);
exporter.Received().Export("somewhere", 99, 999);
}

[Test]
public void ThrowsWhenExistingExportIsRunning()
{
IEraExporter exporter = Substitute.For<IEraExporter>();
TaskCompletionSource importTcs = new TaskCompletionSource();
exporter.Export("somewhere", 99, 999).Returns(importTcs.Task);
AdminEraService adminEraService = new AdminEraService(
Substitute.For<IEraImporter>(),
exporter,
Substitute.For<IProcessExitSource>(),
LimboLogs.Instance);

adminEraService.ExportHistory("somewhere", 99, 999);

Assert.That(() => adminEraService.ExportHistory("somewhere", 99, 999), Throws.Exception);

importTcs.TrySetResult();

// Not throw
adminEraService.ExportHistory("somewhere", 99, 999);
}
}
142 changes: 142 additions & 0 deletions src/Nethermind/Nethermind.Era.Test/E2StoreWriterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Buffers.Binary;
using System.IO.MemoryMappedFiles;
using DotNetty.Buffers;
using FluentAssertions;
using Nethermind.Core.Extensions;
using Nethermind.Serialization.Rlp;
using Snappier;

namespace Nethermind.Era1.Test;
internal class E2StoreWriterTests
{
byte[] TestBytes = new byte[] { 0x0f, 0xf0, 0xff, 0xff };

[TestCase(EntryTypes.Version)]
[TestCase(EntryTypes.CompressedHeader)]
[TestCase(EntryTypes.CompressedBody)]
[TestCase(EntryTypes.CompressedReceipts)]
[TestCase(EntryTypes.Accumulator)]
[TestCase(EntryTypes.BlockIndex)]
public async Task WriteEntry_WritingAnEntry_WritesCorrectHeaderType(ushort type)
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

await sut.WriteEntry(type, Array.Empty<byte>());

Assert.That(BinaryPrimitives.ReadInt16LittleEndian(stream.ToArray()), Is.EqualTo(type));
}

[TestCase(6)]
[TestCase(20)]
[TestCase(32)]
public async Task WriteEntry_WritingAnEntry_WritesCorrectLengthInHeader(int length)
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

await sut.WriteEntry(EntryTypes.CompressedHeader, new byte[length]);

Assert.That(BinaryPrimitives.ReadInt32LittleEndian(stream.ToArray().Slice(2)), Is.EqualTo(length));
}

[TestCase(1)]
[TestCase(5)]
[TestCase(12)]
public async Task WriteEntry_WritingAnEntry_ReturnCorrectNumberofBytesWritten(int length)
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

int result = await sut.WriteEntry(EntryTypes.CompressedHeader, new byte[length]);

Assert.That(result, Is.EqualTo(length + E2StoreWriter.HeaderSize));
}


[Test]
public async Task WriteEntry_WritingAnEntry_ZeroesAtCorrectIndexesInHeader()
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

await sut.WriteEntry(EntryTypes.CompressedHeader, TestBytes);
byte[] bytes = stream.ToArray();

Assert.That(bytes[6], Is.EqualTo(0));
Assert.That(bytes[7], Is.EqualTo(0));
}

[Test]
public async Task WriteEntry_WritingEntryValue_BytesAreWrittenToStream()
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

await sut.WriteEntry(EntryTypes.CompressedHeader, TestBytes);
byte[] result = stream.ToArray();

Assert.That(new ArraySegment<byte>(result, E2StoreWriter.HeaderSize, TestBytes.Length), Is.EquivalentTo(TestBytes));
}

[Test]
public async Task WriteEntryAsSnappy_WritingEntryValue_WritesEncodedBytesToStream()
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

await sut.WriteEntryAsSnappy(EntryTypes.CompressedHeader, TestBytes);
stream.Position = E2StoreWriter.HeaderSize;
using var snappy = new SnappyStream(stream, System.IO.Compression.CompressionMode.Decompress);
byte[] buffer = new byte[32];

Assert.That(() => snappy.Read(buffer), Throws.Nothing);
}

[Test]
public async Task WriteEntryAsSnappy_WritingEntryValue_ReturnsCompressedSize()
{
using MemoryStream stream = new MemoryStream();
using E2StoreWriter sut = new E2StoreWriter(stream);

int result = await sut.WriteEntryAsSnappy(EntryTypes.CompressedHeader, TestBytes);

Assert.That(result, Is.EqualTo(stream.Length));
}

[Test]
public async Task ReadEntryValue_ReadingValueBytesOfEntry_ReturnsBytesRead()
{
string tmpFile = Path.GetTempFileName();
E2StoreWriter sut = new E2StoreWriter(File.OpenWrite(tmpFile));
await sut.WriteEntry(EntryTypes.Accumulator, TestBytes);
sut.Dispose();

using E2StoreReader reader = new E2StoreReader(tmpFile);
(var readBytes, _) = reader.ReadEntryAndDecode(0, buf => buf.ReadAllBytesAsArray(), EntryTypes.Accumulator);
Assert.That(readBytes, Is.EquivalentTo(TestBytes));
Assert.That(readBytes.Length, Is.EqualTo(TestBytes.Length));
}

[Test]
public async Task ReadEntryValueAsSnappy_ReadingValueBytesOfEntry_ReturnsDecompressedBytes()
{
string tmpFile = Path.GetTempFileName();
using E2StoreWriter sut = new E2StoreWriter(File.OpenWrite(tmpFile));
MemoryStream compressed = new();
using SnappyStream snappy = new SnappyStream(compressed, System.IO.Compression.CompressionMode.Compress);
snappy.Write(TestBytes);
snappy.Flush();
long position = sut.Position;
await sut.WriteEntry(EntryTypes.CompressedHeader, compressed.ToArray());
sut.Dispose();

using E2StoreReader reader = new E2StoreReader(tmpFile);
(var readBytes, _) = await reader.ReadSnappyCompressedEntryAndDecode(position, buf => buf.ReadAllBytesAsArray(), EntryTypes.CompressedHeader, default);
Assert.That(readBytes, Is.EquivalentTo(TestBytes));
}
}
Loading
Loading