From cd81c5c8b6d7d38dc13117260b7a390a25595a63 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Fri, 11 Jan 2019 15:32:48 +0000 Subject: [PATCH] move cache to insert func --- consensus/posv/posv.go | 3 ++- core/blockchain.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/consensus/posv/posv.go b/consensus/posv/posv.go index ef4b2ae1d0..2dccf1cd37 100644 --- a/consensus/posv/posv.go +++ b/consensus/posv/posv.go @@ -853,7 +853,7 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state number := header.Number.Uint64() rCheckpoint := chain.Config().Posv.RewardCheckpoint - _ = c.CacheData(header, txs, receipts) + // _ = c.CacheData(header, txs, receipts) if c.HookReward != nil && number%rCheckpoint == 0 { 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) return nil diff --git a/core/blockchain.go b/core/blockchain.go index 4d6c2cc011..5bd0a709be 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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())