move cache to insert func

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-11 15:32:48 +00:00
parent 46c96249bf
commit cd81c5c8b6
2 changed files with 6 additions and 1 deletions

View file

@ -853,7 +853,7 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
number := header.Number.Uint64() number := header.Number.Uint64()
rCheckpoint := chain.Config().Posv.RewardCheckpoint rCheckpoint := chain.Config().Posv.RewardCheckpoint
_ = c.CacheData(header, txs, receipts) // _ = c.CacheData(header, txs, receipts)
if c.HookReward != nil && number%rCheckpoint == 0 { if c.HookReward != nil && number%rCheckpoint == 0 {
err, rewards := c.HookReward(chain, state, header) err, rewards := c.HookReward(chain, state, header)
@ -1045,6 +1045,7 @@ func (c *Posv) CacheData(header *types.Header, txs []*types.Transaction, receipt
} }
} }
log.Debug("Save tx signers to cache", "hash", header.Hash().String(), "number", header.Number, "len(txs)", len(signTxs))
c.BlockSigners.Add(header.Hash(), signTxs) c.BlockSigners.Add(header.Hash(), signTxs)
return nil return nil

View file

@ -506,6 +506,10 @@ func (bc *BlockChain) insert(block *types.Block) {
} }
bc.currentBlock.Store(block) bc.currentBlock.Store(block)
// save cache BlockSigners
engine := bc.Engine().(*posv.Posv)
engine.CacheData(block.Header(), block.Transactions(), bc.GetReceiptsByHash(block.Hash()))
// If the block is better than our head or is on a different chain, force update heads // If the block is better than our head or is on a different chain, force update heads
if updateHeads { if updateHeads {
bc.hc.SetCurrentHeader(block.Header()) bc.hc.SetCurrentHeader(block.Header())