Skip to content

Commit 87d7f63

Browse files
committed
fix: determine F3 participants relative to current network name
1 parent 8ad4cbc commit 87d7f63

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

pkg/vf3/f3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (fff *F3) runSigningLoop(ctx context.Context) {
177177
clear(alreadyParticipated)
178178
}
179179

180-
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
180+
participants := fff.leaser.getParticipantsByInstance(mb.NetworkName, mb.Payload.Instance)
181181
for _, id := range participants {
182182
if _, ok := alreadyParticipated[id]; ok {
183183
continue

pkg/vf3/participation_lease.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,25 @@ func (l *leaser) participate(ticket types.F3ParticipationTicket) (types.F3Partic
108108
return newLease, nil
109109
}
110110

111-
func (l *leaser) getParticipantsByInstance(instance uint64) []uint64 {
111+
func (l *leaser) getParticipantsByInstance(network gpbft.NetworkName, instance uint64) []uint64 {
112112
l.mutex.Lock()
113113
defer l.mutex.Unlock()
114+
currentManifest, _ := l.status()
115+
currentNetwork := currentManifest.NetworkName
116+
if currentNetwork != network {
117+
return nil
118+
}
114119
var participants []uint64
115120
for id, lease := range l.leases {
116-
if instance > lease.ToInstance() {
121+
if currentNetwork != lease.Network {
122+
// Lazily delete any lease that does not belong to network, likely acquired from
123+
// prior manifests.
124+
delete(l.leases, id)
125+
log.Warnf("lost F3 participation lease for miner %d at instance %d due to network mismatch: %s != %s", id, instance, currentNetwork, lease.Network)
126+
} else if instance > lease.ToInstance() {
117127
// Lazily delete the expired leases.
118128
delete(l.leases, id)
129+
log.Warnf("lost F3 participation lease for miner %d due to instance (%d) > lease to instance (%d)", id, instance, lease.ToInstance())
119130
} else {
120131
participants = append(participants, id)
121132
}

pkg/vf3/participation_lease_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ func TestLeaser(t *testing.T) {
4141
require.NoError(t, err)
4242

4343
// Both participants should still be valid.
44-
participants := subject.getParticipantsByInstance(11)
44+
participants := subject.getParticipantsByInstance(testManifest.NetworkName, 11)
4545
require.Len(t, participants, 2)
4646
require.Contains(t, participants, uint64(123))
4747
require.Contains(t, participants, uint64(456))
4848

4949
// After instance 16, only participant 456 should be valid.
50-
participants = subject.getParticipantsByInstance(16)
50+
participants = subject.getParticipantsByInstance(testManifest.NetworkName, 16)
5151
require.Len(t, participants, 1)
5252
require.Contains(t, participants, uint64(456))
5353

5454
// After instance 17, no participant must have a lease.
55-
participants = subject.getParticipantsByInstance(17)
55+
participants = subject.getParticipantsByInstance(testManifest.NetworkName, 17)
5656
require.Empty(t, participants)
5757
})
5858
t.Run("expired ticket", func(t *testing.T) {

0 commit comments

Comments
 (0)