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 790f86d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 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 Expand Up @@ -92,7 +97,7 @@ public void Set(in UInt256 index, byte[] value)
else
{
Span<byte> key = stackalloc byte[32];
ComputeKey(index, ref key);
ComputeKey(index, in key);
SetInternal(key, value);
}
}
Expand Down

0 comments on commit 790f86d

Please sign in to comment.