mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
remove uncle block handling (#523)
This commit is contained in:
parent
78bad64eea
commit
3fe54e28d3
3 changed files with 14 additions and 54 deletions
|
|
@ -240,7 +240,7 @@ func (x *XDPoS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Head
|
|||
func (x *XDPoS) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
|
||||
switch x.config.BlockConsensusVersion(block.Number(), block.Extra(), ExtraFieldCheck) {
|
||||
case params.ConsensusEngineVersion2:
|
||||
return nil
|
||||
return x.EngineV2.VerifyUncles(chain, block)
|
||||
default: // Default "v1"
|
||||
return x.EngineV1.VerifyUncles(chain, block)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package engine_v2
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
|
|
@ -515,6 +516,15 @@ func (x *XDPoS_v2) UpdateMasternodes(chain consensus.ChainReader, header *types.
|
|||
return nil
|
||||
}
|
||||
|
||||
// VerifyUncles implements consensus.Engine, always returning an error for any
|
||||
// uncles as this consensus mechanism doesn't permit uncles.
|
||||
func (x *XDPoS_v2) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
|
||||
if len(block.Uncles()) > 0 {
|
||||
return errors.New("uncles not allowed in XDPoS_v2")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *XDPoS_v2) VerifyHeader(chain consensus.ChainReader, header *types.Header, fullVerify bool) error {
|
||||
err := x.verifyHeader(chain, header, nil, fullVerify)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package miner
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
|
||||
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||
|
|
@ -307,12 +306,7 @@ func (self *worker) update() {
|
|||
timeout.Reset(time.Duration(minePeriod) * time.Second)
|
||||
|
||||
// Handle ChainSideEvent
|
||||
case ev := <-self.chainSideCh:
|
||||
if self.config.XDPoS == nil {
|
||||
self.uncleMu.Lock()
|
||||
self.possibleUncles[ev.Block.Hash()] = ev.Block
|
||||
self.uncleMu.Unlock()
|
||||
}
|
||||
case <-self.chainSideCh:
|
||||
|
||||
// Handle NewTxsEvent
|
||||
case ev := <-self.txsCh:
|
||||
|
|
@ -508,17 +502,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
|
|||
createdAt: time.Now(),
|
||||
}
|
||||
|
||||
if self.config.XDPoS == nil {
|
||||
// when 08 is processed ancestors contain 07 (quick block)
|
||||
for _, ancestor := range self.chain.GetBlocksFromHash(parent.Hash(), 7) {
|
||||
for _, uncle := range ancestor.Uncles() {
|
||||
work.family.Add(uncle.Hash())
|
||||
}
|
||||
work.family.Add(ancestor.Hash())
|
||||
work.ancestors.Add(ancestor.Hash())
|
||||
}
|
||||
}
|
||||
|
||||
// Keep track of transactions which return errors so they can be removed
|
||||
work.tcount = 0
|
||||
self.current = work
|
||||
|
|
@ -800,33 +783,15 @@ func (self *worker) commitNewWork() {
|
|||
work.commitTransactions(self.mux, feeCapacity, txs, specialTxs, self.chain, self.coinbase)
|
||||
// compute uncles for the new block.
|
||||
var (
|
||||
uncles []*types.Header
|
||||
badUncles []common.Hash
|
||||
uncles []*types.Header
|
||||
)
|
||||
if self.config.XDPoS == nil {
|
||||
for hash, uncle := range self.possibleUncles {
|
||||
if len(uncles) == 2 {
|
||||
break
|
||||
}
|
||||
if err := self.commitUncle(work, uncle.Header()); err != nil {
|
||||
log.Trace("Bad uncle found and will be removed", "hash", hash)
|
||||
log.Trace(fmt.Sprint(uncle))
|
||||
|
||||
badUncles = append(badUncles, hash)
|
||||
} else {
|
||||
log.Debug("Committing new uncle to block", "hash", hash)
|
||||
uncles = append(uncles, uncle.Header())
|
||||
}
|
||||
}
|
||||
for _, hash := range badUncles {
|
||||
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.parentState, work.txs, uncles, work.receipts); err != nil {
|
||||
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)))
|
||||
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
||||
|
|
@ -835,21 +800,6 @@ func (self *worker) commitNewWork() {
|
|||
self.push(work)
|
||||
}
|
||||
|
||||
func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
|
||||
hash := uncle.Hash()
|
||||
if work.uncles.Contains(hash) {
|
||||
return fmt.Errorf("uncle not unique")
|
||||
}
|
||||
if !work.ancestors.Contains(uncle.ParentHash) {
|
||||
return fmt.Errorf("uncle's parent unknown (%x)", uncle.ParentHash[0:4])
|
||||
}
|
||||
if work.family.Contains(hash) {
|
||||
return fmt.Errorf("uncle already in family (%x)", hash)
|
||||
}
|
||||
work.uncles.Add(uncle.Hash())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (env *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Address]*big.Int, txs *types.TransactionsByPriceAndNonce, specialTxs types.Transactions, bc *core.BlockChain, coinbase common.Address) {
|
||||
gp := new(core.GasPool).AddGas(env.header.GasLimit)
|
||||
balanceUpdated := map[common.Address]*big.Int{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue