Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions mempool/internal/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ func (iq *Queue[Tx]) Push(tx *Tx) <-chan error {
sub := make(chan error, 1)

if tx == nil {
// TODO: when do we expect this to happen?
close(sub)
return sub
}
if iq.isFull() {

iq.lock.Lock()
if iq.maxSize > 0 && iq.queue.Len() >= iq.maxSize {
iq.lock.Unlock()
sub <- ErrQueueFull
close(sub)
return sub
}

iq.lock.Lock()
iq.queue.PushBack(insertItem[Tx]{tx: tx, sub: sub})
iq.lock.Unlock()

Expand Down Expand Up @@ -168,14 +168,6 @@ func (iq *Queue[Tx]) insertTxs(txs []*Tx) []error {
return errs
}

// isFull returns true if the queue is at capacity and cannot accept anymore
// Tx's, false otherwise.
func (iq *Queue[Tx]) isFull() bool {
iq.lock.RLock()
defer iq.lock.RUnlock()
return iq.queue.Len() >= iq.maxSize
}

// Close stops the main loop of the queue.
func (iq *Queue[Tx]) Close() {
close(iq.done)
Expand Down
Loading