-
-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Describe the bug
Consider this unit test here in #378
it("should not recompute hashTreeRoot() when no fields is changed", () => {
const root = state.hashTreeRoot();
// this causes viewsChanged inside BeaconState container
state.validators.length;
state.balances.length;
// but we should not recompute root, should get from cache instead
const root2 = state.hashTreeRoot();
expect(root2).to.equal(root, "should not recompute hashTreeRoot() when no fields are changed");
});the BeaconState container tracked validators and length as "viewsChanged" and it rebinds the underlying tree to compute new root with same nodes, which results in the same value but different tree/nodes, and we need to rehash the different nodes
note that #378 implemented a cache that returns the same root for multiple ViewDU.hashTreeRoot() calls
Expected behavior
- according to the design of ssz v2, BeaconState container should still track
validatorsandbalancesas "viewsChanged" so that when we modify them they will escalate the change to BeaconState. However when we commit those viewDUs, if we see no change we should not rebind the nodes, and it should return the same cached root
Steps to Reproduce
- Run above unit test on feat: batch hash tree root #378
Metadata
Metadata
Assignees
Labels
No labels