diff --git a/core/state/access_witness.go b/core/state/access_witness.go index 348cb4c66c0b..789bbbc27e3a 100644 --- a/core/state/access_witness.go +++ b/core/state/access_witness.go @@ -251,9 +251,7 @@ func (aw *AccessWitness) Copy() *AccessWitness { } func (aw *AccessWitness) GetTreeKeyVersionCached(addr []byte) []byte { - p := aw.statedb.db.(*VerkleDB).GetTreeKeyHeader(addr) - v := utils.PointToHash(p, utils.VersionLeafKey) - return v[:] + return aw.statedb.db.(*VerkleDB).addrToPoint.GetTreeKeyVersionCached(addr) } func (aw *AccessWitness) TouchAndChargeProofOfAbsence(addr []byte) uint64 { diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index 9fb4614e461c..9ec41ebb090f 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -53,6 +53,12 @@ func (pc PointCache) GetTreeKeyHeader(addr []byte) *verkle.Point { return point } +func (pc PointCache) GetTreeKeyVersionCached(addr []byte) []byte { + p := pc.GetTreeKeyHeader(addr) + v := PointToHash(p, VersionLeafKey) + return v[:] +} + func init() { // The byte array is the Marshalled output of the point computed as such: //cfg, _ := verkle.GetConfig() diff --git a/trie/verkle.go b/trie/verkle.go index b7d2fcf04385..17c3d16500ca 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -78,7 +78,7 @@ func (t *VerkleTrie) TryGetAccount(key []byte) (*types.StateAccount, error) { // it's not as bad because the commitments aren't updated, but it could, in // theory, have to deserialize some more nodes (if there is some sort of cache // dump) - versionkey := utils.GetTreeKeyVersion(key[:]) + versionkey := t.pointCache.GetTreeKeyVersionCached(key) copy(balancekey[:], versionkey) balancekey[31] = utils.BalanceLeafKey copy(noncekey[:], versionkey) @@ -123,7 +123,7 @@ func (t *VerkleTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error err error nonce, balance [32]byte values = make([][]byte, verkle.NodeWidth) - stem = utils.GetTreeKeyVersion(key[:]) + stem = t.pointCache.GetTreeKeyVersionCached(key[:]) ) // Only evaluate the polynomial once @@ -194,7 +194,7 @@ func (t *VerkleTrie) TryDeleteAccount(key []byte) error { // Only evaluate the polynomial once // TODO InsertStem with overwrite of values 0 - versionkey := utils.GetTreeKeyVersion(key[:]) + versionkey := t.pointCache.GetTreeKeyVersionCached(key) copy(balancekey[:], versionkey) balancekey[31] = utils.BalanceLeafKey copy(noncekey[:], versionkey)