diff --git a/pkg/vf3/f3.go b/pkg/vf3/f3.go index b5b95be1ae..baafa85b31 100644 --- a/pkg/vf3/f3.go +++ b/pkg/vf3/f3.go @@ -177,7 +177,7 @@ func (fff *F3) runSigningLoop(ctx context.Context) { clear(alreadyParticipated) } - participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance) + participants := fff.leaser.getParticipantsByInstance(mb.NetworkName, mb.Payload.Instance) for _, id := range participants { if _, ok := alreadyParticipated[id]; ok { continue diff --git a/pkg/vf3/participation_lease.go b/pkg/vf3/participation_lease.go index 70fac54f21..230c5ea026 100644 --- a/pkg/vf3/participation_lease.go +++ b/pkg/vf3/participation_lease.go @@ -108,14 +108,25 @@ func (l *leaser) participate(ticket types.F3ParticipationTicket) (types.F3Partic return newLease, nil } -func (l *leaser) getParticipantsByInstance(instance uint64) []uint64 { +func (l *leaser) getParticipantsByInstance(network gpbft.NetworkName, instance uint64) []uint64 { l.mutex.Lock() defer l.mutex.Unlock() + currentManifest, _ := l.status() + currentNetwork := currentManifest.NetworkName + if currentNetwork != network { + return nil + } var participants []uint64 for id, lease := range l.leases { - if instance > lease.ToInstance() { + if currentNetwork != lease.Network { + // Lazily delete any lease that does not belong to network, likely acquired from + // prior manifests. + delete(l.leases, id) + log.Warnf("lost F3 participation lease for miner %d at instance %d due to network mismatch: %s != %s", id, instance, currentNetwork, lease.Network) + } else if instance > lease.ToInstance() { // Lazily delete the expired leases. delete(l.leases, id) + log.Warnf("lost F3 participation lease for miner %d due to instance (%d) > lease to instance (%d)", id, instance, lease.ToInstance()) } else { participants = append(participants, id) } diff --git a/pkg/vf3/participation_lease_test.go b/pkg/vf3/participation_lease_test.go index 7cf5e2d335..1510e6a984 100644 --- a/pkg/vf3/participation_lease_test.go +++ b/pkg/vf3/participation_lease_test.go @@ -41,18 +41,18 @@ func TestLeaser(t *testing.T) { require.NoError(t, err) // Both participants should still be valid. - participants := subject.getParticipantsByInstance(11) + participants := subject.getParticipantsByInstance(testManifest.NetworkName, 11) require.Len(t, participants, 2) require.Contains(t, participants, uint64(123)) require.Contains(t, participants, uint64(456)) // After instance 16, only participant 456 should be valid. - participants = subject.getParticipantsByInstance(16) + participants = subject.getParticipantsByInstance(testManifest.NetworkName, 16) require.Len(t, participants, 1) require.Contains(t, participants, uint64(456)) // After instance 17, no participant must have a lease. - participants = subject.getParticipantsByInstance(17) + participants = subject.getParticipantsByInstance(testManifest.NetworkName, 17) require.Empty(t, participants) }) t.Run("expired ticket", func(t *testing.T) {