Skip to content

Commit

Permalink
Merge pull request #3348 from onflow/fxamacker/add-nondeterministic-c…
Browse files Browse the repository at this point in the history
…ommit-for-migration

Add Storage.NondeterministicCommit for faster migrations
  • Loading branch information
fxamacker authored May 14, 2024
2 parents 58d55aa + cb7627b commit 25c2174
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m *StorageMigration) WithErrorStacktrace(stacktraceEnabled bool) *StorageM
}

func (m *StorageMigration) Commit() error {
return m.storage.Commit(m.interpreter, false)
return m.storage.NondeterministicCommit(m.interpreter, false)
}

func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) {
Expand Down
17 changes: 16 additions & 1 deletion runtime/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ func (s *Storage) writeContractUpdate(

// Commit serializes/saves all values in the readCache in storage (through the runtime interface).
func (s *Storage) Commit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
return s.commit(inter, commitContractUpdates, true)
}

// NondeterministicCommit serializes and commits all values in the deltas storage
// in nondeterministic order. This function is used when commit ordering isn't
// required (e.g. migration programs).
func (s *Storage) NondeterministicCommit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
return s.commit(inter, commitContractUpdates, false)
}

func (s *Storage) commit(inter *interpreter.Interpreter, commitContractUpdates bool, deterministic bool) error {

if commitContractUpdates {
s.commitContractUpdates(inter)
Expand All @@ -252,7 +263,11 @@ func (s *Storage) Commit(inter *interpreter.Interpreter, commitContractUpdates b
common.UseMemory(s.memoryGauge, common.NewAtreeEncodedSlabMemoryUsage(deltas))

// TODO: report encoding metric for all encoded slabs
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
if deterministic {
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
} else {
return s.PersistentSlabStorage.NondeterministicFastCommit(runtime.NumCPU())
}
}

func (s *Storage) commitNewStorageMaps() error {
Expand Down

0 comments on commit 25c2174

Please sign in to comment.