p2p: remove unused ticketRefByWaitTime and nextTicketReg (#1709)

This commit is contained in:
wit liu 2025-11-14 18:59:39 +08:00 committed by GitHub
parent 47952ac264
commit 4faefad7a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,6 @@ import (
"fmt"
"math"
"math/rand"
"sort"
"time"
"github.com/XinFinOrg/XDPoSChain/common"
@ -140,7 +139,6 @@ type ticketStore struct {
lastBucketFetched timeBucket
nextTicketCached *ticketRef
nextTicketReg mclock.AbsTime
searchTopicMap map[Topic]searchTopic
nextTopicQueryCleanup mclock.AbsTime
@ -287,39 +285,6 @@ func (s *ticketStore) ticketsInWindow(topic Topic) []ticketRef {
return tickets
}
func (s *ticketStore) removeExcessTickets(t Topic) {
tickets := s.ticketsInWindow(t)
if len(tickets) <= wantTicketsInWindow {
return
}
sort.Sort(ticketRefByWaitTime(tickets))
for _, r := range tickets[wantTicketsInWindow:] {
s.removeTicketRef(r)
}
}
type ticketRefByWaitTime []ticketRef
// Len is the number of elements in the collection.
func (s ticketRefByWaitTime) Len() int {
return len(s)
}
func (ref ticketRef) waitTime() mclock.AbsTime {
return ref.t.regTime[ref.idx] - ref.t.issueTime
}
// Less reports whether the element with
// index i should sort before the element with index j.
func (s ticketRefByWaitTime) Less(i, j int) bool {
return s[i].waitTime() < s[j].waitTime()
}
// Swap swaps the elements with indexes i and j.
func (s ticketRefByWaitTime) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s *ticketStore) addTicketRef(r ticketRef) {
topic := r.t.topics[r.idx]
tickets := s.tickets[topic]