From 39ca2a63a99d24a7b29a97e4e305fb51188baaaf Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Tue, 12 Aug 2025 17:45:07 +0530 Subject: [PATCH 01/12] incomplete --- execution_chain/db/aristo/aristo_compute.nim | 81 ++++++++++++-------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 9e0cacb30c..186370e763 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -89,11 +89,32 @@ proc putKeyAtLevel( ok() -template encodeLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped): HashKey = +template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = w.startList(2) w.append(pfx.toHexPrefix(isLeaf = true).data()) + w.wrapEncoding(1) w.append(leafData) - w.finish().digestTo(HashKey) + +template encodeLeaf(pfx: NibblesBuf, leafData: untyped): HashKey = + debugEcho "calling encode Leaf" + debugEcho pfx + debugEcho leafData + var tracker = DynamicRlpLengthTracker() + tracker.initLengthTracker() + tracker.appendLeaf(pfx, leafData) + + if tracker.totalLength < 32: + var writer = initTwoPassWriter(tracker) + writer.appendLeaf(pfx, leafData) + let buf = HashKey.fromBytes(writer.finish) + debugEcho(buf) + buf.value + else: + var writer = initHashWriter(tracker) + writer.appendLeaf(pfx, leafData) + let buf = writer.finish() + debugEcho(buf) + buf.to(HashKey) template encodeBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped): HashKey = w.startList(17) @@ -146,37 +167,36 @@ proc computeKeyImpl( # Top-most level of all the verticies this hash computation depends on var level = level - # TODO this is the same code as when serializing NodeRef, without the NodeRef var writer = initRlpWriter() let key = case vtx.vType of AccLeaf: - let vtx = AccLeafRef(vtx) - writer.encodeLeaf(vtx.pfx): - let - stoID = vtx.stoID - skey = - if stoID.isValid: - let - keyvtxl = ?db.getKey((stoID.vid, stoID.vid), skipLayers) - (skey, sl) = - if keyvtxl[0][0].isValid: - (keyvtxl[0][0], keyvtxl[1]) - else: - ?db.computeKeyImpl( - (stoID.vid, stoID.vid), - batch, - keyvtxl[0][1], - keyvtxl[1], - skipLayers = skipLayers, - ) - level = max(level, sl) - skey - else: - VOID_HASH_KEY - - rlp.encode Account( + let + vtx = AccLeafRef(vtx) + stoID = vtx.stoID + skey = + if stoID.isValid: + let + keyvtxl = ?db.getKey((stoID.vid, stoID.vid), skipLayers) + (skey, sl) = + if keyvtxl[0][0].isValid: + (keyvtxl[0][0], keyvtxl[1]) + else: + ?db.computeKeyImpl( + (stoID.vid, stoID.vid), + batch, + keyvtxl[0][1], + keyvtxl[1], + skipLayers = skipLayers, + ) + level = max(level, sl) + skey + else: + VOID_HASH_KEY + + encodeLeaf(vtx.pfx): + Account( nonce: vtx.account.nonce, balance: vtx.account.balance, storageRoot: skey.to(Hash32), @@ -184,9 +204,8 @@ proc computeKeyImpl( ) of StoLeaf: let vtx = StoLeafRef(vtx) - writer.encodeLeaf(vtx.pfx): - # TODO avoid memory allocation when encoding storage data - rlp.encode(vtx.stoData) + encodeLeaf(vtx.pfx): + vtx.stoData of Branches: # For branches, we need to load the vertices before recursing into them # to exploit their on-disk order From 222e0cfce0ed1d34990ed8be0c217457043c4208 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Tue, 12 Aug 2025 17:49:48 +0530 Subject: [PATCH 02/12] commented code --- execution_chain/db/aristo/aristo_compute.nim | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 186370e763..370c72f6d2 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -129,6 +129,49 @@ template encodeExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey): HashK w.append(branchKey) w.finish().digestTo(HashKey) +# template appendBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped) = +# w.startList(17) +# for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): +# w.append(subKeyForN) +# w.append EmptyBlob +# +# template encodeBranch(vtx: VertexRef, subKeyForN: untyped): HashKey = +# var tracker: DynamicRlpLengthTracker +# tracker.initLengthTracker() +# tracker.appendBranch(vtx, subKeyForN) +# +# if tracker.totalLength < 32: +# var writer = initTwoPassWriter(tracker) +# writer.appendBranch(vtx, subKeyForN) +# let buf = HashKey.fromBytes(writer.finish) +# buf.value +# else: +# var writer = initHashWriter(tracker) +# writer.appendBranch(vtx, subKeyForN) +# let buf = writer.finish() +# buf.to(HashKey) +# +# template appendExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey) = +# w.startList(2) +# w.append(pfx.toHexPrefix(isLeaf = false).data()) +# w.append(branchKey) +# +# template encodeExt(pfx: NibblesBuf, branchKey: untyped): HashKey = +# var tracker: DynamicRlpLengthTracker +# tracker.initLengthTracker() +# tracker.appendExt(pfx, branchKey) +# +# if tracker.totalLength < 32: +# var writer = initTwoPassWriter(tracker) +# writer.appendExt(pfx, branchKey) +# let buf = HashKey.fromBytes(writer.finish) +# buf.value +# else: +# var writer = initHashWriter(tracker) +# writer.appendExt(pfx, branchKey) +# let buf = writer.finish() +# buf.to(HashKey) + proc getKey( db: AristoTxRef, rvid: RootedVertexID, skipLayers: static bool ): Result[((HashKey, VertexRef), int), AristoError] = From cf256e58af707d5aedc065b2bb29026cf6b73a96 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Wed, 20 Aug 2025 19:55:51 +0530 Subject: [PATCH 03/12] use similar structure to ordered trie --- execution_chain/db/aristo/aristo_compute.nim | 138 +++++++++---------- 1 file changed, 68 insertions(+), 70 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 370c72f6d2..e48ed16f3b 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -13,12 +13,19 @@ import std/strformat, chronicles, + eth/rlp, eth/common/[accounts_rlp, base_rlp, hashes_rlp], results, "."/[aristo_desc, aristo_get, aristo_layers], ./aristo_desc/desc_backend -type WriteBatch = tuple[writer: PutHdlRef, count: int, depth: int, prefix: uint64] +type + WriteBatch = tuple[writer: PutHdlRef, count: int, depth: int, prefix: uint64] + + AristoTrieWriter = object + tracker: DynamicRlpLengthTracker + twoPassWriter: RlpTwoPassWriter + hashWriter: RlpHashWriter # Keep write batch size _around_ 1mb, give or take some overhead - this is a # tradeoff between efficiency and memory usage with diminishing returns the @@ -89,88 +96,79 @@ proc putKeyAtLevel( ok() +func init(T: type AristoTrieWriter): T = + result.tracker = DynamicRlpLengthTracker() + result.tracker.initLengthTracker() + result.twoPassWriter = initTwoPassWriter(result.tracker) + result.hashWriter = initHashWriter(result.tracker) + +func clear(self: var AristoTrieWriter) = + self.tracker.clear() + self.twoPassWriter.clear() + self.hashWriter.clear() + template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = w.startList(2) w.append(pfx.toHexPrefix(isLeaf = true).data()) w.wrapEncoding(1) w.append(leafData) + discard rlp.encode(leafData) + +template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey = + w.clear() + w.tracker.appendLeaf(pfx, leafData) -template encodeLeaf(pfx: NibblesBuf, leafData: untyped): HashKey = - debugEcho "calling encode Leaf" - debugEcho pfx - debugEcho leafData - var tracker = DynamicRlpLengthTracker() - tracker.initLengthTracker() - tracker.appendLeaf(pfx, leafData) - - if tracker.totalLength < 32: - var writer = initTwoPassWriter(tracker) - writer.appendLeaf(pfx, leafData) - let buf = HashKey.fromBytes(writer.finish) - debugEcho(buf) + if w.tracker.totalLength < 32: + w.twoPassWriter.reInit(w.tracker) + w.twoPassWriter.appendLeaf(pfx, leafData) + let buf = HashKey.fromBytes(w.twoPassWriter.finish) buf.value else: - var writer = initHashWriter(tracker) - writer.appendLeaf(pfx, leafData) - let buf = writer.finish() - debugEcho(buf) + w.hashWriter.reInit(w.tracker) + w.hashWriter.appendLeaf(pfx, leafData) + let buf = w.hashWriter.finish() buf.to(HashKey) -template encodeBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped): HashKey = +template appendBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped) = w.startList(17) for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): w.append(subKeyForN) w.append EmptyBlob - w.finish().digestTo(HashKey) -template encodeExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey): HashKey = +template encodeBranch(w: var AristoTrieWriter, rvtx: VertexRef, subKeyForN: untyped): HashKey = + w.clear() + w.tracker.appendBranch(vtx, subKeyForN) + + if w.tracker.totalLength < 32: + w.twoPassWriter.reInit(w.tracker) + w.twoPassWriter.appendBranch(vtx, subKeyForN) + let buf = HashKey.fromBytes(w.twoPassWriter.finish) + buf.value + else: + w.hashWriter.reInit(w.tracker) + w.hashWriter.appendBranch(vtx, subKeyForN) + let buf = w.hashWriter.finish() + buf.to(HashKey) + +template appendExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey) = w.startList(2) w.append(pfx.toHexPrefix(isLeaf = false).data()) w.append(branchKey) - w.finish().digestTo(HashKey) - -# template appendBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped) = -# w.startList(17) -# for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): -# w.append(subKeyForN) -# w.append EmptyBlob -# -# template encodeBranch(vtx: VertexRef, subKeyForN: untyped): HashKey = -# var tracker: DynamicRlpLengthTracker -# tracker.initLengthTracker() -# tracker.appendBranch(vtx, subKeyForN) -# -# if tracker.totalLength < 32: -# var writer = initTwoPassWriter(tracker) -# writer.appendBranch(vtx, subKeyForN) -# let buf = HashKey.fromBytes(writer.finish) -# buf.value -# else: -# var writer = initHashWriter(tracker) -# writer.appendBranch(vtx, subKeyForN) -# let buf = writer.finish() -# buf.to(HashKey) -# -# template appendExt(w: var RlpWriter, pfx: NibblesBuf, branchKey: HashKey) = -# w.startList(2) -# w.append(pfx.toHexPrefix(isLeaf = false).data()) -# w.append(branchKey) -# -# template encodeExt(pfx: NibblesBuf, branchKey: untyped): HashKey = -# var tracker: DynamicRlpLengthTracker -# tracker.initLengthTracker() -# tracker.appendExt(pfx, branchKey) -# -# if tracker.totalLength < 32: -# var writer = initTwoPassWriter(tracker) -# writer.appendExt(pfx, branchKey) -# let buf = HashKey.fromBytes(writer.finish) -# buf.value -# else: -# var writer = initHashWriter(tracker) -# writer.appendExt(pfx, branchKey) -# let buf = writer.finish() -# buf.to(HashKey) + +template encodeExt(w: var AristoTrieWriter, pfx: NibblesBuf, branchKey: untyped): HashKey = + w.clear() + w.tracker.appendExt(pfx, branchKey) + + if w.tracker.totalLength < 32: + w.twoPassWriter.reInit(w.tracker) + w.twoPassWriter.appendExt(pfx, branchKey) + let buf = HashKey.fromBytes(w.twoPassWriter.finish) + buf.value + else: + w.hashWriter.reInit(w.tracker) + w.hashWriter.appendExt(pfx, branchKey) + let buf = w.hashWriter.finish() + buf.to(HashKey) proc getKey( db: AristoTxRef, rvid: RootedVertexID, skipLayers: static bool @@ -210,7 +208,7 @@ proc computeKeyImpl( # Top-most level of all the verticies this hash computation depends on var level = level - var writer = initRlpWriter() + var writer = AristoTrieWriter.init() let key = case vtx.vType @@ -238,7 +236,7 @@ proc computeKeyImpl( else: VOID_HASH_KEY - encodeLeaf(vtx.pfx): + writer.encodeLeaf(vtx.pfx): Account( nonce: vtx.account.nonce, balance: vtx.account.balance, @@ -247,7 +245,7 @@ proc computeKeyImpl( ) of StoLeaf: let vtx = StoLeafRef(vtx) - encodeLeaf(vtx.pfx): + writer.encodeLeaf(vtx.pfx): vtx.stoData of Branches: # For branches, we need to load the vertices before recursing into them @@ -307,7 +305,7 @@ proc computeKeyImpl( ) batch.leave(n) - template writeBranch(w: var RlpWriter, vtx: BranchRef): HashKey = + template writeBranch(w: var AristoTrieWriter, vtx: BranchRef): HashKey = w.encodeBranch(vtx): if subvid.isValid: level = max(level, keyvtxs[n][1]) @@ -318,7 +316,7 @@ proc computeKeyImpl( if vtx.vType == ExtBranch: let vtx = ExtBranchRef(vtx) writer.encodeExt(vtx.pfx): - var bwriter = initRlpWriter() + var bwriter = AristoTrieWriter.init() bwriter.writeBranch(vtx) else: writer.writeBranch(vtx) From 2e5d058bfc57fca4b46b25b4a68189c13391422e Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Wed, 20 Aug 2025 20:04:46 +0530 Subject: [PATCH 04/12] comment --- execution_chain/db/aristo/aristo_compute.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index e48ed16f3b..c3e64e2eca 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -14,7 +14,7 @@ import std/strformat, chronicles, eth/rlp, - eth/common/[accounts_rlp, base_rlp, hashes_rlp], + eth/common, results, "."/[aristo_desc, aristo_get, aristo_layers], ./aristo_desc/desc_backend @@ -112,7 +112,6 @@ template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = w.append(pfx.toHexPrefix(isLeaf = true).data()) w.wrapEncoding(1) w.append(leafData) - discard rlp.encode(leafData) template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey = w.clear() From a99e9ba13ed7b7a6c1c9bc5f1c1c51e7bb1cade2 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Wed, 20 Aug 2025 20:12:48 +0530 Subject: [PATCH 05/12] reintroduce the line --- execution_chain/db/aristo/aristo_compute.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index c3e64e2eca..f4b87c3e87 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -113,6 +113,9 @@ template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = w.wrapEncoding(1) w.append(leafData) + # magical line + discard rlp.encode(leafData) + template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey = w.clear() w.tracker.appendLeaf(pfx, leafData) From 8dcbbc0f8f185d8c0c47649003f54779d31ea42f Mon Sep 17 00:00:00 2001 From: bhartnett Date: Tue, 9 Sep 2025 11:46:01 +0800 Subject: [PATCH 06/12] Remove hack. --- execution_chain/db/aristo/aristo_compute.nim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index f4b87c3e87..151ef550f7 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -19,7 +19,7 @@ import "."/[aristo_desc, aristo_get, aristo_layers], ./aristo_desc/desc_backend -type +type WriteBatch = tuple[writer: PutHdlRef, count: int, depth: int, prefix: uint64] AristoTrieWriter = object @@ -113,9 +113,6 @@ template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = w.wrapEncoding(1) w.append(leafData) - # magical line - discard rlp.encode(leafData) - template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey = w.clear() w.tracker.appendLeaf(pfx, leafData) From d9f29dd4a67d4e2ba8e0fa0acdc9b83fbb1985e1 Mon Sep 17 00:00:00 2001 From: bhartnett Date: Tue, 9 Sep 2025 12:45:10 +0800 Subject: [PATCH 07/12] Remove unneeded usages of untyped. Update encodeExt to a func to prevent computing branchKey multiple times within a single call. --- execution_chain/db/aristo/aristo_compute.nim | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 151ef550f7..75b79fad94 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -107,13 +107,13 @@ func clear(self: var AristoTrieWriter) = self.twoPassWriter.clear() self.hashWriter.clear() -template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) = +template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: auto) = w.startList(2) w.append(pfx.toHexPrefix(isLeaf = true).data()) w.wrapEncoding(1) w.append(leafData) -template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey = +template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: auto): HashKey = w.clear() w.tracker.appendLeaf(pfx, leafData) @@ -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 = w.clear() w.tracker.appendExt(pfx, branchKey) @@ -205,9 +205,9 @@ proc computeKeyImpl( # empty state # Top-most level of all the verticies this hash computation depends on - var level = level - - var writer = AristoTrieWriter.init() + var + level = level + writer = AristoTrieWriter.init() let key = case vtx.vType @@ -235,17 +235,17 @@ proc computeKeyImpl( else: VOID_HASH_KEY - writer.encodeLeaf(vtx.pfx): + writer.encodeLeaf(vtx.pfx, Account( nonce: vtx.account.nonce, balance: vtx.account.balance, storageRoot: skey.to(Hash32), codeHash: vtx.account.codeHash, ) + ) of StoLeaf: let vtx = StoLeafRef(vtx) - writer.encodeLeaf(vtx.pfx): - vtx.stoData + writer.encodeLeaf(vtx.pfx, vtx.stoData) of Branches: # For branches, we need to load the vertices before recursing into them # to exploit their on-disk order @@ -314,9 +314,8 @@ proc computeKeyImpl( if vtx.vType == ExtBranch: let vtx = ExtBranchRef(vtx) - writer.encodeExt(vtx.pfx): - var bwriter = AristoTrieWriter.init() - bwriter.writeBranch(vtx) + var bwriter = AristoTrieWriter.init() + writer.encodeExt(vtx.pfx, bwriter.writeBranch(vtx)) else: writer.writeBranch(vtx) From 820f2b0f5604e0f3a252f3052f107c36e3671d34 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Tue, 9 Sep 2025 18:50:58 +0530 Subject: [PATCH 08/12] review --- execution_chain/db/aristo/aristo_compute.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 75b79fad94..1d059e1eb4 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -97,10 +97,14 @@ proc putKeyAtLevel( ok() func init(T: type AristoTrieWriter): T = - result.tracker = DynamicRlpLengthTracker() - result.tracker.initLengthTracker() - result.twoPassWriter = initTwoPassWriter(result.tracker) - result.hashWriter = initHashWriter(result.tracker) + var trk = DynamicRlpLengthTracker() + trk.initLengthTracker() + + AristoTrieWriter( + tracker: trk, + twoPassWriter: initTwoPassWriter(trk), + hashWriter: initHashWriter(trk) + ) func clear(self: var AristoTrieWriter) = self.tracker.clear() From 4856014e0a4be6496d71f496e25819291dd66b75 Mon Sep 17 00:00:00 2001 From: bhartnett Date: Fri, 12 Sep 2025 21:43:44 +0800 Subject: [PATCH 09/12] Remove usages of auto in encodeLeaf. --- execution_chain/db/aristo/aristo_compute.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index 1d059e1eb4..f3eb338f16 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -111,13 +111,13 @@ func clear(self: var AristoTrieWriter) = self.twoPassWriter.clear() self.hashWriter.clear() -template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: auto) = +template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: Account | UInt256) = w.startList(2) w.append(pfx.toHexPrefix(isLeaf = true).data()) w.wrapEncoding(1) w.append(leafData) -template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: auto): HashKey = +template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account | UInt256): HashKey = w.clear() w.tracker.appendLeaf(pfx, leafData) From 8581f94fb6eb333a7e2dcba857710513e67a1a30 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Fri, 12 Sep 2025 19:29:06 +0530 Subject: [PATCH 10/12] fix imports --- execution_chain/db/aristo/aristo_compute.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index f3eb338f16..afeb2e9ba2 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -14,7 +14,7 @@ import std/strformat, chronicles, eth/rlp, - eth/common, + eth/common/[accounts_rlp, base_rlp, hashes_rlp], results, "."/[aristo_desc, aristo_get, aristo_layers], ./aristo_desc/desc_backend From 248018c63b7abfe365d1410b948d7f648188dc86 Mon Sep 17 00:00:00 2001 From: bhartnett Date: Sat, 13 Sep 2025 21:05:55 +0800 Subject: [PATCH 11/12] Make encodeLeaf a func and store hashKeys in encodeBranch. --- execution_chain/db/aristo/aristo_compute.nim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index afeb2e9ba2..d3aef94a23 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -117,7 +117,7 @@ template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: Account | UInt2 w.wrapEncoding(1) w.append(leafData) -template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account | UInt256): HashKey = +func encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account | UInt256): HashKey = w.clear() w.tracker.appendLeaf(pfx, leafData) @@ -132,24 +132,28 @@ template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account let buf = w.hashWriter.finish() buf.to(HashKey) -template appendBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped) = +template appendBranch(w: var RlpWriter, vtx: VertexRef, hashKeys: array[16, HashKey]) = w.startList(17) - for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): - w.append(subKeyForN) + for key in hashKeys: + w.append(key) w.append EmptyBlob template encodeBranch(w: var AristoTrieWriter, rvtx: VertexRef, subKeyForN: untyped): HashKey = + var hashKeys: array[16, HashKey] + for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): + hashKeys[n] = subKeyForN + w.clear() - w.tracker.appendBranch(vtx, subKeyForN) + w.tracker.appendBranch(vtx, hashKeys) if w.tracker.totalLength < 32: w.twoPassWriter.reInit(w.tracker) - w.twoPassWriter.appendBranch(vtx, subKeyForN) + w.twoPassWriter.appendBranch(vtx, hashKeys) let buf = HashKey.fromBytes(w.twoPassWriter.finish) buf.value else: w.hashWriter.reInit(w.tracker) - w.hashWriter.appendBranch(vtx, subKeyForN) + w.hashWriter.appendBranch(vtx, hashKeys) let buf = w.hashWriter.finish() buf.to(HashKey) From e5f1785e9e6ff6c8abea0564453a35df5e45510f Mon Sep 17 00:00:00 2001 From: Ben Hartnett <51288821+bhartnett@users.noreply.github.com> Date: Sun, 14 Sep 2025 19:47:09 +0800 Subject: [PATCH 12/12] Update execution_chain/db/aristo/aristo_compute.nim Co-authored-by: Jacek Sieka --- execution_chain/db/aristo/aristo_compute.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/db/aristo/aristo_compute.nim b/execution_chain/db/aristo/aristo_compute.nim index d3aef94a23..260352150f 100644 --- a/execution_chain/db/aristo/aristo_compute.nim +++ b/execution_chain/db/aristo/aristo_compute.nim @@ -139,7 +139,7 @@ template appendBranch(w: var RlpWriter, vtx: VertexRef, hashKeys: array[16, Hash w.append EmptyBlob template encodeBranch(w: var AristoTrieWriter, rvtx: VertexRef, subKeyForN: untyped): HashKey = - var hashKeys: array[16, HashKey] + var hashKeys {.noinit.}: array[16, HashKey] for (n {.inject.}, subvid {.inject.}) in vtx.allPairs(): hashKeys[n] = subKeyForN