Skip to content

Commit

Permalink
fix: ignore HashComp in Container ViewDU
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jun 27, 2024
1 parent febffda commit 003bbc9
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions packages/ssz/src/viewDU/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,17 @@ class ContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> extends
* - if old _rootNode is hashed, then only need to put pending changes to HashComputationGroup
* - if old _rootNode is not hashed, need to traverse and put to HashComputationGroup
*/
commit(hashComps: HashComputationGroup | null = null): void {
commit(): void {
const isOldRootHashed = this._rootNode.h0 !== null;
if (this.nodesChanged.size === 0 && this.viewsChanged.size === 0) {
if (!isOldRootHashed && hashComps !== null) {
getHashComputations(this._rootNode, hashComps.offset, hashComps.byLevel);
}
return;
}

const nodesChanged: {index: number; node: Node}[] = [];

let hashCompsView: HashComputationGroup | null = null;
// if old root is not hashed, no need to pass HashComputationGroup to child view bc we need to do full traversal here
if (hashComps != null && isOldRootHashed) {
// each view may mutate HashComputationGroup at offset + depth
hashCompsView = {byLevel: hashComps.byLevel, offset: hashComps.offset + this.type.depth};
}
for (const [index, view] of this.viewsChanged) {
const fieldType = this.type.fieldsEntries[index].fieldType as unknown as CompositeTypeAny;
const node = fieldType.commitViewDU(view, hashCompsView);
const node = fieldType.commitViewDU(view);
// Set new node in nodes array to ensure data represented in the tree and fast nodes access is equal
this.nodes[index] = node;
nodesChanged.push({index, node});
Expand All @@ -117,13 +108,14 @@ class ContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> extends
this.type.depth,
indexes,
nodes,
isOldRootHashed ? hashComps : null
// isOldRootHashed ? hashComps : null
null,
);

// old root is not hashed, need to traverse and put to HashComputationGroup
if (!isOldRootHashed && hashComps !== null) {
getHashComputations(this._rootNode, hashComps.offset, hashComps.byLevel);
}
// // old root is not hashed, need to traverse and put to HashComputationGroup
// if (!isOldRootHashed && hashComps !== null) {
// getHashComputations(this._rootNode, hashComps.offset, hashComps.byLevel);
// }

this.nodesChanged.clear();
this.viewsChanged.clear();
Expand Down

0 comments on commit 003bbc9

Please sign in to comment.