diff --git a/pkg/phantom/queue.go b/pkg/phantom/queue.go index a571809..b825535 100644 --- a/pkg/phantom/queue.go +++ b/pkg/phantom/queue.go @@ -97,14 +97,19 @@ func (q *Queue) Pop() *chainhash.Hash { } func (q *Queue) Peek() *chainhash.Hash { - q.muxex.Lock() - - defer q.muxex.Unlock() - - if q.count == 0 { - return nil - } - return q.nodes[q.head] + q.muxex.Lock() + defer q.muxex.Unlock() + + if q.count == 0 { + return nil + } + + // Get the last element by accessing the element at the tail index + index := q.tail - 1 + if index < 0 { + index = len(q.nodes) - 1 + } + return q.nodes[index] } func (q *Queue) Len() int { @@ -113,4 +118,4 @@ func (q *Queue) Len() int { defer q.muxex.Unlock() return q.count -} \ No newline at end of file +}