cache only blocksigners

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-11 10:55:02 +00:00
parent f9ae05c5d5
commit 46c96249bf
3 changed files with 17 additions and 20 deletions

View file

@ -226,7 +226,6 @@ type Posv struct {
lock sync.RWMutex // Protects the signer fields
BlockSigners *lru.Cache
Votes *lru.Cache
HookReward func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) (error, map[string]interface{})
HookPenalty func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error)
HookValidator func(header *types.Header, signers []common.Address) ([]byte, error)

View file

@ -329,14 +329,13 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, number ui
data[blkHash] = append(data[blkHash], from)
}
} else {
log.Info("Failed get from cached", "hash", header.Hash().String(), "number", i)
log.Debug("Failed get from cached", "hash", header.Hash().String(), "number", i)
block := chain.GetBlock(header.Hash(), i)
txs := block.Transactions()
receipts := core.GetBlockReceipts(c.GetDb(), header.Hash(), i)
var signTxs []*types.Transaction
for _, tx := range txs {
if tx.IsSigningTransaction() {
var b uint
for _, r := range receipts {
if r.TxHash == tx.Hash() {
@ -354,7 +353,6 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, number ui
from := *tx.From()
data[blkHash] = append(data[blkHash], from)
}
}
c.BlockSigners.Add(header.Hash(), signTxs)
}
@ -433,7 +431,7 @@ func GetCandidatesOwnerBySigner(validator *contractValidator.TomoValidator, sign
}
// Calculate reward for holders.
func CalculateRewardForHolders(c *posv.Posv, foudationWalletAddr common.Address, validator *contractValidator.TomoValidator, state *state.StateDB, signer common.Address, calcReward *big.Int) (error, map[common.Address]*big.Int) {
func CalculateRewardForHolders(foudationWalletAddr common.Address, validator *contractValidator.TomoValidator, state *state.StateDB, signer common.Address, calcReward *big.Int) (error, map[common.Address]*big.Int) {
rewards, err := GetRewardBalancesRate(foudationWalletAddr, signer, calcReward, validator)
if err != nil {
return err, nil

View file

@ -324,7 +324,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
voterResults := make(map[common.Address]interface{})
if len(signers) > 0 {
for signer, calcReward := range rewardSigners {
err, rewards := contracts.CalculateRewardForHolders(c, foudationWalletAddr, validator, state, signer, calcReward)
err, rewards := contracts.CalculateRewardForHolders(foudationWalletAddr, validator, state, signer, calcReward)
if err != nil {
log.Crit("Fail to calculate reward for holders.", "error", err)
}