From fc3fe9292f7b4e3464b90853e1122de5d40f1e5f Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 17 Jul 2017 13:49:35 -0400 Subject: [PATCH] fixes from review --- cmd/tendermint/commands/run_node.go | 2 +- consensus/state.go | 7 ++++--- mempool/mempool.go | 16 ++++++---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index fce96edcb..b9df28ab8 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -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: diff --git a/consensus/state.go b/consensus/state.go index ff5b42c7b..878b235a3 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -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)) diff --git a/mempool/mempool.go b/mempool/mempool.go index 160ab7d02..fadeb5dac 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -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