Skip to content

Commit 3dc24fa

Browse files
committed
Remove unneeded usages of untyped. Update encodeExt to a func to prevent computing branchKey multiple times within a single call.
1 parent 13bc9b7 commit 3dc24fa

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

execution_chain/db/aristo/aristo_compute.nim

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ func clear(self: var AristoTrieWriter) =
107107
self.twoPassWriter.clear()
108108
self.hashWriter.clear()
109109

110-
template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: untyped) =
110+
template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: auto) =
111111
w.startList(2)
112112
w.append(pfx.toHexPrefix(isLeaf = true).data())
113113
w.wrapEncoding(1)
114114
w.append(leafData)
115115

116-
template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: untyped): HashKey =
116+
template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: auto): HashKey =
117117
w.clear()
118118
w.tracker.appendLeaf(pfx, leafData)
119119

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

157-
template encodeExt(w: var AristoTrieWriter, pfx: NibblesBuf, branchKey: untyped): HashKey =
157+
func encodeExt(w: var AristoTrieWriter, pfx: NibblesBuf, branchKey: HashKey): HashKey =
158158
w.clear()
159159
w.tracker.appendExt(pfx, branchKey)
160160

@@ -205,9 +205,9 @@ proc computeKeyImpl(
205205
# empty state
206206

207207
# Top-most level of all the verticies this hash computation depends on
208-
var level = level
209-
210-
var writer = AristoTrieWriter.init()
208+
var
209+
level = level
210+
writer = AristoTrieWriter.init()
211211

212212
let key =
213213
case vtx.vType
@@ -235,17 +235,17 @@ proc computeKeyImpl(
235235
else:
236236
VOID_HASH_KEY
237237

238-
writer.encodeLeaf(vtx.pfx):
238+
writer.encodeLeaf(vtx.pfx,
239239
Account(
240240
nonce: vtx.account.nonce,
241241
balance: vtx.account.balance,
242242
storageRoot: skey.to(Hash32),
243243
codeHash: vtx.account.codeHash,
244244
)
245+
)
245246
of StoLeaf:
246247
let vtx = StoLeafRef(vtx)
247-
writer.encodeLeaf(vtx.pfx):
248-
vtx.stoData
248+
writer.encodeLeaf(vtx.pfx, vtx.stoData)
249249
of Branches:
250250
# For branches, we need to load the vertices before recursing into them
251251
# to exploit their on-disk order
@@ -314,9 +314,8 @@ proc computeKeyImpl(
314314

315315
if vtx.vType == ExtBranch:
316316
let vtx = ExtBranchRef(vtx)
317-
writer.encodeExt(vtx.pfx):
318-
var bwriter = AristoTrieWriter.init()
319-
bwriter.writeBranch(vtx)
317+
var bwriter = AristoTrieWriter.init()
318+
writer.encodeExt(vtx.pfx, bwriter.writeBranch(vtx))
320319
else:
321320
writer.writeBranch(vtx)
322321

0 commit comments

Comments
 (0)