Skip to content

Commit

Permalink
pm: refresh ticket params before expiry from sender side
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed May 18, 2021
1 parent c14af11 commit 52229de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- \#1875 Update 'trying to transcode' log statement with manifestID (@kyriediculous)
- \#1837 Only log discovery errors when request is not cancelled (@yondonfu)
- \#1877 Refresh TicketParams for the active session before expiry (@kyriediculous)

#### Orchestrator

Expand Down
1 change: 1 addition & 0 deletions pm/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var errInsufficientSenderReserve = errors.New("insufficient sender reserve")
var maxWinProb = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1))

var paramsExpirationBlock = big.NewInt(10)
var paramsExpiryBuffer = int64(1)

// Recipient is an interface which describes an object capable
// of receiving tickets
Expand Down
4 changes: 3 additions & 1 deletion pm/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func (s *sender) validateTicketParams(ticketParams *TicketParams, numTickets int
}

latestBlock := s.timeManager.LastSeenBlock()
if ticketParams.ExpirationBlock.Cmp(latestBlock) <= 0 {

currentBuffer := new(big.Int).Sub(latestBlock, ticketParams.ExpirationBlock).Int64()
if currentBuffer > paramsExpiryBuffer {
return ErrTicketParamsExpired
}

Expand Down
13 changes: 12 additions & 1 deletion pm/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,24 @@ func TestValidateTicketParams_ExpiredParams_ReturnsError(t *testing.T) {
sender.maxEV = big.NewRat(100, 1)
sender.depositMultiplier = 2

sender.timeManager.(*stubTimeManager).lastSeenBlock = big.NewInt(100)

// test expired
ticketParams := defaultTicketParams(t, RandAddress())
ticketParams.ExpirationBlock = big.NewInt(int64(-1))
ticketParams.ExpirationBlock = big.NewInt(int64(1))
err := sender.ValidateTicketParams(&ticketParams)
assert.EqualError(t, err, ErrTicketParamsExpired.Error())

// test within 10% of expiry
ticketParams.ExpirationBlock = big.NewInt(99)
err = sender.ValidateTicketParams(&ticketParams)
assert.Nil(t, err)

// test nil
ticketParams.ExpirationBlock = big.NewInt(105)
err = sender.ValidateTicketParams(&ticketParams)
assert.Nil(t, err)

ticketParams.ExpirationBlock = big.NewInt(0)
err = sender.ValidateTicketParams(&ticketParams)
assert.Nil(t, err)
Expand Down

0 comments on commit 52229de

Please sign in to comment.