Merge pull request #290 from nguyenbatam/change_difficulty_block_in_posv

change difficulty block in POSV consensus
This commit is contained in:
Tam Nguyen 2018-11-21 10:01:14 +07:00 committed by GitHub
commit f95c606469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 8 deletions

View file

@ -742,7 +742,7 @@ func (c *Posv) Prepare(chain consensus.ChainReader, header *types.Header) error
c.lock.RUnlock()
}
// Set the correct difficulty
header.Difficulty = CalcDifficulty(snap, c.signer)
header.Difficulty = big.NewInt(1)
// Ensure the extra data has all it's components
if len(header.Extra) < extraVanity {

View file

@ -828,7 +828,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

View file

@ -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

View file

@ -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)
}
}
@ -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

View file

@ -169,8 +169,8 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
// Make sure the peer's TD is higher than our own
currentBlock := pm.blockchain.CurrentBlock()
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
}