forked from febe19/bazo-miner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_transactions.go
53 lines (46 loc) · 1.52 KB
/
fetch_transactions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package miner
import (
"errors"
"github.com/julwil/bazo-miner/protocol"
"time"
)
// Fetch all txs for a given block and place them into the provided slices.
func fetchTransactions(
initialSetup bool,
block *protocol.Block,
accTxSlice *[]*protocol.AccTx,
fundsTxSlice *[]*protocol.FundsTx,
configTxSlice *[]*protocol.ConfigTx,
stakeTxSlice *[]*protocol.StakeTx,
aggTxSlice *[]*protocol.AggTx,
aggregatedFundsTxSlice *[]*protocol.FundsTx,
updateTxSlice *[]*protocol.UpdateTx,
) error {
//We fetch tx data for each type in parallel -> performance boost.
nrOfChannels := 6
errChan := make(chan error, nrOfChannels)
aggregatedFundsChan := make(chan []*protocol.FundsTx, 10000)
go fetchAccTxData(block, *accTxSlice, initialSetup, errChan)
go fetchFundsTxData(block, *fundsTxSlice, initialSetup, errChan)
go fetchConfigTxData(block, *configTxSlice, initialSetup, errChan)
go fetchStakeTxData(block, *stakeTxSlice, initialSetup, errChan)
go fetchUpdateTxData(block, *updateTxSlice, initialSetup, errChan)
go fetchAggTxData(block, *aggTxSlice, initialSetup, errChan, aggregatedFundsChan)
//Wait for all goroutines to finish.
for cnt := 0; cnt < nrOfChannels; cnt++ {
err := <-errChan
if err != nil {
return err
}
}
if len(*aggTxSlice) > 0 {
logger.Printf("-- Fetch AggTxData - Start")
select {
case *aggregatedFundsTxSlice = <-aggregatedFundsChan:
case <-time.After(10 * time.Minute):
return errors.New("Fetching FundsTx aggregated in AggTx failed.")
}
logger.Printf("-- Fetch AggTxData - End")
}
return nil
}