Skip to content

Commit 928eb17

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 928eb17

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

chain/lf3/f3.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,25 @@ 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
152-
}
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-
}
150+
case <-fff.leaser.notifyParticipation:
151+
case mb = <-msgCh: // never closed
152+
clear(alreadyParticipated)
153+
}
154+
155+
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
156+
for _, id := range participants {
157+
if _, ok := alreadyParticipated[id]; ok {
158+
continue
159+
} else if err := participateOnce(ctx, mb, id); err != nil {
160+
log.Errorf("while participating for miner f0%d: %+v", id, err)
161+
} else {
162+
alreadyParticipated[id] = struct{}{}
158163
}
159164
}
160165
}

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)