fix duplicate hook rewards with --announceTxs

This commit is contained in:
AnilChinchawale 2018-11-22 12:43:16 +05:30
parent ba8e4f46bf
commit 428d3e2f9c
3 changed files with 24 additions and 8 deletions

View file

@ -57,8 +57,8 @@ var (
)
const (
bodyCacheLimit = 256
blockCacheLimit = 256
bodyCacheLimit = 2560
blockCacheLimit = 2560
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
badBlockLimit = 10

View file

@ -18,8 +18,11 @@ package eth
import (
"context"
"encoding/json"
"github.com/ethereum/go-ethereum/consensus/XDPoS"
"io/ioutil"
"math/big"
"path/filepath"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
@ -241,6 +244,18 @@ func (s *EthApiBackend) GetRewardByHash(hash common.Hash) map[string]interface{}
if rewards != nil {
return rewards
}
} else {
header := s.eth.blockchain.GetHeaderByHash(hash)
if header != nil {
data, err := ioutil.ReadFile(filepath.Join(s.eth.config.StoreRewardFolder, header.Number.String()+"."+header.Hash().Hex()))
if err == nil {
rewards := make(map[string]interface{})
err = json.Unmarshal(data, &rewards)
if err == nil {
return rewards
}
}
}
}
return make(map[string]interface{})
}

View file

@ -613,12 +613,13 @@ func (self *worker) commitNewWork() {
delete(self.possibleUncles, hash)
}
}
// Create the new block to seal with the consensus engine
if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.txs, uncles, work.receipts); err != nil {
log.Error("Failed to finalize block for sealing", "err", err)
return
}
if atomic.LoadInt32(&self.mining) == 1 {
if atomic.LoadInt32(&self.mining) == 1 {
// Create the new block to seal with the consensus engine
if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.txs, uncles, work.receipts); err != nil {
log.Error("Failed to finalize block for sealing", "err", err)
return
}
}
log.Info("Committing new block", "number", work.Block.Number(), "txs", work.tcount, "special txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
self.lastParentBlockCommit = parent.Hash().Hex()