Skip to content

Commit cb7627b

Browse files
committed
Add Storage.NondeterministicCommit for migrations
1 parent 58d55aa commit cb7627b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

migrations/migration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (m *StorageMigration) WithErrorStacktrace(stacktraceEnabled bool) *StorageM
8686
}
8787

8888
func (m *StorageMigration) Commit() error {
89-
return m.storage.Commit(m.interpreter, false)
89+
return m.storage.NondeterministicCommit(m.interpreter, false)
9090
}
9191

9292
func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) {

runtime/storage.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ func (s *Storage) writeContractUpdate(
229229

230230
// Commit serializes/saves all values in the readCache in storage (through the runtime interface).
231231
func (s *Storage) Commit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
232+
return s.commit(inter, commitContractUpdates, true)
233+
}
234+
235+
// NondeterministicCommit serializes and commits all values in the deltas storage
236+
// in nondeterministic order. This function is used when commit ordering isn't
237+
// required (e.g. migration programs).
238+
func (s *Storage) NondeterministicCommit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
239+
return s.commit(inter, commitContractUpdates, false)
240+
}
241+
242+
func (s *Storage) commit(inter *interpreter.Interpreter, commitContractUpdates bool, deterministic bool) error {
232243

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

254265
// TODO: report encoding metric for all encoded slabs
255-
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
266+
if deterministic {
267+
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
268+
} else {
269+
return s.PersistentSlabStorage.NondeterministicFastCommit(runtime.NumCPU())
270+
}
256271
}
257272

258273
func (s *Storage) commitNewStorageMaps() error {

0 commit comments

Comments
 (0)