Skip to content

Commit

Permalink
fix(f3): when returning a partially used lease, trim its ValidityTerm (
Browse files Browse the repository at this point in the history
…#12667)

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
  • Loading branch information
Kubuxu authored Nov 1, 2024
1 parent 2657108 commit 49f3b55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chain/lf3/participation_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (l *leaser) participate(ticket api.F3ParticipationTicket) (api.F3Participat
if found {
// short-circuite for reparticipation.
if currentLease == newLease {
newLease.ValidityTerm = newLease.ToInstance() - instant.ID
newLease.FromInstance = instant.ID
return newLease, nil
}
if currentLease.Network == newLease.Network && currentLease.FromInstance > newLease.FromInstance {
Expand Down
9 changes: 9 additions & 0 deletions chain/lf3/participation_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func TestLeaser(t *testing.T) {
require.Equal(t, issuer.String(), lease.Issuer)
require.Equal(t, uint64(10), lease.FromInstance) // Current instance (10) + offset (5)
require.Equal(t, uint64(5), lease.ValidityTerm) // Current instance (10) + offset (5)

progress.currentInstance += 2

lease, err = subject.participate(ticket)
require.NoError(t, err)
require.Equal(t, uint64(123), lease.MinerID)
require.Equal(t, issuer.String(), lease.Issuer)
require.Equal(t, uint64(12), lease.FromInstance) // Current instance (10) + offset (5)
require.Equal(t, uint64(3), lease.ValidityTerm) // Current instance (10) + offset (5)
})
t.Run("get participants", func(t *testing.T) {
progress.currentInstance = 11
Expand Down

0 comments on commit 49f3b55

Please sign in to comment.