Skip to content

Commit

Permalink
Revert "fix: do not rebind nodes if child ViewDU is not changed (#380)"
Browse files Browse the repository at this point in the history
This reverts commit deecd52.
  • Loading branch information
twoeths committed Jul 16, 2024
1 parent 54db5be commit 07317d0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/ssz/src/viewDU/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export abstract class TreeViewDU<T extends CompositeType<unknown, unknown, unkno
// remember not to do a commit() before calling this function
// in ethereum consensus, the only type goes with TVDU is BeaconState and it's really more efficient to hash the tree in batch
// if consumers don't want to batch hash, just go with `this.node.root` similar to what View.hashTreeRoot() does
// there should not be another ViewDU.hashTreeRoot() during this flow so it's safe to reuse nextHashComps

const hashComps = nextHashComps;
this.commit(hashComps);
if (nextHashComps.byLevel.length > 0 || nextHashComps.offset !== 0) {
Expand Down
9 changes: 3 additions & 6 deletions packages/ssz/src/viewDU/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,9 @@ export class ArrayCompositeTreeViewDU<

for (const [index, view] of this.viewsChanged) {
const node = this.type.elementType.commitViewDU(view, hashCompsView);
// there's a chance the view is not changed, no need to rebind nodes in that case
if (this.nodes[index] !== node) {
// 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});
}
// 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});

// Cache the view's caches to preserve it's data after 'this.viewsChanged.clear()'
const cache = this.type.elementType.cacheOfViewDU(view);
Expand Down
9 changes: 3 additions & 6 deletions packages/ssz/src/viewDU/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@ class ContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> extends
for (const [index, view] of this.viewsChanged) {
const fieldType = this.type.fieldsEntries[index].fieldType as unknown as CompositeTypeAny;
const node = fieldType.commitViewDU(view, hashCompsView);
// there's a chance the view is not changed, no need to rebind nodes in that case
if (this.nodes[index] !== node) {
// 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});
}
// 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});

// Cache the view's caches to preserve it's data after 'this.viewsChanged.clear()'
const cache = fieldType.cacheOfViewDU(view);
Expand Down
29 changes: 0 additions & 29 deletions packages/ssz/test/unit/unchangedViewDUs.test.ts

This file was deleted.

0 comments on commit 07317d0

Please sign in to comment.