fix fist epoch issue

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-14 13:16:40 +00:00
parent 584d60c63f
commit 9a9ecc37a3
3 changed files with 7 additions and 5 deletions

View file

@ -1038,6 +1038,7 @@ func (c *Posv) CacheData(header *types.Header, txs []*types.Transaction, receipt
}
if b == types.ReceiptStatusFailed {
log.Debug("Sign tx failed", "hash", tx.Hash().String())
continue
}

View file

@ -307,7 +307,7 @@ func DecryptRandomizeFromSecretsAndOpening(secrets [][32]byte, opening [32]byte)
}
// Calculate reward for reward checkpoint.
func GetRewardForCheckpoint(chainDb ethdb.Database, c *posv.Posv, chain consensus.ChainReader, number uint64, rCheckpoint uint64, totalSigner *uint64) (map[common.Address]*rewardLog, error) {
func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, number uint64, rCheckpoint uint64, totalSigner *uint64) (map[common.Address]*rewardLog, error) {
// Not reward for singer of genesis block and only calculate reward at checkpoint block.
prevCheckpoint := number - (rCheckpoint * 2)
startBlockNumber := prevCheckpoint + 1
@ -332,12 +332,12 @@ func GetRewardForCheckpoint(chainDb ethdb.Database, c *posv.Posv, chain consensu
log.Debug("Failed get from cached", "hash", header.Hash().String(), "number", i)
block := chain.GetBlock(header.Hash(), i)
txs := block.Transactions()
receipts := core.GetBlockReceipts(chainDb, header.Hash(), i)
receipts := core.GetBlockReceipts(c.GetDb(), header.Hash(), i)
var signTxs []*types.Transaction
for _, tx := range txs {
if tx.IsSigningTransaction() {
b := types.ReceiptStatusSuccessful
var b uint
for _, r := range receipts {
if r.TxHash == tx.Hash() {
b = r.Status
@ -345,7 +345,8 @@ func GetRewardForCheckpoint(chainDb ethdb.Database, c *posv.Posv, chain consensu
}
}
if b == types.ReceiptStatusFailed {
if b == types.ReceiptStatusFailed && i >= rCheckpoint {
log.Debug("Sign tx failed", "hash", tx.Hash().String())
continue
}

View file

@ -312,7 +312,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
chainReward = rewardInflation(chainReward, number, common.BlocksPerYear)
totalSigner := new(uint64)
signers, err := contracts.GetRewardForCheckpoint(eth.chainDb, c, chain, number, rCheckpoint, totalSigner)
signers, err := contracts.GetRewardForCheckpoint(c, chain, number, rCheckpoint, totalSigner)
log.Debug("Time Get Signers", "block", header.Number.Uint64(), "time", common.PrettyDuration(time.Since(start)))
if err != nil {