From 63d646772428a8cb857c383ef458cb94183d49e1 Mon Sep 17 00:00:00 2001 From: Nguyen Ba Tam Date: Wed, 2 Jan 2019 10:34:01 +0700 Subject: [PATCH] fix duplicate hook rewards with --announceTxs --- core/blockchain.go | 4 ++-- eth/api_backend.go | 15 +++++++++++++++ miner/worker.go | 10 +++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index a01275da5d..5521ff617b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -57,8 +57,8 @@ var ( ) const ( - bodyCacheLimit = 256 - blockCacheLimit = 256 + bodyCacheLimit = 2560 + blockCacheLimit = 2560 maxFutureBlocks = 256 maxTimeFutureBlocks = 30 badBlockLimit = 10 diff --git a/eth/api_backend.go b/eth/api_backend.go index 3b34e843ef..7f2b9b7944 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -18,8 +18,11 @@ package eth import ( "context" + "encoding/json" "github.com/ethereum/go-ethereum/consensus/posv" + "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{}) } diff --git a/miner/worker.go b/miner/worker.go index 9baefbce40..a5d5167fb4 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -612,12 +612,12 @@ 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 { + // 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()