Skip to content

Commit

Permalink
StorageTree added
Browse files Browse the repository at this point in the history
  • Loading branch information
Scooletz committed Aug 16, 2024
1 parent 24a595b commit 5b87d45
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Nethermind/Nethermind.State/StorageTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Logging;
Expand Down Expand Up @@ -46,12 +48,15 @@ public StorageTree(IScopedTrieStore? trieStore, Hash256 rootHash, ILogManager? l
TrieType = TrieType.Storage;
}

private static void ComputeKey(in UInt256 index, ref Span<byte> key)
private static void ComputeKey(in UInt256 index, in Span<byte> key)
{
index.ToBigEndian(key);

// in situ calculation
KeccakHash.ComputeHashBytesToSpan(key, key);
ValueHash256 keyHash = KeccakCache.Compute(key);

// Assign to update the argument
Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(key))
= Unsafe.As<ValueHash256, Vector256<byte>>(ref keyHash);
}

[SkipLocalsInit]
Expand All @@ -63,7 +68,7 @@ public byte[] Get(in UInt256 index, Hash256? storageRoot = null)
}

Span<byte> key = stackalloc byte[32];
ComputeKey(index, ref key);
ComputeKey(index, key);
return GetArray(key, storageRoot);
}

Expand Down

0 comments on commit 5b87d45

Please sign in to comment.