Skip to content

Commit

Permalink
fix(f3): send the last gpbft message for each new participant
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stebalien committed Oct 10, 2024
1 parent e769bdf commit 928eb17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 15 additions & 10 deletions chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,25 @@ func (fff *F3) runSigningLoop(ctx context.Context) {

msgCh := fff.inner.MessagesToSign()

loop:
var mb *gpbft.MessageBuilder
alreadyParticipated := make(map[uint64]struct{})
for ctx.Err() == nil {
select {
case <-ctx.Done():
return
case mb, ok := <-msgCh:
if !ok {
continue loop
}
participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
for _, id := range participants {
if err := participateOnce(ctx, mb, id); err != nil {
log.Errorf("while participating for miner f0%d: %+v", id, err)
}
case <-fff.leaser.notifyParticipation:
case mb = <-msgCh: // never closed
clear(alreadyParticipated)
}

participants := fff.leaser.getParticipantsByInstance(mb.Payload.Instance)
for _, id := range participants {
if _, ok := alreadyParticipated[id]; ok {
continue
} else if err := participateOnce(ctx, mb, id); err != nil {
log.Errorf("while participating for miner f0%d: %+v", id, err)
} else {
alreadyParticipated[id] = struct{}{}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions chain/lf3/participation_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ type leaser struct {
issuer peer.ID
status f3Status
maxLeasableInstances uint64
// Signals that a lease was created and/or updated.
notifyParticipation chan struct{}
}

func newParticipationLeaser(nodeId peer.ID, status f3Status, maxLeasedInstances uint64) *leaser {
return &leaser{
leases: make(map[uint64]api.F3ParticipationLease),
issuer: nodeId,
status: status,
notifyParticipation: make(chan struct{}, 1),
maxLeasableInstances: maxLeasedInstances,
}
}
Expand Down Expand Up @@ -99,6 +102,10 @@ func (l *leaser) participate(ticket api.F3ParticipationTicket) (api.F3Participat
return api.F3ParticipationLease{}, api.ErrF3ParticipationTicketStartBeforeExisting
}
l.leases[newLease.MinerID] = newLease
select {
case l.notifyParticipation <- struct{}{}:
default:
}
return newLease, nil
}

Expand Down

0 comments on commit 928eb17

Please sign in to comment.