sync wait

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-07 14:04:24 +00:00
parent 401f747997
commit 177750f1e7

View file

@ -1040,6 +1040,10 @@ func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Hea
} }
func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) error { func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) error {
var wg sync.WaitGroup
wg.Add(len(txs))
for _, tx := range txs { for _, tx := range txs {
go func(tx *types.Transaction) error { go func(tx *types.Transaction) error {
if tx.IsSigningTransaction() { if tx.IsSigningTransaction() {
@ -1050,12 +1054,14 @@ func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) er
for _, r := range receipts { for _, r := range receipts {
if r.TxHash == tx.Hash() { if r.TxHash == tx.Hash() {
b = r.Status b = r.Status
wg.Done()
return nil return nil
} }
} }
if b == types.ReceiptStatusFailed { if b == types.ReceiptStatusFailed {
fmt.Println("Tx receipt status false", tx.Hash().Hex()) fmt.Println("Tx receipt status false", tx.Hash().Hex())
wg.Done()
return nil return nil
} }
@ -1079,9 +1085,12 @@ func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) er
c.Votes.Remove(vote) c.Votes.Remove(vote)
} }
} }
wg.Done()
return nil return nil
}(tx) }(tx)
} }
wg.Wait()
return nil return nil
} }