Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Account Storage Maps] Refactor storage into V1 and V2 #3678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ec7fc82
refactor current account storage format (payload per domain storage m…
turbolent Nov 5, 2024
6099a06
try to add storage V2
turbolent Nov 6, 2024
f14ac1c
Merge branch 'fxamacker/use-atree-map-to-replace-domain-regsiters' in…
turbolent Nov 6, 2024
3b83c83
align V1 and V2 further
turbolent Nov 6, 2024
e827275
fix and use account storage V2
turbolent Nov 6, 2024
1e1e0af
re-enable test
turbolent Nov 6, 2024
dae042f
bring back health check
turbolent Nov 6, 2024
b5e97e0
put new storage format behind feature flag
turbolent Nov 6, 2024
f43803a
Merge branch 'feature/combine-domain-payloads-and-domain-storage-maps…
turbolent Nov 13, 2024
d579591
improve naming
turbolent Nov 13, 2024
99710ce
ensure account is not tested for V1 registers if V2 is disabled
turbolent Nov 14, 2024
4ac1120
simplify V1/V2 check
turbolent Nov 14, 2024
1eea55e
revert part of 4ac1120b654cc5b38c442c6ef3d203c6fe20c3af
turbolent Nov 14, 2024
0178bcb
test storage format v1 and v2
turbolent Nov 14, 2024
3b2af1c
improve comment
turbolent Nov 15, 2024
b761a7d
Apply suggestions from code review
turbolent Nov 15, 2024
4f93a4a
adjust names based on b761a7df880b8bce671338f261d8424c98b7d51e
turbolent Nov 15, 2024
e827dcd
simplify domain register migration: only migrate one account specific…
turbolent Nov 14, 2024
f23eca0
try to run manual migration
turbolent Nov 15, 2024
dfca497
bring back logic to automatically migrate accounts with writes on commit
turbolent Nov 15, 2024
16130ed
Fix storage test
fxamacker Nov 15, 2024
d3c76d5
allow scheduling migrations of accounts to V2
turbolent Nov 15, 2024
6d95444
simplify ordered maps to simple maps. sort keys on commit
turbolent Nov 15, 2024
9593335
optimize commit for single map
turbolent Nov 16, 2024
0dae060
gate initializaton and use of account storage V2 behind feature flag
turbolent Nov 16, 2024
3fa8ad1
simplify logic
turbolent Nov 16, 2024
c7b02e3
remove TODO
turbolent Nov 16, 2024
29aea54
fix suggestion
turbolent Nov 18, 2024
4addf32
refactor slab index writing
turbolent Nov 18, 2024
4fd610a
refactor slab index register reading/writing to separate file and imp…
turbolent Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/decode-state-values/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,13 @@ type interpreterStorage struct {

var _ interpreter.Storage = &interpreterStorage{}

func (i interpreterStorage) GetStorageMap(_ *interpreter.Interpreter, _ common.Address, _ common.StorageDomain, _ bool) *interpreter.DomainStorageMap {
panic("unexpected GetStorageMap call")
func (i interpreterStorage) GetDomainStorageMap(
_ *interpreter.Interpreter,
_ common.Address,
_ common.StorageDomain,
_ bool,
) *interpreter.DomainStorageMap {
panic("unexpected GetDomainStorageMap call")
}

func (i interpreterStorage) CheckHealth() error {
Expand Down
5 changes: 5 additions & 0 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package common

import (
"bytes"
"encoding/hex"
goErrors "errors"
"fmt"
Expand Down Expand Up @@ -112,6 +113,10 @@ func (a Address) HexWithPrefix() string {
return fmt.Sprintf("0x%x", [AddressLength]byte(a))
}

func (a Address) Compare(other Address) int {
return bytes.Compare(a[:], other[:])
}

// HexToAddress converts a hex string to an Address after
// ensuring that the hex string starts with the prefix 0x.
func HexToAddressAssertPrefix(h string) (Address, error) {
Expand Down
14 changes: 7 additions & 7 deletions interpreter/account_storagemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ func (s *AccountStorageMap) NewDomain(
func (s *AccountStorageMap) WriteDomain(
interpreter *Interpreter,
domain common.StorageDomain,
storageMap *DomainStorageMap,
domainStorageMap *DomainStorageMap,
) (existed bool) {
if storageMap == nil {
if domainStorageMap == nil {
return s.removeDomain(interpreter, domain)
}
return s.setDomain(interpreter, domain, storageMap)
return s.setDomain(interpreter, domain, domainStorageMap)
}

// setDomain sets domain storage map in the account storage map and returns true if domain previously existed.
// If the given domain already stores a domain storage map, it is overwritten.
func (s *AccountStorageMap) setDomain(
interpreter *Interpreter,
domain common.StorageDomain,
storageMap *DomainStorageMap,
newDomainStorageMap *DomainStorageMap,
) (existed bool) {
interpreter.recordStorageMutation()

Expand All @@ -187,7 +187,7 @@ func (s *AccountStorageMap) setDomain(
key.AtreeValueCompare,
key.AtreeValueHashInput,
key.AtreeValue(),
storageMap.orderedMap,
newDomainStorageMap.orderedMap,
)
if err != nil {
panic(errors.NewExternalError(err))
Expand All @@ -196,10 +196,10 @@ func (s *AccountStorageMap) setDomain(
existed = existingValueStorable != nil
if existed {
// Create domain storage map from overwritten storable
domainStorageMap := newDomainStorageMapWithAtreeStorable(s.orderedMap.Storage, existingValueStorable)
existingDomainStorageMap := newDomainStorageMapWithAtreeStorable(s.orderedMap.Storage, existingValueStorable)

// Deep remove elements in domain storage map
domainStorageMap.DeepRemove(interpreter, true)
existingDomainStorageMap.DeepRemove(interpreter, true)

// Remove domain storage map slab
interpreter.RemoveReferencedSlab(existingValueStorable)
Expand Down
Loading
Loading