This commit is contained in:
Roy Crihfield 2020-09-07 21:02:30 -05:00
parent 66d6acc1fe
commit cd3d9f27cf

View File

@ -31,7 +31,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/postgres" "github.com/vulcanize/ipfs-blockchain-watcher/pkg/postgres"
iter "github.com/vulcanize/go-eth-state-node-iterator/pkg/iterator" iter "github.com/vulcanize/go-eth-state-node-iterator/iterator"
) )
var ( var (
@ -201,12 +201,8 @@ func (s *Service) createSnapshot(it trie.NodeIterator, headerID int64) error {
// Full-trie snapshot using goroutines // Full-trie snapshot using goroutines
func (s *Service) createSnapshotAsync(tree state.Trie, headerID int64, workers uint) error { func (s *Service) createSnapshotAsync(tree state.Trie, headerID int64, workers uint) error {
errors := make(chan error) errors := make(chan error)
finished := make(chan bool)
var wg sync.WaitGroup var wg sync.WaitGroup
for _, it := range iter.SubtrieIterators(tree, workers) {
iters := iter.SubtrieIterators(tree, workers)
for _, it := range iters {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
@ -215,15 +211,12 @@ func (s *Service) createSnapshotAsync(tree state.Trie, headerID int64, workers u
} }
}() }()
} }
go func() { go func() {
defer close(finished) defer close(errors)
wg.Wait() wg.Wait()
}() }()
select { select {
case <-finished:
break
case err := <-errors: case err := <-errors:
return err return err
} }