Skip to content

Conversation

chirag-parmar
Copy link
Contributor

@chirag-parmar chirag-parmar commented Aug 20, 2025

closed duplicate: #3226
fixes: #3164

Uses the rlp hash writer for Aristo DB's computeKey implementation

@chirag-parmar chirag-parmar mentioned this pull request Aug 20, 2025
@chirag-parmar chirag-parmar changed the title Hash writer aristo nimbusel: use hash writer for aristo computeKey Aug 20, 2025
@bhartnett bhartnett changed the title nimbusel: use hash writer for aristo computeKey Use hash writer for aristo computeKey Sep 9, 2025
@bhartnett bhartnett marked this pull request as ready for review September 9, 2025 05:23
@bhartnett bhartnett changed the title Use hash writer for aristo computeKey Use hash writer for aristo computeKey Sep 9, 2025
w.startList(2)
w.append(pfx.toHexPrefix(isLeaf = true).data())
w.wrapEncoding(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this call to wrapEnconding depend on leafData being of a particular type? if yes, why use auto?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about wrapEncoding but the reason I changed this line was that we are passing a type account or slot and don't need to pass in a block of statements. Perhaps it would be better to make it even more strict and use Account | UInt256 as the type.


template encodeBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped): HashKey =
template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: auto): HashKey =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple evaluations of leafData - auto or untyped doesn't really matter in this context, they behave the same

Copy link
Contributor

@bhartnett bhartnett Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this change wasn't related to reducing the evaluations. I just wanted to remove the untyped parameter.

@@ -154,7 +154,7 @@ template appendExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey) =
w.append(pfx.toHexPrefix(isLeaf = false).data())
w.append(branchKey)

template encodeExt(w: var AristoTrieWriter, pfx: NibblesBuf, branchKey: untyped): HashKey =
func encodeExt(w: var AristoTrieWriter, pfx: NibblesBuf, branchKey: HashKey): HashKey =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the one which reduces the evaluations of branchKey from 2 per call to 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same thing applies to subKeyForN and leafData - they need to either be stored in a variable or encodeBranch/encodeLeaf need to be made func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use optimised rlp hash writer in aristo_compute
3 participants