Browse Source

mempool: chan bool -> chan struct{}

pull/2029/head
Ethan Buchman 6 years ago
parent
commit
15b112e669
3 changed files with 8 additions and 8 deletions
  1. +4
    -4
      mempool/mempool.go
  2. +2
    -2
      mempool/mempool_test.go
  3. +2
    -2
      state/services.go

+ 4
- 4
mempool/mempool.go View File

@ -78,7 +78,7 @@ type Mempool struct {
recheckCursor *clist.CElement // next expected response
recheckEnd *clist.CElement // re-checking stops here
notifiedTxsAvailable bool
txsAvailable chan bool // fires once for each height, when the mempool is not empty
txsAvailable chan struct{} // fires once for each height, when the mempool is not empty
// Keep a cache of already-seen txs.
// This reduces the pressure on the proxyApp.
@ -130,7 +130,7 @@ func NewMempool(
// 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) EnableTxsAvailable() {
mem.txsAvailable = make(chan bool, 1)
mem.txsAvailable = make(chan struct{}, 1)
}
// SetLogger sets the Logger.
@ -348,7 +348,7 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
// TxsAvailable returns a channel which fires once for every height,
// and only when transactions are available in the mempool.
// NOTE: the returned channel may be nil if EnableTxsAvailable was not called.
func (mem *Mempool) TxsAvailable() <-chan bool {
func (mem *Mempool) TxsAvailable() <-chan struct{} {
return mem.txsAvailable
}
@ -360,7 +360,7 @@ func (mem *Mempool) notifyTxsAvailable() {
// channel cap is 1, so this will send once
mem.notifiedTxsAvailable = true
select {
case mem.txsAvailable <- true:
case mem.txsAvailable <- struct{}{}:
default:
}
}


+ 2
- 2
mempool/mempool_test.go View File

@ -38,7 +38,7 @@ func newMempoolWithApp(cc proxy.ClientCreator) *Mempool {
return mempool
}
func ensureNoFire(t *testing.T, ch <-chan bool, timeoutMS int) {
func ensureNoFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
select {
case <-ch:
@ -47,7 +47,7 @@ func ensureNoFire(t *testing.T, ch <-chan bool, timeoutMS int) {
}
}
func ensureFire(t *testing.T, ch <-chan bool, timeoutMS int) {
func ensureFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
select {
case <-ch:


+ 2
- 2
state/services.go View File

@ -27,7 +27,7 @@ type Mempool interface {
Flush()
FlushAppConn() error
TxsAvailable() <-chan bool
TxsAvailable() <-chan struct{}
EnableTxsAvailable()
}
@ -43,7 +43,7 @@ func (m MockMempool) Reap(n int) types.Txs { retur
func (m MockMempool) Update(height int64, txs types.Txs) error { return nil }
func (m MockMempool) Flush() {}
func (m MockMempool) FlushAppConn() error { return nil }
func (m MockMempool) TxsAvailable() <-chan bool { return make(chan bool) }
func (m MockMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
func (m MockMempool) EnableTxsAvailable() {}
//------------------------------------------------------


Loading…
Cancel
Save