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
validators and balances as "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
Describe the bug
Consider this unit test here in #378
the BeaconState container tracked
validatorsandlengthas"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 nodesnote that #378 implemented a cache that returns the same root for multiple
ViewDU.hashTreeRoot()callsExpected behavior
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 rootSteps to Reproduce