From 101147994ad267aa6f2d986304837a64dd5d9124 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 4 Apr 2019 12:55:55 +0200 Subject: [PATCH] add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. --- mempool/clist_mempool.go | 5 ----- mempool/mempool.go | 8 +++++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index bbff3b98f..b6694c9b2 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -194,15 +194,10 @@ func (mem *CListMempool) Flush() { _ = atomic.SwapInt64(&mem.txsBytes, 0) } -// TxsFront returns the first transaction in the ordered list for peer -// goroutines to call .NextWait() on. func (mem *CListMempool) TxsFront() *clist.CElement { return mem.txs.Front() } -// TxsWaitChan returns a channel to wait on transactions. It will be closed -// once the mempool is not empty (ie. the internal `mem.txs` has at least one -// element) func (mem *CListMempool) TxsWaitChan() <-chan struct{} { return mem.txs.WaitChan() } diff --git a/mempool/mempool.go b/mempool/mempool.go index 6a789f26d..b04f3f68c 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -35,8 +35,14 @@ type Mempool interface { // transactions (~ all available transactions). ReapMaxTxs(max int) types.Txs - // UNSAFE + // TxsWaitChan returns a channel to wait on transactions. It will be closed + // once the mempool is not empty (ie. the internal `mem.txs` has at least one + // element) TxsWaitChan() <-chan struct{} + + // TxsFront returns the first transaction in the ordered list for peer + // goroutines to call .NextWait() on. + // FIXME: leaking implementation details! TxsFront() *clist.CElement // Lock locks the mempool. The consensus must be able to hold lock to safely update.