Merge pull request #233 from nguyenbatam/m1_mine_block_but_only_broadcast

m1 mine block but only broadcast block wait m2 validate
This commit is contained in:
Tuna 2018-10-25 10:05:37 +07:00 committed by GitHub
commit d11350503b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View file

@ -20,7 +20,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"math/big"
"sync"
"sync/atomic"
@ -706,11 +705,10 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
return
}
// Send the block to a subset of our peers
transfer := peers[:int(math.Sqrt(float64(len(peers))))]
for _, peer := range transfer {
for _, peer := range peers {
peer.SendNewBlock(block, td)
}
log.Trace("Propagated block", "hash", hash, "recipients", len(transfer), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
log.Trace("Propagated block", "hash", hash, "recipients", len(peers), "duration", common.PrettyDuration(time.Since(block.ReceivedAt)))
return
}
// Otherwise if the block is indeed in out own chain, announce it

View file

@ -301,6 +301,10 @@ func (self *worker) wait() {
continue
}
block := result.Block
if self.config.Posv != nil && block.NumberU64() >= self.config.Posv.Epoch {
self.mux.Post(core.NewMinedBlockEvent{Block: block})
continue
}
work := result.Work
// Update the block hash in all logs since it is now available and not when the
@ -641,7 +645,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
// Check whether the tx is replay protected. If we're not in the EIP155 hf
// phase, start ignoring the sender until we do.
if tx.Protected() && !env.config.IsEIP155(env.header.Number) {
log.Debug("Ignoring reply protected special transaction", "hash", tx.Hash(), "eip155", env.config.EIP155Block)
log.Trace("Ignoring reply protected special transaction", "hash", tx.Hash(), "eip155", env.config.EIP155Block)
continue
}
// Start executing the transaction
@ -650,11 +654,11 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
switch err {
case core.ErrNonceTooLow:
// New head notification data race between the transaction pool and miner, shift
log.Debug("Skipping special transaction with low nonce", "sender", from, "nonce", tx.Nonce(), "to", tx.To())
log.Trace("Skipping special transaction with low nonce", "sender", from, "nonce", tx.Nonce(), "to", tx.To())
case core.ErrNonceTooHigh:
// Reorg notification data race between the transaction pool and miner, skip account =
log.Debug("Skipping account with special transaction hight nonce", "sender", from, "nonce", tx.Nonce(), "to", tx.To())
log.Trace("Skipping account with special transaction hight nonce", "sender", from, "nonce", tx.Nonce(), "to", tx.To())
case nil:
// Everything ok, collect the logs and shift in the next transaction from the same account