From ff23652d50dcf43f569736019237e71d0b6fead4 Mon Sep 17 00:00:00 2001
From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com>
Date: Wed, 20 May 2020 14:31:03 +0200
Subject: [PATCH] GC: reducing copying in stateObject.updateTrie (#557)

* It's unnecessary to copy key in stateObject.updateTrie

* Move value copying from stateObject.updateTrie down to TrieStateWriter
---
 core/state/database.go     | 2 +-
 core/state/state_object.go | 4 ----
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/core/state/database.go b/core/state/database.go
index 77a1e0091f..e7836b3b38 100644
--- a/core/state/database.go
+++ b/core/state/database.go
@@ -1368,7 +1368,7 @@ func (tsw *TrieStateWriter) WriteAccountStorage(_ context.Context, address commo
 	}
 	m1[seckey] = struct{}{}
 	if len(v) > 0 {
-		m[seckey] = v
+		m[seckey] = common.CopyBytes(v)
 	} else {
 		m[seckey] = nil
 	}
diff --git a/core/state/state_object.go b/core/state/state_object.go
index 5513940cb6..4067a3a900 100644
--- a/core/state/state_object.go
+++ b/core/state/state_object.go
@@ -232,9 +232,6 @@ func (so *stateObject) setState(key, value common.Hash) {
 // updateTrie writes cached storage modifications into the object's storage trie.
 func (so *stateObject) updateTrie(ctx context.Context, stateWriter StateWriter) error {
 	for key, value := range so.dirtyStorage {
-		key := key
-		value := value
-
 		original := so.blockOriginStorage[key]
 		so.originStorage[key] = value
 
@@ -358,7 +355,6 @@ func (so *stateObject) CodeHash() []byte {
 	return so.data.CodeHash[:]
 }
 
-
 func (so *stateObject) Balance() *big.Int {
 	return &so.data.Balance
 }
-- 
GitLab