Skip to content

Commit

Permalink
fixup! db,pm: avoid redeeming expired tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Oct 20, 2020
1 parent 3a458d2 commit f0ed105
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pm/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/golang/glog"
)

const ticketValidityPeriod = 2

// RedeemableEmitter is an interface that describes methods for
// emitting redeemable tickets
type RedeemableEmitter interface {
Expand Down Expand Up @@ -77,7 +79,7 @@ func (q *ticketQueue) Redeemable() chan *redemption {

// Length returns the current length of the queue
func (q *ticketQueue) Length() (int, error) {
return q.store.WinningTicketCount(q.sender, new(big.Int).Sub(q.tm.LastInitializedRound(), big.NewInt(2)).Int64())
return q.store.WinningTicketCount(q.sender, new(big.Int).Sub(q.tm.LastInitializedRound(), big.NewInt(ticketValidityPeriod)).Int64())
}

// startQueueLoop blocks until the ticket queue is non-empty. When the queue is non-empty
Expand Down Expand Up @@ -106,7 +108,7 @@ ticketLoop:
continue
}
for i := 0; i < int(numTickets); i++ {
nextTicket, err := q.store.SelectEarliestWinningTicket(q.sender, new(big.Int).Sub(q.tm.LastInitializedRound(), big.NewInt(2)).Int64())
nextTicket, err := q.store.SelectEarliestWinningTicket(q.sender, new(big.Int).Sub(q.tm.LastInitializedRound(), big.NewInt(ticketValidityPeriod)).Int64())
if err != nil {
glog.Errorf("Unable select earliest winning ticket err=%v", err)
continue ticketLoop
Expand Down

0 comments on commit f0ed105

Please sign in to comment.