Skip to content

Commit

Permalink
Merge branch 'main' into importer
Browse files Browse the repository at this point in the history
  • Loading branch information
Scooletz committed Oct 28, 2024
2 parents dd3394f + b08fd0e commit 3a51ea0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/Paprika.Importer/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Paprika Importer

Use the following steps to import from Nethermind’s DB

- Switch to the `importer` branch
- `git checkout remotes/origin/importer`
- Fetch the submodules
- `git submodule update --init --recursive`
- Build Paprika.Importer
- `dotnet build .\\src\\Paprika.Importer\\Paprika.Importer.sln`
- Run
- `cd .\\src\\Paprika.Importer`
- `dotnet run -- path_to_nethermind_db_mainnet`
24 changes: 15 additions & 9 deletions src/Paprika/Chain/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ private async Task FlusherTask()
// Commit, but flush only if there's nothing more to apply.
// If there are more blocks, leave it to the external _db.Flush() called outside of this loop.
await batch.Commit(noMoreBlocksToApply
? CommitOptions.FlushDataOnly
: CommitOptions.DangerNoFlush);
? CommitOptions.FlushDataOnly
: CommitOptions.DangerNoFlush);

// inform blocks about flushing
lock (_blockLock)
Expand Down Expand Up @@ -500,7 +500,7 @@ private class BlockState : RefCountingDisposable, IWorldState, ICommit, IProvide

private readonly ReadOnlyBatchCountingRefs _batch;
private readonly CommittedBlockState[] _ancestors;
private readonly BitFilter _ancestorsFilter;
private readonly BitFilter? _ancestorsFilter;

private readonly Blockchain _blockchain;

Expand Down Expand Up @@ -1141,7 +1141,7 @@ private ReadOnlySpanOwnerWithMetadata<byte> TryGetAncestors(scoped in Key key,
{
var destroyedHash = CommittedBlockState.GetDestroyedHash(key);

if (_ancestorsFilter.MayContainAny(keyHash, destroyedHash))
if (_ancestorsFilter.HasValue && _ancestorsFilter.GetValueOrDefault().MayContainAny(keyHash, destroyedHash))
{
ushort depth = 1;

Expand Down Expand Up @@ -1258,7 +1258,7 @@ protected override void CleanUp()
_xorMissed.Dispose();
_prefetcher?.Dispose();
_filter.Return(Pool);
_ancestorsFilter.Return(Pool);
_ancestorsFilter?.Return(Pool);

// release all the ancestors
foreach (var ancestor in _ancestors)
Expand Down Expand Up @@ -1482,7 +1482,8 @@ public ReadOnlyState(Keccak stateRoot, ReadOnlyBatchCountingRefs batch, Committe
Hash = stateRoot;
}

public ReadOnlyState(Keccak stateRoot, ReadOnlyBatchCountingRefs batch, CommittedBlockState[] ancestors, BitFilter ancestorsFilter, BufferPool pool)
public ReadOnlyState(Keccak stateRoot, ReadOnlyBatchCountingRefs batch, CommittedBlockState[] ancestors,
BitFilter? ancestorsFilter, BufferPool pool)
{
_batch = batch;
_ancestors = ancestors;
Expand Down Expand Up @@ -1547,7 +1548,8 @@ private ReadOnlySpanOwnerWithMetadata<byte> TryGet(scoped in Key key, scoped Rea
{
var destroyedHash = CommittedBlockState.GetDestroyedHash(key);

if (_ancestorsFilter == null || _ancestorsFilter.GetValueOrDefault().MayContainAny(keyHash, destroyedHash))
if (_ancestorsFilter == null ||
_ancestorsFilter.GetValueOrDefault().MayContainAny(keyHash, destroyedHash))
{
ushort depth = 1;

Expand Down Expand Up @@ -1730,6 +1732,7 @@ private void DeleteByPrefixes(IBatch batch)
prefixes = Key.ReadFrom(prefixes, out var prefixToDelete);
batch.DeleteByPrefix(prefixToDelete);
}

_prefixesToDelete.ResetWrittenCount();
}

Expand Down Expand Up @@ -1953,8 +1956,11 @@ public void Dispose()
/// </summary>
/// <param name="ancestors"></param>
/// <returns></returns>
private BitFilter CreateAncestorsFilter(CommittedBlockState[] ancestors)
private BitFilter? CreateAncestorsFilter(CommittedBlockState[] ancestors)
{
if (ancestors.Length == 0)
return null;

var filter = CreateBitFilter();
foreach (var ancestor in ancestors)
{
Expand Down Expand Up @@ -1988,4 +1994,4 @@ private static void ApplyImpl(IBatch batch, PooledSpanDictionary dict, Blockchai
blockchain._pool.Return(page);
}
}
}
}

0 comments on commit 3a51ea0

Please sign in to comment.