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 ( const (
bodyCacheLimit = 256 bodyCacheLimit = 2560
blockCacheLimit = 256 blockCacheLimit = 2560
maxFutureBlocks = 256 maxFutureBlocks = 256
maxTimeFutureBlocks = 30 maxTimeFutureBlocks = 30
badBlockLimit = 10 badBlockLimit = 10

View file

@ -18,8 +18,11 @@ package eth
import ( import (
"context" "context"
"encoding/json"
"github.com/ethereum/go-ethereum/consensus/XDPoS" "github.com/ethereum/go-ethereum/consensus/XDPoS"
"io/ioutil"
"math/big" "math/big"
"path/filepath"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -241,6 +244,18 @@ func (s *EthApiBackend) GetRewardByHash(hash common.Hash) map[string]interface{}
if rewards != nil { if rewards != nil {
return rewards 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{}) return make(map[string]interface{})
} }

View file

@ -613,12 +613,13 @@ func (self *worker) commitNewWork() {
delete(self.possibleUncles, hash) delete(self.possibleUncles, hash)
} }
} }
// Create the new block to seal with the consensus engine if atomic.LoadInt32(&self.mining) == 1 {
if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.txs, uncles, work.receipts); err != nil { // Create the new block to seal with the consensus engine
log.Error("Failed to finalize block for sealing", "err", err) if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.txs, uncles, work.receipts); err != nil {
return log.Error("Failed to finalize block for sealing", "err", err)
} return
if atomic.LoadInt32(&self.mining) == 1 { }
}
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))) 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.unconfirmed.Shift(work.Block.NumberU64() - 1)
self.lastParentBlockCommit = parent.Hash().Hex() self.lastParentBlockCommit = parent.Hash().Hex()