Skip to content

Commit

Permalink
Skip decode for value node in CopyStates
Browse files Browse the repository at this point in the history
  • Loading branch information
sky1045 committed Nov 3, 2023
1 parent 278c042 commit e5b8e66
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Libplanet/Store/Trie/MerkleTrie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,18 @@ internal IEnumerable<HashDigest<SHA256>> IterateHashNodes()
break;
}

bool GuessValueNodeByPath(in ImmutableArray<byte> path)
bool GuessValueNode(in ImmutableArray<byte> path, byte[] value)
{
if (path.Length < 2)
{
return false;
}

if (value.Length > 597)
{
return true;
}

bool isStartedWithUnderbar = (path[0] << 4) + path[1] == '_';

bool isStatePath = !isStartedWithUnderbar &&
Expand All @@ -284,29 +289,25 @@ bool GuessValueNodeByPath(in ImmutableArray<byte> path)

// It assumes every length of value nodes is same with Address' hexadecimal
// string's hexadecimal string's size.
bool isValueNode = GuessValueNodeByPath(path);
bool isValueNode = GuessValueNode(path, value);
bool noFingerprint = value.All(x => x != '*');
if (noFingerprint)
{
yield return (key, value);

// To avoid decode value node, it decodes when only there is '*' character,
// fingerprint.
if (isValueNode)
{
continue;
}
}

var node = NodeDecoder.Decode(_codec.Decode(value, LoadIndirectValue));
if (!noFingerprint && !(node is null))
if (isValueNode)
{
yield return (key, _codec.Encode(node.ToBencodex()));
continue;
}

if (isValueNode)
var node = NodeDecoder.Decode(_codec.Decode(value, LoadIndirectValue));
if (!noFingerprint && !(node is null))
{
continue;
yield return (key, _codec.Encode(node.ToBencodex()));
}

switch (node)
Expand Down

0 comments on commit e5b8e66

Please sign in to comment.