From 8294bcf2a6f4cb12db3ada7d45106fdf54a88dd2 Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 18 Dec 2020 15:39:48 +0800 Subject: [PATCH 1/3] eth/download/statesync : state hash sum optimized --- eth/downloader/statesync.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/eth/downloader/statesync.go b/eth/downloader/statesync.go index 69bd13c2f79b..4d6f7832c94c 100644 --- a/eth/downloader/statesync.go +++ b/eth/downloader/statesync.go @@ -18,17 +18,16 @@ package downloader import ( "fmt" - "hash" - "sync" - "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie" "golang.org/x/crypto/sha3" + "sync" + "time" ) // stateReq represents a batch of state fetch requests grouped together into @@ -260,9 +259,9 @@ func (d *Downloader) spindownStateSync(active map[string]*stateReq, finished []* type stateSync struct { d *Downloader // Downloader instance to access and manage current peerset - root common.Hash // State root currently being synced - sched *trie.Sync // State trie sync scheduler defining the tasks - keccak hash.Hash // Keccak256 hasher to verify deliveries with + root common.Hash // State root currently being synced + sched *trie.Sync // State trie sync scheduler defining the tasks + keccak crypto.KeccakState // Keccak256 hasher to verify deliveries with trieTasks map[common.Hash]*trieTask // Set of trie node tasks currently queued for retrieval codeTasks map[common.Hash]*codeTask // Set of byte code tasks currently queued for retrieval @@ -299,7 +298,7 @@ func newStateSync(d *Downloader, root common.Hash) *stateSync { d: d, root: root, sched: state.NewStateSync(root, d.stateDB, d.stateBloom), - keccak: sha3.NewLegacyKeccak256(), + keccak: sha3.NewLegacyKeccak256().(crypto.KeccakState), trieTasks: make(map[common.Hash]*trieTask), codeTasks: make(map[common.Hash]*codeTask), deliver: make(chan *stateReq), @@ -590,7 +589,7 @@ func (s *stateSync) processNodeData(blob []byte) (common.Hash, error) { res := trie.SyncResult{Data: blob} s.keccak.Reset() s.keccak.Write(blob) - s.keccak.Sum(res.Hash[:0]) + s.keccak.Read(res.Hash[:0]) err := s.sched.Process(res) return res.Hash, err } From c30e7e0bca0ea39e0745759606b4d412ee4f0783 Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 18 Dec 2020 17:48:40 +0800 Subject: [PATCH 2/3] go fmt with blank in imports --- eth/downloader/statesync.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eth/downloader/statesync.go b/eth/downloader/statesync.go index 4d6f7832c94c..5b54ef6aeb4a 100644 --- a/eth/downloader/statesync.go +++ b/eth/downloader/statesync.go @@ -18,6 +18,9 @@ package downloader import ( "fmt" + "sync" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" @@ -26,8 +29,6 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie" "golang.org/x/crypto/sha3" - "sync" - "time" ) // stateReq represents a batch of state fetch requests grouped together into From 92aec0569a0fdf06e1d2634e5d76eef037b65e66 Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 18 Dec 2020 19:17:02 +0800 Subject: [PATCH 3/3] keccak read arg fix --- eth/downloader/statesync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/downloader/statesync.go b/eth/downloader/statesync.go index 5b54ef6aeb4a..6231588ad286 100644 --- a/eth/downloader/statesync.go +++ b/eth/downloader/statesync.go @@ -590,7 +590,7 @@ func (s *stateSync) processNodeData(blob []byte) (common.Hash, error) { res := trie.SyncResult{Data: blob} s.keccak.Reset() s.keccak.Write(blob) - s.keccak.Read(res.Hash[:0]) + s.keccak.Read(res.Hash[:]) err := s.sched.Process(res) return res.Hash, err }