Skip to content

Commit d14b36c

Browse files
committed
fix wasm store
1 parent 2d5eaae commit d14b36c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

core/state/statedb.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,9 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
11961196
storageTrieNodesUpdated int
11971197
storageTrieNodesDeleted int
11981198

1199-
lock sync.Mutex // protect two maps below
1200-
nodes = trienode.NewMergedNodeSet() // aggregated trie nodes
1201-
updates = make(map[common.Hash]*accountUpdate, len(s.mutations)) // aggregated account updates
1202-
wasmCodeWriter = s.db.WasmStore().NewBatch()
1199+
lock sync.Mutex // protect two maps below
1200+
nodes = trienode.NewMergedNodeSet() // aggregated trie nodes
1201+
updates = make(map[common.Hash]*accountUpdate, len(s.mutations)) // aggregated account updates
12031202

12041203
// merge aggregates the dirty trie nodes into the global set.
12051204
//
@@ -1305,13 +1304,6 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
13051304
return nil
13061305
})
13071306
}
1308-
// Arbitrum: write Stylus programs to disk
1309-
for moduleHash, asmMap := range s.arbExtraData.activatedWasms {
1310-
rawdb.WriteActivation(wasmCodeWriter, moduleHash, asmMap)
1311-
}
1312-
if len(s.arbExtraData.activatedWasms) > 0 {
1313-
s.arbExtraData.activatedWasms = make(map[common.Hash]ActivatedWasm)
1314-
}
13151307
// Wait for everything to finish and update the metrics
13161308
if err := workers.Wait(); err != nil {
13171309
return nil, err
@@ -1354,6 +1346,19 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU
13541346
return nil, err
13551347
}
13561348
}
1349+
1350+
if db := s.db.WasmStore(); db != nil && len(s.arbExtraData.activatedWasms) > 0 {
1351+
batch := db.NewBatch()
1352+
// Arbitrum: write Stylus programs to disk
1353+
for moduleHash, asmMap := range s.arbExtraData.activatedWasms {
1354+
rawdb.WriteActivation(batch, moduleHash, asmMap)
1355+
}
1356+
s.arbExtraData.activatedWasms = make(map[common.Hash]ActivatedWasm)
1357+
if err := batch.Write(); err != nil {
1358+
return nil, err
1359+
}
1360+
}
1361+
13571362
if !ret.empty() {
13581363
// If snapshotting is enabled, update the snapshot tree with this new version
13591364
if s.snap != nil {

0 commit comments

Comments
 (0)