beacon-chain-java
beacon-chain-java copied to clipboard
Prevent hash_tree_root caching of mutable objects
CachingBeaconChainSpec::hash_tree_root can be passed with a mutable object, e.g. MutableBeaconState or WriteList/WriteVector. Thus it can return wrong value, if the mutable object is modified, since the caching code uses Object identity (BeaconStateImple::hashCode is not overridden).
There are several possible ways to solve the problem:
- implement proper
BeaconStateImple::hashCodeto match theBeaconStateImple::equalsimplementation - Invalidate cache based on updates
- Do not cache mutable objects. This will require implementing an appropriate flag/interface to manifest (im)mutability.