mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
move cache data to insert func
This commit is contained in:
parent
73efc02259
commit
e50c789c77
3 changed files with 9 additions and 4 deletions
|
|
@ -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
|
// the state remains as is and uncles are dropped
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
|
|
@ -1033,7 +1033,7 @@ func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Hea
|
||||||
return masternodes
|
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
|
var signTxs []*types.Transaction
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
if tx.IsSigningTransaction() {
|
if tx.IsSigningTransaction() {
|
||||||
|
|
@ -1054,6 +1054,7 @@ func (c *Posv) cacheData(header *types.Header, txs []*types.Transaction, receipt
|
||||||
}
|
}
|
||||||
|
|
||||||
c.BlockSigners.Add(header.Hash(), signTxs)
|
c.BlockSigners.Add(header.Hash(), signTxs)
|
||||||
|
fmt.Println("Add cache BLockSigners", header.Hash().String(), len(signTxs), c.BlockSigners.Len())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1071,7 +1072,7 @@ func (c *Posv) GetSignData(chain consensus.ChainReader, startBlockNumber uint64,
|
||||||
data[blkHash] = append(data[blkHash], from)
|
data[blkHash] = append(data[blkHash], from)
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
return data, nil
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, blockSign
|
||||||
} else {
|
} else {
|
||||||
data, err := c.GetSignData(chain, startBlockNumber, endBlockNumber)
|
data, err := c.GetSignData(chain, startBlockNumber, endBlockNumber)
|
||||||
if err != nil {
|
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++ {
|
for i := startBlockNumber; i <= endBlockNumber; i++ {
|
||||||
|
|
|
||||||
|
|
@ -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())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue