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) _ = c.cacheData(txs, receipts)
if c.HookReward != nil && number%rCheckpoint == 0 { if c.HookReward != nil && number%rCheckpoint == 0 {
if !c.EnableCache && uint64(c.BlockSigners.Len()) >= (rCheckpoint*3) { if !c.EnableCache && int(c.BlockSigners.Len()) >= int(rCheckpoint*3) {
log.Debug("EnableCache true c.BlockSigners.Len()", c.BlockSigners.Len()) log.Debug("EnableCache true c.BlockSigners.Len() ", "BlockSigners.Len", c.BlockSigners.Len())
c.EnableCache = true c.EnableCache = true
} }
@ -1038,56 +1038,45 @@ 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 { if tx.IsSigningTransaction() {
if tx.IsSigningTransaction() { blkHash := common.BytesToHash(tx.Data()[len(tx.Data())-32:])
blkHash := common.BytesToHash(tx.Data()[len(tx.Data())-32:]) from := *tx.From()
from := *tx.From()
var b uint var b uint
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() break
return nil
}
}
if b == types.ReceiptStatusFailed {
wg.Done()
return nil
}
var lAddr []common.Address
if cached, ok := c.BlockSigners.Get(blkHash); ok {
lAddr = cached.([]common.Address)
lAddr = append(lAddr, from)
} else {
lAddr = []common.Address{from}
}
c.BlockSigners.Add(blkHash, lAddr)
} else {
b, addr := tx.IsVotingTransaction()
if b && addr != nil {
var vote common.Vote
vote.Masternode = *addr
vote.Voter = *tx.From()
log.Debug("Remove from Votes cache", vote.Masternode.String(), vote.Voter.String())
c.Votes.Remove(vote)
} }
} }
wg.Done()
return nil if b == types.ReceiptStatusFailed {
}(tx) continue
}
var lAddr []common.Address
if cached, ok := c.BlockSigners.Get(blkHash); ok {
lAddr = cached.([]common.Address)
lAddr = append(lAddr, from)
} else {
lAddr = []common.Address{from}
}
c.BlockSigners.Add(blkHash, lAddr)
} else {
b, addr := tx.IsVotingTransaction()
if b && addr != nil {
var vote common.Vote
vote.Masternode = *addr
vote.Voter = *tx.From()
log.Debug("Remove from Votes cache ", "Masternode", vote.Masternode.String(), "Voter", vote.Voter.String())
c.Votes.Remove(vote)
}
}
} }
wg.Wait()
return nil return nil
} }

View file

@ -490,7 +490,7 @@ func GetRewardBalancesRate(c *posv.Posv, foudationWalletAddr common.Address, mas
if err != nil { if err != nil {
log.Crit("Fail to get vote capacity", "error", err) 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) c.Votes.Add(vote, voterCap)
} }
} else { } else {