fix bug logging, async

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-08 05:45:42 +00:00
parent b042f3ca81
commit d8ac726f30
2 changed files with 36 additions and 47 deletions

View file

@ -862,8 +862,8 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
_ = c.cacheData(txs, receipts)
if c.HookReward != nil && number%rCheckpoint == 0 {
if !c.EnableCache && uint64(c.BlockSigners.Len()) >= (rCheckpoint*3) {
log.Debug("EnableCache true c.BlockSigners.Len()", c.BlockSigners.Len())
if !c.EnableCache && int(c.BlockSigners.Len()) >= int(rCheckpoint*3) {
log.Debug("EnableCache true c.BlockSigners.Len() ", "BlockSigners.Len", c.BlockSigners.Len())
c.EnableCache = true
}
@ -1038,12 +1038,7 @@ func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Hea
}
func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) error {
var wg sync.WaitGroup
wg.Add(len(txs))
for _, tx := range txs {
go func(tx *types.Transaction) error {
if tx.IsSigningTransaction() {
blkHash := common.BytesToHash(tx.Data()[len(tx.Data())-32:])
from := *tx.From()
@ -1052,14 +1047,12 @@ func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) er
for _, r := range receipts {
if r.TxHash == tx.Hash() {
b = r.Status
wg.Done()
return nil
break
}
}
if b == types.ReceiptStatusFailed {
wg.Done()
return nil
continue
}
var lAddr []common.Address
@ -1078,16 +1071,12 @@ func (c *Posv) cacheData(txs []*types.Transaction, receipts []*types.Receipt) er
vote.Masternode = *addr
vote.Voter = *tx.From()
log.Debug("Remove from Votes cache", vote.Masternode.String(), vote.Voter.String())
log.Debug("Remove from Votes cache ", "Masternode", vote.Masternode.String(), "Voter", vote.Voter.String())
c.Votes.Remove(vote)
}
}
wg.Done()
return nil
}(tx)
}
wg.Wait()
return nil
}

View file

@ -490,7 +490,7 @@ func GetRewardBalancesRate(c *posv.Posv, foudationWalletAddr common.Address, mas
if err != nil {
log.Crit("Fail to get vote capacity", "error", err)
}
log.Debug("Add to Votes cache", vote.Masternode.String(), vote.Voter.String(), voterCap.String())
log.Debug("Add to Votes cache ", "vote.Masternode", vote.Masternode.String(), "vote.Voter", vote.Voter.String(), "voterCap", voterCap.String())
c.Votes.Add(vote, voterCap)
}
} else {