Merge pull request #416 from thanhnguyennguyen/ignore-txs-at-checkpoint

Won't grasp txs at checkpoint
This commit is contained in:
Tuna 2019-01-29 10:23:30 +07:00 committed by GitHub
commit 8ce071d3b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -900,7 +900,8 @@ func (c *Posv) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan
return nil, errUnknownBlock return nil, errUnknownBlock
} }
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing) // For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
if c.config.Period == 0 && len(block.Transactions()) == 0 { // checkpoint blocks have no tx
if c.config.Period == 0 && len(block.Transactions()) == 0 && number % c.config.Epoch != 0 {
return nil, errWaitTransactions return nil, errWaitTransactions
} }
// Don't hold the signer fields for the entire sealing procedure // Don't hold the signer fields for the entire sealing procedure

View file

@ -583,14 +583,22 @@ func (self *worker) commitNewWork() {
if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 { if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(work.state) misc.ApplyDAOHardFork(work.state)
} }
pending, err := self.eth.TxPool().Pending() // won't grasp txs at checkpoint
if err != nil { var (
log.Error("Failed to fetch pending transactions", "err", err) txs *types.TransactionsByPriceAndNonce
return specialTxs types.Transactions
)
if self.config.Posv != nil && header.Number.Uint64() % self.config.Posv.Epoch != 0 {
pending, err := self.eth.TxPool().Pending()
if err != nil {
log.Error("Failed to fetch pending transactions", "err", err)
return
}
txs, specialTxs = types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
} }
txs, specialTxs := types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
work.commitTransactions(self.mux, txs, specialTxs, self.chain, self.coinbase) work.commitTransactions(self.mux, txs, specialTxs, self.chain, self.coinbase)
// compute uncles for the new block. // compute uncles for the new block.
var ( var (
uncles []*types.Header uncles []*types.Header
@ -621,7 +629,7 @@ func (self *worker) commitNewWork() {
return return
} }
if atomic.LoadInt32(&self.mining) == 1 { 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))) 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) self.unconfirmed.Shift(work.Block.NumberU64() - 1)
self.lastParentBlockCommit = parent.Hash().Hex() self.lastParentBlockCommit = parent.Hash().Hex()
} }
@ -697,6 +705,10 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
log.Trace("Not enough gas for further transactions", "gp", gp) log.Trace("Not enough gas for further transactions", "gp", gp)
break break
} }
if txs == nil {
log.Info("this block has no transaction")
break
}
// Retrieve the next transaction and abort if all done // Retrieve the next transaction and abort if all done
tx := txs.Peek() tx := txs.Peek()
if tx == nil { if tx == nil {