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 {