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 324 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 239 commits
Commits
Show all changes
324 commits
Select commit Hold shift + click to select a range
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
ccc205b
Addressing comment
asdacap Nov 19, 2024
db6818f
Use arraypool
asdacap Nov 19, 2024
9391acb
Address comoment
asdacap Nov 19, 2024
9027a72
Parallelize checksum
asdacap Nov 19, 2024
95f9489
Whitespace
asdacap Nov 19, 2024
af2be08
Fix receipt issue
asdacap Nov 20, 2024
0062e2f
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Nov 20, 2024
fe71a86
Whitespace
asdacap Nov 20, 2024
b1b1a08
Fix error msg
asdacap Nov 20, 2024
bc2daad
Fix non optional rpc param
asdacap Nov 25, 2024
774d8dd
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Nov 25, 2024
8e487ec
Add back global.json
asdacap Nov 25, 2024
c6d3d0c
Better log
asdacap Nov 25, 2024
e52c0cb
Throw on empty era directory
asdacap Nov 27, 2024
685e927
Fix fast sync after import
asdacap Nov 28, 2024
2945364
Persist lowest inserted header
asdacap Nov 28, 2024
8ed3ee4
Only set lowest inserted header in fast header
asdacap Nov 28, 2024
ea2b491
Fix build
asdacap Nov 28, 2024
e938df4
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Nov 29, 2024
6dfdd44
Fix build
asdacap Nov 29, 2024
7aeebf1
Isolate enque batch
asdacap Nov 29, 2024
a2514c0
Down download persisted blocks
asdacap Nov 29, 2024
724ecfd
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Nov 29, 2024
b192ced
Merge remote-tracking branch 'origin/master' into change/use-persiste…
asdacap Dec 2, 2024
76001c2
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Dec 2, 2024
0ed716e
Fix test
asdacap Dec 3, 2024
2bb720b
Minor cleanup
asdacap Dec 3, 2024
9f8bf78
Minor comment
asdacap Dec 3, 2024
de2d398
Unit test persisted header
asdacap Dec 3, 2024
89e1416
Fix test
asdacap Dec 3, 2024
d3116aa
Fix test
asdacap Dec 3, 2024
8ef72d7
Whitespace
asdacap Dec 3, 2024
24dac75
No need for on lowest inserted headers
asdacap Dec 3, 2024
0a4548f
Reseet bench precombiles
asdacap Dec 3, 2024
dc6e7b4
Fix test
asdacap Dec 3, 2024
8e3c899
Whitespace
asdacap Dec 3, 2024
0b7cbe1
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Dec 3, 2024
42964e9
Merge remote-tracking branch 'origin/master' into change/use-persiste…
asdacap Dec 3, 2024
4545c10
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Dec 3, 2024
e5397b9
Fix empty blocktree edge case
asdacap Dec 3, 2024
6569082
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Dec 5, 2024
7c2efad
Merge branch 'master' into change/use-persisted-pointer-for-fast-header
asdacap Dec 5, 2024
744691b
More log on sync pointers
asdacap Dec 11, 2024
b2f021a
Fix old headers does not finish
asdacap Dec 11, 2024
63def2e
Merge branch 'change/use-persisted-pointer-for-fast-header' into feat…
asdacap Dec 11, 2024
edd99a1
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Dec 13, 2024
7c8d8d7
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Dec 18, 2024
f61c0ee
Move log logic to measured progress
asdacap Dec 18, 2024
590a0dc
Skipped rate
asdacap Dec 18, 2024
9b38d1b
Renamed to progress logger
asdacap Dec 18, 2024
a2018fa
Fix some measurement
asdacap Dec 18, 2024
99aca3f
Fix receipt barrier
asdacap Dec 18, 2024
2b405e2
Fix test
asdacap Dec 18, 2024
8ae228d
Unit test progress logger
asdacap Dec 18, 2024
6aabd04
Merge branch 'feature/skipped-progress' into feature/era-import
asdacap Dec 18, 2024
6d88215
Whitespacet
asdacap Dec 18, 2024
5d1b1aa
Fix alignment
asdacap Dec 18, 2024
be0ecba
Fix test
asdacap Dec 18, 2024
4c76773
How about now?
asdacap Dec 18, 2024
1d3d936
Merge branch 'feature/skipped-progress' into feature/era-import
asdacap Dec 19, 2024
88b00f9
Code cleanup
asdacap Dec 19, 2024
5ab4f19
Use values for report state
asdacap Dec 19, 2024
3e202c7
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Dec 19, 2024
e76d6ec
Reduce change
asdacap Dec 19, 2024
c380949
Reduce change
asdacap Dec 19, 2024
954cf0a
Merge branch 'feature/skipped-progress' into feature/era-import
asdacap Dec 19, 2024
d165f29
Cleanup
asdacap Dec 19, 2024
98ced0b
Fix unbounded memory usage with era imported node
asdacap Dec 20, 2024
b806644
Merge branch 'fix/unbound-loaded-dependencies' into feature/era-import
asdacap Dec 20, 2024
065908f
Fix build
asdacap Dec 20, 2024
3c4c1aa
Fix double insert
asdacap Dec 20, 2024
f9bcbab
Merge remote-tracking branch 'origin/master' into feature/skipped-pro…
asdacap Dec 20, 2024
a4c8a82
Fix conflict
asdacap Dec 20, 2024
436f4f3
Merge branch 'feature/skipped-progress' into feature/era-import
asdacap Dec 20, 2024
7121f3e
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Dec 23, 2024
d6a2e90
Merge remote-tracking branch 'origin/master' into feature/era-import
asdacap Dec 23, 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