Skip to content

Commit

Permalink
fix: when returning a partially used lease, trim its ValidityTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Nov 8, 2024
1 parent c425e59 commit f1fcbb4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/filecoin-project/go-commp-utils v0.1.3
github.com/filecoin-project/go-crypto v0.1.0
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6
github.com/filecoin-project/go-f3 v0.7.0
github.com/filecoin-project/go-f3 v0.7.2
github.com/filecoin-project/go-fil-commcid v0.2.0
github.com/filecoin-project/go-fil-markets v1.28.2
github.com/filecoin-project/go-jsonrpc v0.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6 h1:EsbXTWsBKT764qtX4M
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6/go.mod h1:cX1acvFVWC5EXnnmFPWEFXbO7nLUdSZa+nqgi1QpTpw=
github.com/filecoin-project/go-ds-versioning v0.1.2 h1:to4pTadv3IeV1wvgbCbN6Vqd+fu+7tveXgv/rCEZy6w=
github.com/filecoin-project/go-ds-versioning v0.1.2/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4=
github.com/filecoin-project/go-f3 v0.7.0 h1:JNo39SAELT5hEn+rmQZbSJQBJfmGJtp70RfyWJrIayY=
github.com/filecoin-project/go-f3 v0.7.0/go.mod h1:QoxuoK4aktNZD1R/unlhNbhV6TnlNTAbA/QODCnAjak=
github.com/filecoin-project/go-f3 v0.7.2 h1:YQgxxSMzCSQniZqwDjyNkIRz3pnzCtOrtaS5ldIaUDA=
github.com/filecoin-project/go-f3 v0.7.2/go.mod h1:QoxuoK4aktNZD1R/unlhNbhV6TnlNTAbA/QODCnAjak=
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.2.0 h1:B+5UX8XGgdg/XsdUpST4pEBviKkFOw+Fvl2bLhSKGpI=
Expand Down
2 changes: 2 additions & 0 deletions pkg/vf3/participation_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (l *leaser) participate(ticket types.F3ParticipationTicket) (types.F3Partic
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
20 changes: 20 additions & 0 deletions pkg/vf3/participation_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ func TestLeaser(t *testing.T) {
require.Nil(t, ticket)
})

t.Run("participate", func(t *testing.T) {
ticket, err := subject.getOrRenewParticipationTicket(123, nil, 5)
require.NoError(t, err)
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(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
ticket1, err := subject.getOrRenewParticipationTicket(123, nil, 4)
Expand Down

0 comments on commit f1fcbb4

Please sign in to comment.