Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/ssz/src/viewDU/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ export class ArrayCompositeTreeViewDU<

for (const [index, view] of this.viewsChanged) {
const node = this.type.elementType.commitViewDU(view, offsetView, byLevelView);
// 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});
// 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});
}

// 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: 6 additions & 3 deletions packages/ssz/src/viewDU/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ export class BasicContainerTreeViewDU<Fields extends Record<string, Type<unknown
for (const [index, view] of this.viewsChanged) {
const fieldType = this.type.fieldsEntries[index].fieldType as unknown as CompositeTypeAny;
const node = fieldType.commitViewDU(view, offsetView, byLevelView);
// 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});
// 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});
}

// Cache the view's caches to preserve it's data after 'this.viewsChanged.clear()'
const cache = fieldType.cacheOfViewDU(view);
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/test/unit/unchangedViewDUs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {getRandomState} from "../utils/generateEth2Objs.js";
describe("Unchanged ViewDUs", () => {
const state = sszAltair.BeaconState.toViewDU(getRandomState(100));

it.skip("should not recompute batchHashTreeRoot() when no fields is changed", () => {
it("should not recompute batchHashTreeRoot() when no fields is changed", () => {
const root = state.batchHashTreeRoot();
// this causes viewsChanged inside BeaconState container
state.validators.length;
Expand Down