mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-26 08:26:20 +00:00
change difficulty block in XDPoS
This commit is contained in:
parent
176b51f1f8
commit
bbadba469b
4 changed files with 12 additions and 8 deletions
|
|
@ -831,7 +831,7 @@ func (pool *TxPool) promoteSpecialTx(addr common.Address, tx *types.Transaction)
|
|||
go func() {
|
||||
for _, btx := range broadcastTxs {
|
||||
pool.specialTxFeed.Send(TxPreEvent{btx})
|
||||
log.Debug("Pooled new special transaction", "hash", tx.Hash(), "from", addr, "to", tx.To(), "nonce", tx.Nonce())
|
||||
log.Trace("Pooled new special transaction", "hash", tx.Hash(), "from", addr, "to", tx.To(), "nonce", tx.Nonce())
|
||||
}
|
||||
}()
|
||||
return true, nil
|
||||
|
|
|
|||
|
|
@ -605,7 +605,7 @@ func (f *Fetcher) rescheduleComplete(complete *time.Timer) {
|
|||
func (f *Fetcher) enqueue(peer string, block *types.Block) {
|
||||
hash := block.Hash()
|
||||
if f.knowns.Contains(hash) {
|
||||
log.Debug("Discarded propagated block, knowns block", "peer", peer, "number", block.Number(), "hash", hash, "limit", blockLimit)
|
||||
log.Debug("Discarded propagated block, known block", "peer", peer, "number", block.Number(), "hash", hash, "limit", blockLimit)
|
||||
return
|
||||
}
|
||||
// Ensure the peer isn't DOSing us
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ func (pm *ProtocolManager) Start(maxPeers int) {
|
|||
pm.txSub = pm.txpool.SubscribeTxPreEvent(pm.txCh)
|
||||
go pm.txBroadcastLoop()
|
||||
|
||||
// broadcast special transactions
|
||||
// broadcast special transactions
|
||||
pm.specialTxCh = make(chan core.TxPreEvent, txChanSize)
|
||||
pm.specialTxSub = pm.txpool.SubscribeSpecialTxPreEvent(pm.specialTxCh)
|
||||
go pm.specialTxBroadcastLoop()
|
||||
|
|
@ -651,14 +651,17 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
trueTD = new(big.Int).Sub(request.TD, request.Block.Difficulty())
|
||||
)
|
||||
// Update the peers total difficulty if better than the previous
|
||||
if _, td := p.Head(); trueTD.Cmp(td) > 0 {
|
||||
_, td := p.Head()
|
||||
currentBlock := pm.blockchain.CurrentBlock()
|
||||
currentTd := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
||||
log.Debug("NewBlockMsg", "p", p, "number", request.Block.NumberU64(), "trueTD", trueTD, "td", td, "currentTd", currentTd)
|
||||
if trueTD.Cmp(td) > 0 {
|
||||
p.SetHead(trueHead, trueTD)
|
||||
|
||||
// Schedule a sync if above ours. Note, this will not fire a sync for a gap of
|
||||
// a singe block (as the true TD is below the propagated block), however this
|
||||
// scenario should easily be covered by the fetcher.
|
||||
currentBlock := pm.blockchain.CurrentBlock()
|
||||
if trueTD.Cmp(pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())) > 0 {
|
||||
if trueTD.Cmp(currentTd) > 0 {
|
||||
go pm.synchronise(p)
|
||||
}
|
||||
}
|
||||
|
|
@ -705,7 +708,7 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
|
|||
return
|
||||
}
|
||||
// Send the block to a subset of our peers
|
||||
for _, peer := range peers {
|
||||
for _, peer := range peers {
|
||||
peer.SendNewBlock(block, td)
|
||||
}
|
||||
log.Trace("Propagated block", "hash", hash, "recipients", len(peers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
|
||||
|
|
@ -739,7 +742,7 @@ func (pm *ProtocolManager) BroadcastSpecialTx(hash common.Hash, tx *types.Transa
|
|||
for _, peer := range peers {
|
||||
peer.SendSpecialTransactions(tx)
|
||||
}
|
||||
log.Debug("Broadcast special transaction", "hash", hash, "recipients", len(peers))
|
||||
log.Trace("Broadcast special transaction", "hash", hash, "recipients", len(peers))
|
||||
}
|
||||
|
||||
// Mined broadcast loop
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
|||
td := pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
||||
|
||||
pHead, pTd := peer.Head()
|
||||
log.Debug("ProtocolManager synchronise ", "p", peer, "pTd", pTd, "currentTd", td)
|
||||
if pTd.Cmp(td) <= 0 {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue