Skip to content

Commit 3fe54e2

Browse files
authored
remove uncle block handling (#523)
1 parent 78bad64 commit 3fe54e2

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

consensus/XDPoS/XDPoS.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (x *XDPoS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Head
240240
func (x *XDPoS) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
241241
switch x.config.BlockConsensusVersion(block.Number(), block.Extra(), ExtraFieldCheck) {
242242
case params.ConsensusEngineVersion2:
243-
return nil
243+
return x.EngineV2.VerifyUncles(chain, block)
244244
default: // Default "v1"
245245
return x.EngineV1.VerifyUncles(chain, block)
246246
}

consensus/XDPoS/engines/engine_v2/engine.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package engine_v2
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"math/big"
78
"os"
@@ -515,6 +516,15 @@ func (x *XDPoS_v2) UpdateMasternodes(chain consensus.ChainReader, header *types.
515516
return nil
516517
}
517518

519+
// VerifyUncles implements consensus.Engine, always returning an error for any
520+
// uncles as this consensus mechanism doesn't permit uncles.
521+
func (x *XDPoS_v2) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
522+
if len(block.Uncles()) > 0 {
523+
return errors.New("uncles not allowed in XDPoS_v2")
524+
}
525+
return nil
526+
}
527+
518528
func (x *XDPoS_v2) VerifyHeader(chain consensus.ChainReader, header *types.Header, fullVerify bool) error {
519529
err := x.verifyHeader(chain, header, nil, fullVerify)
520530
if err != nil {

miner/worker.go

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package miner
1919
import (
2020
"bytes"
2121
"encoding/binary"
22-
"fmt"
2322

2423
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
2524
"github.com/XinFinOrg/XDPoSChain/accounts"
@@ -307,12 +306,7 @@ func (self *worker) update() {
307306
timeout.Reset(time.Duration(minePeriod) * time.Second)
308307

309308
// Handle ChainSideEvent
310-
case ev := <-self.chainSideCh:
311-
if self.config.XDPoS == nil {
312-
self.uncleMu.Lock()
313-
self.possibleUncles[ev.Block.Hash()] = ev.Block
314-
self.uncleMu.Unlock()
315-
}
309+
case <-self.chainSideCh:
316310

317311
// Handle NewTxsEvent
318312
case ev := <-self.txsCh:
@@ -508,17 +502,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
508502
createdAt: time.Now(),
509503
}
510504

511-
if self.config.XDPoS == nil {
512-
// when 08 is processed ancestors contain 07 (quick block)
513-
for _, ancestor := range self.chain.GetBlocksFromHash(parent.Hash(), 7) {
514-
for _, uncle := range ancestor.Uncles() {
515-
work.family.Add(uncle.Hash())
516-
}
517-
work.family.Add(ancestor.Hash())
518-
work.ancestors.Add(ancestor.Hash())
519-
}
520-
}
521-
522505
// Keep track of transactions which return errors so they can be removed
523506
work.tcount = 0
524507
self.current = work
@@ -800,33 +783,15 @@ func (self *worker) commitNewWork() {
800783
work.commitTransactions(self.mux, feeCapacity, txs, specialTxs, self.chain, self.coinbase)
801784
// compute uncles for the new block.
802785
var (
803-
uncles []*types.Header
804-
badUncles []common.Hash
786+
uncles []*types.Header
805787
)
806-
if self.config.XDPoS == nil {
807-
for hash, uncle := range self.possibleUncles {
808-
if len(uncles) == 2 {
809-
break
810-
}
811-
if err := self.commitUncle(work, uncle.Header()); err != nil {
812-
log.Trace("Bad uncle found and will be removed", "hash", hash)
813-
log.Trace(fmt.Sprint(uncle))
814788

815-
badUncles = append(badUncles, hash)
816-
} else {
817-
log.Debug("Committing new uncle to block", "hash", hash)
818-
uncles = append(uncles, uncle.Header())
819-
}
820-
}
821-
for _, hash := range badUncles {
822-
delete(self.possibleUncles, hash)
823-
}
824-
}
825789
// Create the new block to seal with the consensus engine
826790
if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.parentState, work.txs, uncles, work.receipts); err != nil {
827791
log.Error("Failed to finalize block for sealing", "err", err)
828792
return
829793
}
794+
830795
if atomic.LoadInt32(&self.mining) == 1 {
831796
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)))
832797
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
@@ -835,21 +800,6 @@ func (self *worker) commitNewWork() {
835800
self.push(work)
836801
}
837802

838-
func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
839-
hash := uncle.Hash()
840-
if work.uncles.Contains(hash) {
841-
return fmt.Errorf("uncle not unique")
842-
}
843-
if !work.ancestors.Contains(uncle.ParentHash) {
844-
return fmt.Errorf("uncle's parent unknown (%x)", uncle.ParentHash[0:4])
845-
}
846-
if work.family.Contains(hash) {
847-
return fmt.Errorf("uncle already in family (%x)", hash)
848-
}
849-
work.uncles.Add(uncle.Hash())
850-
return nil
851-
}
852-
853803
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) {
854804
gp := new(core.GasPool).AddGas(env.header.GasLimit)
855805
balanceUpdated := map[common.Address]*big.Int{}

0 commit comments

Comments
 (0)