Skip to content

Commit

Permalink
mpt: Rework encode_child()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 20, 2023
1 parent e02d62e commit 5087032
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/state/mpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,18 @@ void MPTNode::insert(const Path& path, bytes&& value) // NOLINT(misc-no-recursi
}
}

bytes MPTNode::encode() const // NOLINT(misc-no-recursion)
/// Encodes a node and optionally hashes the encoded bytes
/// if their length exceeds the specified threshold.
static bytes encode_child(const MPTNode& child) noexcept // NOLINT(misc-no-recursion)
{
static constexpr auto encode_child = [](const MPTNode& child) { // NOLINT(misc-no-recursion)
if (auto e = child.encode(); e.size() < 32)
return e; // "short" node
else
return rlp::encode(keccak256(e));
};
if (auto e = child.encode(); e.size() < 32)
return e; // "short" node
else
return rlp::encode(keccak256(e));
}

bytes MPTNode::encode() const // NOLINT(misc-no-recursion)
{
bytes encoded;
switch (m_kind)
{
Expand Down

0 comments on commit 5087032

Please sign in to comment.