func GetBlocks(blockChan chan<- *types.Block, client *ethclient.Client, startBlock int64, endBlock int64, concurrency int) {
	var blockWorkerWg sync.WaitGroup         // for waiting for all workers to finish
	blockHeightChan := make(chan int64, 100) // channel for workers to know which heights to download

	// Start eth client thread pool
	for w := 1; w <= concurrency; w++ {
		blockWorkerWg.Add(1)

		// Worker gets a block height from blockHeightChan, downloads it, and puts it in the blockChan
		go func() {
			defer blockWorkerWg.Done()
			for blockHeight := range blockHeightChan {
				// fmt.Println(blockHeight)
				block, err := client.BlockByNumber(context.Background(), big.NewInt(blockHeight))
				if err != nil {
					log.Println("Error getting block:", blockHeight, err)
					continue
				}
				blockChan <- block
			}
		}()
	}

	// Push blockheights into channel, for workers to pick up
	for currentBlockNumber := startBlock; currentBlockNumber <= endBlock; currentBlockNumber++ {
		blockHeightChan <- currentBlockNumber
	}

	// Close worker channel and wait for workers to finish
	close(blockHeightChan)
	blockWorkerWg.Wait()
}
// GetBlocks is a fast block query pipeline. It queries blocks concurrently and pushes it into a channel for processing.
GetBlocks is a fast block query pipeline. It queries blocks concurrently and pushes it into a channel for processing.
// GetBlocks is a fast block query pipeline . It queries blocks concurrently and pushes it into a channel for processing .
func GetBlocks(blockChan chan<- *types.Block, client *ethclient.Client, startBlock int64, endBlock int64, concurrency int) {
	var blockWorkerWg sync.WaitGroup         
	blockHeightChan := make(chan int64, 100) 
	for w := 1; w <= concurrency; w++ {
		blockWorkerWg.Add(1)
		go func() {
			defer blockWorkerWg.Done()
			for blockHeight := range blockHeightChan {
				block, err := client.BlockByNumber(context.Background(), big.NewInt(blockHeight))
				if err != nil {
					log.Println("Error getting block:", blockHeight, err)
					continue
				}
				blockChan <- block
			}
		}()
	}
	for currentBlockNumber := startBlock; currentBlockNumber <= endBlock; currentBlockNumber++ {
		blockHeightChan <- currentBlockNumber
	}
	close(blockHeightChan)
	blockWorkerWg.Wait()
}
func GetBlocks ( blockChan chan <- * types . Block , client * ethclient . Client , startBlock int64 , endBlock int64 , concurrency int ) { var blockWorkerWg sync . WaitGroup blockHeightChan := make ( chan int64 , 100 ) for w := 1 ; w <= concurrency ; w ++ { blockWorkerWg . Add ( 1 ) go func ( ) { defer blockWorkerWg . Done ( ) for blockHeight := range blockHeightChan { block , err := client . BlockByNumber ( context . Background ( ) , big . NewInt ( blockHeight ) ) if err != nil { log . Println ( " " , blockHeight , err ) continue } blockChan <- block } } ( ) } for currentBlockNumber := startBlock ; currentBlockNumber <= endBlock ; currentBlockNumber ++ { blockHeightChan <- currentBlockNumber } close ( blockHeightChan ) blockWorkerWg . Wait ( ) }
GetBlocks is a fast block query pipeline.
GetBlocks is a fast block query pipeline .
// for waiting for all workers to finish // channel for workers to know which heights to download // Start eth client thread pool // Worker gets a block height from blockHeightChan, downloads it, and puts it in the blockChan // fmt.Println(blockHeight) // Push blockheights into channel, for workers to pick up // Close worker channel and wait for workers to finish