Condition added self.config.XDPoS != nil

This commit is contained in:
AnilChinchawale 2019-01-31 04:51:28 +05:30
parent e2beaa0fba
commit d5101dc3ed
5 changed files with 31 additions and 80 deletions

32
internal/jsre/deps/bindata.go Normal file → Executable file

File diff suppressed because one or more lines are too long

0
internal/jsre/deps/deps.go Normal file → Executable file
View file

View file

@ -18,10 +18,8 @@ package les
import (
"context"
"encoding/json"
"io/ioutil"
"github.com/ethereum/go-ethereum/consensus/XDPoS"
"math/big"
"path/filepath"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
@ -204,25 +202,11 @@ func (b *LesApiBackend) GetEngine() consensus.Engine {
return b.eth.engine
}
func (s *LesApiBackend) GetRewardByHash(hash common.Hash) map[string]interface{} {
header := s.eth.blockchain.GetHeaderByHash(hash)
if header != nil {
data, err := ioutil.ReadFile(filepath.Join(common.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
}
} else {
data, err = ioutil.ReadFile(filepath.Join(common.StoreRewardFolder, header.Number.String()+"."+header.HashNoValidator().Hex()))
if err == nil {
rewards := make(map[string]interface{})
err = json.Unmarshal(data, &rewards)
if err == nil {
return rewards
}
}
if c, ok := s.eth.Engine().(*XDPoS.XDPoS); ok {
rewards := c.GetRewards(hash)
if rewards != nil {
return rewards
}
}
return make(map[string]interface{})
}
}

View file

@ -18,7 +18,6 @@ package miner
import (
"bytes"
"encoding/binary"
"fmt"
"math/big"
"os"
@ -411,10 +410,8 @@ func (self *worker) wait() {
}
}
// Send tx sign to smart contract blockSigners.
if block.NumberU64()%common.MergeSignRange == 0 || !self.config.IsTIP2019(block.Number()) {
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block, self.chainDb); err != nil {
log.Error("Fail to create tx sign for signer", "error", "err")
}
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block, self.chainDb); err != nil {
log.Error("Fail to create tx sign for signer", "error", "err")
}
}
}
@ -555,7 +552,6 @@ func (self *worker) commitNewWork() {
if atomic.LoadInt32(&self.mining) == 1 {
header.Coinbase = self.coinbase
}
if err := self.engine.Prepare(self.chain, header); err != nil {
log.Error("Failed to prepare header for new block", "err", err)
return
@ -584,22 +580,12 @@ func (self *worker) commitNewWork() {
if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(work.state)
}
if self.config.IsTIPEVMSigner(header.Number) {
work.state.DeleteAddress(common.HexToAddress(common.BlockSigners))
}
// won't grasp txs at checkpoint
var (
txs *types.TransactionsByPriceAndNonce
specialTxs types.Transactions
)
if self.config.XDPoS != nil && header.Number.Uint64()%self.config.XDPoS.Epoch != 0 {
pending, err := self.eth.TxPool().Pending()
if err != nil {
log.Error("Failed to fetch pending transactions", "err", err)
return
}
txs, specialTxs = types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
pending, err := self.eth.TxPool().Pending()
if err != nil {
log.Error("Failed to fetch pending transactions", "err", err)
return
}
txs, specialTxs := types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
work.commitTransactions(self.mux, txs, specialTxs, self.chain, self.coinbase)
// compute uncles for the new block.
@ -632,7 +618,7 @@ func (self *worker) commitNewWork() {
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.lastParentBlockCommit = parent.Hash().Hex()
}
@ -675,17 +661,6 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
log.Trace("Ignoring reply protected special transaction", "hash", tx.Hash(), "eip155", env.config.EIP155Block)
continue
}
if tx.To().Hex() == common.BlockSigners {
if len(tx.Data()) < 68 {
log.Trace("Data special transaction invalid lenght", "hash", tx.Hash(), "data", len(tx.Data()))
continue
}
blkNumber := binary.BigEndian.Uint64(tx.Data()[8:40])
if blkNumber >= env.header.Number.Uint64() || blkNumber <= env.header.Number.Uint64()-env.config.XDPoS.Epoch*2 {
log.Trace("Data special transaction invalid number", "hash", tx.Hash(), "blkNumber", blkNumber, "miner", env.header.Number)
continue
}
}
// Start executing the transaction
env.state.Prepare(tx.Hash(), common.Hash{}, env.tcount)
nonce := env.state.GetNonce(from)
@ -719,10 +694,6 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
log.Trace("Not enough gas for further transactions", "gp", gp)
break
}
if txs == nil {
log.Info("this block has no transaction")
break
}
// Retrieve the next transaction and abort if all done
tx := txs.Peek()
if tx == nil {
@ -817,4 +788,4 @@ func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, c
env.receipts = append(env.receipts, receipt)
return nil, receipt.Logs
}
}

View file

@ -65,7 +65,7 @@ type Config struct {
// databases or flat files. This enables ephemeral nodes which can fully reside
// in memory.
DataDir string
// Configuration of peer-to-peer networking.
P2P p2p.Config
@ -436,4 +436,4 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
}
}
return accounts.NewManager(backends...), ephemeral, nil
}
}