From 52229de8462dc1414acab832e9c955e7e2e4e55f Mon Sep 17 00:00:00 2001 From: Nico Vergauwen Date: Thu, 6 May 2021 21:01:49 +0200 Subject: [PATCH] pm: refresh ticket params before expiry from sender side --- CHANGELOG_PENDING.md | 1 + pm/recipient.go | 1 + pm/sender.go | 4 +++- pm/sender_test.go | 13 ++++++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 0ed519ee6e..d2622590a0 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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 diff --git a/pm/recipient.go b/pm/recipient.go index 894b2b0b75..6823d0f39f 100644 --- a/pm/recipient.go +++ b/pm/recipient.go @@ -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 diff --git a/pm/sender.go b/pm/sender.go index 570c3864b7..0efdf849ad 100644 --- a/pm/sender.go +++ b/pm/sender.go @@ -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 } diff --git a/pm/sender_test.go b/pm/sender_test.go index 8217ed5106..9bd77a246a 100644 --- a/pm/sender_test.go +++ b/pm/sender_test.go @@ -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)