From 169887f39f40e6cd0ea5138b263f281056c86c1a Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 31 Aug 2020 11:03:37 -0500 Subject: [PATCH] number of workers instead of divide depth update w/ iterator change --- cmd/stateSnapshot.go | 8 ++++---- pkg/snapshot/service.go | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index 1ea4451..b978e58 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -44,8 +44,8 @@ func stateSnapshot() { logWithCommand.Fatal(err) } height := viper.GetInt64("snapshot.blockHeight") - divideDepth := viper.GetInt("snapshot.divideDepth") - params := snapshot.SnapshotParams{DivideDepth: divideDepth} + workers := viper.GetUint("snapshot.workers") + params := snapshot.SnapshotParams{Workers: workers} if height < 0 { if err := snapshotService.CreateLatestSnapshot(params); err != nil { logWithCommand.Fatal(err) @@ -65,10 +65,10 @@ func init() { stateSnapshotCmd.PersistentFlags().String("leveldb-path", "", "path to primary datastore") stateSnapshotCmd.PersistentFlags().String("ancient-path", "", "path to ancient datastore") stateSnapshotCmd.PersistentFlags().String("block-height", "", "blockheight to extract state at") - stateSnapshotCmd.PersistentFlags().Int("divide-depth", 0, "trie depth to divide concurrent work at") + stateSnapshotCmd.PersistentFlags().Int("workers", 0, "number of concurrent workers to use") viper.BindPFlag("leveldb.path", stateSnapshotCmd.PersistentFlags().Lookup("leveldb-path")) viper.BindPFlag("leveldb.ancient", stateSnapshotCmd.PersistentFlags().Lookup("ancient-path")) viper.BindPFlag("snapshot.blockHeight", stateSnapshotCmd.PersistentFlags().Lookup("block-height")) - viper.BindPFlag("snapshot.divideDepth", stateSnapshotCmd.PersistentFlags().Lookup("divide-depth")) + viper.BindPFlag("snapshot.workers", stateSnapshotCmd.PersistentFlags().Lookup("workers")) } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 8edf7be..af9289d 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -39,7 +39,6 @@ var ( emptyNode, _ = rlp.EncodeToBytes([]byte{}) emptyCodeHash = crypto.Keccak256([]byte{}) emptyContractRoot = crypto.Keccak256Hash(emptyNode) - spawnDepth = 2 ) type Service struct { @@ -67,7 +66,7 @@ func NewSnapshotService(con ServiceConfig) (*Service, error) { type SnapshotParams struct { Height uint64 - DivideDepth int + Workers uint } func (s *Service) CreateSnapshot(params SnapshotParams) error { @@ -88,8 +87,8 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { if err != nil { return err } - if params.DivideDepth > 0 { - return s.createSnapshotAsync(t, headerID, params.DivideDepth) + if params.Workers > 0 { + return s.createSnapshotAsync(t, headerID, params.Workers) } else { return s.createSnapshot(t.NodeIterator(nil), headerID) } @@ -200,12 +199,12 @@ func (s *Service) createSnapshot(it iter.NodeIterator, headerID int64) error { } // Full-trie snapshot using goroutines -func (s *Service) createSnapshotAsync(tree state.Trie, headerID int64, depth int) error { +func (s *Service) createSnapshotAsync(tree state.Trie, headerID int64, workers uint) error { errors := make(chan error) finished := make(chan bool) var wg sync.WaitGroup - iter.VisitSubtries(tree, depth, func (it iter.NodeIterator) { + iter.VisitSubtries(tree, workers, func (it iter.NodeIterator) { wg.Add(1) go func() { defer wg.Done()