Skip to content

Commit

Permalink
Use cache for Try*Account
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Mar 15, 2023
1 parent 08513ec commit 65b1c84
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions core/state/access_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions trie/utils/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 65b1c84

Please sign in to comment.