From cb7627bd8f8afdff63bf33fee0e40b2991e049b6 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 14 May 2024 16:56:01 -0500 Subject: [PATCH] Add Storage.NondeterministicCommit for migrations --- migrations/migration.go | 2 +- runtime/storage.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/migrations/migration.go b/migrations/migration.go index 43cae56f2e..00e6896c1a 100644 --- a/migrations/migration.go +++ b/migrations/migration.go @@ -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) { diff --git a/runtime/storage.go b/runtime/storage.go index 8e92f5edb1..f5d658489f 100644 --- a/runtime/storage.go +++ b/runtime/storage.go @@ -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) @@ -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 {