move cache data to insert func

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-11 04:58:10 +00:00
parent 73efc02259
commit e50c789c77
3 changed files with 9 additions and 4 deletions

View file

@ -877,7 +877,7 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
}
}
_ = c.cacheData(header, txs, receipts)
// _ = c.cacheData(header, txs, receipts)
// the state remains as is and uncles are dropped
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
@ -1033,7 +1033,7 @@ func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Hea
return masternodes
}
func (c *Posv) cacheData(header *types.Header, txs []*types.Transaction, receipts []*types.Receipt) error {
func (c *Posv) CacheData(header *types.Header, txs []*types.Transaction, receipts []*types.Receipt) error {
var signTxs []*types.Transaction
for _, tx := range txs {
if tx.IsSigningTransaction() {
@ -1054,6 +1054,7 @@ func (c *Posv) cacheData(header *types.Header, txs []*types.Transaction, receipt
}
c.BlockSigners.Add(header.Hash(), signTxs)
fmt.Println("Add cache BLockSigners", header.Hash().String(), len(signTxs), c.BlockSigners.Len())
return nil
}
@ -1071,7 +1072,7 @@ func (c *Posv) GetSignData(chain consensus.ChainReader, startBlockNumber uint64,
data[blkHash] = append(data[blkHash], from)
}
} else {
return nil, errors.New("Failed get blocksigners from cache")
return nil, errors.New("Failed get blocksigners from cache " + block.Hash().String() + " " + block.Number.String())
}
}
return data, nil

View file

@ -353,7 +353,7 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, blockSign
} else {
data, err := c.GetSignData(chain, startBlockNumber, endBlockNumber)
if err != nil {
log.Crit("Fail to get signers from cache.", "endBlockNumber", startBlockNumber, "startBlockNumber", endBlockNumber)
log.Crit("Fail to get signers from cache.", "startBlockNumber", startBlockNumber, "endBlockNumber", endBlockNumber, "error", err)
}
for i := startBlockNumber; i <= endBlockNumber; i++ {

View file

@ -506,6 +506,10 @@ func (bc *BlockChain) insert(block *types.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 updateHeads {
bc.hc.SetCurrentHeader(block.Header())