Skip to content

Commit 5efee6a

Browse files
committed
fix(f3): send the last gpbft message for each new participant
Otherwise, we can get into a situation where everyone is waiting for the next round to participate, but we'll never get there because not enough participants acted in the current round.
1 parent e769bdf commit 5efee6a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

chain/lf3/f3.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,28 @@ func (fff *F3) runSigningLoop(ctx context.Context) {
141141

142142
msgCh := fff.inner.MessagesToSign()
143143

144-
loop:
144+
var mb *gpbft.MessageBuilder
145+
alreadyParticipated := make(map[uint64]struct{})
145146
for ctx.Err() == nil {
146147
select {
147148
case <-ctx.Done():
148149
return
149-
case mb, ok := <-msgCh:
150-
if !ok {
151-
continue loop
150+
case <-fff.leaser.notifyParticipation:
151+
if mb == nil {
152+
continue
152153
}
153-
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
154-
for _, id := range participants {
155-
if err := participateOnce(ctx, mb, id); err != nil {
156-
log.Errorf("while participating for miner f0%d: %+v", id, err)
157-
}
154+
case mb = <-msgCh: // never closed
155+
clear(alreadyParticipated)
156+
}
157+
158+
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
159+
for _, id := range participants {
160+
if _, ok := alreadyParticipated[id]; ok {
161+
continue
162+
} else if err := participateOnce(ctx, mb, id); err != nil {
163+
log.Errorf("while participating for miner f0%d: %+v", id, err)
164+
} else {
165+
alreadyParticipated[id] = struct{}{}
158166
}
159167
}
160168
}

chain/lf3/participation_lease.go

+7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ type leaser struct {
2323
issuer peer.ID
2424
status f3Status
2525
maxLeasableInstances uint64
26+
// Signals that a lease was created and/or updated.
27+
notifyParticipation chan struct{}
2628
}
2729

2830
func newParticipationLeaser(nodeId peer.ID, status f3Status, maxLeasedInstances uint64) *leaser {
2931
return &leaser{
3032
leases: make(map[uint64]api.F3ParticipationLease),
3133
issuer: nodeId,
3234
status: status,
35+
notifyParticipation: make(chan struct{}, 1),
3336
maxLeasableInstances: maxLeasedInstances,
3437
}
3538
}
@@ -99,6 +102,10 @@ func (l *leaser) participate(ticket api.F3ParticipationTicket) (api.F3Participat
99102
return api.F3ParticipationLease{}, api.ErrF3ParticipationTicketStartBeforeExisting
100103
}
101104
l.leases[newLease.MinerID] = newLease
105+
select {
106+
case l.notifyParticipation <- struct{}{}:
107+
default:
108+
}
102109
return newLease, nil
103110
}
104111

0 commit comments

Comments
 (0)