Browse Source

fixes from review

pull/591/head
Ethan Buchman 7 years ago
parent
commit
fc3fe9292f
3 changed files with 11 additions and 14 deletions
  1. +1
    -1
      cmd/tendermint/commands/run_node.go
  2. +4
    -3
      consensus/state.go
  3. +6
    -10
      mempool/mempool.go

+ 1
- 1
cmd/tendermint/commands/run_node.go View File

@ -47,7 +47,7 @@ func AddNodeFlags(cmd *cobra.Command) {
cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")
// consensus flags
cmd.Flags().Bool("consensus.no_empty_blocks", config.Consensus.NoEmptyBlocks, "Prevent empty blocks from being proposed by correct processes")
cmd.Flags().Bool("consensus.no_empty_blocks", config.Consensus.NoEmptyBlocks, "Only produce blocks when there are txs and when the AppHash changes")
}
// Users wishing to:


+ 4
- 3
consensus/state.go View File

@ -790,9 +790,9 @@ func (cs *ConsensusState) enterNewRound(height int, round int) {
func (cs *ConsensusState) waitForTxs(height, round int) {
// if we're the proposer, start a heartbeat routine
// to tell other peers we're just waiting for txs (for debugging)
done := make(chan struct{})
defer close(done)
if cs.isProposer() {
done := make(chan struct{})
defer close(done)
go cs.proposerHeartbeat(done)
}
@ -816,7 +816,8 @@ func (cs *ConsensusState) proposerHeartbeat(done chan struct{}) {
}
}
// Enter: from enter NewRound(height,round), once txs are in the mempool
// Enter (!NoEmptyBlocks): from enterNewRound(height,round)
// Enter (NoEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
func (cs *ConsensusState) enterPropose(height int, round int) {
if cs.Height != height || round < cs.Round || (cs.Round == round && RoundStepPropose <= cs.Step) {
cs.Logger.Debug(cmn.Fmt("enterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))


+ 6
- 10
mempool/mempool.go View File

@ -100,6 +100,7 @@ func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool) *M
// FireOnTxsAvailable initializes the TxsAvailable channel,
// ensuring it will trigger once every height when transactions are available.
// NOTE: not thread safe - should only be called once, on startup
func (mem *Mempool) FireOnTxsAvailable() {
mem.txsAvailable = make(chan struct{}, 1)
}
@ -225,7 +226,7 @@ func (mem *Mempool) resCbNormal(req *abci.Request, res *abci.Response) {
tx: req.GetCheckTx().Tx,
}
mem.txs.PushBack(memTx)
mem.alertIfTxsAvailable()
mem.notifyIfTxsAvailable()
} else {
// ignore bad transaction
mem.logger.Info("Bad Transaction", "res", r)
@ -268,20 +269,13 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
atomic.StoreInt32(&mem.rechecking, 0)
mem.logger.Info("Done rechecking txs")
mem.alertIfTxsAvailable()
mem.notifyIfTxsAvailable()
}
default:
// ignore other messages
}
}
func (mem *Mempool) alertIfTxsAvailable() {
if !mem.notifiedTxsAvailable && mem.Size() > 0 {
mem.notifiedTxsAvailable = true
mem.txsAvailable <- struct{}{}
}
}
// TxsAvailable returns a channel which fires once for every height,
// and only when transactions are available in the mempool.
// XXX: Will panic if mem.FireOnTxsAvailable() has not been called.
@ -292,7 +286,7 @@ func (mem *Mempool) TxsAvailable() chan struct{} {
return mem.txsAvailable
}
func (mem *Mempool) alertIfTxsAvailable() {
func (mem *Mempool) notifyIfTxsAvailable() {
if mem.txsAvailable != nil &&
!mem.notifiedTxsAvailable && mem.Size() > 0 {
@ -345,6 +339,8 @@ func (mem *Mempool) Update(height int, txs types.Txs) {
}
// Set height
// NOTE: the height is not set until Update is first called
// (so it will be wrong after a restart until the next block)
mem.height = height
mem.notifiedTxsAvailable = false


Loading…
Cancel
Save