Skip to content

Commit e44b2dc

Browse files
Arachnidkaralabe
authored andcommitted
[release 1.4.12] core/state: Fix memory expansion bug by not copying clean objects
(cherry picked from commit 581b320)
1 parent 99a0c76 commit e44b2dc

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

core/state/state_object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (self *StateObject) Copy() *StateObject {
187187
stateObject.codeHash = common.CopyBytes(self.codeHash)
188188
stateObject.nonce = self.nonce
189189
stateObject.trie = self.trie
190-
stateObject.code = common.CopyBytes(self.code)
190+
stateObject.code = self.code
191191
stateObject.initCode = common.CopyBytes(self.initCode)
192192
stateObject.storage = self.storage.Copy()
193193
stateObject.remove = self.remove

core/state/state_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ func TestSnapshot2(t *testing.T) {
149149
so0.balance = big.NewInt(42)
150150
so0.nonce = 43
151151
so0.SetCode([]byte{'c', 'a', 'f', 'e'})
152-
so0.remove = true
152+
so0.remove = false
153153
so0.deleted = false
154-
so0.dirty = false
154+
so0.dirty = true
155155
state.SetStateObject(so0)
156+
state.Commit()
156157

157158
// and one with deleted == true
158159
so1 := state.GetStateObject(stateobjaddr1)
@@ -173,6 +174,7 @@ func TestSnapshot2(t *testing.T) {
173174
state.Set(snapshot)
174175

175176
so0Restored := state.GetStateObject(stateobjaddr0)
177+
so0Restored.GetState(storageaddr)
176178
so1Restored := state.GetStateObject(stateobjaddr1)
177179
// non-deleted is equal (restored)
178180
compareStateObjects(so0Restored, so0, t)

core/state/statedb.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ func (self *StateDB) Copy() *StateDB {
324324
state, _ := New(common.Hash{}, self.db)
325325
state.trie = self.trie
326326
for k, stateObject := range self.stateObjects {
327-
state.stateObjects[k] = stateObject.Copy()
327+
if stateObject.dirty {
328+
state.stateObjects[k] = stateObject.Copy()
329+
}
328330
}
329331

330332
state.refund.Set(self.refund)
@@ -364,7 +366,6 @@ func (s *StateDB) IntermediateRoot() common.Hash {
364366
stateObject.Update()
365367
s.UpdateStateObject(stateObject)
366368
}
367-
stateObject.dirty = false
368369
}
369370
}
370371
return s.trie.Hash()

0 commit comments

Comments
 (0)