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

Cadence Account Storage Map Migration #6761

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions cmd/util/ledger/util/atree_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/onflow/atree"
"github.com/onflow/cadence/interpreter"

"github.com/onflow/cadence/common"
"github.com/onflow/cadence/runtime"
Expand Down Expand Up @@ -104,10 +105,11 @@ func LoadAtreeSlabsInStorage(
}

func CheckStorageHealth(
inter *interpreter.Interpreter,
address common.Address,
storage *runtime.Storage,
registers registers.Registers,
domains []string,
domains []common.StorageDomain,
nWorkers int,
) error {

Expand All @@ -117,7 +119,7 @@ func CheckStorageHealth(
}

for _, domain := range domains {
_ = storage.GetStorageMap(address, domain, false)
_ = storage.GetDomainStorageMap(inter, address, domain, false)
}

return storage.CheckHealth()
Expand Down
14 changes: 0 additions & 14 deletions cmd/util/ledger/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

"github.com/onflow/atree"
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/stdlib"

"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/ledger"
Expand Down Expand Up @@ -247,15 +245,3 @@ func (p *PayloadsLedger) AllocateSlabIndex(owner []byte) (atree.SlabIndex, error

panic("AllocateSlabIndex not expected to be called")
}

var StorageMapDomains = []string{
common.PathDomainStorage.Identifier(),
common.PathDomainPrivate.Identifier(),
common.PathDomainPublic.Identifier(),
runtime.StorageDomainContract,
stdlib.InboxStorageDomain,
stdlib.CapabilityControllerStorageDomain,
stdlib.CapabilityControllerTagStorageDomain,
stdlib.PathCapabilityStorageDomain,
stdlib.AccountCapabilityStorageDomain,
}
8 changes: 6 additions & 2 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
// create a block with 2 collections with 2 transactions each
block := generateBlock(collectionCount, transactionsPerCollection, rag)

serviceEvents := systemcontracts.ServiceEventsForChain(execCtx.Chain.ChainID())
chainID := execCtx.Chain.ChainID()
serviceEvents := systemcontracts.ServiceEventsForChain(chainID)

randomSource := unittest.EpochSetupRandomSourceFixture()
payload, err := ccf.Decode(nil, unittest.EpochSetupFixtureCCF(randomSource))
Expand Down Expand Up @@ -700,6 +701,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
chainID,
func(_ runtime.Config) runtime.Runtime {
return emittingRuntime
},
Expand Down Expand Up @@ -747,7 +749,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
// make sure event index sequence are valid
for i := 0; i < result.BlockExecutionResult.Size(); i++ {
collectionResult := result.CollectionExecutionResultAt(i)
unittest.EnsureEventsIndexSeq(t, collectionResult.Events(), execCtx.Chain.ChainID())
unittest.EnsureEventsIndexSeq(t, collectionResult.Events(), chainID)
}

sEvents := result.AllServiceEvents() // all events should have been collected
Expand Down Expand Up @@ -815,6 +817,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
execCtx.Chain.ChainID(),
func(_ runtime.Config) runtime.Runtime {
return rt
})),
Expand Down Expand Up @@ -930,6 +933,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
execCtx.Chain.ChainID(),
func(_ runtime.Config) runtime.Runtime {
return rt
})),
Expand Down
1 change: 1 addition & 0 deletions engine/execution/computation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func DefaultFVMOptions(chainID flow.ChainID, cadenceTracing bool, extensiveTraci
runtime.Config{
TracingEnabled: cadenceTracing,
},
chainID,
)),
fvm.WithEVMEnabled(true),
}
Expand Down
1 change: 1 addition & 0 deletions engine/execution/computation/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func benchmarkComputeBlock(
reusableRuntime.NewReusableCadenceRuntimePool(
ReusableCadenceRuntimePoolSize,
runtime.Config{},
chainID,
)),
)
snapshotTree := testutil.RootBootstrappedLedger(
Expand Down
102 changes: 102 additions & 0 deletions fvm/accountV2Migration/AccountV2Migration.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
access(all)
contract AccountV2Migration {

access(all)
enum StorageFormat: UInt8 {
access(all)
case Unknown

access(all)
case V1

access(all)
case V2
}

access(all)
event Migrated(
addressStartIndex: UInt64,
count: UInt64
)

access(all)
resource Admin {
access(all)
fun setEnabled(_ isEnabled: Bool) {
AccountV2Migration.isEnabled = isEnabled
}

access(all)
fun setNextAddressStartIndex(_ nextAddressStartIndex: UInt64) {
AccountV2Migration.nextAddressStartIndex = nextAddressStartIndex
}

access(all)
fun setBatchSize(_ batchSize: UInt64) {
AccountV2Migration.batchSize = batchSize
}

access(all)
fun migrateNextBatch() {
AccountV2Migration.migrateNextBatch()
}
}

access(all)
let adminStoragePath: StoragePath

access(all)
var isEnabled: Bool

access(all)
var nextAddressStartIndex: UInt64

access(all)
var batchSize: UInt64

init() {
self.adminStoragePath = /storage/accountV2MigrationAdmin
self.isEnabled = false
self.nextAddressStartIndex = 1
self.batchSize = 10

self.account.storage.save(
<-create Admin(),
to: self.adminStoragePath
)
}

access(contract)
fun migrateNextBatch() {
if !self.isEnabled {
return
}

let batchSize = self.batchSize
if batchSize <= 0 {
return
}

let startIndex = self.nextAddressStartIndex

if !scheduleAccountV2Migration(
addressStartIndex: startIndex,
count: batchSize
) {
return
}

self.nextAddressStartIndex = startIndex + batchSize

emit Migrated(
addressStartIndex: startIndex,
count: batchSize
)
}

access(all)
fun getAccountStorageFormat(address: Address): StorageFormat? {
let rawStorageFormat = getAccountStorageFormat(address: address)
return StorageFormat(rawValue: rawStorageFormat)
}
}
Loading
Loading