Skip to content

Commit

Permalink
Do not enforce Branch size
Browse files Browse the repository at this point in the history
- Keccaks will be optional, so Size wont be known AOT
  • Loading branch information
emlautarom1 committed Jun 21, 2023
1 parent 52eb6db commit 92262ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Paprika.Tests/Merkle/NodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class NodeTests
{
[Test]
[TestCase(typeof(Node.Header), 1)]
[TestCase(typeof(Node.Branch), 35)]
[TestCase(typeof(Node.Branch), 64)]
[TestCase(typeof(Node.Leaf), 64)]
[TestCase(typeof(Node.Extension), 32)]
public void Struct_size(Type type, int expectedSize)
Expand Down Expand Up @@ -101,7 +101,7 @@ public void Branch_read_write(ushort nibbleBitSet, Keccak keccak)
{
var branch = new Node.Branch(nibbleBitSet, keccak);

Span<byte> encoded = stackalloc byte[Node.Branch.Size];
Span<byte> encoded = stackalloc byte[branch.MaxByteLength];
_ = branch.WriteTo(encoded);
_ = Node.Branch.ReadFrom(encoded, out var decoded);

Expand Down Expand Up @@ -214,7 +214,7 @@ public void Node_read_branch()
var keccak = Values.Key0;

var branch = new Node.Branch(nibbleBitSet, keccak);
Span<byte> buffer = stackalloc byte[Node.Branch.Size];
Span<byte> buffer = stackalloc byte[branch.MaxByteLength];
_ = branch.WriteTo(buffer);
_ = Node.ReadFrom(buffer, out var nodeType, out _, out _, out var actual);

Expand Down
8 changes: 1 addition & 7 deletions src/Paprika/Merkle/MerkleNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,13 @@ public override string ToString() =>
$"}}";
}

[StructLayout(LayoutKind.Explicit, Pack = 1, Size = Size)]
public readonly ref struct Branch
{
public const int Size = 35;
public int MaxByteLength => 35;
private const int NibbleBitSetSize = sizeof(ushort);

[FieldOffset(0)]
public readonly Header Header;

[FieldOffset(1)]
public readonly ushort NibbleBitSet;

[FieldOffset(3)]
public readonly Keccak Keccak;

// TODO: What interface do we want to expose for nibbles?
Expand Down

0 comments on commit 92262ac

Please sign in to comment.